PICU
PICU is Carbon's [Node] Utilities
Utilities will be added as they are needed.
NPM
npm install picu --save
Arrays
var arrayUtils = array;
.inbetween
Injects a new value inbetween each cell
var a = 1 2 3;var b = arrayUtils;// b -> [1, 'x', 2, 'x', 3]
.shuffle
Shuffles an array
var a = 1 2 3;var b = arrayUtils;// b -> [3, 1, 2]
Functions
var functionUtils = function;
.curry
Creates a new function, based on a target function
var { return a + '.' + b + '.' + c;}; ; // 'x.y.z' var newFunc = functionUtils; ; // 'A.O.K'
.queueUntilReady
Returns a convenient function which will queue all callbacks until some async logic is ready
var resources; // this function must be `done` before any callback for `getNextResource` will be fired { // assume pullS3Resources will pull a lot of resources from S3, and is therefore slow ;} // getNextResource will now be a function that takes a callbackvar getNextResource = functionUtils; // using it; ; // getNextResource can be called before getAllResources is `done`, but callbacks to getNextResource will be queued until getAllResources is `done`// once getAllResources is `done`, any future call to getNextResource will fire immediately
Strings
var stringUtils = string;
.pluralize
Pluralizes a string, based on some input number
stringUtils; // dogstringUtils; // dogsstringUtils; // 'goose'stringUtils; // 'geese'stringUtils; // '0 geese'stringUtils; // 'There were 2 dogs'
.capitalize
Simply capitalizes the first letter of a string
stringUtils; // 'Warren'
.pad
Pads (on the right) a string
stringUtils; // 'hello 'stringUtils; // 'hello~~~~~'
.replace
Replaces text in a template with passed values
stringUtils;// -> 'Tom M. will pick up your car' stringUtils;// -> 'Tom M. will pick up your car' stringUtils;// -> 'You are assigned to pick up Jess\' car'
.hexToRgb
Converts a hex color value to an array of [R, G, B]
stringUtils; // [ 174, 118, 250 ]
.ensureHexColor
Ensures a color string is a 6 character hash color
stringUtils; // -> '#f0f0f0'stringUtils; // -> '#f0f0f0'stringUtils; // -> 'f0f0f0'stringUtils; // -> '#bbaa77'
.hexToInt
Converts a hex string to an integer
stringUtils; // -> 15769510stringUtils; // -> 16711731
.escapeRegExp
Escapes a string so it can be used in new RegExp(str)
var prepared = stringUtils;// prepared = '\\+2 people\\. \\+3 cars'var expr = prepared;
Numbers
var numberUtils = number;
.intToHex
Converts a integer to a hex string
numberUtils; // -> #f09fa6
.random
Gives a random number between a min & max (inclusive) with an optional precision
numberUtils; // -> 64numberUtils; // -> 33numberUtils; // -> 70 numberUtils; // -> 77numberUtils; // -> 49numberUtils; // -> 51 numberUtils; // -> 12.8431
Objects
var objectUtils = object;
.extend
Given an object, update or add keys on another (deeply)
var result = objectUtils;// result = { a: 12, b: 99, z: 404 };// first object is modified