suid-js

Suids are Scoped Unique IDs that are short and sweet

2
0
2
2
JavaScript
public

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.

version
license
build status
mind BLOWN

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

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.valueOf()) // 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 © 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/

v0.3.3[beta]