suid-js
v0.12.0
Published
Javascript implementation of Scoped Unique IDs
Downloads
20
Readme
suid-js
Javascript implementation of Scoped Unique IDs
Suids are distributed, Scoped, Unique IDs that are short and sweet.
See the main project for details.
Install
npm install --save suid-js
Require
var Suid = require('suid-js')
Import
import Suid from 'suid-js'
Use
- Create a Suid from a number
- Create a Suid from a string
- Get a Suid's underlying value
- Convert a Suid to a number
- Convert a Suid to a string
- Convert a Suid array to a number array
- Convert a Suid array to a string array
- Convert a number array to a Suid array
- Convert a string array to a Suid array
Create a Suid from a number
var id = new Suid(1903154)
alert(id) // 14she
Create a Suid from a string
var id = new Suid('14she')
alert(id) // 14she
Get a Suid's underlying value
var id = new Suid("14she")
alert(id.value) // 1903154
Convert a Suid to a number
var id = new Suid('14she')
var val = id.toNumber()
alert(val) // 1903154
Convert a Suid to a String
var id = new Suid('14she')
var val = id.toString()
alert(val) // 14she
Convert a Suid array to a number array
var ids = [new Suid(1903154), new Suid(1903155), new Suid(1903156)]
alert(ids) // [14she, 14shf, 14shg]
var vals = Suid.toNumber(ids)
alert(vals) // [1903154, 1903155, 1903156]
Convert a Suid array to a string array
var ids = [new Suid(1903154), new Suid(1903155), new Suid(1903156)]
alert(ids) // [14she, 14shf, 14shg]
var vals = Suid.toString(ids)
alert(vals) // [14she, 14shf, 14shg]
Convert a number array to a Suid array
var vals = [1903154, 1903155, 1903156]
alert(vals) // [1903154, 1903155, 1903156]
var ids = Suid.from(vals)
alert(ids) // [14she, 14shf, 14shg]
Convert a string array to a Suid array
var vals = ['14she', '14shf', '14shg']
alert(vals) // [14she, 14shf, 14shg]
var ids = Suid.from(vals)
alert(ids) // [14she, 14shf, 14shg]
Issues
Bugs, feedback, questions and discussion are welcome on the issue tracker.
Copyright
Copyright (c) 2017 by Stijn de Witt. Some rights reserved.
License
Creative Commons Attribution 4.0 International (CC BY 4.0) https://creativecommons.org/licenses/by/4.0/