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

@dylanirlbeck/re-nanoid

v0.2.1

Published

A tiny, secure, URL-friendly, unique string ID generator for Reason/OCaml

Downloads

6

Readme

re-nanoid

A tiny, secure, URL-friendly, unique string ID generator for ReasonML/OCaml, inspired by ai/nanoid.

open NanoId

let id = nanoid(); // "V1StGXR8_Z5jdHi6B-myT"W

Why re-nanoid?

Fast. It's 16% faster than UUID package.

Safe. It uses cryptographically strong random APIs and guarantees a proper distribution of symbols.

Compact. It uses a larger alphabet than UUID (A-Za-z0-9_-) and has a similar number of unique IDs in just 21 symbols instead of 36.

See ai/nanoid's excellent documentation for more background about random identifier generation and comparisons with UUID v4.

Installation

BuckleScript

$ yarn add @dylanirlbeck/re-nanoid

Then add @dylanirlbeck/re-nanoid to your bs-dependencies in bsconfig.json

{
   ...
   "bs-dependencies": ["@dylanirlbeck/re-nanoid"]
}

Native

Coming soon...

Usage

As of now, the following examples work for BuckleScript. The Native library will be released soon.

Simple

The main module uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters by default, though this size is variable (see below).

open NanoId;

let id = nanoid(); // "V1StGXR8_Z5jdHi6B-myT"

If you want to reduce the ID size (and increase collision probability), you can pass the size as an argument. You can also increase the ID size (to a maximum of 36).

open NanoId;

let id = nanoid(~size=10, ()); // "1s_t232nj_"

Custom length or alphabet

Likewise, if you want to use a different alphabet, you can use the customAlphabet function. Note that this function also takes a size parameter.

open NanoId;

let alphabet = "#$@jasssfaª•¶";
let size = 7;

let nanoid = customAlphabet(~size, ~alphabet, ());

let id = nanoid(); // "jfa##$·"

Note the use of the () as the last parameter of the function call.

Custom random bytes generator

Note that this function might not work yet.

customRandom allows you to create a nanoid and replace the default random bytes generator.

open NanoId;

let rbg = size: int => {
  // Put generator logic here
};

let nanoid = customRandom(~alphabet="abcdef", ~size=10, rbg, ());

let id = nanoid(); // "fbaefaadeb"

Contributing

Pull requests are welcome!

Testing

BucklesScript - Jest

In order to run the tests as they stand currently, open a new terminal window and run yarn watch to re-compile upon Reason file changes. In yet another window, run yarn test to watch for changes to compiled files and re-run the tests if changes are detected.

Native - Rely

Native tests do not yet exist, but they should be present soon.

License

re-nanoid is MIT licensed.

Other

This library was born out of a project at HackIllinois 2020. See our Devpost submission here!