Option 1, npm:
npm install z-core and then
var Z = require('z-core');
Option 2, bower:
bower install z-core
Option 3, download it manually from the
dist folder of this repo.
If you care about shaving off some bytes and you only target ES6-compatible environments, then you can use
z-core-es6.js. It assumes that there is a native promise-implementation, as provided by ES6. The standard Z implementation comes with a small polyfill though.
Minimified (not gziped) the code is about 10k for the standard version, compatibile with all environments, and about 4k for the ES6-version.
bindSync to create promise-friendly functions from sync functions.
var pmin = ZbindSyncMathmin;// It can still be called with regular valuespmin10 5thenconsole.logminValue; // 5;// But is can also be called with promisesvar promise = returnsTheValue2AsPromise;pminpromise 5thenconsole.logminValue; // 2;
bindAsync to create promise-friendly functions from async functions.
var postPromisedJSON = ZbindAsyncpostJSON;var agePromise = returnsTheValue28AsPromise;// Note that it's called with a mix of regular values an promisespostPromisedJSON'/people' name: 'Jakob' age: agePromise thenconsole.logres; // the result of the request;
Extend the promises returned by Z using mixins.
Zmixinreturn thisvalueprop;return thisvaluetoLowerCase;if n == nulln = 1;return thisvalueslice0 n;console.logthisvalue;;var getPromisedJSON = ZbindAsyncgetJSON;var firstThreeInName = getPromisedJSON'/cookies/123'get'name'toLowerCasefirst3;firstThreeInName.log;
There are several mixin packages available for your convenience:
And even bundles where certain set of mixins have already been applied: