This package has been deprecated

Author message:

this function has been merged into @ayonli/jsext

sequid
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Sequid

A tiny tool to produce sequential numeric IDs.

import sequid from "sequid";
import * as assert from "assert";
 
var seq = sequid();
 
assert.strictEqual(seq.next().value, 1);
assert.strictEqual(seq.next().value, 2);
assert.strictEqual(seq.next().value, 3);
 
var seq2 = sequid(Number.MAX_SAFE_INTEGER - 3);
 
assert.strictEqual(seq2.next().value, Number.MAX_SAFE_INTEGER - 2);
assert.strictEqual(seq2.next().value, Number.MAX_SAFE_INTEGER - 1);
assert.strictEqual(seq2.next().value, Number.MAX_SAFE_INTEGER);
assert.strictEqual(seq2.next().value, undefined);
 
var seq3 = sequid(Number.MAX_SAFE_INTEGER - 3, true);
 
assert.strictEqual(seq3.next().value, Number.MAX_SAFE_INTEGER - 2);
assert.strictEqual(seq3.next().value, Number.MAX_SAFE_INTEGER - 1);
assert.strictEqual(seq3.next().value, Number.MAX_SAFE_INTEGER);
assert.strictEqual(seq3.next().value, Number.MAX_SAFE_INTEGER - 2);
 
console.log("#### OK ####");

API

function sequid(offset?: number, loop?: boolean): IterableIterator<number>

If offset is provided, the sequence will produce the first id started from the next number of the offset. If the id reaches Number.MAX_SAFE_INTEGER, judging by the loop argument, the iterator may restart from the very offset, or break the sequence and quit iterating.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Published

Version History

  • Version
    Downloads (Last 7 Days)
    • Published

Package Sidebar

Install

npm i sequid

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

4.31 kB

Total Files

7

Last publish

Collaborators

  • ayonli