npm install --save kriz
For backend environment:
const { core, io, http } = require('kriz');
For front-end environment:
const { core, io, http } = require('kriz/frontend');
const { b64Encode, b64Decode, firstly, isNumeric, uniqid } = core;
const { readFile, readJson, readJsonSync } = io;
const { post, queryString } = http;
Conveniently start the code with a new promise.
firstly(() => {
// do some work or throw
}).then(...).catch(...)
Base64 encode data, supporting UTF-8 characters. Taken from here.
let b64Str = b64Encode(data)
Base64 decode data, supporting UTF-8 characters. Taken from here.
let data = b64Decode(b64Str)
Test if the input is a numeric value. Taken from jQuery.
isNumeric(123.4); // true
isNumeric('123.4'); // true
isNumeric('0xabc'); // true
isNumeric('abc'); // false
isNumeric(Infinity); // false
isNumeric(NaN); // false
isNumeric(null); // false
isNumeric(undefined); // false
Generate a fairly random string like PHP uniqid.
let randomString = uniqid('key-', true);
Promified fs.readFile
readFile(path, options).then(data => { ... })
Promified fs.readFile + JSON.parse
readJson(file, options).then(json => { ... })
Synchronous version of fs.readJson
let json = readJsonSync(path, options);
Promified HTTP post request.
post(url, data).then((response, body) => { ... })
Build query string from key-values.
let body = queryString({key1: value1, key2: value2})