Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zen-id

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zen-id

generate random strings by pattern, including checksums and validation

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

zen-id

Generate random strings by pattern, including checksums and validation.

Some notes about this code:

  • Conceptually based on gen-id package by domudall
  • No guarantees of complete uniqueness, but longer patterns should be ok
  • Written for nodejs, but could be adapted to other Javascript environments
  • This is my first published npm package, be nice

Installation

Use npm:

npm install zen-id

Basic Usage

The goal for this code is to be as flexible as possible. There are a number of different ways it can be used. Hopefully the "usage" section will be expanded in the future, but read the (short) code to learn more in the meantime.

var format = 'AAAaaacchhhcc';
var zen_id = require('zen-id').create(format);

var my_id = zen_id.generate();                  // => 'HYKzbk7473e99'
var is_valid = zen_id.validate(my_id);          // => true

Formats

The constructor and most of the fuctions accept a format string composed of characters from the following table:

CharacterRangeDescription
n0-9numeric
h0-9a-fhex
aa-zlowercase a-z
AA-Zuppercase A-Z
x0-9a-znumeric or lowercase a-z
X0-9A-Za-znumeric or a-z any case
zA-Za-za-z any case
c-checksum character

Any non-format character is repeated verbatim in the output.

Validation

The validate(id) method can be used to check if a value matches the format pattern. Can be useful comparing any pattern, but possibly most useful with checksums. See following section.

Checksums

Checksums are character values applied to certain output positions based on the random (pattern) input up to that point. Checksums are also valuable to detect input errors.

Checksums are not infallible, nor is this packages's caluation method so fixed that you could assume previously generated IDs would validate against the same format in the future. At least in the early stages, the calculation method is subject to change.

Checksums are best used to detect a situation where an apparently invalid code was entered based on the format, not as an ultimate test of whether the code was ever issued, or not.

Credits and Notes

zen-id is based on the npm package gen-id by @domudall which mostly worked great for me, but I wanted to make a few tweaks (mostly to add validation). When I delved into the code it didn't work for me stylistically so I decided to publish my own rendition of this functionality, rather than add in code I wrote and try to get a pull request accepted with possibly clashing coding styles. The name was chosen as a take on gen-id but also because it was what I consider one of my "zen" coding projects (something I do to either wind-up or wind-down mentally).

License

Free software under MIT License.

Keywords

FAQs

Package last updated on 25 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc