scuid

WebJar for scuid

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

scuid
Последняя версия

Последняя версия

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

scuid
WebJar for scuid
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/jhermsmeier/node-scuid

Скачать scuid

Имя Файла Размер
scuid-1.1.0.pom
scuid-1.1.0.jar 5 KB
scuid-1.1.0-sources.jar 22 bytes
scuid-1.1.0-javadoc.jar 22 bytes
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/scuid/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>scuid</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/scuid/
implementation 'org.webjars.npm:scuid:1.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/scuid/
implementation ("org.webjars.npm:scuid:1.1.0")
'org.webjars.npm:scuid:jar:1.1.0'
<dependency org="org.webjars.npm" name="scuid" rev="1.1.0">
  <artifact name="scuid" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='scuid', version='1.1.0')
)
libraryDependencies += "org.webjars.npm" % "scuid" % "1.1.0"
[org.webjars.npm/scuid "1.1.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

scuid

npm npm license npm downloads build status

Collision-resistant IDs optimized for horizontal scaling and performance.

A slim, alternative, and compatible implementation of cuid for node, also featuring a wide range of options, as well as custom random number generator support. It can serve as a drop-in replacement, and is also faster than cuid.

Install via npm

$ npm install --save scuid

Usage

var scuid = require( 'scuid' )

Generate an ID

var id = scuid()
> 'ciux3hs0x0000io10cusdm8r2'

Generate a slug

var slug = scuid.slug()
> '6x1i0r0'

Get the process' fingerprint

var fingerprint = scuid.fingerprint()
> 'io10'

Use a custom (P)RNG

// Create a random number generator;
// It has to have a method called `random`
var generator = {
  random: function() {
    return 5 // chosen by fair dice roll
  }
}

// Create a custom scuid instance
var scuid = require( 'scuid' ).create({
  rng: generator
})

Use other custom options

Note that fiddeling with these might make your IDs incompatible with cuid's guarantees.

var scuid = require( 'scuid' ).create({
  prefix: 'c', // the ID's prefix
  base: 36, // radix used in .toString() calls (2-36)
  blockSize: 4, // block size to pad and trim to
  fill: '0', // block padding character
  pid: process.pid, // process ID
  fingerprint: scuid.createFingerprint( [pid], [hostname] ), // Machine fingerprint
  rng: Math, // Random number generator
})

Tests

Just like cuid, collision resistance for both – slugs and IDs – is tested over 1 million and 2 million iterations respectively. To run the tests, run:

$ npm test

Benchmarks

$ npm run compare
NANOBENCH version 2               |    NANOBENCH version 2
> nanobench benchmark/index.js    |    > nanobench benchmark/cuid.js
                                  |
# id  1000000                   <<<   # id  1000000
ok ~1 s (1 s + 439835 ns)        <<<   ok ~4.74 s (4 s + 737960551 ns)
                                  |
# slug  1000000                 <<<   # slug  1000000
ok ~859 ms (0 s + 858990359 ns)  <<<   ok ~2.67 s (2 s + 665230762 ns)
                                  |
# fingerprint  1000000          >>>   # fingerprint  1000000
ok ~1.87 ms (0 s + 1870116 ns)   >>>   ok ~1.57 ms (0 s + 1571116 ns)
                                  |
all benchmarks completed         <<<   all benchmarks completed
ok ~1.86 s (1 s + 861300310 ns)  <<<   ok ~7.4 s (7 s + 404762429 ns)

Версии библиотеки

Версия
1.1.0