1.0.6 • Published 7 years ago

kriz v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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

1.0.6

7 years ago

1.0.5-b

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago