npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

beacon-tool

v1.2.7

Published

Collection of bluetooth beaconing tools.

Downloads

29

Readme

Beacon Tool CircleCI

Collection of bluetooth beacon signal utility functions.

NPM

Features

Beacon Tool allows you to generate, inspect and validate various bluetooth beacon payloads.

Installation

Via NPM:

npm i [-g] beacon-tool

Via Yarn:

yarn [global] add beacon-tool

Usage

Payload generation

beaconTool.generate(format, [pretty])

Generates a payload for the given format.

(string, [boolean]) => string
format string

The format to generate.

Recognized formats:
  • 'ibeacon': Generates an 'iBeacon' UUID.
  • 'altbeacon': Generates an AltBeacon BeaconID.
  • 'eddystoneuid': Generates an Eddystone namespace-instance ID pair.

These strings are exposed as constants in beaconTool.signals.

pretty boolean optional
Default: false

Whether or not to to add dashes to the returned payload string.

See beatify() for further information.

Returns string

A payload string for the given result.

Example

const beaconTool = require('beacon-tool');

const uuid = beaconTool.generate(beaconTool.signals.iBeacon.key);
console.log(uuid);
// de93f975b5d74c9ea8a606fd7cf9d45b

const prettyUUID = beaconTool.generate(beaconTool.signals.iBeacon.key);
console.log(prettyUUID);
// de93f975-b5d7-4c9e-a8a6-06fd7cf9d45b

Payload validation

beaconTool.validate(payload, format)

Validates a signal payload against a given format.

(string, string) => boolean
payload string

The payload to validate.

format string

The format to generate.

See Recognized Formats for information on format specification.

Returns boolean

Whether or not the given payload is valid for the given format.

Example

const beaconTool = require('beacon-tool');

const isValidIBeacon = beaconTool.validate(
  '259771A0-2DFB-4554-B817-2FBFDB5DB1A7',
  beaconTool.signals.iBeacon.key
);

if (isValidIBeacon) {
  console.info('valid');
} else {
  console.info('error');
}

Payload beautifier

beaconTool.beautify(payload, format)

Beautifies, i.e. adds dashes, to a given payload. beautify() returns a new string.

AltBeacon specification does not specify any representation of it's beacon id with dashes, therefore beautifying an AltBeacon payload will not have any effect.

(string, string) => string
payload string

The payload to beatify.

format string

The payload format.

See Recognized Formats for information on format specification.

Returns string

The beatified payload.

Example

const beaconTool = require('beacon-tool');

const beautifiedPayload = beaconTool.beatify(
  'DE93F975B5D74C9EA8A606FD7CF9D45B',
  beaconTool.signals.iBeacon.key
);

console.log(beatifiedPayload);
// DE93F975-B5D7-4C9E-A8A6-06FD7CF9D45B

Payload identification

beaconTool.identify(payload)

Tries to identify a given payload.

(string) => array

Example

const beaconTool = require('beacon-tool');
const candidates = beaconTool.identify('DE93F975-B5D7-4C9E-A8A6-06FD7CF9D45B');

candidates.forEach((candidate) => {
  console.info(`${beaconTool.get(candidate).displayName}`);
});
// iBeacon
payload string

The payload to identify.

Returns array

An array of potential candidates. The returned array contains the keys of potential candiate formats.

Payload information

beaconTool.get(format)

Retrieves information about a given format.

(string) => object
format string

The format to retrieve information for.

See Recognized Formats for information on format specification.

Returns object

A signal information object.

See signals for futher information.

Example

const beaconTool = require('beacon-tool');
console.log(beaconTool.get('ibeacon'));
/**
{
  dashes: [8, 12, 16, 20],
  displayName: 'iBeacon',
  key: 'ibeacon',
  length: 32
}
*/

beaconTool.signals

Beacon signal constants.

const beaconTool = require('beacon-tool');

console.log(beaconTool.signals);
/**
{
  altBeacon: {
    displayName: 'AltBeacon',
    key: 'altbeacon',
    length: 40
  },
  iBeacon: {
    dashes: [8, 12, 16, 20],
    displayName: 'iBeacon',
    key: 'ibeacon',
    length: 32
  },
  eddystoneUid: {
    dashes: [20],
    displayName: 'Eddystone UID',
    instanceId: {
      length: 12
    },
    key: 'eddystoneuid',
    length: 32,
    namespace: {
      length: 20
    }
  }
}
*/

Changelog

License: MIT