-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
7 changed files
with
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { applyArrayMethod } from './applyArrayMethod' | ||
|
||
/** | ||
* Replaces an array by a new array with all sub-array elements concatenated into it recursively up to the specified depth. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} [depth] Depth level. | ||
* @return {Object} Returns the updated object. | ||
* @see {@link https://mdn.io/Array.prototype.flat|Array.prototype.flat} for more information. | ||
* @since 2.0.0 | ||
*/ | ||
const flat = applyArrayMethod(Array.prototype.flat, { mutating: false }) | ||
|
||
export { flat } |
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,30 @@ | ||
/* eslint-env jest */ | ||
import { flat } from 'array' | ||
import { immutaTest } from 'test.utils' | ||
describe('array.map', () => { | ||
it('should map elements and flatten', () => { | ||
immutaTest({ | ||
nested: { | ||
prop: [ | ||
[1, 2], | ||
[3, 4], | ||
], | ||
}, | ||
other: {}, | ||
}, ['nested.prop'], (input, path) => { | ||
const output = flat(input, path) | ||
expect(output).toEqual({ | ||
nested: { | ||
prop: [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
], | ||
}, | ||
other: {}, | ||
}) | ||
return output | ||
}) | ||
}) | ||
}) |
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,16 @@ | ||
import { applyArrayMethod } from './applyArrayMethod' | ||
|
||
/** | ||
* Replaces an array mapping each element using a mapping function, then flattening the result into a new array. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {function} callback The function invoked per iteration. | ||
* @return {Object} Returns the updated object. | ||
* @see {@link https://mdn.io/Array.prototype.flatMap|Array.prototype.flatMap} for more information. | ||
* @since 2.0.0 | ||
*/ | ||
const flatMap = applyArrayMethod(Array.prototype.flatMap, { mutating: false }) | ||
|
||
export { flatMap } |
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,30 @@ | ||
/* eslint-env jest */ | ||
import { flatMap } from 'array' | ||
import { immutaTest } from 'test.utils' | ||
describe('array.map', () => { | ||
it('should map elements and flatten', () => { | ||
immutaTest({ | ||
nested: { | ||
prop: [ | ||
{ arr: [1, 2] }, | ||
{ arr: [3, 4] }, | ||
], | ||
}, | ||
other: {}, | ||
}, ['nested.prop'], (input, path) => { | ||
const output = flatMap(input, path, ({ arr }) => arr) | ||
expect(output).toEqual({ | ||
nested: { | ||
prop: [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
], | ||
}, | ||
other: {}, | ||
}) | ||
return output | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ export { | |
copyWithin, | ||
fill, | ||
filter, | ||
flat, | ||
flatMap, | ||
map, | ||
pop, | ||
push, | ||
|