JSPM

maxuniqid

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q36600F
  • License ISC

Make counter functions that deliver, one-by-one, all available integers: 0, 1, …, MAX_INT, -1, -2, …, MIN_INT, then throw a RangeError. AMD/UMD package.

Package Exports

  • maxuniqid

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (maxuniqid) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

maxuniqid

Make counter functions that deliver, one-by-one, all available integers: 0, 1, …, MAX_INT, -1, -2, …, MIN_INT, then throw a RangeError. AMD/UMD package.

Usage

From test/usage.js:

var ids, makeIdCounter = require('maxuniqid'), nextId = makeIdCounter(),
  MAX_ID = Number.MAX_SAFE_INTEGER + 1,
  MIN_ID = Number.MIN_SAFE_INTEGER - 1;

ids = [ nextId(), nextId(), nextId() ];
equal(ids, [ 0, 1, 2 ]);

nextId.reset(0);
ids = [ nextId(), nextId(), nextId() ];
equal(ids, [ 0, 1, 2 ]);

nextId.reset(42);
ids = [ nextId(), nextId(), nextId() ];
equal(ids, [ 42, 43, 44 ]);

nextId.reset(-23);
ids = [ nextId(), nextId(), nextId() ];
equal(ids, [ -23, -24, -25 ]);

// Make sure our MAX_ID really touches the limit:
equal(MAX_ID, MAX_ID + 1);

nextId.reset(Number.MAX_SAFE_INTEGER - 1);
ids = [ nextId(), nextId(), nextId(), nextId(), nextId() ];
equal(ids, [ 9007199254740990,
             9007199254740991,
             9007199254740992,
             -1, -2 ]);

// Make sure our MIN_ID really touches the limit:
equal(MIN_ID, MIN_ID - 1);

nextId.reset(Number.MIN_SAFE_INTEGER + 1);
ids = [ nextId(), nextId(), nextId() ];
equal(ids, [ -9007199254740990,
             -9007199254740991,
             -9007199254740992 ]);

try {
  ids = 'still alive';
  nextId();
} catch (err) {
  ids = String(err).substr(0, 12);
}
equal(ids, 'RangeError: ');

License

ISC