-
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.
* ✨ Add array.filter * ✨ Add array.map * ✨ Add array.pop * 💡 Add array.map JSDoc * ✨ Add array.shift * ✨ Add array.sort * 💡 Update array functions JSDoc * 🚚 Move math functions to lang * ✅ Update array tests titles * ✅ Update tests titles to have namespace * 🔥 Remove set, update and unset aliases from object * ♻️ Simplify namespaces indexes * ♻️ Run number functions operands into Number * 💡 Replace/remove lodash mentions * ✨ Add string.concat * ♻️ Use convertStringMethod in string.replace * 🐛 Avoid name conflicts in flow * 🚨 fix linter error in flow generated files * 🚨 fix linter error in flow generated files * ✨ Add string.padEnd * ✨ Add string.padStart * ✨ Add string.slice * ✨ Add string.substr * ✨ Add string.substring * ✨ Add toLocaleLowerCase * ✨ Add string.toLocaleUpperCase * ✨ Add string.toLowerCase and string.toUpperCase * ✨ Add string.trim * ✨ Add string.trimLeft and string.trimRight * ✅ fix tests
- Loading branch information
Showing
95 changed files
with
904 additions
and
185 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,18 @@ | ||
import { convertArrayMethod } from './convertArrayMethod' | ||
|
||
/** | ||
* Replaces by an array of elements <code>predicate</code> returns truthy for. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {function} predicate The function invoked per iteration. | ||
* @return {Object} Returns the updated object. | ||
* @example filter({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop', v => v % 2) // => { nested: { prop: [1, 3] } } | ||
* @see {@link https://mdn.io/Array.prototype.filter|Array.prototype.filter} for more information. | ||
* @since 1.0.0 | ||
* @flow | ||
*/ | ||
const filter = convertArrayMethod('filter', false) | ||
|
||
export { filter } |
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,36 @@ | ||
/* eslint-env jest */ | ||
import { filter } from 'array' | ||
import { immutaTest } from 'test.utils' | ||
|
||
describe('array.filter', () => { | ||
|
||
it('should filter elements', () => { | ||
immutaTest((input, path) => { | ||
const output = filter(input, path, v => v % 2 === 0) | ||
expect(output).toEqual({ | ||
nested: { prop: [2, 4] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: [1, 2, 3, 4] }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
|
||
it('should replace deep undefined with array', () => { | ||
immutaTest((input, path) => { | ||
const output = filter(input, path, () => true) | ||
expect(output).toEqual({ nested: { prop: [] } }) | ||
return output | ||
}, undefined, 'nested.prop') | ||
}) | ||
|
||
it('should wrap value in an array', () => { | ||
immutaTest((input, path) => { | ||
const output = filter(input, path, () => true) | ||
expect(output).toEqual({ nested: { prop: [2] } }) | ||
return output | ||
}, { nested: { prop: 2 } }, 'nested.prop') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import { concat } from './concat' | ||
import { fill } from './fill' | ||
import { push } from './push' | ||
import { reverse } from './reverse' | ||
import { slice } from './slice' | ||
import { splice } from './splice' | ||
import { unshift } from './unshift' | ||
|
||
/** | ||
* Array functions. | ||
* @namespace array | ||
* @since 0.1.6 | ||
*/ | ||
export { | ||
concat, | ||
fill, | ||
push, | ||
reverse, | ||
slice, | ||
splice, | ||
unshift, | ||
} | ||
|
||
export { filter } from './filter' | ||
export { concat } from './concat' | ||
export { fill } from './fill' | ||
export { map } from './map' | ||
export { pop } from './pop' | ||
export { push } from './push' | ||
export { reverse } from './reverse' | ||
export { shift } from './shift' | ||
export { slice } from './slice' | ||
export { splice } from './splice' | ||
export { sort } from './sort' | ||
export { unshift } from './unshift' |
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,18 @@ | ||
import { convertArrayMethod } from './convertArrayMethod' | ||
|
||
/** | ||
* Replaces by an array of values by running each element in the former collection thru callback. | ||
* @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. | ||
* @example map({ nested: { prop: [1, 2, 3] } }, 'nested.prop', v => v * 2) // => { nested: { prop: [2, 4, 6] } } | ||
* @see {@link https://mdn.io/Array.prototype.map|Array.prototype.map} for more information. | ||
* @since 1.0.0 | ||
* @flow | ||
*/ | ||
const map = convertArrayMethod('map', false) | ||
|
||
export { map } |
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,36 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { map } from 'array' | ||
|
||
describe('array.map', () => { | ||
|
||
it('should map elements', () => { | ||
immutaTest((input, path) => { | ||
const output = map(input, path, v => v * v) | ||
expect(output).toEqual({ | ||
nested: { prop: [1, 4, 9, 16] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: [1, 2, 3, 4] }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
|
||
it('should replace deep undefined with array', () => { | ||
immutaTest((input, path) => { | ||
const output = map(input, path, v => v) | ||
expect(output).toEqual({ nested: { prop: [] } }) | ||
return output | ||
}, undefined, 'nested.prop') | ||
}) | ||
|
||
it('should wrap value in an array', () => { | ||
immutaTest((input, path) => { | ||
const output = map(input, path, v => v * v) | ||
expect(output).toEqual({ nested: { prop: [4] } }) | ||
return output | ||
}, { nested: { prop: 2 } }, 'nested.prop') | ||
}) | ||
}) |
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 @@ | ||
import { convertArrayMethod } from './convertArrayMethod' | ||
|
||
/** | ||
* Replaces by an array of elements with last element removed. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @return {Object} Returns the updated object. | ||
* @example pop({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [1, 2, 3] } } | ||
* @see {@link https://mdn.io/Array.prototype.pop|Array.prototype.pop} for more information. | ||
* @since 1.0.0 | ||
* @flow | ||
*/ | ||
const pop = convertArrayMethod('pop') | ||
|
||
export { pop } |
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,42 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { pop } from 'array' | ||
|
||
describe('array.pop', () => { | ||
|
||
it('should remove last element', () => { | ||
immutaTest((input, path) => { | ||
const output = pop(input, path) | ||
expect(output).toEqual({ | ||
nested: { prop: [1, 2, 3] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: [1, 2, 3, 4] }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
|
||
it('should replace deep undefined with array', () => { | ||
immutaTest((input, path) => { | ||
const output = pop(input, path, () => true) | ||
expect(output).toEqual({ nested: { prop: [] } }) | ||
return output | ||
}, undefined, 'nested.prop') | ||
}) | ||
|
||
it('should wrap value in array and remove it', () => { | ||
immutaTest((input, path) => { | ||
const output = pop(input, path) | ||
expect(output).toEqual({ | ||
nested: { prop: [] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: 123 }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
}) |
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,17 @@ | ||
import { convertArrayMethod } from './convertArrayMethod' | ||
|
||
/** | ||
* Replaces by an array of elements with first element removed. | ||
* @function | ||
* @memberof array | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @return {Object} Returns the updated object. | ||
* @example shift({ nested: { prop: [1, 2, 3, 4] } }, 'nested.prop') // => { nested: { prop: [2, 3, 4] } } | ||
* @see {@link https://mdn.io/Array.prototype.shift|Array.prototype.shift} for more information. | ||
* @since 1.0.0 | ||
* @flow | ||
*/ | ||
const shift = convertArrayMethod('shift') | ||
|
||
export { shift } |
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,42 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { shift } from 'array' | ||
|
||
describe('array.shift', () => { | ||
|
||
it('should remove first element', () => { | ||
immutaTest((input, path) => { | ||
const output = shift(input, path) | ||
expect(output).toEqual({ | ||
nested: { prop: [2, 3, 4] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: [1, 2, 3, 4] }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
|
||
it('should replace deep undefined with array', () => { | ||
immutaTest((input, path) => { | ||
const output = shift(input, path, () => true) | ||
expect(output).toEqual({ nested: { prop: [] } }) | ||
return output | ||
}, undefined, 'nested.prop') | ||
}) | ||
|
||
it('should wrap value in array and remove it', () => { | ||
immutaTest((input, path) => { | ||
const output = shift(input, path) | ||
expect(output).toEqual({ | ||
nested: { prop: [] }, | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: 123 }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
}) |
Oops, something went wrong.