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

zen-id

v0.1.4

Published

generate random strings by pattern, including checksums and validation

Downloads

6

Readme

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:

| Character | Range | Description | | --------- | ----- | ----------- | | n | 0-9 | numeric | | h | 0-9a-f | hex | | a | a-z | lowercase a-z | | A | A-Z | uppercase A-Z | | x | 0-9a-z | numeric or lowercase a-z | | X | 0-9A-Za-z | numeric or a-z any case | | z | A-Za-z | a-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.