@livechat/data-utils
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -31,2 +31,18 @@ function add(first, second) { | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
function chain(fn, listOrFn) { | ||
if (typeof listOrFn === 'function') { | ||
return function (list) { | ||
return fn(listOrFn(list))(list); | ||
}; | ||
} | ||
return flatMap(fn, listOrFn); | ||
} | ||
var isArray = Array.isArray; | ||
@@ -44,5 +60,5 @@ | ||
function mapValues(iteratee, obj) { | ||
function mapValues(mapper, obj) { | ||
return Object.keys(obj).reduce(function (acc, key) { | ||
acc[key] = iteratee(obj[key]); | ||
acc[key] = mapper(obj[key]); | ||
return acc; | ||
@@ -64,12 +80,70 @@ }, {}); | ||
function camelCase(text) { | ||
return text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (__, p1) { | ||
// slightly simplified version of https://github.com/sindresorhus/camelcase/blob/a526ef0399f9a1310eaacafa0ae4a69da4a2f1ad/index.js | ||
// TODO: possibly could be rewritten using short-ish regexp | ||
var preserveCamelCase = function preserveCamelCase(input) { | ||
var text = input; | ||
var isLastCharLower = false; | ||
var isLastCharUpper = false; | ||
var isLastLastCharUpper = false; | ||
for (var index = 0; index < text.length; index++) { | ||
var char = text[index]; | ||
if (isLastCharLower && /[a-zA-Z]/.test(char) && char.toUpperCase() === char) { | ||
text = text.slice(0, index) + '-' + text.slice(index); | ||
isLastCharLower = false; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = true; | ||
index++; | ||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(char) && char.toLowerCase() === char) { | ||
text = text.slice(0, index - 1) + '-' + text.slice(index - 1); | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = false; | ||
isLastCharLower = true; | ||
} else { | ||
isLastCharLower = char.toLowerCase() === char; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = char.toUpperCase() === char; | ||
} | ||
} | ||
return text; | ||
}; | ||
function camelCase(input) { | ||
var text = input.trim(); | ||
if (text.length === 0) { | ||
return ''; | ||
} | ||
if (text.length === 1) { | ||
return text.toLowerCase(); | ||
} | ||
if (/^[a-z\d]+$/.test(text)) { | ||
return text; | ||
} | ||
var hasUpperCase = text !== text.toLowerCase(); | ||
if (hasUpperCase) { | ||
text = preserveCamelCase(text); | ||
} | ||
text = text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (match, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
return text; | ||
} | ||
function compact(collection) { | ||
return isArray(collection) ? collection.filter(Boolean) : Object.keys(collection).reduce(function (result, key) { | ||
if (collection[key]) { | ||
result[key] = collection[key]; | ||
return isArray(collection) ? collection.filter(function (value) { | ||
return value !== null && value !== undefined; | ||
}) : Object.keys(collection).reduce(function (result, key) { | ||
var value = collection[key]; | ||
if (value !== null && value !== undefined) { | ||
result[key] = value; | ||
} | ||
@@ -92,2 +166,29 @@ return result; | ||
function debounce(ms, fn) { | ||
var timeoutId = void 0; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(timeoutId); | ||
timeoutId = setTimeout.apply(undefined, [fn, ms].concat(args)); | ||
}; | ||
} | ||
function isNil(value) { | ||
return value === null || value === undefined; | ||
} | ||
function defaultTo(defaultValue) { | ||
return function (value) { | ||
return isNil(value) ? defaultValue : value; | ||
}; | ||
} | ||
function drop(count, arr) { | ||
return arr.slice(count); | ||
} | ||
function dropRight(count, arr) { | ||
@@ -97,2 +198,6 @@ return arr.slice(0, -count); | ||
function ensureArray(maybeArr) { | ||
return isArray(maybeArr) ? maybeArr : [maybeArr]; | ||
} | ||
// eslint-disable-next-line consistent-return | ||
@@ -119,2 +224,9 @@ function find(predicate, arr) { | ||
// eslint-disable-next-line consistent-return | ||
function findKey(predicate, obj) { | ||
return find(function (key) { | ||
return predicate(obj[key]); | ||
}, Object.keys(obj)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
function findLast(predicate, arr) { | ||
@@ -142,8 +254,2 @@ for (var index = arr.length - 1; index >= 0; index--) { | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
// eslint-disable-next-line lodash-fp/prefer-identity | ||
@@ -292,16 +398,13 @@ function identity(value) { | ||
function memoize(func) { | ||
var keys = []; | ||
var values = []; | ||
function memoizeWith(keyResolver, func) { | ||
var cache = {}; | ||
return function () { | ||
var key = arguments.length <= 0 ? undefined : arguments[0]; | ||
var index = keys.indexOf(key); | ||
var key = keyResolver.apply(undefined, arguments); | ||
if (index !== -1) { | ||
return values[index]; | ||
if (hasOwn(key, cache)) { | ||
return cache[key]; | ||
} | ||
var value = func.apply(undefined, arguments); | ||
keys.push(key); | ||
values.push(value); | ||
cache[key] = value; | ||
return value; | ||
@@ -311,2 +414,6 @@ }; | ||
function memoize(func) { | ||
return memoizeWith(identity, func); | ||
} | ||
function memoizeOne(fn) { | ||
@@ -381,2 +488,31 @@ var called = false; | ||
function over(fns) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return fns.map(function (fn) { | ||
return fn.apply(undefined, args); | ||
}); | ||
}; | ||
} | ||
function takeLast(count, arr) { | ||
return arr.slice(-count); | ||
} | ||
function overArgs(fn, transformers) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var transformed = transformers.map(function (transform, index) { | ||
return transform(args[index]); | ||
}); | ||
return args.length > transformed.length ? fn.apply(undefined, transformed.concat(takeLast(args.length - transformed.length, args))) : fn.apply(undefined, transformed); | ||
}; | ||
} | ||
function pick(props, obj) { | ||
@@ -428,2 +564,24 @@ return props.reduce(function (acc, prop) { | ||
// based on https://github.com/lukeed/dset/blob/f8ce2f65d4adae7842492eb519a7e55de9abdf38/src/index.js | ||
function set$1(_keys, val, input) { | ||
var keys = _keys.split ? _keys.split('.') : _keys; | ||
var length = keys.length; | ||
// TODO: we should clone as we go instead of doing a deep copy upfront | ||
var obj = cloneDeep(input); | ||
var pointer = obj; | ||
for (var index = 0; index < length; ++index) { | ||
var pointerValue = pointer[keys[index]]; | ||
if (index === length - 1) { | ||
pointer = pointer[keys[index]] = val; | ||
// eslint-disable-next-line eqeqeq | ||
} else if (pointerValue == null) { | ||
pointer = pointer[keys[index]] = {}; | ||
} else { | ||
pointer = pointer[keys[index]] = pointerValue; | ||
} | ||
} | ||
return obj; | ||
} | ||
// https://github.com/reactjs/react-redux/blob/5d792a283554cff3d2f54fad1be1f79cbcab33fe/src/utils/shallowEqual.js | ||
@@ -460,2 +618,19 @@ | ||
function sliceDiff(slice, obj) { | ||
var picked = pickByIndexed(function (value, key) { | ||
return value !== obj[key]; | ||
}, slice); | ||
return isEmpty(picked) ? null : picked; | ||
} | ||
// TODO: this could be written a lot better | ||
function snakeCase(str) { | ||
var snakeCased = str.replace(/[A-Z]|([\-_ ]+)/g, function (match) { | ||
var code = match.charCodeAt(0); | ||
var upperCased = code > 64 && code < 91; | ||
return upperCased ? '_' + match.toLowerCase() : '_'; | ||
}); | ||
return snakeCased[0] === '_' ? snakeCased.substr(1) : snakeCased; | ||
} | ||
function splitAt(splitPoint, arr) { | ||
@@ -486,2 +661,8 @@ // TODO first item from the tuple could be replaced by dropRight | ||
function spread(fn) { | ||
return function (args) { | ||
return fn.apply(undefined, args); | ||
}; | ||
} | ||
function sum(numbers) { | ||
@@ -491,2 +672,6 @@ return numbers.reduce(add, 0); | ||
function take(count, arr) { | ||
return arr.slice(0, count); | ||
} | ||
function takeRightWhileFrom(predicate, startIndex, arr) { | ||
@@ -501,8 +686,7 @@ var endIndex = findLastIndexFrom(function (element) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var result = void 0; | ||
var trailing = void 0; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return result = fn.apply(undefined, arguments); | ||
fn.apply(undefined, arguments); | ||
}; | ||
@@ -518,9 +702,8 @@ | ||
if (now - lastCall >= ms) { | ||
return invoke.apply(undefined, args); | ||
invoke.apply(undefined, args); | ||
return; | ||
} | ||
clearTimeout(trailing); | ||
trailing = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
return result; | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
@@ -535,2 +718,27 @@ } | ||
function trailingThrottle(ms, fn) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return fn.apply(undefined, arguments); | ||
}; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var now = Date.now(); | ||
if (now - lastCall >= ms) { | ||
lastCall = Date.now(); | ||
} | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
} | ||
var leadingWhiteSpace = /^\s+/; | ||
@@ -548,8 +756,9 @@ | ||
function uniq(arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr)) | ||
function uniqBy(iteratee, arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr.map(iteratee))) | ||
var seen = []; | ||
return arr.filter(function (element) { | ||
if (seen.indexOf(element) === -1) { | ||
seen.push(element); | ||
var key = iteratee(element); | ||
if (seen.indexOf(key) === -1) { | ||
seen.push(key); | ||
return true; | ||
@@ -561,2 +770,6 @@ } | ||
function uniq(arr) { | ||
return uniqBy(identity, arr); | ||
} | ||
function update(index, newElement, arr) { | ||
@@ -572,2 +785,2 @@ return [].concat(arr.slice(0, index), [newElement], arr.slice(index + 1, arr.length)); | ||
export { add, assign, cloneDeep, camelCase, compact, compose, dropRight, find, findIndex, findLast, findLastIndex, findLastIndexFrom, flatMap, flatten, forOwn, fromPairs, generateRandomId, generateUniqueId, get$1 as get, getOr, groupBy, groupKeys, hasOwn, identity, includes, isArray, isEmpty, isObject, keyBy, last, mapKeys, mapValues, mapValuesIndexed, merge, mergeAll, memoize, memoizeOne, noop, numericSortBy, omit, omitBy, omitByIndexed, once, pick, pickBy, pickByIndexed, pickOwn, reject, removeAt, shallowEqual, splitAt, splitRightWhenAccum, sum, takeRightWhileFrom, throttle, toPairs, trimStart, trimEnd, uniq, update, values, without }; | ||
export { add, assign, chain, cloneDeep, camelCase, compact, compose, debounce, defaultTo, drop, dropRight, ensureArray, find, findIndex, findKey, findLast, findLastIndex, findLastIndexFrom, flatMap, flatten, forOwn, fromPairs, generateRandomId, generateUniqueId, get$1 as get, getOr, groupBy, groupKeys, hasOwn, identity, includes, isArray, isEmpty, isNil, isObject, keyBy, last, mapKeys, mapValues, mapValuesIndexed, merge, mergeAll, memoize, memoizeOne, memoizeWith, noop, numericSortBy, omit, omitBy, omitByIndexed, once, over, overArgs, pick, pickBy, pickByIndexed, pickOwn, reject, removeAt, set$1 as set, shallowEqual, sliceDiff, snakeCase, splitAt, splitRightWhenAccum, spread, sum, take, takeLast, takeRightWhileFrom, throttle, toPairs, trailingThrottle, trimStart, trimEnd, uniq, uniqBy, update, values, without }; |
@@ -35,2 +35,18 @@ 'use strict'; | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
function chain(fn, listOrFn) { | ||
if (typeof listOrFn === 'function') { | ||
return function (list) { | ||
return fn(listOrFn(list))(list); | ||
}; | ||
} | ||
return flatMap(fn, listOrFn); | ||
} | ||
var isArray = Array.isArray; | ||
@@ -48,5 +64,5 @@ | ||
function mapValues(iteratee, obj) { | ||
function mapValues(mapper, obj) { | ||
return Object.keys(obj).reduce(function (acc, key) { | ||
acc[key] = iteratee(obj[key]); | ||
acc[key] = mapper(obj[key]); | ||
return acc; | ||
@@ -68,12 +84,70 @@ }, {}); | ||
function camelCase(text) { | ||
return text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (__, p1) { | ||
// slightly simplified version of https://github.com/sindresorhus/camelcase/blob/a526ef0399f9a1310eaacafa0ae4a69da4a2f1ad/index.js | ||
// TODO: possibly could be rewritten using short-ish regexp | ||
var preserveCamelCase = function preserveCamelCase(input) { | ||
var text = input; | ||
var isLastCharLower = false; | ||
var isLastCharUpper = false; | ||
var isLastLastCharUpper = false; | ||
for (var index = 0; index < text.length; index++) { | ||
var char = text[index]; | ||
if (isLastCharLower && /[a-zA-Z]/.test(char) && char.toUpperCase() === char) { | ||
text = text.slice(0, index) + '-' + text.slice(index); | ||
isLastCharLower = false; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = true; | ||
index++; | ||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(char) && char.toLowerCase() === char) { | ||
text = text.slice(0, index - 1) + '-' + text.slice(index - 1); | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = false; | ||
isLastCharLower = true; | ||
} else { | ||
isLastCharLower = char.toLowerCase() === char; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = char.toUpperCase() === char; | ||
} | ||
} | ||
return text; | ||
}; | ||
function camelCase(input) { | ||
var text = input.trim(); | ||
if (text.length === 0) { | ||
return ''; | ||
} | ||
if (text.length === 1) { | ||
return text.toLowerCase(); | ||
} | ||
if (/^[a-z\d]+$/.test(text)) { | ||
return text; | ||
} | ||
var hasUpperCase = text !== text.toLowerCase(); | ||
if (hasUpperCase) { | ||
text = preserveCamelCase(text); | ||
} | ||
text = text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (match, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
return text; | ||
} | ||
function compact(collection) { | ||
return isArray(collection) ? collection.filter(Boolean) : Object.keys(collection).reduce(function (result, key) { | ||
if (collection[key]) { | ||
result[key] = collection[key]; | ||
return isArray(collection) ? collection.filter(function (value) { | ||
return value !== null && value !== undefined; | ||
}) : Object.keys(collection).reduce(function (result, key) { | ||
var value = collection[key]; | ||
if (value !== null && value !== undefined) { | ||
result[key] = value; | ||
} | ||
@@ -96,2 +170,29 @@ return result; | ||
function debounce(ms, fn) { | ||
var timeoutId = void 0; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(timeoutId); | ||
timeoutId = setTimeout.apply(undefined, [fn, ms].concat(args)); | ||
}; | ||
} | ||
function isNil(value) { | ||
return value === null || value === undefined; | ||
} | ||
function defaultTo(defaultValue) { | ||
return function (value) { | ||
return isNil(value) ? defaultValue : value; | ||
}; | ||
} | ||
function drop(count, arr) { | ||
return arr.slice(count); | ||
} | ||
function dropRight(count, arr) { | ||
@@ -101,2 +202,6 @@ return arr.slice(0, -count); | ||
function ensureArray(maybeArr) { | ||
return isArray(maybeArr) ? maybeArr : [maybeArr]; | ||
} | ||
// eslint-disable-next-line consistent-return | ||
@@ -123,2 +228,9 @@ function find(predicate, arr) { | ||
// eslint-disable-next-line consistent-return | ||
function findKey(predicate, obj) { | ||
return find(function (key) { | ||
return predicate(obj[key]); | ||
}, Object.keys(obj)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
function findLast(predicate, arr) { | ||
@@ -146,8 +258,2 @@ for (var index = arr.length - 1; index >= 0; index--) { | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
// eslint-disable-next-line lodash-fp/prefer-identity | ||
@@ -296,16 +402,13 @@ function identity(value) { | ||
function memoize(func) { | ||
var keys = []; | ||
var values = []; | ||
function memoizeWith(keyResolver, func) { | ||
var cache = {}; | ||
return function () { | ||
var key = arguments.length <= 0 ? undefined : arguments[0]; | ||
var index = keys.indexOf(key); | ||
var key = keyResolver.apply(undefined, arguments); | ||
if (index !== -1) { | ||
return values[index]; | ||
if (hasOwn(key, cache)) { | ||
return cache[key]; | ||
} | ||
var value = func.apply(undefined, arguments); | ||
keys.push(key); | ||
values.push(value); | ||
cache[key] = value; | ||
return value; | ||
@@ -315,2 +418,6 @@ }; | ||
function memoize(func) { | ||
return memoizeWith(identity, func); | ||
} | ||
function memoizeOne(fn) { | ||
@@ -385,2 +492,31 @@ var called = false; | ||
function over(fns) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return fns.map(function (fn) { | ||
return fn.apply(undefined, args); | ||
}); | ||
}; | ||
} | ||
function takeLast(count, arr) { | ||
return arr.slice(-count); | ||
} | ||
function overArgs(fn, transformers) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var transformed = transformers.map(function (transform, index) { | ||
return transform(args[index]); | ||
}); | ||
return args.length > transformed.length ? fn.apply(undefined, transformed.concat(takeLast(args.length - transformed.length, args))) : fn.apply(undefined, transformed); | ||
}; | ||
} | ||
function pick(props, obj) { | ||
@@ -432,2 +568,24 @@ return props.reduce(function (acc, prop) { | ||
// based on https://github.com/lukeed/dset/blob/f8ce2f65d4adae7842492eb519a7e55de9abdf38/src/index.js | ||
function set$1(_keys, val, input) { | ||
var keys = _keys.split ? _keys.split('.') : _keys; | ||
var length = keys.length; | ||
// TODO: we should clone as we go instead of doing a deep copy upfront | ||
var obj = cloneDeep(input); | ||
var pointer = obj; | ||
for (var index = 0; index < length; ++index) { | ||
var pointerValue = pointer[keys[index]]; | ||
if (index === length - 1) { | ||
pointer = pointer[keys[index]] = val; | ||
// eslint-disable-next-line eqeqeq | ||
} else if (pointerValue == null) { | ||
pointer = pointer[keys[index]] = {}; | ||
} else { | ||
pointer = pointer[keys[index]] = pointerValue; | ||
} | ||
} | ||
return obj; | ||
} | ||
// https://github.com/reactjs/react-redux/blob/5d792a283554cff3d2f54fad1be1f79cbcab33fe/src/utils/shallowEqual.js | ||
@@ -464,2 +622,19 @@ | ||
function sliceDiff(slice, obj) { | ||
var picked = pickByIndexed(function (value, key) { | ||
return value !== obj[key]; | ||
}, slice); | ||
return isEmpty(picked) ? null : picked; | ||
} | ||
// TODO: this could be written a lot better | ||
function snakeCase(str) { | ||
var snakeCased = str.replace(/[A-Z]|([\-_ ]+)/g, function (match) { | ||
var code = match.charCodeAt(0); | ||
var upperCased = code > 64 && code < 91; | ||
return upperCased ? '_' + match.toLowerCase() : '_'; | ||
}); | ||
return snakeCased[0] === '_' ? snakeCased.substr(1) : snakeCased; | ||
} | ||
function splitAt(splitPoint, arr) { | ||
@@ -490,2 +665,8 @@ // TODO first item from the tuple could be replaced by dropRight | ||
function spread(fn) { | ||
return function (args) { | ||
return fn.apply(undefined, args); | ||
}; | ||
} | ||
function sum(numbers) { | ||
@@ -495,2 +676,6 @@ return numbers.reduce(add, 0); | ||
function take(count, arr) { | ||
return arr.slice(0, count); | ||
} | ||
function takeRightWhileFrom(predicate, startIndex, arr) { | ||
@@ -505,8 +690,7 @@ var endIndex = findLastIndexFrom(function (element) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var result = void 0; | ||
var trailing = void 0; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return result = fn.apply(undefined, arguments); | ||
fn.apply(undefined, arguments); | ||
}; | ||
@@ -522,9 +706,8 @@ | ||
if (now - lastCall >= ms) { | ||
return invoke.apply(undefined, args); | ||
invoke.apply(undefined, args); | ||
return; | ||
} | ||
clearTimeout(trailing); | ||
trailing = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
return result; | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
@@ -539,2 +722,27 @@ } | ||
function trailingThrottle(ms, fn) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return fn.apply(undefined, arguments); | ||
}; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var now = Date.now(); | ||
if (now - lastCall >= ms) { | ||
lastCall = Date.now(); | ||
} | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
} | ||
var leadingWhiteSpace = /^\s+/; | ||
@@ -552,8 +760,9 @@ | ||
function uniq(arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr)) | ||
function uniqBy(iteratee, arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr.map(iteratee))) | ||
var seen = []; | ||
return arr.filter(function (element) { | ||
if (seen.indexOf(element) === -1) { | ||
seen.push(element); | ||
var key = iteratee(element); | ||
if (seen.indexOf(key) === -1) { | ||
seen.push(key); | ||
return true; | ||
@@ -565,2 +774,6 @@ } | ||
function uniq(arr) { | ||
return uniqBy(identity, arr); | ||
} | ||
function update(index, newElement, arr) { | ||
@@ -578,2 +791,3 @@ return [].concat(arr.slice(0, index), [newElement], arr.slice(index + 1, arr.length)); | ||
exports.assign = assign; | ||
exports.chain = chain; | ||
exports.cloneDeep = cloneDeep; | ||
@@ -583,5 +797,10 @@ exports.camelCase = camelCase; | ||
exports.compose = compose; | ||
exports.debounce = debounce; | ||
exports.defaultTo = defaultTo; | ||
exports.drop = drop; | ||
exports.dropRight = dropRight; | ||
exports.ensureArray = ensureArray; | ||
exports.find = find; | ||
exports.findIndex = findIndex; | ||
exports.findKey = findKey; | ||
exports.findLast = findLast; | ||
@@ -605,2 +824,3 @@ exports.findLastIndex = findLastIndex; | ||
exports.isEmpty = isEmpty; | ||
exports.isNil = isNil; | ||
exports.isObject = isObject; | ||
@@ -616,2 +836,3 @@ exports.keyBy = keyBy; | ||
exports.memoizeOne = memoizeOne; | ||
exports.memoizeWith = memoizeWith; | ||
exports.noop = noop; | ||
@@ -623,2 +844,4 @@ exports.numericSortBy = numericSortBy; | ||
exports.once = once; | ||
exports.over = over; | ||
exports.overArgs = overArgs; | ||
exports.pick = pick; | ||
@@ -630,14 +853,22 @@ exports.pickBy = pickBy; | ||
exports.removeAt = removeAt; | ||
exports.set = set$1; | ||
exports.shallowEqual = shallowEqual; | ||
exports.sliceDiff = sliceDiff; | ||
exports.snakeCase = snakeCase; | ||
exports.splitAt = splitAt; | ||
exports.splitRightWhenAccum = splitRightWhenAccum; | ||
exports.spread = spread; | ||
exports.sum = sum; | ||
exports.take = take; | ||
exports.takeLast = takeLast; | ||
exports.takeRightWhileFrom = takeRightWhileFrom; | ||
exports.throttle = throttle; | ||
exports.toPairs = toPairs; | ||
exports.trailingThrottle = trailingThrottle; | ||
exports.trimStart = trimStart; | ||
exports.trimEnd = trimEnd; | ||
exports.uniq = uniq; | ||
exports.uniqBy = uniqBy; | ||
exports.update = update; | ||
exports.values = values; | ||
exports.without = without; |
@@ -37,2 +37,18 @@ (function (global, factory) { | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
function chain(fn, listOrFn) { | ||
if (typeof listOrFn === 'function') { | ||
return function (list) { | ||
return fn(listOrFn(list))(list); | ||
}; | ||
} | ||
return flatMap(fn, listOrFn); | ||
} | ||
var isArray = Array.isArray; | ||
@@ -50,5 +66,5 @@ | ||
function mapValues(iteratee, obj) { | ||
function mapValues(mapper, obj) { | ||
return Object.keys(obj).reduce(function (acc, key) { | ||
acc[key] = iteratee(obj[key]); | ||
acc[key] = mapper(obj[key]); | ||
return acc; | ||
@@ -70,12 +86,70 @@ }, {}); | ||
function camelCase(text) { | ||
return text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (__, p1) { | ||
// slightly simplified version of https://github.com/sindresorhus/camelcase/blob/a526ef0399f9a1310eaacafa0ae4a69da4a2f1ad/index.js | ||
// TODO: possibly could be rewritten using short-ish regexp | ||
var preserveCamelCase = function preserveCamelCase(input) { | ||
var text = input; | ||
var isLastCharLower = false; | ||
var isLastCharUpper = false; | ||
var isLastLastCharUpper = false; | ||
for (var index = 0; index < text.length; index++) { | ||
var char = text[index]; | ||
if (isLastCharLower && /[a-zA-Z]/.test(char) && char.toUpperCase() === char) { | ||
text = text.slice(0, index) + '-' + text.slice(index); | ||
isLastCharLower = false; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = true; | ||
index++; | ||
} else if (isLastCharUpper && isLastLastCharUpper && /[a-zA-Z]/.test(char) && char.toLowerCase() === char) { | ||
text = text.slice(0, index - 1) + '-' + text.slice(index - 1); | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = false; | ||
isLastCharLower = true; | ||
} else { | ||
isLastCharLower = char.toLowerCase() === char; | ||
isLastLastCharUpper = isLastCharUpper; | ||
isLastCharUpper = char.toUpperCase() === char; | ||
} | ||
} | ||
return text; | ||
}; | ||
function camelCase(input) { | ||
var text = input.trim(); | ||
if (text.length === 0) { | ||
return ''; | ||
} | ||
if (text.length === 1) { | ||
return text.toLowerCase(); | ||
} | ||
if (/^[a-z\d]+$/.test(text)) { | ||
return text; | ||
} | ||
var hasUpperCase = text !== text.toLowerCase(); | ||
if (hasUpperCase) { | ||
text = preserveCamelCase(text); | ||
} | ||
text = text.replace(/^[_.\- ]+/, '').toLowerCase().replace(/[_.\- ]+(\w|$)/g, function (match, p1) { | ||
return p1.toUpperCase(); | ||
}); | ||
return text; | ||
} | ||
function compact(collection) { | ||
return isArray(collection) ? collection.filter(Boolean) : Object.keys(collection).reduce(function (result, key) { | ||
if (collection[key]) { | ||
result[key] = collection[key]; | ||
return isArray(collection) ? collection.filter(function (value) { | ||
return value !== null && value !== undefined; | ||
}) : Object.keys(collection).reduce(function (result, key) { | ||
var value = collection[key]; | ||
if (value !== null && value !== undefined) { | ||
result[key] = value; | ||
} | ||
@@ -98,2 +172,29 @@ return result; | ||
function debounce(ms, fn) { | ||
var timeoutId = void 0; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
clearTimeout(timeoutId); | ||
timeoutId = setTimeout.apply(undefined, [fn, ms].concat(args)); | ||
}; | ||
} | ||
function isNil(value) { | ||
return value === null || value === undefined; | ||
} | ||
function defaultTo(defaultValue) { | ||
return function (value) { | ||
return isNil(value) ? defaultValue : value; | ||
}; | ||
} | ||
function drop(count, arr) { | ||
return arr.slice(count); | ||
} | ||
function dropRight(count, arr) { | ||
@@ -103,2 +204,6 @@ return arr.slice(0, -count); | ||
function ensureArray(maybeArr) { | ||
return isArray(maybeArr) ? maybeArr : [maybeArr]; | ||
} | ||
// eslint-disable-next-line consistent-return | ||
@@ -125,2 +230,9 @@ function find(predicate, arr) { | ||
// eslint-disable-next-line consistent-return | ||
function findKey(predicate, obj) { | ||
return find(function (key) { | ||
return predicate(obj[key]); | ||
}, Object.keys(obj)); | ||
} | ||
// eslint-disable-next-line consistent-return | ||
function findLast(predicate, arr) { | ||
@@ -148,8 +260,2 @@ for (var index = arr.length - 1; index >= 0; index--) { | ||
function flatMap(iteratee, arr) { | ||
var _ref; | ||
return (_ref = []).concat.apply(_ref, arr.map(iteratee)); | ||
} | ||
// eslint-disable-next-line lodash-fp/prefer-identity | ||
@@ -298,16 +404,13 @@ function identity(value) { | ||
function memoize(func) { | ||
var keys = []; | ||
var values = []; | ||
function memoizeWith(keyResolver, func) { | ||
var cache = {}; | ||
return function () { | ||
var key = arguments.length <= 0 ? undefined : arguments[0]; | ||
var index = keys.indexOf(key); | ||
var key = keyResolver.apply(undefined, arguments); | ||
if (index !== -1) { | ||
return values[index]; | ||
if (hasOwn(key, cache)) { | ||
return cache[key]; | ||
} | ||
var value = func.apply(undefined, arguments); | ||
keys.push(key); | ||
values.push(value); | ||
cache[key] = value; | ||
return value; | ||
@@ -317,2 +420,6 @@ }; | ||
function memoize(func) { | ||
return memoizeWith(identity, func); | ||
} | ||
function memoizeOne(fn) { | ||
@@ -387,2 +494,31 @@ var called = false; | ||
function over(fns) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return fns.map(function (fn) { | ||
return fn.apply(undefined, args); | ||
}); | ||
}; | ||
} | ||
function takeLast(count, arr) { | ||
return arr.slice(-count); | ||
} | ||
function overArgs(fn, transformers) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var transformed = transformers.map(function (transform, index) { | ||
return transform(args[index]); | ||
}); | ||
return args.length > transformed.length ? fn.apply(undefined, transformed.concat(takeLast(args.length - transformed.length, args))) : fn.apply(undefined, transformed); | ||
}; | ||
} | ||
function pick(props, obj) { | ||
@@ -434,2 +570,24 @@ return props.reduce(function (acc, prop) { | ||
// based on https://github.com/lukeed/dset/blob/f8ce2f65d4adae7842492eb519a7e55de9abdf38/src/index.js | ||
function set$1(_keys, val, input) { | ||
var keys = _keys.split ? _keys.split('.') : _keys; | ||
var length = keys.length; | ||
// TODO: we should clone as we go instead of doing a deep copy upfront | ||
var obj = cloneDeep(input); | ||
var pointer = obj; | ||
for (var index = 0; index < length; ++index) { | ||
var pointerValue = pointer[keys[index]]; | ||
if (index === length - 1) { | ||
pointer = pointer[keys[index]] = val; | ||
// eslint-disable-next-line eqeqeq | ||
} else if (pointerValue == null) { | ||
pointer = pointer[keys[index]] = {}; | ||
} else { | ||
pointer = pointer[keys[index]] = pointerValue; | ||
} | ||
} | ||
return obj; | ||
} | ||
// https://github.com/reactjs/react-redux/blob/5d792a283554cff3d2f54fad1be1f79cbcab33fe/src/utils/shallowEqual.js | ||
@@ -466,2 +624,19 @@ | ||
function sliceDiff(slice, obj) { | ||
var picked = pickByIndexed(function (value, key) { | ||
return value !== obj[key]; | ||
}, slice); | ||
return isEmpty(picked) ? null : picked; | ||
} | ||
// TODO: this could be written a lot better | ||
function snakeCase(str) { | ||
var snakeCased = str.replace(/[A-Z]|([\-_ ]+)/g, function (match) { | ||
var code = match.charCodeAt(0); | ||
var upperCased = code > 64 && code < 91; | ||
return upperCased ? '_' + match.toLowerCase() : '_'; | ||
}); | ||
return snakeCased[0] === '_' ? snakeCased.substr(1) : snakeCased; | ||
} | ||
function splitAt(splitPoint, arr) { | ||
@@ -492,2 +667,8 @@ // TODO first item from the tuple could be replaced by dropRight | ||
function spread(fn) { | ||
return function (args) { | ||
return fn.apply(undefined, args); | ||
}; | ||
} | ||
function sum(numbers) { | ||
@@ -497,2 +678,6 @@ return numbers.reduce(add, 0); | ||
function take(count, arr) { | ||
return arr.slice(0, count); | ||
} | ||
function takeRightWhileFrom(predicate, startIndex, arr) { | ||
@@ -507,8 +692,7 @@ var endIndex = findLastIndexFrom(function (element) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var result = void 0; | ||
var trailing = void 0; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return result = fn.apply(undefined, arguments); | ||
fn.apply(undefined, arguments); | ||
}; | ||
@@ -524,9 +708,8 @@ | ||
if (now - lastCall >= ms) { | ||
return invoke.apply(undefined, args); | ||
invoke.apply(undefined, args); | ||
return; | ||
} | ||
clearTimeout(trailing); | ||
trailing = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
return result; | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
@@ -541,2 +724,27 @@ } | ||
function trailingThrottle(ms, fn) { | ||
var lastCall = Date.now() - 2 * ms; | ||
var trailingId = void 0; | ||
var invoke = function invoke() { | ||
lastCall = Date.now(); | ||
return fn.apply(undefined, arguments); | ||
}; | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var now = Date.now(); | ||
if (now - lastCall >= ms) { | ||
lastCall = Date.now(); | ||
} | ||
clearTimeout(trailingId); | ||
trailingId = setTimeout.apply(undefined, [invoke, lastCall - now + ms].concat(args)); | ||
}; | ||
} | ||
var leadingWhiteSpace = /^\s+/; | ||
@@ -554,8 +762,9 @@ | ||
function uniq(arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr)) | ||
function uniqBy(iteratee, arr) { | ||
// with polyfills this could be just: return Array.from(new Set(arr.map(iteratee))) | ||
var seen = []; | ||
return arr.filter(function (element) { | ||
if (seen.indexOf(element) === -1) { | ||
seen.push(element); | ||
var key = iteratee(element); | ||
if (seen.indexOf(key) === -1) { | ||
seen.push(key); | ||
return true; | ||
@@ -567,2 +776,6 @@ } | ||
function uniq(arr) { | ||
return uniqBy(identity, arr); | ||
} | ||
function update(index, newElement, arr) { | ||
@@ -580,2 +793,3 @@ return [].concat(arr.slice(0, index), [newElement], arr.slice(index + 1, arr.length)); | ||
exports.assign = assign; | ||
exports.chain = chain; | ||
exports.cloneDeep = cloneDeep; | ||
@@ -585,5 +799,10 @@ exports.camelCase = camelCase; | ||
exports.compose = compose; | ||
exports.debounce = debounce; | ||
exports.defaultTo = defaultTo; | ||
exports.drop = drop; | ||
exports.dropRight = dropRight; | ||
exports.ensureArray = ensureArray; | ||
exports.find = find; | ||
exports.findIndex = findIndex; | ||
exports.findKey = findKey; | ||
exports.findLast = findLast; | ||
@@ -607,2 +826,3 @@ exports.findLastIndex = findLastIndex; | ||
exports.isEmpty = isEmpty; | ||
exports.isNil = isNil; | ||
exports.isObject = isObject; | ||
@@ -618,2 +838,3 @@ exports.keyBy = keyBy; | ||
exports.memoizeOne = memoizeOne; | ||
exports.memoizeWith = memoizeWith; | ||
exports.noop = noop; | ||
@@ -625,2 +846,4 @@ exports.numericSortBy = numericSortBy; | ||
exports.once = once; | ||
exports.over = over; | ||
exports.overArgs = overArgs; | ||
exports.pick = pick; | ||
@@ -632,12 +855,20 @@ exports.pickBy = pickBy; | ||
exports.removeAt = removeAt; | ||
exports.set = set$1; | ||
exports.shallowEqual = shallowEqual; | ||
exports.sliceDiff = sliceDiff; | ||
exports.snakeCase = snakeCase; | ||
exports.splitAt = splitAt; | ||
exports.splitRightWhenAccum = splitRightWhenAccum; | ||
exports.spread = spread; | ||
exports.sum = sum; | ||
exports.take = take; | ||
exports.takeLast = takeLast; | ||
exports.takeRightWhileFrom = takeRightWhileFrom; | ||
exports.throttle = throttle; | ||
exports.toPairs = toPairs; | ||
exports.trailingThrottle = trailingThrottle; | ||
exports.trimStart = trimStart; | ||
exports.trimEnd = trimEnd; | ||
exports.uniq = uniq; | ||
exports.uniqBy = uniqBy; | ||
exports.update = update; | ||
@@ -644,0 +875,0 @@ exports.values = values; |
@@ -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(n,t){return n+t}var r={}.hasOwnProperty;function o(n,t){return r.call(t,n)}function e(){return(e=Object.assign||function(r){for(var n=arguments.length,t=Array(1<n?n-1:0),e=1;e<n;e++)t[e-1]=arguments[e];return t.forEach(function(n){for(var t in n)o(t,n)&&(r[t]=n[t])}),r}).apply(void 0,arguments)}var u=Array.isArray,i="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 c(n){return"object"===(void 0===n?"undefined":i(n))&&null!==n&&!u(n)}function f(r,e){return Object.keys(e).reduce(function(n,t){return n[t]=r(e[t]),n},{})}function a(n,t,r){for(var e=t;0<=e;e--)if(n(r[e]))return e;return-1}function l(n,t){var r;return(r=[]).concat.apply(r,t.map(n))}function d(n){return n}function s(t,r){return Object.keys(r).forEach(function(n){t(r[n],n)})}function p(){return Math.random().toString(36).substring(2)}function y(n,t){for(var r="string"==typeof n?n.split("."):n,e=0,u=t;u&&e<r.length;)u=u[r[e++]];return u}function v(n){return 0===(u(n)?n:Object.keys(n)).length}function m(r,e){if(v(e))return r;var u={};return s(function(n,t){u[t]=o(t,e)?c(r[t])&&c(e[t])?m(r[t],e[t]):e[t]:r[t]},r),s(function(n,t){o(t,u)||(u[t]=e[t])},e),u}function h(t){return Object.keys(t).map(function(n){return t[n]})}function g(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t],t)||(n[t]=e[t]),n},{})}function b(n,t){return n===t?0!==n||0!==t||1/n==1/t:n!=n&&t!=t}function O(n,t){return[t.slice(0,n),t.slice(n,t.length)]}var j=/^\s+/;var k=/\s+$/;n.add=t,n.assign=e,n.cloneDeep=function n(t){return u(t)?t.map(n):c(t)?f(n,t):t},n.camelCase=function(n){return n.replace(/^[_.\- ]+/,"").toLowerCase().replace(/[_.\- ]+(\w|$)/g,function(n,t){return t.toUpperCase()})},n.compact=function(r){return u(r)?r.filter(Boolean):Object.keys(r).reduce(function(n,t){return r[t]&&(n[t]=r[t]),n},{})},n.compose=function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];return t.reduce(function(n,t){return function(){return n(t.apply(void 0,arguments))}})},n.dropRight=function(n,t){return t.slice(0,-n)},n.find=function(n,t){for(var r=0;r<t.length;r++){var e=t[r];if(n(e))return e}},n.findIndex=function(n,t){for(var r=0;r<t.length;r++)if(n(t[r]))return r;return-1},n.findLast=function(n,t){for(var r=t.length-1;0<=r;r--)if(n(t[r]))return t[r]},n.findLastIndex=function(n,t){return a(n,t.length-1,t)},n.findLastIndexFrom=a,n.flatMap=l,n.flatten=function(n){return l(d,n)},n.forOwn=s,n.fromPairs=function(n){return n.reduce(function(n,t){return n[t[0]]=t[1],n},{})},n.generateRandomId=p,n.generateUniqueId=function n(t){var r=p();return o(r,t)?n(t):r},n.get=y,n.getOr=function(n,t,r){var e=y(t,r);return null!=e?e:n},n.groupBy=function(u,o){return Object.keys(o).reduce(function(n,t){var r=o[t],e=u(r);return n[e]=n[e]||[],n[e].push(r),n},{})},n.groupKeys=function(e,u){return Object.keys(u).reduce(function(n,t){var r=e(t);return n[r]=n[r]||{},n[r][t]=u[t],n},{})},n.hasOwn=o,n.identity=d,n.includes=function(n,t){return-1!==t.indexOf(n)},n.isArray=u,n.isEmpty=v,n.isObject=c,n.keyBy=function(r,n){return n.reduce(function(n,t){return n[t[r]]=t,n},{})},n.last=function(n){return 0<n.length?n[n.length-1]:null},n.mapKeys=function(r,e){return Object.keys(e).reduce(function(n,t){return n[r(t)]=e[t],n},{})},n.mapValues=f,n.mapValuesIndexed=function(r,e){return Object.keys(e).reduce(function(n,t){return n[t]=r(e[t],t),n},{})},n.merge=m,n.mergeAll=function(n){if(0===n.length)return{};var t=n[0];return n.slice(1).reduce(function(n,t){return m(n,t)},t)},n.memoize=function(e){var u=[],o=[];return function(){var n=0<arguments.length?arguments[0]:void 0,t=u.indexOf(n);if(-1!==t)return o[t];var r=e.apply(void 0,arguments);return u.push(n),o.push(r),r}},n.memoizeOne=function(n){var t=!1,r=void 0,e=void 0;return function(){return t&&(0<arguments.length?arguments[0]:void 0)===e?r:(t=!0,e=0<arguments.length?arguments[0]:void 0,r=n.apply(void 0,arguments))}},n.noop=function(){},n.numericSortBy=function(t,n){var r="function"==typeof t?t:function(n){return y(t,n)};return(u(n)?[].concat(n):h(n)).sort(function(n,t){return r(n)-r(t)})},n.omit=function(r,n){return g(function(n,t){return-1!==r.indexOf(t)},n)},n.omitBy=function(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t])||(n[t]=e[t]),n},{})},n.omitByIndexed=g,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,r){return n.reduce(function(n,t){return n[t]=r[t],n},{})},n.pickBy=function(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t])&&(n[t]=e[t]),n},{})},n.pickByIndexed=function(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t],t)&&(n[t]=e[t]),n},{})},n.pickOwn=function(n,r){return n.reduce(function(n,t){return o(t,r)&&(n[t]=r[t]),n},{})},n.reject=function(t,n){return n.filter(function(n){return!t(n)})},n.removeAt=function(n,t){var r=[].concat(t);return r.splice(n,1),r},n.shallowEqual=function(n,t){if(b(n,t))return!0;if("object"!==(void 0===n?"undefined":i(n))||null===n||"object"!==(void 0===t?"undefined":i(t))||null===t)return!1;var r=Object.keys(n);if(r.length!==Object.keys(t).length)return!1;for(var e=0;e<r.length;e++)if(!o(r[e],t)||!b(n[r[e]],t[r[e]]))return!1;return!0},n.splitAt=O,n.splitRightWhenAccum=function(n,t,r){for(var e=r.length;0<e;e--){var u=n(r[e-1],t);if(t=u[1],u[0])return O(e-1,r)}return[[],r]},n.sum=function(n){return n.reduce(t,0)},n.takeRightWhileFrom=function(t,n,r){var e=a(function(n){return!t(n)},n,r);return e===n?[]:r.slice(e+1,n+1)},n.throttle=function(u,n){var o=Date.now()-2*u,i=void 0,c=void 0,f=function(){return o=Date.now(),i=n.apply(void 0,arguments)};return function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];var e=Date.now();return e-o<u?(clearTimeout(c),c=setTimeout.apply(void 0,[f,o-e+u].concat(t)),i):f.apply(void 0,t)}},n.toPairs=function(t){return Object.keys(t).map(function(n){return[n,t[n]]})},n.trimStart=function(n){return n.replace(j,"")},n.trimEnd=function(n){return n.replace(k,"")},n.uniq=function(n){var t=[];return n.filter(function(n){return-1===t.indexOf(n)&&(t.push(n),!0)})},n.update=function(n,t,r){return[].concat(r.slice(0,n),[t],r.slice(n+1,r.length))},n.values=h,n.without=function(t,n){return n.filter(function(n){return-1===t.indexOf(n)})},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(n,t){return n+t}var r={}.hasOwnProperty;function o(n,t){return r.call(t,n)}function e(){return(e=Object.assign||function(r){for(var n=arguments.length,t=Array(1<n?n-1:0),e=1;e<n;e++)t[e-1]=arguments[e];return t.forEach(function(n){for(var t in n)o(t,n)&&(r[t]=n[t])}),r}).apply(void 0,arguments)}function u(n,t){var r;return(r=[]).concat.apply(r,t.map(n))}var i=Array.isArray,c="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 f(n){return"object"===(void 0===n?"undefined":c(n))&&null!==n&&!i(n)}function a(r,e){return Object.keys(e).reduce(function(n,t){return n[t]=r(e[t]),n},{})}function l(n){return i(n)?n.map(l):f(n)?a(l,n):n}function s(n){return null==n}function d(n,t){for(var r=0;r<t.length;r++){var e=t[r];if(n(e))return e}}function p(n,t,r){for(var e=t;0<=e;e--)if(n(r[e]))return e;return-1}function v(n){return n}function y(t,r){return Object.keys(r).forEach(function(n){t(r[n],n)})}function g(){return Math.random().toString(36).substring(2)}function h(n,t){for(var r="string"==typeof n?n.split("."):n,e=0,u=t;u&&e<r.length;)u=u[r[e++]];return u}function m(n){return 0===(i(n)?n:Object.keys(n)).length}function b(r,e){if(m(e))return r;var u={};return y(function(n,t){u[t]=o(t,e)?f(r[t])&&f(e[t])?b(r[t],e[t]):e[t]:r[t]},r),y(function(n,t){o(t,u)||(u[t]=e[t])},e),u}function O(r,e){var u={};return function(){var n=r.apply(void 0,arguments);if(o(n,u))return u[n];var t=e.apply(void 0,arguments);return u[n]=t}}function k(t){return Object.keys(t).map(function(n){return t[n]})}function j(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t],t)||(n[t]=e[t]),n},{})}function w(n,t){return t.slice(-n)}function A(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t],t)&&(n[t]=e[t]),n},{})}function x(n,t){return n===t?0!==n||0!==t||1/n==1/t:n!=n&&t!=t}function C(n,t){return[t.slice(0,n),t.slice(n,t.length)]}var D=/^\s+/;var L=/\s+$/;function B(r,n){var e=[];return n.filter(function(n){var t=r(n);return-1==e.indexOf(t)&&(e.push(t),!0)})}n.add=t,n.assign=e,n.chain=function(t,r){return"function"==typeof r?function(n){return t(r(n))(n)}:u(t,r)},n.cloneDeep=l,n.camelCase=function(n){var t=n.trim();return 0===t.length?"":1===t.length?t.toLowerCase():/^[a-z\d]+$/.test(t)?t:(t!==t.toLowerCase()&&(t=function(n){for(var t=n,r=!1,e=!1,u=!1,o=0;o<t.length;o++){var i=t[o];r&&/[a-zA-Z]/.test(i)&&i.toUpperCase()===i?(t=t.slice(0,o)+"-"+t.slice(o),u=e,e=!(r=!1),o++):e&&u&&/[a-zA-Z]/.test(i)&&i.toLowerCase()===i?(t=t.slice(0,o-1)+"-"+t.slice(o-1),u=e,r=!(e=!1)):(r=i.toLowerCase()===i,u=e,e=i.toUpperCase()===i)}return t}(t)),t=t.replace(/^[_.\- ]+/,"").toLowerCase().replace(/[_.\- ]+(\w|$)/g,function(n,t){return t.toUpperCase()}))},n.compact=function(e){return i(e)?e.filter(function(n){return null!=n}):Object.keys(e).reduce(function(n,t){var r=e[t];return null!=r&&(n[t]=r),n},{})},n.compose=function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];return t.reduce(function(n,t){return function(){return n(t.apply(void 0,arguments))}})},n.debounce=function(e,u){var o=void 0;return function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];clearTimeout(o),o=setTimeout.apply(void 0,[u,e].concat(t))}},n.defaultTo=function(t){return function(n){return s(n)?t:n}},n.drop=function(n,t){return t.slice(n)},n.dropRight=function(n,t){return t.slice(0,-n)},n.ensureArray=function(n){return i(n)?n:[n]},n.find=d,n.findIndex=function(n,t){for(var r=0;r<t.length;r++)if(n(t[r]))return r;return-1},n.findKey=function(t,r){return d(function(n){return t(r[n])},Object.keys(r))},n.findLast=function(n,t){for(var r=t.length-1;0<=r;r--)if(n(t[r]))return t[r]},n.findLastIndex=function(n,t){return p(n,t.length-1,t)},n.findLastIndexFrom=p,n.flatMap=u,n.flatten=function(n){return u(v,n)},n.forOwn=y,n.fromPairs=function(n){return n.reduce(function(n,t){return n[t[0]]=t[1],n},{})},n.generateRandomId=g,n.generateUniqueId=function n(t){var r=g();return o(r,t)?n(t):r},n.get=h,n.getOr=function(n,t,r){var e=h(t,r);return null!=e?e:n},n.groupBy=function(u,o){return Object.keys(o).reduce(function(n,t){var r=o[t],e=u(r);return n[e]=n[e]||[],n[e].push(r),n},{})},n.groupKeys=function(e,u){return Object.keys(u).reduce(function(n,t){var r=e(t);return n[r]=n[r]||{},n[r][t]=u[t],n},{})},n.hasOwn=o,n.identity=v,n.includes=function(n,t){return-1!=t.indexOf(n)},n.isArray=i,n.isEmpty=m,n.isNil=s,n.isObject=f,n.keyBy=function(r,n){return n.reduce(function(n,t){return n[t[r]]=t,n},{})},n.last=function(n){return 0<n.length?n[n.length-1]:null},n.mapKeys=function(r,e){return Object.keys(e).reduce(function(n,t){return n[r(t)]=e[t],n},{})},n.mapValues=a,n.mapValuesIndexed=function(r,e){return Object.keys(e).reduce(function(n,t){return n[t]=r(e[t],t),n},{})},n.merge=b,n.mergeAll=function(n){if(0===n.length)return{};var t=n[0];return n.slice(1).reduce(function(n,t){return b(n,t)},t)},n.memoize=function(n){return O(v,n)},n.memoizeOne=function(n){var t=!1,r=void 0,e=void 0;return function(){return t&&(0<arguments.length?arguments[0]:void 0)===e?r:(t=!0,e=0<arguments.length?arguments[0]:void 0,r=n.apply(void 0,arguments))}},n.memoizeWith=O,n.noop=function(){},n.numericSortBy=function(t,n){var r="function"==typeof t?t:function(n){return h(t,n)};return(i(n)?[].concat(n):k(n)).sort(function(n,t){return r(n)-r(t)})},n.omit=function(r,n){return j(function(n,t){return-1!=r.indexOf(t)},n)},n.omitBy=function(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t])||(n[t]=e[t]),n},{})},n.omitByIndexed=j,n.once=function(n){var t=!1,r=void 0;return function(){return t?r:(t=!0,r=n.apply(void 0,arguments))}},n.over=function(e){return function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];return e.map(function(n){return n.apply(void 0,t)})}},n.overArgs=function(u,o){return function(){for(var n=arguments.length,r=Array(n),t=0;t<n;t++)r[t]=arguments[t];var e=o.map(function(n,t){return n(r[t])});return u.apply(void 0,e.length<r.length?e.concat(w(r.length-e.length,r)):e)}},n.pick=function(n,r){return n.reduce(function(n,t){return n[t]=r[t],n},{})},n.pickBy=function(r,e){return Object.keys(e).reduce(function(n,t){return r(e[t])&&(n[t]=e[t]),n},{})},n.pickByIndexed=A,n.pickOwn=function(n,r){return n.reduce(function(n,t){return o(t,r)&&(n[t]=r[t]),n},{})},n.reject=function(t,n){return n.filter(function(n){return!t(n)})},n.removeAt=function(n,t){var r=[].concat(t);return r.splice(n,1),r},n.set=function(n,t,r){for(var e=n.split?n.split("."):n,u=e.length,o=l(r),i=o,c=0;c<u;++c){var f=i[e[c]];i=i[e[c]]=c===u-1?t:null==f?{}:f}return o},n.shallowEqual=function(n,t){if(x(n,t))return!0;if("object"!==(void 0===n?"undefined":c(n))||null===n||"object"!==(void 0===t?"undefined":c(t))||null===t)return!1;var r=Object.keys(n);if(r.length!==Object.keys(t).length)return!1;for(var e=0;e<r.length;e++)if(!o(r[e],t)||!x(n[r[e]],t[r[e]]))return!1;return!0},n.sliceDiff=function(n,r){var t=A(function(n,t){return n!==r[t]},n);return m(t)?null:t},n.snakeCase=function(n){var t=n.replace(/[A-Z]|([\-_ ]+)/g,function(n){var t=n.charCodeAt(0);return 64<t&&t<91?"_"+n.toLowerCase():"_"});return"_"===t[0]?t.substr(1):t},n.splitAt=C,n.splitRightWhenAccum=function(n,t,r){for(var e=r.length;0<e;e--){var u=n(r[e-1],t);if(t=u[1],u[0])return C(e-1,r)}return[[],r]},n.spread=function(t){return function(n){return t.apply(void 0,n)}},n.sum=function(n){return n.reduce(t,0)},n.take=function(n,t){return t.slice(0,n)},n.takeLast=w,n.takeRightWhileFrom=function(t,n,r){var e=p(function(n){return!t(n)},n,r);return e===n?[]:r.slice(e+1,n+1)},n.throttle=function(u,n){var o=Date.now()-2*u,i=void 0,c=function(){o=Date.now(),n.apply(void 0,arguments)};return function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];var e=Date.now();e-o<u?(clearTimeout(i),i=setTimeout.apply(void 0,[c,o-e+u].concat(t))):c.apply(void 0,t)}},n.toPairs=function(t){return Object.keys(t).map(function(n){return[n,t[n]]})},n.trailingThrottle=function(u,o){var i=Date.now()-2*u,c=void 0;return function(){for(var n=arguments.length,t=Array(n),r=0;r<n;r++)t[r]=arguments[r];var e=Date.now();e-i<u||(i=Date.now()),clearTimeout(c),c=setTimeout.apply(void 0,[function(){return i=Date.now(),o.apply(void 0,arguments)},i-e+u].concat(t))}},n.trimStart=function(n){return n.replace(D,"")},n.trimEnd=function(n){return n.replace(L,"")},n.uniq=function(n){return B(v,n)},n.uniqBy=B,n.update=function(n,t,r){return[].concat(r.slice(0,n),[t],r.slice(n+1,r.length))},n.values=k,n.without=function(t,n){return n.filter(function(n){return-1==t.indexOf(n)})},Object.defineProperty(n,"__esModule",{value:!0})}); |
{ | ||
"name": "@livechat/data-utils", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Collections utility functions", | ||
@@ -24,3 +24,3 @@ "contributors": [ | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.57.1", | ||
"rollup": "^0.63.5", | ||
"rollup-plugin-babel": "^2.7.1", | ||
@@ -27,0 +27,0 @@ "rollup-plugin-commonjs": "^8.2.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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
68778
2075
0