A very strange tool for describing tokens, how to use it's only to you!
npm i --save tokenism
import { createToken } from 'tokenism';
const token = createToken('token', 'Any token', () => Math.random().toString());
token.name(); // "token"
token.caption(); // "Any token"
token.value(); // "0.31454363456"
token.value(); // "0.12476585686"
token.value(); // "0.68209487562"
token.toJSON();
// {
// name: "token",
// caption: "Any token",
// value: "0.68209487562",
// optional: false,
// }
// Shorty
const tok = token.as('tok');
tok.name(); // "tok"
tok.caption(); // "Any token"
// Shorty with caption
const shortyTok = tok.as(null, 'Shorty token');
shortyTok.name(); // "tok"
shortyTok.caption(); // "Shorty token"
import { createToken, composeTokens } from 'tokenism';
const unread = createToken('unread', 'Unread flag', () => Math.random() > .5);
const pinned = createToken('pinnd', 'Pinned flag', () => Math.random() > .5);
const flags = createToken('flags', 'Flags object', composeTokens(
unread,
pinned,
));
flags.value();
// {
// unread: true,
// pinned: false,
// }
flags.toJSON();
// {
// name: "flags",
// caption: "Flags object",
// optional: false,
// value: {
// unread: {name: "unread", ...},
// pinned: {name: "pinned", ...},
// },
// }
- createToken(name:
string
, caption:string
, generator:() => T
):Token
- composeTokens(...tokens:
Token[]
):CompositeTokenValue
Instance method
- as(newName:
string | null
, newCaption?:string | null
, newValue?:T | (() => T)
):Token
- optional(newCaption?:
string | null
, newValue?:T | (() => T)
):Token
- name():
string
- caption():
string
- value():
T
- toJSON():
object
npm i
npm test
, code coverage