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

qinu

v2.0.0

Published

Highly customizable generator of [random] strings

Downloads

2,027

Readme

qinu NPM version Bower version

Highly customizable generator of [random] strings.

Installation

Via NPM

Install the package

$ npm install qinu

require it

const qinu = require('qinu')

Via Bower

Install the package

$ bower install qinu

add script on page

<script src="/bower_components/qinu/qinu.min.js"></script>

as well you can do it with RequireJS or any similar tool.

Usage

Basic usage

// Generates 32-character random string, e.g. '4plugjpebgyqduvwcy7lo74wj4idxu5w'
const randomString = qinu()

Using with options

// Generates 64-character random string
// that contains only hexadecimal numbers,
// e.g. 'df6x4ou3p5tar625301dfuftqd8rh9kxwcjl6t0mtmxke3a9q8wuu3nhvrtrn3na'
const randomString = qinu({
  // The length of output string
  length: 64,
  // The set of characters to be used by qinu
  dict: '1234567890abcdef'
})

Using with template

// Generates string corresponding to template,
// e.g. 'LABEL: hjwjd4hk4cpx7b1ekh9vdmvsnob228bf SUFIX'
const randomString = qinu(
  // Set template for output string
  { template: '%arg[0]%: %qinu% %arg[1]%' },
  // Pass arguments for template
  [ 'LABEL', 'SUFIX' ]
)

%qinu% will be replaced with generated random string. Each passed argument will replace the relative code %arg[<index>]%.

Instead of array you can pass all template arguments as function arguments:

// It works the same as an example above
const randomString = qinu(
  // Set template for output string
  { template: '%arg[0]%: %qinu% %arg[1]%' },
  // Pass arguments for template
  'LABEL',
  'SUFIX'
)

There is another option to pass arguments to the template, via args option:

// Still, the same as examples above
const randomString = qinu({
  template: '%arg[0]%: %qinu% %arg[1]%',
  args: [ 'LABEL', 'SUFIX' ]
})

In case when both described options will be used arguments will be merged: args from the options object will be in the beginning and arguments from the function argument will be in the end:

// Still, no difference
const randomString = qinu(
  {
    template: '%arg[0]%: %qinu% %arg[1]%',
    args: [ 'LABEL' ]
  },
  'SUFIX'
)

Using predefined options

You can create qinu-generator with predefined options:

const qinuCustom = qinu.create({
  template: '%arg[0]%-%arg[1]%-%qinu%'
})

// Generates string corresponding to template,
// e.g. 'group-label-wh0qothao58nk0zno2g86ct4gl3j9wa7'
const randomString = qinuCustom('group', 'label')
// or use it with array
const anotherRandomString = qinuCustom(['group', 'label'])

When using qinu.create() generated results are ordered in a sequence. This behavior can be changed using random option

Shortcut for length property

In case you need to specify only the length:

// Generates 64-character random string
const randomString = qinu(64)

// The shortcut can be applied to create method as well:
const generateRandom10Characters = qinu.create(10)
// Generate 10-character random string
const randomString = generateRandom10Characters()

Generating unique sequence (random option)

In case if absolute uniqueness is required during the session, qinu.create() creates a function that first generate a random value and then iterate it one-by-one. This makes it impossible to generate the same string unless all possible combinations wasn't generated.

const next = qinu.create({ length: 3, dict: 'abc' })
next() // 'abb'
next() // 'abc'
next() // 'aca'

If randomness is preferred pass random: true when create generator:

const generate = qinu.create({ random: true, length: 3, dict: 'abc' })
generate() // 'ccb'
generate() // 'aaa'
generate() // 'baa'

License

MIT © Stanislav Termosa