@livechat/data-utils
Advanced tools
Comparing version 0.1.0 to 0.2.0-0
@@ -85,2 +85,10 @@ function assign() { | ||
function forOwn(callback, obj) { | ||
for (var prop in obj) { | ||
if (hasOwn(prop, obj)) { | ||
callback(obj[prop], prop); | ||
} | ||
} | ||
} | ||
function fromPairs(pairs) { | ||
@@ -185,2 +193,52 @@ return pairs.reduce(function (obj, _ref) { | ||
function merge(objA, objB) { | ||
var result = {}; | ||
forOwn(function (value, key) { | ||
if (hasOwn(key, objB)) { | ||
if (isObject(objA[key]) && isObject(objB[key])) { | ||
result[key] = merge(objA[key], objB[key]); | ||
} else { | ||
result[key] = objB[key]; | ||
} | ||
} else { | ||
result[key] = objA[key]; | ||
} | ||
}, objA); | ||
forOwn(function (value, key) { | ||
if (!hasOwn(key, result)) { | ||
result[key] = objB[key]; | ||
} | ||
}, objB); | ||
return result; | ||
} | ||
function mergeAll(objs) { | ||
if (objs.length === 0) { | ||
return {}; | ||
} | ||
var first = objs[0], | ||
rest = objs.slice(1); | ||
return rest.reduce(function (merged, obj) { | ||
return merge(merged, obj); | ||
}, first); | ||
} | ||
function memoize(fn) { | ||
var memoized = void 0; | ||
var cacheKey = void 0; | ||
return function () { | ||
if ((arguments.length <= 0 ? undefined : arguments[0]) === cacheKey) { | ||
return memoized; | ||
} | ||
cacheKey = arguments.length <= 0 ? undefined : arguments[0]; | ||
memoized = fn.apply(undefined, arguments); | ||
return memoized; | ||
}; | ||
} | ||
function noop() {} | ||
@@ -356,2 +414,2 @@ | ||
export { assign, cloneDeep, dropRight, find, findIndex, findLast, findLastIndex, flatMap, flatten, fromPairs, generateRandomId, generateUniqueId, get, getOr, hasOwn, identity, includes, isArray, isEmpty, isObject, keyBy, last, mapKeys, mapValues, mapValuesIndexed, noop, numericSortBy, omit, omitByIndexed, once, pick, pickBy, pickByIndexed, pickOwn, removeAt, splitAt, splitRightWhenAccum, throttle, toPairs, trimEnd, uniq, values, without }; | ||
export { assign, cloneDeep, dropRight, find, findIndex, findLast, findLastIndex, flatMap, flatten, forOwn, fromPairs, generateRandomId, generateUniqueId, get, getOr, hasOwn, identity, includes, isArray, isEmpty, isObject, keyBy, last, mapKeys, mapValues, mapValuesIndexed, merge, mergeAll, memoize, noop, numericSortBy, omit, omitByIndexed, once, pick, pickBy, pickByIndexed, pickOwn, removeAt, splitAt, splitRightWhenAccum, throttle, toPairs, trimEnd, uniq, values, without }; |
@@ -89,2 +89,10 @@ 'use strict'; | ||
function forOwn(callback, obj) { | ||
for (var prop in obj) { | ||
if (hasOwn(prop, obj)) { | ||
callback(obj[prop], prop); | ||
} | ||
} | ||
} | ||
function fromPairs(pairs) { | ||
@@ -189,2 +197,52 @@ return pairs.reduce(function (obj, _ref) { | ||
function merge(objA, objB) { | ||
var result = {}; | ||
forOwn(function (value, key) { | ||
if (hasOwn(key, objB)) { | ||
if (isObject(objA[key]) && isObject(objB[key])) { | ||
result[key] = merge(objA[key], objB[key]); | ||
} else { | ||
result[key] = objB[key]; | ||
} | ||
} else { | ||
result[key] = objA[key]; | ||
} | ||
}, objA); | ||
forOwn(function (value, key) { | ||
if (!hasOwn(key, result)) { | ||
result[key] = objB[key]; | ||
} | ||
}, objB); | ||
return result; | ||
} | ||
function mergeAll(objs) { | ||
if (objs.length === 0) { | ||
return {}; | ||
} | ||
var first = objs[0], | ||
rest = objs.slice(1); | ||
return rest.reduce(function (merged, obj) { | ||
return merge(merged, obj); | ||
}, first); | ||
} | ||
function memoize(fn) { | ||
var memoized = void 0; | ||
var cacheKey = void 0; | ||
return function () { | ||
if ((arguments.length <= 0 ? undefined : arguments[0]) === cacheKey) { | ||
return memoized; | ||
} | ||
cacheKey = arguments.length <= 0 ? undefined : arguments[0]; | ||
memoized = fn.apply(undefined, arguments); | ||
return memoized; | ||
}; | ||
} | ||
function noop() {} | ||
@@ -369,2 +427,3 @@ | ||
exports.flatten = flatten; | ||
exports.forOwn = forOwn; | ||
exports.fromPairs = fromPairs; | ||
@@ -386,2 +445,5 @@ exports.generateRandomId = generateRandomId; | ||
exports.mapValuesIndexed = mapValuesIndexed; | ||
exports.merge = merge; | ||
exports.mergeAll = mergeAll; | ||
exports.memoize = memoize; | ||
exports.noop = noop; | ||
@@ -388,0 +450,0 @@ exports.numericSortBy = numericSortBy; |
@@ -91,2 +91,10 @@ (function (global, factory) { | ||
function forOwn(callback, obj) { | ||
for (var prop in obj) { | ||
if (hasOwn(prop, obj)) { | ||
callback(obj[prop], prop); | ||
} | ||
} | ||
} | ||
function fromPairs(pairs) { | ||
@@ -191,2 +199,52 @@ return pairs.reduce(function (obj, _ref) { | ||
function merge(objA, objB) { | ||
var result = {}; | ||
forOwn(function (value, key) { | ||
if (hasOwn(key, objB)) { | ||
if (isObject(objA[key]) && isObject(objB[key])) { | ||
result[key] = merge(objA[key], objB[key]); | ||
} else { | ||
result[key] = objB[key]; | ||
} | ||
} else { | ||
result[key] = objA[key]; | ||
} | ||
}, objA); | ||
forOwn(function (value, key) { | ||
if (!hasOwn(key, result)) { | ||
result[key] = objB[key]; | ||
} | ||
}, objB); | ||
return result; | ||
} | ||
function mergeAll(objs) { | ||
if (objs.length === 0) { | ||
return {}; | ||
} | ||
var first = objs[0], | ||
rest = objs.slice(1); | ||
return rest.reduce(function (merged, obj) { | ||
return merge(merged, obj); | ||
}, first); | ||
} | ||
function memoize(fn) { | ||
var memoized = void 0; | ||
var cacheKey = void 0; | ||
return function () { | ||
if ((arguments.length <= 0 ? undefined : arguments[0]) === cacheKey) { | ||
return memoized; | ||
} | ||
cacheKey = arguments.length <= 0 ? undefined : arguments[0]; | ||
memoized = fn.apply(undefined, arguments); | ||
return memoized; | ||
}; | ||
} | ||
function noop() {} | ||
@@ -371,2 +429,3 @@ | ||
exports.flatten = flatten; | ||
exports.forOwn = forOwn; | ||
exports.fromPairs = fromPairs; | ||
@@ -388,2 +447,5 @@ exports.generateRandomId = generateRandomId; | ||
exports.mapValuesIndexed = mapValuesIndexed; | ||
exports.merge = merge; | ||
exports.mergeAll = mergeAll; | ||
exports.memoize = memoize; | ||
exports.noop = noop; | ||
@@ -390,0 +452,0 @@ exports.numericSortBy = numericSortBy; |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.DataUtils={})}(this,function(n){"use strict";function t(){return(t=Object.assign||function(n){for(var t=arguments.length,r=Array(t>1?t-1:0),e=1;t>e;e++)r[e-1]=arguments[e];return r.forEach(function(t){for(var r in t)i(r,t)&&(n[r]=t[r])}),n}).apply(void 0,arguments)}function r(n,t){var r;return(r=[]).concat.apply(r,t.map(n))}function e(){return Math.random().toString(36).substring(2)}function u(n,t){for(var r="string"==typeof n?n.split("."):n,e=0,u=t;u&&r.length>e;)u=u[r[e++]];return u}var o={}.hasOwnProperty;function i(n,t){return o.call(t,n)}function c(n){return n}var f=Array.isArray;var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function l(n){return"object"===(void 0===n?"undefined":a(n))&&null!==n&&!f(n)}function d(n,t){return Object.keys(t).reduce(function(r,e){return r[e]=n(t[e]),r},{})}function s(n,t){return[t.slice(0,n),t.slice(n,t.length)]}var p=/\s+$/;function y(n){return Object.keys(n).map(function(t){return n[t]})}n.assign=t,n.cloneDeep=function n(t){return f(t)?t.map(n):l(t)?d(n,t):t},n.dropRight=function(n,t){return t.slice(0,-n)},n.find=function(n,t){for(var r=0;t.length>r;r++){var e=t[r];if(n(e))return e}},n.findIndex=function(n,t){for(var r=0;t.length>r;r++)if(n(t[r]))return r;return-1},n.findLast=function(n,t){for(var r=t.length-1;r>=0;r--)if(n(t[r]))return t[r]},n.findLastIndex=function(n,t){for(var r=t.length-1;r>=0;r--)if(n(t[r]))return r;return-1},n.flatMap=r,n.flatten=function(n){return r(c,n)},n.fromPairs=function(n){return n.reduce(function(n,t){return n[t[0]]=t[1],n},{})},n.generateRandomId=e,n.generateUniqueId=function n(t){var r=e();return i(r,t)?n(t):r},n.get=u,n.getOr=function(n,t,r){var e=u(t,r);return null!=e?e:n},n.hasOwn=i,n.identity=c,n.includes=function(n,t){return-1!==t.indexOf(n)},n.isArray=f,n.isEmpty=function(n){return 0===Object.keys(n).length},n.isObject=l,n.keyBy=function(n,t){return t.reduce(function(t,r){return t[r[n]]=r,t},{})},n.last=function(n){return n.length>0?n[n.length-1]:null},n.mapKeys=function(n,t){return Object.keys(t).reduce(function(r,e){return r[n(e)]=t[e],r},{})},n.mapValues=d,n.mapValuesIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return r[e]=n(t[e],e),r},{})},n.noop=function(){},n.numericSortBy=function(n,t){var r="function"==typeof n?n:function(t){return u(n,t)};return(f(t)?[].concat(t):y(t)).sort(function(n,t){return r(n)-r(t)})},n.omit=function(n,t){return Object.keys(t).filter(function(t){return-1===n.indexOf(t)}).reduce(function(n,r){return n[r]=t[r],n},{})},n.omitByIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e],e)||(r[e]=t[e]),r},{})},n.once=function(n){var t=!1,r=void 0;return function(){return t?r:(t=!0,r=n.apply(void 0,arguments))}},n.pick=function(n,t){return n.reduce(function(n,r){return n[r]=t[r],n},{})},n.pickBy=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e])&&(r[e]=t[e]),r},{})},n.pickByIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e],e)&&(r[e]=t[e]),r},{})},n.pickOwn=function(n,t){return n.reduce(function(n,r){return i(r,t)&&(n[r]=t[r]),n},{})},n.removeAt=function(n,t){var r=[].concat(t);return r.splice(n,1),r},n.splitAt=s,n.splitRightWhenAccum=function(n,t,r){for(var e=r.length;e>0;e--){var u=n(r[e-1],t);if(t=u[1],u[0])return s(e-1,r)}return[[],r]},n.throttle=function(n,t){var r=Date.now()-2*n,e=void 0,u=void 0,o=function(){return r=Date.now(),e=t.apply(void 0,arguments)};return function(){for(var t=arguments.length,i=Array(t),c=0;t>c;c++)i[c]=arguments[c];var f=Date.now();return n>f-r?(clearTimeout(u),u=setTimeout.apply(void 0,[o,r-f+n].concat(i)),e):o.apply(void 0,i)}},n.toPairs=function(n){return Object.keys(n).map(function(t){return[t,n[t]]})},n.trimEnd=function(n){return n.replace(p,"")},n.uniq=function(n){var t=[];return n.filter(function(n){return-1===t.indexOf(n)&&(t.push(n),!0)})},n.values=y,n.without=function(n,t){return t.filter(function(t){return-1===n.indexOf(t)})},Object.defineProperty(n,"__esModule",{value:!0})}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.DataUtils={})}(this,function(n){"use strict";function t(){return(t=Object.assign||function(n){for(var t=arguments.length,r=Array(t>1?t-1:0),e=1;t>e;e++)r[e-1]=arguments[e];return r.forEach(function(t){for(var r in t)c(r,t)&&(n[r]=t[r])}),n}).apply(void 0,arguments)}function r(n,t){var r;return(r=[]).concat.apply(r,t.map(n))}function e(n,t){for(var r in t)c(r,t)&&n(t[r],r)}function u(){return Math.random().toString(36).substring(2)}function o(n,t){for(var r="string"==typeof n?n.split("."):n,e=0,u=t;u&&r.length>e;)u=u[r[e++]];return u}var i={}.hasOwnProperty;function c(n,t){return i.call(t,n)}function f(n){return n}var a=Array.isArray;var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};function d(n){return"object"===(void 0===n?"undefined":l(n))&&null!==n&&!a(n)}function s(n,t){return Object.keys(t).reduce(function(r,e){return r[e]=n(t[e]),r},{})}function p(n,t){var r={};return e(function(e,u){r[u]=c(u,t)?d(n[u])&&d(t[u])?p(n[u],t[u]):t[u]:n[u]},n),e(function(n,e){c(e,r)||(r[e]=t[e])},t),r}function y(n,t){return[t.slice(0,n),t.slice(n,t.length)]}var v=/\s+$/;function m(n){return Object.keys(n).map(function(t){return n[t]})}n.assign=t,n.cloneDeep=function n(t){return a(t)?t.map(n):d(t)?s(n,t):t},n.dropRight=function(n,t){return t.slice(0,-n)},n.find=function(n,t){for(var r=0;t.length>r;r++){var e=t[r];if(n(e))return e}},n.findIndex=function(n,t){for(var r=0;t.length>r;r++)if(n(t[r]))return r;return-1},n.findLast=function(n,t){for(var r=t.length-1;r>=0;r--)if(n(t[r]))return t[r]},n.findLastIndex=function(n,t){for(var r=t.length-1;r>=0;r--)if(n(t[r]))return r;return-1},n.flatMap=r,n.flatten=function(n){return r(f,n)},n.forOwn=e,n.fromPairs=function(n){return n.reduce(function(n,t){return n[t[0]]=t[1],n},{})},n.generateRandomId=u,n.generateUniqueId=function n(t){var r=u();return c(r,t)?n(t):r},n.get=o,n.getOr=function(n,t,r){var e=o(t,r);return null!=e?e:n},n.hasOwn=c,n.identity=f,n.includes=function(n,t){return-1!==t.indexOf(n)},n.isArray=a,n.isEmpty=function(n){return 0===Object.keys(n).length},n.isObject=d,n.keyBy=function(n,t){return t.reduce(function(t,r){return t[r[n]]=r,t},{})},n.last=function(n){return n.length>0?n[n.length-1]:null},n.mapKeys=function(n,t){return Object.keys(t).reduce(function(r,e){return r[n(e)]=t[e],r},{})},n.mapValues=s,n.mapValuesIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return r[e]=n(t[e],e),r},{})},n.merge=p,n.mergeAll=function(n){if(0===n.length)return{};var t=n[0];return n.slice(1).reduce(function(n,t){return p(n,t)},t)},n.memoize=function(n){var t=void 0,r=void 0;return function(){return(arguments.length>0?arguments[0]:void 0)===r?t:(r=arguments.length>0?arguments[0]:void 0,t=n.apply(void 0,arguments))}},n.noop=function(){},n.numericSortBy=function(n,t){var r="function"==typeof n?n:function(t){return o(n,t)};return(a(t)?[].concat(t):m(t)).sort(function(n,t){return r(n)-r(t)})},n.omit=function(n,t){return Object.keys(t).filter(function(t){return-1===n.indexOf(t)}).reduce(function(n,r){return n[r]=t[r],n},{})},n.omitByIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e],e)||(r[e]=t[e]),r},{})},n.once=function(n){var t=!1,r=void 0;return function(){return t?r:(t=!0,r=n.apply(void 0,arguments))}},n.pick=function(n,t){return n.reduce(function(n,r){return n[r]=t[r],n},{})},n.pickBy=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e])&&(r[e]=t[e]),r},{})},n.pickByIndexed=function(n,t){return Object.keys(t).reduce(function(r,e){return n(t[e],e)&&(r[e]=t[e]),r},{})},n.pickOwn=function(n,t){return n.reduce(function(n,r){return c(r,t)&&(n[r]=t[r]),n},{})},n.removeAt=function(n,t){var r=[].concat(t);return r.splice(n,1),r},n.splitAt=y,n.splitRightWhenAccum=function(n,t,r){for(var e=r.length;e>0;e--){var u=n(r[e-1],t);if(t=u[1],u[0])return y(e-1,r)}return[[],r]},n.throttle=function(n,t){var r=Date.now()-2*n,e=void 0,u=void 0,o=function(){return r=Date.now(),e=t.apply(void 0,arguments)};return function(){for(var t=arguments.length,i=Array(t),c=0;t>c;c++)i[c]=arguments[c];var f=Date.now();return n>f-r?(clearTimeout(u),u=setTimeout.apply(void 0,[o,r-f+n].concat(i)),e):o.apply(void 0,i)}},n.toPairs=function(n){return Object.keys(n).map(function(t){return[t,n[t]]})},n.trimEnd=function(n){return n.replace(v,"")},n.uniq=function(n){var t=[];return n.filter(function(n){return-1===t.indexOf(n)&&(t.push(n),!0)})},n.values=m,n.without=function(n,t){return t.filter(function(t){return-1===n.indexOf(t)})},Object.defineProperty(n,"__esModule",{value:!0})}); |
{ | ||
"name": "@livechat/data-utils", | ||
"version": "0.1.0", | ||
"version": "0.2.0-0", | ||
"description": "Collections utility functions", | ||
@@ -13,5 +13,3 @@ "contributors": [ | ||
"jsnext:main": "dist/data-utils.es", | ||
"files": [ | ||
"dist" | ||
], | ||
"files": ["dist"], | ||
"keywords": [], | ||
@@ -24,3 +22,3 @@ "dependencies": {}, | ||
"babel-preset-stage-2": "^6.24.1", | ||
"jest": "^21.2.1", | ||
"jest": "^22.4.0", | ||
"lerna-alias": "^1.0.0", | ||
@@ -27,0 +25,0 @@ "rimraf": "^2.6.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35211
1135