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

@telemok/unique-var-name

v0.0.1

Published

JS unique short var names generator without collisions

Downloads

1

Readme

unique-var-name (beta version)

JS unique short var names generator without collisions

Features

  • Shortest names.
  • First symbol not digit. URL and name-friendly: No special characters.
  • Not random names.
  • ([a-zA-Z_][0-9a-zA-Z_]*) name format.
  • Counter: "a", "b", ..., "z", "A", ..., "Z", "_", "a0", "a1", ..., "a_", "b0", ... "__", "a00", ...
  • Can be used as variable names, class names, id, and other.
  • Like a num.toString(radix), but radix increased from 36 to 63 and first symbol not digit.
  • No dependencies. No network connection.
  • Different counter for each key/prefix.
  • Fast: 210-240M calls / second (Ryzen 5500U).

Examples:

Available in folder /examples/

1. Show how to generate var names

import {nextUniqueVarName} from "@telemok/unique-var-name.js"

let m = new Set();
for (let i = 0; i < 7370; i++) {
	let s = nextUniqueVarName();
	console.log(i, s);
	if (m.has(s))
		throw(new Error(s))
	m.add(s);
}
/* output:
0 a
1 b
2 c
...
49 X
50 Y
51 Z
52 _
53 a0
54 a1
55 a2
...
3388 _X
3389 _Y
3390 _Z
3391 __
3392 a00
3393 a01
3394 a02
...
7357 a_X
7358 a_Y
7359 a_Z
7360 a__
7361 b00
7362 b01
7363 b02
...
*/

2. Show how to generate strings with prefix

import {nextUniqueString} from "@telemok/unique-var-name.js"

for (let i = 0; i < 7370; i++) {
	let s = nextUniqueString("prefix_");
	let sA1 = nextUniqueString("_");
	let sA2 = nextUniqueString("_");
	console.log(i, s, sA1, sA2);
}
/* output:
0 prefix_0 _0 _1
1 prefix_1 _2 _3
2 prefix_2 _4 _5
...
29 prefix_t _W _X
30 prefix_u _Y _Z
31 prefix_v __ _10
32 prefix_w _11 _12
33 prefix_x _13 _14

//new size begin on symbol "1", skip "0"
*/

Source code:

https://npmjs.com/@telemok/unique-var-name

Installation:

  1. Create your NodeJs, Browser or Webview app.
  2. Run: npm import @telemok/unique-var-name
  3. Code: import { nextUniqueVarName } from '@telemok/unique-var-name';
  4. Code: var nextName = nextUniqueVarName();

Functions:

/* Different counter for each key.
240M calls / second (Ryzen 5500U).
return unique shortest string with first symbol not digit
*/
nextUniqueVarName(key);

/* Different counter for each prefix.
210M calls / second (Ryzen 5500U).
return prefix + unique shortest string
*/
nextUniqueString(prefix);

/*Return one random char from string*/
getRandomCharOfString(str);

Tests:

Test1.Generate 30000000 unique names

ok

Another libs another authors:

Warning, table has many mistakes!

Url | Lng | Resultlength | Collis | Can bevar name | # | Regex| Comment --- | --- | -------------- | ------ | ------------------ |---| ---- | ------ https://npmjs.com/package/@telemok/unique-var-name nextUniqueVarName (key) | JS | short | auto | yes | n | [a-zA-Z_][a-zA-Z0-9_]* | this https://npmjs.com/package/@telemok/unique-var-name nextUniqueString (prefix) | JS | short | auto | no | n | [a-zA-Z0-9_]* | this .toString(radix) | JS | short | manual | no | - | [0-9a-z]* | https://npmjs.com/package/@gorebel/css-class-generator | JS | short | manual | no | | [-a-zA-Z]+ | https://npmjs.com/package/scopeid | JS | short | auto | no | n | [0-9] | https://npmjs.com/package/element-id-generator | JS | short | auto | no | 1 | [0-9a-z] | https://npmjs.com/package/nanoid | JS | 21 | chance | no | | [A-Za-z0-9_-]{21} | fast?popular https://npmjs.com/package/identifier | JS | fix | chance | no | | [a-zA-Z0-9_]{n} | https://npmjs.com/package/node-random-name | JS | no | chance | no | | humannames | https://npmjs.com/package/unique-names-generator | JS | no | chance | no | | goodsnames | https://npmjs.com/package/project-name-generator | JS | no | chance | no | | projectnames | https://npmjs.com/package/unique-string | JS | 32 | chance | no | | [a-z0-9]{32} | 14M dl https://npmjs.com/package/@paralleldrive/cuid2 | JS | 24 | chance | no | | [a-z0-9]{24} | https://npmjs.com/package/randomstring | JS | ? | chance | ? | | [a-z0-9]+ | https://npmjs.com/package/random-ext | JS | ? | chance | ? | | [a-z0-9]+ | https://npmjs.com/package/hat | JS | 32 | chance | no | | [a-z0-9]{32} | https://npmjs.com/package/randomized-string | JS | no | chance | no | | [a-z0-9A-Z] | https://npmjs.com/package/meaningful-string | JS | fix | chance | no | | [A-Za-z0-9] | https://npmjs.com/package/generate-unique-id | JS | fix | chance | no | | [custom]{n} | 6K dl https://npmjs.com/package/unique-slug | JS | fix | | no | | [0-9A-H]{4} | 19M dl https://npmjs.com/package/puid-js | JS | fix | | * | | [custom]{n} | https://npmjs.com/package/random-string-gen | JS | fix | | * | | [0-9a-zA-Z]{n} | https://npmjs.com/package/lite-id | JS | fix | | no | | [0-9a-zA-Z_] | https://npmjs.com/package/random-web-token | JS | fix | | no | | [0-9a-zA-Z]{n} | https://npmjs.com/package/uniqider | JS | 16 | | no | | [0-9a-zA-Z]{16} |