-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from dictor93/feat/lodash
Feature. Lodash functions migration
- Loading branch information
Showing
25 changed files
with
568 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
/** | ||
* Assigns the object properties from the sources | ||
* | ||
* @param {object} object | ||
* @param {...(object|Function)} rest | ||
* @returns {object} | ||
*/ | ||
const assignInWith = (object, ...rest) => { | ||
if (rest.length === 0) return object | ||
const customizer = rest.pop() | ||
if (typeof customizer !== 'function') return object | ||
if (rest.length === 0) return object | ||
rest.forEach((source) => { | ||
for (const key in source) { | ||
const value = customizer ? customizer(object[key], source[key], key, object, source) : undefined | ||
object[key] = value === undefined ? source[key] : value | ||
} | ||
}) | ||
return object | ||
} | ||
|
||
module.exports = assignInWith |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
const isObject = require('./isObject') | ||
|
||
/** | ||
* Clone the object | ||
* | ||
* @param {any} obj | ||
* @returns {any} | ||
*/ | ||
const clone = (obj) => { | ||
if (Array.isArray(obj)) { | ||
return obj.slice() | ||
} | ||
if (isObject(obj)) { | ||
return Object.assign({}, obj) | ||
} | ||
return obj | ||
} | ||
|
||
module.exports = clone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
/** | ||
* Returns the index of the last element in the array that satisfies the provided testing function. | ||
* | ||
* @param {Array} array | ||
* @param {Function} predicate | ||
* @param {number} fromIndex | ||
* @returns {number} | ||
*/ | ||
const findLastIndex = (array, predicate, fromIndex) => { | ||
let index = fromIndex || array.length - 1 | ||
while (index >= 0) { | ||
if (predicate(array[index])) { | ||
return index | ||
} | ||
index-- | ||
} | ||
return -1 | ||
} | ||
|
||
module.exports = findLastIndex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
/** | ||
* Checks if `object` is a match with `source`. | ||
* | ||
* @param {Object} object The object to inspect. | ||
* @param {Object} source The object of property values to match. | ||
* @returns {boolean} Returns `true` if `object` is a match, else `false`. | ||
*/ | ||
const isMatch = (object, source) => { | ||
if (object === source) return true | ||
if (!object) return false | ||
if (!source) return true | ||
if (typeof source === 'string') { | ||
if (typeof object === 'string') { | ||
return object.slice(0, source.length) === source | ||
} | ||
return false | ||
} | ||
if (Object.keys(source)?.length) { | ||
for (const key in source) { | ||
if (!isMatch(object[key], source[key])) return false | ||
} | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
module.exports = isMatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* | ||
* @param {*} value The value to check | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false` | ||
*/ | ||
const isObjectLike = (value) => { | ||
return typeof value === 'object' && value !== null | ||
} | ||
|
||
module.exports = isObjectLike |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict' | ||
|
||
/** | ||
* Returns the mean of an array of numbers. | ||
* | ||
* @param {Array<number>} arr | ||
* @returns {number} | ||
*/ | ||
const mean = (arr) => { | ||
const length = arr ? arr.length : 0 | ||
if (length === 0) { | ||
return NaN | ||
} | ||
return arr.reduce((acc, val) => +acc + +val, 0) / arr.length | ||
} | ||
|
||
module.exports = mean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict' | ||
|
||
/** | ||
* Returns the union of the given arrays. | ||
* | ||
* @param {...Array} arrays The arrays to inspect. | ||
* @returns {Array} Returns the new array of combined values. | ||
*/ | ||
const union = (...arrays) => { | ||
if (arrays.length === 0) return [] | ||
const result = [] | ||
arrays.forEach((array) => { | ||
Array.isArray(array) && array.forEach((value) => { | ||
if (!result.includes(value)) { | ||
result.push(value) | ||
} | ||
}) | ||
}) | ||
return result | ||
} | ||
|
||
module.exports = union |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
/** | ||
* Returns a new array with unique values, using a comparator function. | ||
* | ||
* @param {Array} array The array to inspect. | ||
* @param {Function} comparator The comparator function. | ||
* @returns {Array} Returns the new array of filtered values. | ||
*/ | ||
const uniqWith = (array, comparator) => { | ||
if (!Array.isArray(array)) { | ||
return [] | ||
} | ||
if (typeof comparator !== 'function') { | ||
return array | ||
} | ||
return array.filter((item, index) => { | ||
return array.findIndex((other) => comparator(item, other)) === index | ||
}) | ||
} | ||
|
||
module.exports = uniqWith |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const pathToArray = require('./util/pathToArray') | ||
|
||
/** | ||
* Update the object with the updater by path | ||
* | ||
* @param {object} object | ||
* @param {string} path | ||
* @param {function} updater | ||
*/ | ||
const update = (object, path, updater) => { | ||
if (!object) return | ||
if (!path) return | ||
if (!updater) return | ||
const pathArray = pathToArray(path) | ||
pathArray.reduce((parent, key, index) => { | ||
if (index === pathArray.length - 1) { | ||
parent[key] = updater(parent[key]) | ||
return parent | ||
} | ||
if (!parent[key]) { | ||
parent[key] = {} | ||
} | ||
return parent[key] | ||
}, object) | ||
} | ||
|
||
module.exports = update |
Oops, something went wrong.