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

record-locator

v1.0.5

Published

A record locator is short, easy to read and pronounceable string. This module encodes integers into record locator strings and can decode them back into integers.

Downloads

608

Readme

record-locator Build Status

A Node.js module that encodes integers into a short, easy to read and pronounceable string.

What is a 'Record Locator'?

A record locator is an alphanumeric string that represents an integer.

A record locator can be used to provide a human-readable representation of a database primary key, providing users with a short, easy-to-read and pronounceable string. Record locators can be useful when you need to generate a document reference, confirmation number, reservation number or a booking reference to share with your users.

DKHR uses record locators to provide Taxfox customers with an easy way to reference PDF documents associated to them.

Examples

  • The integer 8128 encodes to the record locator 9Y2
  • The integer 3141592 encodes to the record locator 4ZVYR
  • The integer 355688197484 encodes to the record locator DEADBEEF

You can encode more than 33.5 million integers in a five-character record locator: the largest five-character record locator, ZZZZZ, represents the integer 33554431.

For more information, see Wikipedia's record locator article.

Installation

Use Node.js's default package manager (npm) to install the record-locator module into your project:

npm install --save record-locator

Usage

Encoding an integer into a record locator string:

var recordLocator = require('record-locator');
var documentId = 3141592;
var documentReference = recordLocator.encode(documentId);

// console.log output: 4ZVYR
console.log(documentReference);

Decoding a record locator string back into an integer:

var recordLocator = require('record-locator');
var documentReference = '4ZVYR';
var documentId = recordLocator.decode(documentReference);

// console.log output: 3141592
console.log(documentId);

Error Handling

The record-locator module will throw an exception error under the following circumstances:

  • encode() or decode() is called with no argument
  • encode() or decode() is called with an empty value
  • encode() is called with a value that is not number
  • encode() is called with a value that is not a positive integer

You can use a standard try/catch block to handle these error scenarios:

var recordLocator = require('record-locator');
var invalidDocumentId = -12345;
var documentReference;

try {
	documentReference = recordLocator.encode(invalidDocumentId);
} catch (e) {
	// console.log output: [Error: Argument is not a positive integer]
	console.log(e);
}

For more information on error handling, see Joyent's reference: Error Handling in Node.js

Character Canonicalization

Certain characters, such as the letters "B" and "S", as well as the numbers 0 (zero) and 1 (one), are not used in record locators as there is the potential for confusion with other characters.

These specific characters are automatically replaced by encode() and decode() as follows:

| Character | Replacement Letter | |-----------|-----------------------| | B | P | | S | F | | 0 | O | | 1 | I |

Related Libraries

The following third-party libraries provide alternative implementations that can also be used to encode and decode record locators: