chutils
Ever find yourself feeling repetitive, a bit of the coding déjà blues? While your mind may be momentarily suffering from a relapse, your fingers don't have to with these utility function designed to win back some "me" time.
Version
2.0.0
Utility List (thus far)
type
- shouldBe: get the "working" variable type (Thanks to Angus )
const type: shouldBe = typeof null // "object" // "null" typeof // "object" // "array" typeof {}{} // "object"shouldBe {}{} // "promise"
safe
- assign: safely assign deeply-nested properties
const safe: assign = let obj = package: 'chutils' obj = ; /*obj = { package: 'chutils', deeply: { nested: { layer: 'hi' } }} */
- get: safely get deeply-nested properties
const safe: get = const obj = package: 'chutils' deeply: nested: layer: 'hi' // 'hi' // even with different object notations // 'hi' // no more TypeError accessing properties of undefinedobjimaginarylayer // TypeError: Cannot read property 'imaginary' of undefined // undefined
compare
- value: safely compare deeply-nested property value (strict comparision)
const compare: value = const obj = package: 'chutils' deeply: nested: layer: 'hi' // true // even with different object notations // true // no more TypeError accessing properties of undefinedobjimaginarylayer // TypeError: Cannot read property 'imaginary' of undefined // false
- shouldBe: safely compare deeply-nested property value to it's type.shouldBe value
const compare: shouldBe = const obj = package: 'chutils' deeply: nested: layer: 'hi' arr: 123 promiseObj: Promise // true // true
async
- dePromisify: unwraps an ES6 Promise to its nostalgic error-first callback form
const async: dePromisify = const bluebird = const fs = const readFileAsync = bluebirdconst readFileCB =
- dePromisifyAll: iterates through an object's enumerable properties and dePromisifies the functions
const async: dePromisifyAll = const bluebird = let fs = bluebirdfs = fs
- promisify: wraps an error-first callback function into an ES6 Promise
const async: promisify = const fs = const readFileAsync =
- promisifyAll: iterates through an object's enumerable properties and promisifies the functions
const async: promisifyAll = const fs = fs
Installation
Native ES6 Promises is required therefore Node v4.2.4+
$ npm i chutils
Testing
$ npm i chutils$ cd ./node_modules/chutils$ npm i$ npm run test
License
MIT