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

cdkey

v2.0.2

Published

Generate random strings by template.

Downloads

11

Readme

node-cdkey

Build Status Coverage Status

Generate random string by template.

Installation

npm i cdkey

Basic Usage

Browser

<script src="https://unpkg.com/cdkey/dist/cdkey.min.js"></script>
<script>
  console.log(cdkey.default()) // eC8q-8ERg-fTZa-Vh2o
</script>

Node.js

import cdkey from 'cdkey' // esm

const cdkey = require('cdkey/lib').default // cjs

console.log(cdkey()) // eC8q-8ERg-fTZa-Vh2o

Advenced Usage

Simple amount

Generate string by default template (diablo style).

cdkey([Number amount])
cdkey() // eC8q-8ERg-fTZa-Vh2o
cdkey(2) // [ 'kcsi-V5xR-1xv8-zq7q', 'cumh-jYVn-5vL9-mwLM' ]

Template

Generate string by custom template.

cdkey(String template, [Number amount], [Object syntax])

| syntax | chars for random | exclude non-readable chars | | ------ | --------------------- | -------------------------- | | 0 | [0-9] | [01] | | A | [A-Z] | [OI] | | a | [a-z] | [l] | | X | [0-9] + [A-Z] | [01OI] | | x | [0-9] + [a-z] | [01l] | | ? | [0-9] + [A-Z] + [a-z] | [01OIl] |

cdkey('XXXX') // 7F3K
cdkey('????', 2) // [ 'cUwc', 'n9zu' ]

cdkey('AAAA', { A: 'AB' }) // ABBA
cdkey('cccc', 2, { c: 'ABC' }) // [ 'BCAA', 'ACAB' ]

Options

Generate string by custom or builtin options.

cdkey(Object options, [Number amount, [String template | Number length]])
  • The 2ed argument would override options.amount
  • The 3rd argument would override options.template or options.length, depand on style.

| attribute | type | default | | ---------------- | ------ | ------- | | options.char | string | | | options.length | number | | | options.template | string | | | options.syntax | object | | | options.amount | number | 1 |

char + length (custom)

cdkey({
  char: 'abc',
  length: 4
})
// acab

cdkey({
  char: 'abc',
  length: 4,
  amount: 2
}, 1, 3)
// aca

template + syntax (custom)

cdkey({
  template: 'aaaa',
  syntax: {
    a: '012'
  },
  amount: 2
})
// [ "1220", "2001" ]

cdkey({
  template: '0000',
  syntax: {
    a: '012'
  },
  amount: 5
}, 2, 'aaaa')
// [ "1220", "2001" ]

char + length (builtin options)

| key | char | length | | ------------------- | ------------- | ------ | | ALPHANUMERIC | [0-9 a-z A-Z] | 32 | | ALPHABETIC | [a-z A-Z] | 32 | | NUMBER, NUMERIC | [0-9] | 32 | | UPPER | [A-Z] | 32 | | LOWER | [a-z] | 32 | | HEX | [0-9 A-F] | 32 |

import { cdkey, NUMBER } from 'cdkey'

cdkey(NUMBER) // 22030189956236488846744098007707
cdkey(NUMBER, 2, 8) // [ '05250373', '42852368' ]

template + syntax (builtin options)

| key | template | | --------- | --------------------- | | DEFAULT | '????-????-????-????' | | DIABLO | 'XXXX-XXXX-XXXX-XXXX' |

import { cdkey, DIABLO } from 'cdkey'

cdkey(DIABLO, 2) // [ '2F2L-HJTG-P4L6-QBTZ', 'F1XM-K9JZ-ED9L-EPL9' ]

Fluent (chain methods)

Generate string by custom options and chain methods.

import { create } from 'cdkey'

create()
  .char(String chars)
  .length(Number length)
  .template(String template)
  .syntax(Object syntax)
  .amount(Number amount)
  .gen()
create()
  .char('012')
  .length(8)
  .gen()
// 01201002

create()
  .template('AAAA')
  .syntax({ A: 'ABC' })
  .amount(2)
  .gen()
// [ 'BCAA', 'ACAB' ]

Helper methods

import { syntax } from 'cdkey'
syntax() // To get default syntax object.
// {
//   '0': '23456789',
//   'A': 'ABCDEFGHJKLMNPQRSTUVWXYZ',
//   'a': 'abcdefghijkmnopqrstuvwxyz',
//   'X': '23456789ABCDEFGHJKLMNPQRSTUVWXYZ',
//   'x': '23456789abcdefghijkmnopqrstuvwxyz',
//   '?': '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
// }

TODO

  • escape string in template.
  • command line support.
  • ~~browser support.~~

License

MIT