kriz
v1.0.6
Published
Utilities for frontend / backend JavaScript development.
Downloads
2
Readme
kriz
Installation
npm install --save kriz
API
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;
core
.firstly
Conveniently start the code with a new promise.
firstly(() => {
// do some work or throw
}).then(...).catch(...)
.b64Encode
Base64 encode data, supporting UTF-8 characters. Taken from here.
let b64Str = b64Encode(data)
.b64Decode
Base64 decode data, supporting UTF-8 characters. Taken from here.
let data = b64Decode(b64Str)
.isNumeric
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
.uniqid(prefix, more_entropy)
Generate a fairly random string like PHP uniqid.
let randomString = uniqid('key-', true);
io
.readFile (for backend only)
Promified fs.readFile
readFile(path, options).then(data => { ... })
.readJson (for backend only)
Promified fs.readFile + JSON.parse
readJson(file, options).then(json => { ... })
.readJsonSync (for backend only)
Synchronous version of fs.readJson
let json = readJsonSync(path, options);
http
.post (for backend only)
Promified HTTP post request.
post(url, data).then((response, body) => { ... })
.queryString
Build query string from key-values.
let body = queryString({key1: value1, key2: value2})