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

id-generators

v1.0.6

Published

id-generators is small JavaScript library to generate ID with awesome Unique ID libraries.

Downloads

20

Readme

id-generators

NPM Version LICENSE Build Status code style: prettier

id-generators is small JavaScript library to generate ID with awesome Unique ID libraries.

Installation

npm install id-generators

Usages

const generators = require("id-generators");
const generator = generators.get("nanoid");
const generate = generator();

console.log("ID: " + generate());
// ID: gCa0wL_8ElTje5cwOci1d
console.log("ID: " + generate());
// ID: 5C_YAjgQl4iM3zK-TValY
console.log("ID: " + generate());
// ID: gQOOwCoQyfCuGK7fgINLd

If you want to customize ID, you can pass an option as an argument to the generator function.

const generators = require("id-generators");
const generator = generators.get("nanoid-simple");
const generate = generator({ size: 25 });

console.log("ID: " + generate());
// ID: oa9wj0kfm50gv2qse8l5xup0u
console.log("ID: " + generate());
// ID: xn5ff5odiylg4jehhhp9vtlxv
console.log("ID: " + generate());
// ID: dff7ay5x38k1pkc2pxjv7elky

| generator type | ID length | character set | options/default | description | | ------------------------------------------- | --------- | ------------------------ | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | cuid (default) | 25 | a-z0-9, start with c | | use cuid() generated string. e.g. ck2bi7fxf00013ryng5jr1rer | | cuid-slug | 7-10 | a-z0-9 | | use cuid.slug() generated string. e.g. xh23npi | | nanoid /nanoid-good | 21 | A-Za-z0-9_- | size/21 | use nanoid() or nanoid-good generated string. e.g. EwUTt2eoka-oEV5kf-o0O | | nanoid-simple /nanoid-simple-good | 24 | a-z0-9 | size/24 | use nanoid/generate or nanoid-good/generate generated string. e.g. pfldm3gg8h9psydphotqe71d | | nanoid-lowercase /nanoid-lowercase-good | 26 | a-z | size/26 | use nanoid/generate or nanoid-good/generate generated string. e.g. jsjxoibprplrdoitjmppotjrnm |

If use nanoid-good or nanoid-xxx-good, you should install nanoid-good manually.

npm install nanoid-good

Define Custom Generators

This sample shows how to register a generator function. The generator function should return a function that returns a ID.

const { register } = require("id-generators");

register("my_custom_id", function (option) {
  option = option || {};
  let size = option.size || 8;
  let prefix = option.prefix || "items-";
  return function (title) {
    return (
      prefix + title.toLowerCase().replace(/[^\w]/g, "").substring(0, size)
    );
  };
});
const generators = require("id-generators");
const generator = generators.get("my_custom_id");
const generate = generator({ size: 6 });

console.log("ID: " + generate("Hello World!"));
// ID: items-hellow
console.log("ID: " + generate("Foo Bar!"));
// ID: items-foobar

Related

  • Awesome Unique ID - A curated list of awesome Unique ID libraries and resources.
  • cuid - Collision-resistant ids optimized for horizontal scaling and binary search lookup performance.
  • nanoid - A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
  • nanoid-good - Guarantees you will not get any obscene words or other profanity in your ids generated by Nano ID.

License

Copyright (c) 2019 dailyrandomphoto. Licensed under the MIT license.