web-id
Convert strings into web-usable ids.
Usage
$ npm install web-id
const WebId = ;const myId = '1. This café is _so_ cliché!';
Getters / Setters
These are only available on an instantiated class.
.original
- The original, unaltered string.
.safe
- Get the web safe id.
myIdsafe; // this-cafe-is-so-cliche
.delimiter
or .delim
- Get or set the current delimiter. Default is -
.
Note that only unreserved characters are allowed: ALPHA / DIGIT / '-' / '.' / '_' / '~'.
myIddelimiter // -myIddelimiter = '_'; // set the delimiter to _myIdsafe; // now equal to 'this_cafe_is_so_cliche'myIddelimiter = '&'; // assertion error
.iterated
or .iter
- Get the iterated id (see the .iterate()
method).
myIditerated // this-cafe-is-so-cliche-1
.unique
- Get the web safe id with a 12-digit hex attached to the end. Note that this is not guaranteed to be unique.
myIdunique // this-cafe-is-so-cliche-f065aa5a683c
Methods
.iterate()
- iterate the id. Retrieve the iterated id with the .iterated
or .iter
getters. Chainable.
myIditerated // this-cafe-is-so-cliche-1myIditer // this-cafe-is-so-cliche-1
.safeUnique(str)
(static) - Same as the .unique
getter, but static. Will always use the default delimiter (-
).
WebId; // this-cafe-is-so-cliche-f065aa5a683c
.webSafe(str)
(static) - Same as the .safe
getter, but static. Will always use the default delimiter (-
).
WebId; // this-cafe-is-so-cliche
.randomHex(len)
(static) - Returns a random hex number of length len
.
WebId; // 5c11525465451802758a534e