-
Notifications
You must be signed in to change notification settings - Fork 3
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 #176 from dhershman1/dev
v3.0.0
- Loading branch information
Showing
31 changed files
with
1,223 additions
and
655 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,41 @@ | ||
import _curry3 from '../_internals/_curry3.js' | ||
|
||
/** | ||
* @name adjust | ||
* @since v3.0.0 | ||
* @function | ||
* @category Array | ||
* @sig Number -> (a -> a) -> [a] -> [a] | ||
* @description Applies a function to the value at the given index of an array, returning a new copy of the array with the element at the given index replaced with the result of the function application. | ||
* @param {Number} idx The index the value we want to change is at | ||
* @param {Function} fn The function to apply | ||
* @param {Array} list The array of data | ||
* @return {Array} A copy of the supplied array with the element at index `idx` replaced with the value returned by applying `fn` to the existing element. | ||
* @example | ||
* import { adjust, inc, toUpper } from 'kyanite' | ||
* | ||
* adjust(1, inc, [0, 1, 2, 3]) // => [0, 2, 2, 3] | ||
* adjust(1, toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c'] | ||
* | ||
* // adjust can also be curried | ||
* | ||
* const fn = adjust(1) | ||
* | ||
* fn(toUpper, ['a', 'b', 'c']) // => ['a', 'B', 'c] | ||
*/ | ||
const adjust = (idx, fn, list) => { | ||
const len = list.length | ||
|
||
if (idx >= len || idx < -len) { | ||
return list | ||
} | ||
|
||
const _idx = (len + idx) % len | ||
const _list = [...list] | ||
|
||
_list[_idx] = fn(_list[_idx]) | ||
|
||
return _list | ||
} | ||
|
||
export default _curry3(adjust) |
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,36 @@ | ||
/** | ||
* @name keys | ||
* @function | ||
* @since v3.0.0 | ||
* @category Object | ||
* @sig { k: v } -> [k] | ||
* @description Returns a list of all the own properties of an object | ||
* @param {Object} obj The object we want to pull the keys from | ||
* @return {Array} Returns an array of keys from the provided object | ||
* | ||
* @example | ||
* import { keys } from 'kyanite' | ||
* | ||
* keys({ a: 1, b: 2, c: 3, d: { x: 100, y: 200 } }) // => ['a', 'b', 'c', 'd'] | ||
*/ | ||
const keys = obj => { | ||
if (typeof Object.keys === 'function') { | ||
return Object(obj) !== obj ? [] : Object.keys(obj) | ||
} | ||
|
||
if (Object(obj) !== obj) { | ||
return [] | ||
} | ||
|
||
const ks = [] | ||
|
||
for (const prop in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, prop) && prop !== 'length') { | ||
ks.push(prop) | ||
} | ||
} | ||
|
||
return ks | ||
} | ||
|
||
export default keys |
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
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
Oops, something went wrong.