-
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 #175 from dhershman1/dev
v2.1.0
- Loading branch information
Showing
15 changed files
with
1,872 additions
and
2,721 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
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,28 @@ | ||
import _curry2 from '../_internals/_curry2.js' | ||
import take from './take.js' | ||
|
||
/** | ||
* @name dropLast | ||
* @since v2.1.0 | ||
* @function | ||
* @category Array | ||
* @sig Number -> Array -> Array | ||
* @description Returns a list containing all but the last n elements of the given list. | ||
* @param {Number} n The number of values we want to drop | ||
* @param {Array} list The array we want to drop from | ||
* @return {Array} An array with the indicated values removed from the array | ||
* | ||
* @example | ||
* import { dropLast } from 'kyanite' | ||
* | ||
* dropLast(3, [1, 2, 3, 4, 5]) // => [1, 2] | ||
* | ||
* // It's also curried | ||
* | ||
* const d = dropLast(3) | ||
* | ||
* d([1, 2, 3, 4, 5]) // => [1, 2] | ||
*/ | ||
const dropLast = (n, list) => take(n < list.length ? list.length - n : 0, list) | ||
|
||
export default _curry2(dropLast) |
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,28 @@ | ||
import _curry2 from '../_internals/_curry2.js' | ||
import drop from './drop.js' | ||
|
||
/** | ||
* @name takeLast | ||
* @function | ||
* @since v2.1.0 | ||
* @category Array | ||
* @sig Number -> Array -> Array | ||
* @description Returns a new list containing the last n elements of the given list. If n > list.length, returns a list of list.length elements. | ||
* @param {Number} n The index we want our take to start at | ||
* @param {Array|String} list The array we are taking from | ||
* @return {Array|String} A new array of the values taken | ||
* | ||
* @example | ||
* import { takeLast } from 'kyanite' | ||
* | ||
* takeLast(3, [1, 2, 3, 4, 5]) // => [3, 4, 5] | ||
* | ||
* // It's also curried | ||
* | ||
* const t = takeLast(3) | ||
* | ||
* t([1, 2, 3, 4, 5]) // => [3, 4, 5] | ||
*/ | ||
const takeLast = (n, list) => drop(n >= 0 ? list.length - n : 0, list) | ||
|
||
export default _curry2(takeLast) |
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 _curry2 from '../_internals/_curry2.js' | ||
|
||
/** | ||
* @name pick | ||
* @function | ||
* @since v2.1.0 | ||
* @category Object | ||
* @sig [k] -> { k: a } -> { k: a } | ||
* @description Picks only the requested keys from a provided object | ||
* @param {Array} keys The keys we want to pick out of the object | ||
* @param {Object} obj The object to pull the data from | ||
* @return {Object} Returns a new object of only the picked keys provided | ||
* | ||
* @example | ||
* import { pick } from 'kyanite' | ||
* | ||
* pick(['a', 'd'], { a: 1, b: 2, c: 3, d: 4 }) // => { a: 1, d: 4 } | ||
* pick(['a', 'e', 'f'], { a: 3 }) // => { a: 3 } | ||
* | ||
* // Is also curried | ||
* | ||
* const picker = pick(['a', 'd']) | ||
* | ||
* picker({ a: 1, b: 2, c: 3, d: 4 }) // => { a: 1, d: 4 } | ||
*/ | ||
const pick = _curry2(function pick (keys, obj) { | ||
const result = {} | ||
let idx = 0 | ||
|
||
while (idx < keys.length) { | ||
if (keys[idx] in obj) { | ||
result[keys[idx]] = obj[keys[idx]] | ||
} | ||
|
||
idx += 1 | ||
} | ||
|
||
return result | ||
}) | ||
|
||
export default pick |
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,30 @@ | ||
import dropLast from '../../src/array/dropLast.js' | ||
import test from 'tape' | ||
|
||
test('dropLast -- Handles dropping values', t => { | ||
const results = dropLast(3, [1, 2, 3, 4, 5]) | ||
|
||
t.same(results, [1, 2]) | ||
t.end() | ||
}) | ||
|
||
test('dropLast -- Handles dropping values when number is larger than length', t => { | ||
const results = dropLast(6, [1, 2, 3, 4, 5]) | ||
|
||
t.same(results, []) | ||
t.end() | ||
}) | ||
|
||
test('dropLast -- Handles invalid data sets', t => { | ||
const results = dropLast(3, []) | ||
|
||
t.same(results, []) | ||
t.end() | ||
}) | ||
|
||
test('dropLast -- Is curried', t => { | ||
const d = dropLast(3) | ||
|
||
t.same(d([1, 2, 3, 4, 5]), [1, 2]) | ||
t.end() | ||
}) |
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,38 @@ | ||
import takeLast from '../../src/array/takeLast.js' | ||
import test from 'tape' | ||
|
||
test('takeLast -- Handles taking values from an array', t => { | ||
const results = takeLast(3, [1, 2, 3, 4, 5]) | ||
|
||
t.same(results, [3, 4, 5]) | ||
t.end() | ||
}) | ||
|
||
test('takeLast -- Handles values if the number is bigger than the length', t => { | ||
const results = takeLast(7, [1, 2, 3, 4, 5]) | ||
|
||
t.same(results, [1, 2, 3, 4, 5]) | ||
t.end() | ||
}) | ||
|
||
test('takeLast -- Handles taking values from a string', t => { | ||
const results = takeLast(3, '12345') | ||
|
||
t.same(results, '345') | ||
t.end() | ||
}) | ||
|
||
test('takeLast -- Handles empty arrays passed in', t => { | ||
const results = takeLast(3, []) | ||
|
||
t.same(results, []) | ||
t.end() | ||
}) | ||
|
||
test('takeLast -- Is curried', t => { | ||
const ta = takeLast(3) | ||
|
||
t.same(ta([1, 2, 3, 4, 5]), [3, 4, 5], 'curried result returned [3, 4, 5]') | ||
t.same(ta([]), [], 'curried result returned an empty array') | ||
t.end() | ||
}) |
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,34 @@ | ||
import test from 'tape' | ||
import pick from '../../src/object/pick.js' | ||
|
||
test('pick -- picks the requested keys', t => { | ||
const results = pick(['a', 'd'], { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}) | ||
|
||
t.same(results, { a: 1, d: 4 }) | ||
t.end() | ||
}) | ||
|
||
test('pick -- picks only the requested keys', t => { | ||
const results = pick(['a', 'e', 'f'], { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4 | ||
}) | ||
|
||
t.same(results, { a: 1 }) | ||
t.end() | ||
}) | ||
|
||
test('pick -- is curried', t => { | ||
const picker = pick(['a', 'd']) | ||
|
||
t.same(picker({ a: 1, b: 2, c: 3, d: 4 }), { a: 1, d: 4 }) | ||
t.same(picker({ a: 1, b: 2, c: 3 }), { a: 1 }) | ||
t.end() | ||
}) |
Oops, something went wrong.