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

custom-unique

v1.0.6

Published

Generate custom and random unique strings

Downloads

19

Readme

custom-unique

Generate custom and random unique strings.

npm install --save custom-unique

Examples

var customUnique = require('custom-unique');

var gen = customUnique.compile({n: '1n4n68dma98560d', a: '1234567890'}, '((n))-((a))-((n))-((a))');
gen(); // 08nmd5mn5a6141d-2335291955-6068n84a989n0a5-4633515073
gen(); // dnm85966885n60n-3751472625-4mdnd8606081854-5222094747

var serialGen = customUnique.compile({c: '1234567890', b: 'abcedfgh'}, '((c)4)-((b)4)-((c)4)-((b)4)');
serialGen(); // 4830-heea-0194-gfeg
serialGen(); // 5593-chcg-3889-ccch

API

function compile(config, format)

Creates a function that returns random strings.

Return value: function ([prefix][, suffix])

  • config (Object) An object containing all values that will replace the corresponding placeholders in format.
  • format (String) An string containing placeholders that will be replaced by random values composed by config.

Explanation

The keys of config can be referenced in format. Those references will be replaced by a random string composed of chars from the value of that key.

To reference a property from config, use the following syntax in format: ((property)).

This reference will be replaced by a random value composed of chars from config[property] , and it will have the length equal to config[property].

var config = {ex: '123'};
var format = '--((ex))--';

var gen = customUnique.compile(config, format);
gen(); // --231--
gen(); // --312--

You can define the length yourself using this syntax: ((property)length).

var config = {ex: '123'};
var format = '--((ex)10)--';

var gen = customUnique.compile(config, format);
gen(); // --1132222311--
gen(); // --1312313113--

You may add prefixes and suffixes to the generated strings.

var config = {ex: '123'};
var format = '--((ex)10)--';

var gen = customUnique.compile(config, format);
gen('ID-'); // ID---2212122311--
gen('', 'HI'); // --1312313113--HI
gen('PHOTO', 'HI'); // PHOTO--1312313113--HI