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

@sibevin/random-token

v2.0.3

Published

A simple way to generate a random token.

Downloads

353

Readme

Random Token

doccument npm version github coverage

A simple way to generate a random token.

Usage

Import package first

import * as RandomToken from '@sibevin/random-token'

Use gen to create a random token with a given length.

RandomToken.gen({ length: 32 })
// JxpwdIA37LlHan4otl55PZYyyZrEdsQT

Some options can help to modify the token format.

RandomToken.gen({ length: 32, seed: 'alphabet', casing: 'upper', mask: 'ABC', friendly: true })
// AHMSJZPTDQMBEHQBXEEXPDQRHRKDNJST

Or just simplify as:

RandomToken.gen({ length: 32, seed: 'a', casing: 'u', mask: 'ABC', friendly: true })
// DNJERZGWGJQTFYGYWGHAZEBGBRQFPHPF

Options

Seed

Use seed option to customize the random characters. Here are available options:

Use 'a' (or 'alphabet', 'l', 'letter') to create a token with alphabets.

RandomToken.gen({ length: 32, seed: 'a' })
// NbbtqjmHWJGdibjoesgomGHulEJKnwcI

Use 'n' (or 'number', 10, 1) to create a token with numbers.

RandomToken.gen({ length: 32, seed: 'n' })
// 33541506785847193366752025692500

Use 'b' (or 'binary', 2) to create a binary token.

RandomToken.gen({ length: 32, seed: 'b' })
// 11100101111000011100111111001100

Use 'o' (or 'octal', 'oct', 8) to create a octal token.

RandomToken.gen({ length: 32, seed: 'o' })
// 76032641643460774414624667410327

Use 'h' (or 'hexadecimal', 'hex', 16) to create a hexadecimal token.

RandomToken.gen({ length: 32, seed: 'h' })
// 07dc6320bf1c03811df7339dbf2c82c3

Use a string to customize random seeds.

RandomToken.gen({ length: 32, seed: 'abc' })
// bcabcbbcaaabcccabaabcacbcbbabbac

Casing

Use casing option to modify the token case. Here are available options:

Use 'u' (or 'upper') to create an uppercase token.

RandomToken.gen({ length: 32, casing: 'u' })
// 9PO37CS829XBTOJ1FYWBIV51H8JZSR19

Use 'l' (or 'lower') to create a lowercase token.

RandomToken.gen({ length: 32, casing: 'l' })
// wijjn2hl9dsy6os5yuyshbdlr9n5nlwu

Use 'm' (or 'mixed') to create a mixed-case token. It is the default option for alphabet and random-generated seeds. Note that the mixed-casing is not supported with customized seeds.

RandomToken.gen({ length: 32, seed: 'abc', casing: 'm' })
// Error: Invalid Parameters: casing. The mixed casing is not supported with customized seeds.

Casing is not supported with following seed options: 'number', 'binary', 'octal'.

RandomToken.genf({ length: 32, seed: 'number', casing: 'l' })
// Error: Invalid Parameters: casing. The casing is not supported with number seeds

Mask

Use mask option to filter characters which you don't want to appear on the generated token.

RandomToken.gen({ length: 32, mask: '123abcABC' })
// vhZp88dKzRZGxfQHqfx7DOL8jKTkWUuO

Friendly

Use friendly option to remove the ambiguous characters, the default mask includes 1, I, l, i, 0, O, o, Q, D, C, c, G, 9, 6, U, u, V, v, E, F, M, N, 8, B.

RandomToken.gen({ length: 32, friendly: true })
// hTTSgXdHzy5wkymnd3qjR44LXLp43qrY

The default friendly option is false. There is a convenient method genf using friendly: true by default.

RandomToken.genf({ length: 32 })
// aTjkzhnZm75zZPt45nT3jHgnrmRmzbkY

Note that the friendly option is supported with alphabet or random-generated seeds (no 'seed' is given) only.

RandomToken.genf({ length: 32, seed: 'abc' })
// Error: Invalid Parameters: friendly. The friendly mask is supported with alphabet or random-generated seeds (no "seed" is given) only.

Test

npm run test

Support

Support the continuous development of the project with concrete actions. Any form of help means a lot to us.

ko-fi

Authors

Kait Wang

Copyright

Copyright (c) 2019-2024 Kait Wang. Released under the MIT license.