Travis build: 875
This commit is contained in:
61
README.md
61
README.md
@ -363,6 +363,7 @@ _30s.average(1, 2, 3);
|
|||||||
* [`bindAll`](#bindall)
|
* [`bindAll`](#bindall)
|
||||||
* [`deepClone`](#deepclone)
|
* [`deepClone`](#deepclone)
|
||||||
* [`deepFreeze`](#deepfreeze)
|
* [`deepFreeze`](#deepfreeze)
|
||||||
|
* [`deepMapKeys`](#deepmapkeys-)
|
||||||
* [`defaults`](#defaults)
|
* [`defaults`](#defaults)
|
||||||
* [`dig`](#dig)
|
* [`dig`](#dig)
|
||||||
* [`equals`](#equals-)
|
* [`equals`](#equals-)
|
||||||
@ -6707,6 +6708,66 @@ o[1][0] = 4; // not allowed as well
|
|||||||
|
|
||||||
<br>[⬆ Back to top](#contents)
|
<br>[⬆ Back to top](#contents)
|
||||||
|
|
||||||
|
### deepMapKeys 
|
||||||
|
|
||||||
|
Deep maps an object keys.
|
||||||
|
|
||||||
|
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
|
||||||
|
|
||||||
|
Use `Object.keys(obj)` to iterate over the object's keys.
|
||||||
|
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const deepMapKeys = (obj, f) =>
|
||||||
|
Array.isArray(obj)
|
||||||
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
|
: typeof obj === 'object'
|
||||||
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
|
const val = obj[current];
|
||||||
|
acc[f(current)] =
|
||||||
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
: obj;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
const obj = {
|
||||||
|
foo: '1',
|
||||||
|
nested: {
|
||||||
|
child: {
|
||||||
|
withArray: [
|
||||||
|
{
|
||||||
|
grandChild: ['hello']
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"FOO":"1",
|
||||||
|
"NESTED":{
|
||||||
|
"CHILD":{
|
||||||
|
"WITHARRAY":[
|
||||||
|
{
|
||||||
|
"GRANDCHILD":[ 'hello' ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#contents)
|
||||||
|
|
||||||
### defaults
|
### defaults
|
||||||
|
|
||||||
Assigns default values for all properties in an object that are `undefined`.
|
Assigns default values for all properties in an object that are `undefined`.
|
||||||
|
|||||||
@ -378,6 +378,7 @@
|
|||||||
</h4><ul><li><a tags="object,function,intermediate" href="./object#bindall">bindAll</a></li>
|
</h4><ul><li><a tags="object,function,intermediate" href="./object#bindall">bindAll</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#deepclone">deepClone</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#deepclone">deepClone</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#deepfreeze">deepFreeze</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#deepfreeze">deepFreeze</a></li>
|
||||||
|
<li><a tags="object,recursion,advanced" href="./object#deepmapkeys">deepMapKeys</a></li>
|
||||||
<li><a tags="object,intermediate" href="./object#defaults">defaults</a></li>
|
<li><a tags="object,intermediate" href="./object#defaults">defaults</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#dig">dig</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#dig">dig</a></li>
|
||||||
<li><a tags="object,array,type,advanced" href="./object#equals">equals</a></li>
|
<li><a tags="object,array,type,advanced" href="./object#equals">equals</a></li>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -378,6 +378,7 @@
|
|||||||
</h4><ul><li><a tags="object,function,intermediate" href="./object#bindall">bindAll</a></li>
|
</h4><ul><li><a tags="object,function,intermediate" href="./object#bindall">bindAll</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#deepclone">deepClone</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#deepclone">deepClone</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#deepfreeze">deepFreeze</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#deepfreeze">deepFreeze</a></li>
|
||||||
|
<li><a tags="object,recursion,advanced" href="./object#deepmapkeys">deepMapKeys</a></li>
|
||||||
<li><a tags="object,intermediate" href="./object#defaults">defaults</a></li>
|
<li><a tags="object,intermediate" href="./object#defaults">defaults</a></li>
|
||||||
<li><a tags="object,recursion,intermediate" href="./object#dig">dig</a></li>
|
<li><a tags="object,recursion,intermediate" href="./object#dig">dig</a></li>
|
||||||
<li><a tags="object,array,type,advanced" href="./object#equals">equals</a></li>
|
<li><a tags="object,array,type,advanced" href="./object#equals">equals</a></li>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -8,35 +8,33 @@ Use `Object.keys(obj)` to iterate over the object's keys.
|
|||||||
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const deepMapKeys = (obj, f) => (
|
const deepMapKeys = (obj, f) =>
|
||||||
Array.isArray(obj)
|
Array.isArray(obj)
|
||||||
? obj.map(val => deepMapKeys(val, f))
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
: (typeof obj === 'object')
|
: typeof obj === 'object'
|
||||||
? Object.keys(obj).reduce((acc, current) => {
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
const val = obj[current];
|
const val = obj[current];
|
||||||
acc[f(current)] = (val !== null && typeof val === 'object')
|
acc[f(current)] =
|
||||||
? deepMapKeys(val, f)
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
: acc[f(current)] = val;
|
return acc;
|
||||||
return acc;
|
}, {})
|
||||||
}, {})
|
: obj;
|
||||||
: obj
|
|
||||||
);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const obj = {
|
const obj = {
|
||||||
foo:'1',
|
foo: '1',
|
||||||
nested:{
|
nested: {
|
||||||
child:{
|
child: {
|
||||||
withArray:[
|
withArray: [
|
||||||
{
|
{
|
||||||
grandChild:[ 'hello' ]
|
grandChild: ['hello']
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const upperKeysObj = deepMapKeys(obj, (key) => key.toUpperCase());
|
const upperKeysObj = deepMapKeys(obj, key => key.toUpperCase());
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
"FOO":"1",
|
"FOO":"1",
|
||||||
|
|||||||
13
test/_30s.js
13
test/_30s.js
@ -224,6 +224,17 @@ const deepFreeze = obj =>
|
|||||||
prop =>
|
prop =>
|
||||||
!(obj[prop] instanceof Object) || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
|
!(obj[prop] instanceof Object) || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
|
||||||
) || Object.freeze(obj);
|
) || Object.freeze(obj);
|
||||||
|
const deepMapKeys = (obj, f) =>
|
||||||
|
Array.isArray(obj)
|
||||||
|
? obj.map(val => deepMapKeys(val, f))
|
||||||
|
: typeof obj === 'object'
|
||||||
|
? Object.keys(obj).reduce((acc, current) => {
|
||||||
|
const val = obj[current];
|
||||||
|
acc[f(current)] =
|
||||||
|
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||||
|
return acc;
|
||||||
|
}, {})
|
||||||
|
: obj;
|
||||||
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
||||||
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
const defer = (fn, ...args) => setTimeout(fn, 1, ...args);
|
||||||
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
const degreesToRads = deg => (deg * Math.PI) / 180.0;
|
||||||
@ -1492,4 +1503,4 @@ const speechSynthesis = message => {
|
|||||||
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
const squareSum = (...args) => args.reduce((squareSum, number) => squareSum + Math.pow(number, 2), 0);
|
||||||
|
|
||||||
|
|
||||||
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
|
module.exports = {CSVToArray,CSVToJSON,JSONToFile,JSONtoCSV,RGBToHex,URLJoin,UUIDGeneratorBrowser,UUIDGeneratorNode,all,allEqual,any,approximatelyEqual,arrayToCSV,arrayToHtmlList,ary,atob,attempt,average,averageBy,bifurcate,bifurcateBy,bind,bindAll,bindKey,binomialCoefficient,bottomVisible,btoa,byteSize,call,capitalize,capitalizeEveryWord,castArray,chainAsync,chunk,clampNumber,cloneRegExp,coalesce,coalesceFactory,collectInto,colorize,compact,compose,composeRight,converge,copyToClipboard,countBy,countOccurrences,counter,createElement,createEventHub,currentURL,curry,dayOfYear,debounce,decapitalize,deepClone,deepFlatten,deepFreeze,deepMapKeys,defaults,defer,degreesToRads,delay,detectDeviceType,difference,differenceBy,differenceWith,dig,digitize,distance,drop,dropRight,dropRightWhile,dropWhile,elementContains,elementIsVisibleInViewport,elo,equals,escapeHTML,escapeRegExp,everyNth,extendHex,factorial,fibonacci,filterFalsy,filterNonUnique,filterNonUniqueBy,findKey,findLast,findLastIndex,findLastKey,flatten,flattenObject,flip,forEachRight,forOwn,forOwnRight,formatDuration,fromCamelCase,functionName,functions,gcd,geometricProgression,get,getColonTimeFromDate,getDaysDiffBetweenDates,getImages,getMeridiemSuffixOfInteger,getScrollPosition,getStyle,getType,getURLParameters,groupBy,hammingDistance,hasClass,hasFlags,hashBrowser,hashNode,head,hexToRGB,hide,httpGet,httpPost,httpsRedirect,hz,inRange,indentString,indexOfAll,initial,initialize2DArray,initializeArrayWithRange,initializeArrayWithRangeRight,initializeArrayWithValues,initializeNDArray,insertAfter,insertBefore,intersection,intersectionBy,intersectionWith,invertKeyValues,is,isAbsoluteURL,isAfterDate,isAnagram,isArrayLike,isBeforeDate,isBoolean,isBrowser,isBrowserTabFocused,isDivisible,isDuplexStream,isEmpty,isEven,isFunction,isLowerCase,isNegativeZero,isNil,isNull,isNumber,isObject,isObjectLike,isPlainObject,isPrime,isPrimitive,isPromiseLike,isReadableStream,isSameDate,isSorted,isStream,isString,isSymbol,isTravisCI,isUndefined,isUpperCase,isValidJSON,isWritableStream,join,last,lcm,longestItem,lowercaseKeys,luhnCheck,mapKeys,mapObject,mapString,mapValues,mask,matches,matchesWith,maxBy,maxDate,maxN,median,memoize,merge,midpoint,minBy,minDate,minN,mostPerformant,negate,nest,nodeListToArray,none,nthArg,nthElement,objectFromPairs,objectToPairs,observeMutations,off,offset,omit,omitBy,on,onUserInputChange,once,orderBy,over,overArgs,pad,palindrome,parseCookie,partial,partialRight,partition,percentile,permutations,pick,pickBy,pipeAsyncFunctions,pipeFunctions,pluralize,powerset,prefix,prettyBytes,primes,promisify,pull,pullAtIndex,pullAtValue,pullBy,radsToDegrees,randomHexColorCode,randomIntArrayInRange,randomIntegerInRange,randomNumberInRange,readFileLines,rearg,recordAnimationFrames,redirect,reduceSuccessive,reduceWhich,reducedFilter,reject,remove,removeNonASCII,renameKeys,reverseString,round,runAsync,runPromisesInSeries,sample,sampleSize,scrollToTop,sdbm,serializeCookie,setStyle,shallowClone,shank,show,shuffle,similarity,size,sleep,smoothScroll,sortCharactersInString,sortedIndex,sortedIndexBy,sortedLastIndex,sortedLastIndexBy,splitLines,spreadOver,stableSort,standardDeviation,stringPermutations,stripHTMLTags,sum,sumBy,sumPower,symmetricDifference,symmetricDifferenceBy,symmetricDifferenceWith,tail,take,takeRight,takeRightWhile,takeWhile,throttle,timeTaken,times,toCamelCase,toCurrency,toDecimalMark,toHash,toKebabCase,toOrdinalSuffix,toSafeInteger,toSnakeCase,toTitleCase,toggleClass,tomorrow,transform,triggerEvent,truncateString,truthCheckCollection,unary,uncurry,unescapeHTML,unflattenObject,unfold,union,unionBy,unionWith,uniqueElements,uniqueElementsBy,uniqueElementsByRight,uniqueSymmetricDifference,untildify,unzip,unzipWith,validateNumber,when,without,words,xProd,yesNo,zip,zipObject,zipWith,JSONToDate,binarySearch,celsiusToFahrenheit,cleanObj,collatz,countVowels,factors,fahrenheitToCelsius,fibonacciCountUntilNum,fibonacciUntilNum,heronArea,howManyTimes,httpDelete,httpPut,isArmstrongNumber,isSimilar,kmphToMph,levenshteinDistance,mphToKmph,pipeLog,quickSort,removeVowels,solveRPN,speechSynthesis,squareSum}
|
||||||
Reference in New Issue
Block a user