unique-integer
v1.0.0
Published
Generate a unique integer
Downloads
338
Maintainers
Readme
Functions
const id = uniqueInteger()
const ceiling = 1000 const floor = 0 const id = avoidClashes({ ceiling, floor }) assert(id > ceiling) assert(id < floor)
uniqueInteger() ⇒ number
Generate a unique integer - default exported function
import uniqueInteger from 'unique-integer'
const id = uniqueInteger()
Kind: global function
Returns: number - A unique integer
avoidClashes(options) ⇒ number
Generate a unique integer avoiding a particular range
import assert from 'assert'
import { avoidClashes } from 'unique-integer'
const ceiling = 1000
const floor = 0
const id = avoidClashes({ ceiling, floor })
assert(id > ceiling)
assert(id < floor)
Kind: global function
Returns: number - A unique integer
| Param | Type | Description | | --- | --- | --- | | options | Object | | | options.ceiling | number | lower bound of the range to avoid | | options.floor | number | upper bound of the range to avoid |