cint.min.js
5.87 KB
/** A Javascript utility belt with an emphasis on Functional Programming.
@module cint
@author Raine Lourie
@version v8.2.1 (Fri, 13 Feb 2015 20:24:14 GMT)
*/
cint=function(){"use strict";function n(n,r){return n.replace(/{([^{}]*)}/g,function(n,t){return t in r?r[t]:n})}function r(n,r){return 0===n.indexOf(r)&&""!==r}function t(n,r){return n.split(r)[0]}function e(n,r){var t=n.indexOf(r);return t>=0?n.substring(t+r.length):n}function u(n,r,u){return t(e(n,r),u)}function o(n,r,t){return(r||"")+n+(t||r||"")}function i(n,r,t){return t=t||"",c(r,function(){return n}).join(t)}function a(n){var r=function(n){return n.length?n[0].toUpperCase()+n.substring(1).toLowerCase():""};return n.split(" ").map(r).join(" ")}function f(n){var r=n%10;return n+(n>=11&&13>=n?"th":1===r?"st":2===r?"nd":3===r?"rd":"th")}function c(n,r){for(var t=[],e=0;n>e;e++)t.push(r(e));return t}function l(n,r){return n+r}function p(){return arguments.length?Array.prototype.reduce.call(arguments,l):0}function s(n,r){if(!r)throw new Error("You must specific a property name or mappable function.");for(var t="function"==typeof r?r:function(n){return n[r]},e=[],u={},o=n.length,i=0;o>i;i++){var a=t(n[i]);a in u||(u[a]=[],e.push({key:a,items:u[a]})),u[a].push(n[i])}return e}function y(n){for(var r={},t=n.length,e=0;t>e;e++){var u=r[n[e]]||0;r[n[e]]=u+1}return r}function v(n){for(var r={},t=0;t<n.length;t++){var e=n[t];for(var u in e){var o=e[u];r[o]||(r[o]={}),r[o][u]=(r[o][u]||0)+1}}return r}function h(n,r){return void 0===r||null===r?n[0]:(r%n.length+n.length)%n.length}function g(n,r){return n[h(n,r)]}function m(n,r){for(var t=[],e=n.length,u=0;e>u;u++)t.push(g(n,u+r));return t}function d(n,r){for(var t=[],e=n.length,u=0;e>u;u++)t.push(r(n[u],u));return x.apply(n,t)}function b(n,r,t){for(var e=Array.prototype.slice.apply(arguments,[3]),u=e.length,o=[],i=n.length,a=0;r>a&&i>a;a++)o.push(n[a]);for(a=0;u>a;a++)o.push(e[a]);for(a=r+t;i>a;a++)o.push(n[a]);return o}function j(n,r){for(var t=n.length,e=[],u=0;t>u;){var o=Math.ceil((t-u)/r--);e.push(n.slice(u,u+=o))}return e}function A(n,r){var t={};return t[n]=r,t}function w(n,r){return n[r]}function O(n,r,t){return n[r]=t,n}function k(n,r,t){return function(e){return O(e,t||r,n(e[r]))}}function C(n,r,t){var e=[];for(var u in n)e.push(u+t+n[u]);return e.join(r)}function x(){for(var n={},r=arguments.length,t=0;r>t;t++){var e=arguments[t];for(var u in e)"object"!==F(e[u])||e[u].constructor!==Object||null===e[u]||e[u]instanceof Array?void 0!==e[u]&&(n[u]=e[u]):n[u]=x(n[u],e[u])}return n}function _(n,r){var t={};for(var e in n){var u=r(e,n[e]);for(var o in u)t[o]=u[o]}return t}function V(n,r){r=r||function(n,r){return{key:n,value:r}};var t=[];for(var e in n)t.push(r(e,n[e]));return t}function E(n,r){var t={};for(var e in n)r(e,n[e])&&(t[e]=n[e]);return t}function S(n,r){var t={};for(var e in n)t[e in r?r[e]:e]=n[e];return t}function T(n,r){return n(r),r}function L(n){return console.log(n),n}function K(n){return function(){return!n.apply(this,arguments)}}function M(n,r,t){return function(){var e=Array.prototype.slice.call(arguments);0>r&&(r=h(e,r)+1);var u=[e,r,0].concat(t),o=b.apply(this,u);return n.apply(this,o)}}function P(n,r){return function(){var t=Array.prototype.slice.call(arguments,0,r);return n.apply(this,t)}}function U(n){return"function"==typeof n?U(n()):n}function q(n,r){var t=this;return r=r||console.log.bind(console),function(){var e=Array.prototype.slice.call(arguments),u=n.apply(t,e);return r.call(t,n,e,u),u}}function z(n){return function(r){var t=Array.prototype.slice.call(arguments,1);return n.apply(r,t)}}function G(n){return function(){var r=this,t=Array.prototype.slice.call(arguments),e=Q(t);setTimeout(function(){try{var u=n.apply(r,t);e(null,u)}catch(o){e(o)}},0)}}function I(n,r){return n>r?1:r>n?-1:0}function N(n,r,t){return I(r[n],t[n])}function W(n){if(!(n&&n instanceof Array))throw new Error("props is falsey or not an Array");return function(r,t){for(var e=n.length,u=0;e>u;u++){var o,i,a;if("function"==typeof n[u])o=n[u](r),i=n[u](t),a="asc";else if(n[u].toLowerCase().indexOf(" ")>=0){var f=n[u].split(" ");o=r[f[0]],i=t[f[0]],a=f[1].toLowerCase()}else o=r[n[u]],i=t[n[u]],a="asc";if(o!=i)return"asc"==a?I(o,i):I(i,o)}return 0}}function Y(n,r){if(typeof n!=typeof r)return!1;if(n instanceof Array){if(n.length!==r.length)return!1;for(var t=0,e=n.length;e>t;t++)if(!r||!r[t]||!Y(n[t],r[t]))return!1}else if("number"==typeof n||"string"==typeof n||"boolean"==typeof n||"undefined"==typeof n){if(n!==r)return!1}else{if(Object.keys(n).length!==Object.keys(r))return n===r;for(var u in n)if(!(u in r&&r[u]===n[u]))return!1}return!0}function B(n){return void 0!==n&&null!==n&&""!==n}function D(r){if(void 0===r)return"undefined";if(null===r)return"null";if("string"==typeof r||"number"==typeof r)return""+r;if("array"===F(r))return"_[{0}]_".format(r.map(D).join(","));if("object"===F(r)){var t="";for(var e in r)t+=n("{0}_:_{1}",[e,D(r[e])]);return n("_{{0}}_",[t])}throw new Error("Unhashable value: "+r)}function F(n){var r=typeof n;return"object"===r&&(n?"number"!=typeof n.length||n.propertyIsEnumerable("length")||"function"!=typeof n.splice||(r="array"):r="null"),r}function H(n,r){var t=new n;return n.apply(t,r),t}function J(n){return n.toString()}var Q=M(g,1,-1),R=function(){var n=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)};return function(){return n()+n()+"-"+n()+"-"+n()+"-"+n()+"-"+n()+n()+n()}}();return{supplant:n,startsWith:r,before:t,after:e,between:u,bookend:o,repeatString:i,toTitleCase:a,ordinal:f,mapNumber:c,addTwo:l,add:p,orderedGroup:s,tally:y,tallyProps:v,index:g,rotate:m,toObject:d,spliced:b,chunk:j,keyValue:A,getValue:w,setValue:O,mapOverKey:k,joinObject:C,mapObject:_,toArray:V,filterObject:E,changeKeys:S,tap:T,look:L,not:K,partialAt:M,aritize:P,callTillValue:U,spy:q,inContext:z,toAsync:G,compare:I,compareProperty:N,dynamicCompare:W,equals:Y,isValue:B,hash:D,guid:R,typeOf:F,"new":H,intoString:J}}(),"undefined"!=typeof module&&(module.exports=cint);