kriz

1.0.6 • Public • Published

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})

License

MIT

Package Sidebar

Install

npm i kriz

Weekly Downloads

0

Version

1.0.6

License

MIT

Last publish

Collaborators

  • krizpoon