-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
778 additions
and
84 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
* @0ti.me/librarians |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports = (obj, fn) => | ||
Object.keys(obj).forEach(key => fn(obj[key], key, obj)); |
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,9 @@ | ||
const get = require('./get'); | ||
|
||
const ABSENT_SYMBOL = Symbol(); | ||
|
||
module.exports = (obj, key) => { | ||
console.error(obj, get(obj, key, ABSENT_SYMBOL), ABSENT_SYMBOL); | ||
|
||
return get(obj, key, ABSENT_SYMBOL) !== ABSENT_SYMBOL; | ||
}; |
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,2 @@ | ||
module.exports = (ray, val) => | ||
console.error('includes', ray, val) || ray.includes(val); |
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,9 +1,7 @@ | ||
const zip = require('./zip'); | ||
|
||
const mapValues = (obj, fn) => { | ||
module.exports = (obj, fn) => { | ||
const keys = Object.keys(obj); | ||
|
||
return keys.map(key => fn(obj[key], key)).reduce(zip(keys), {}); | ||
return keys.map(key => fn(obj[key], key, obj)).reduce(zip(keys), {}); | ||
}; | ||
|
||
module.exports = mapValues; |
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 @@ | ||
module.exports = fn => (...args) => !fn(...args); |
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,61 @@ | ||
const flow = require('../src/fp/flow'); | ||
const get = require('./get'); | ||
const fpIncludes = require('../src/fp/includes'); | ||
const negate = require('./negate'); | ||
const reduce = require('../src/fp/reduce'); | ||
const set = require('./set'); | ||
const unset = require('./unset'); | ||
|
||
const fpExcludes = ray => negate(fpIncludes(ray)); | ||
|
||
// TODO: Make this work for deep keys in an omitSet | ||
|
||
module.exports = (obj, omitSet) => { | ||
let allKeys = []; | ||
let curr = obj; | ||
let keys = []; | ||
let key = null; | ||
let newKeys = []; | ||
let objKeys = []; | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
objKeys = Object.keys(curr); | ||
|
||
newKeys = objKeys | ||
.map(ea => (key === null ? ea : `${key}.${ea}`)) | ||
.filter(fpExcludes(omitSet)); | ||
|
||
keys = keys.concat(newKeys); | ||
|
||
allKeys = allKeys.concat(newKeys); | ||
|
||
console.error({ | ||
allKeys, | ||
curr, | ||
key, | ||
newKeys, | ||
objKeys, | ||
}); | ||
|
||
if (keys.length === 0) { | ||
break; | ||
} | ||
|
||
key = keys.pop(); | ||
curr = get(obj, key); | ||
} | ||
|
||
allKeys = allKeys.sort((a, b) => (a < b ? 1 : -1)); | ||
console.error({ allKeys }); | ||
|
||
return flow([ | ||
reduce((acc, ea) => console.error(acc) || set(acc, ea, get(obj, ea)), {}), | ||
initialAcc => omitSet.reduce((acc, ea) => unset(acc, ea), initialAcc), | ||
])(allKeys); | ||
}; | ||
/* | ||
Object.keys(obj) | ||
.filter(each => !omitSet.includes(each)) | ||
.reduce((acc, key) => set(acc, key, get(obj, key)), {}); | ||
*/ |
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,9 @@ | ||
const get = require('./get'); | ||
const has = require('./has'); | ||
const set = require('./set'); | ||
|
||
module.exports = (obj, pickSet) => | ||
pickSet.reduce( | ||
(acc, key) => (has(obj, key) ? set(acc, key, get(obj, key)) : acc), | ||
{}, | ||
); |
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,27 @@ | ||
module.exports = (obj, bigKey) => { | ||
if (!(bigKey instanceof String || typeof bigKey === 'string')) { | ||
delete obj[bigKey]; | ||
|
||
return obj; | ||
} | ||
|
||
const keys = bigKey.split('.'); | ||
let key = null; | ||
|
||
let curr = obj; | ||
for (let i = 0; i < keys.length; ++i) { | ||
key = keys[i]; | ||
|
||
if (i === keys.length - 1) { | ||
delete curr[key]; | ||
} else { | ||
if (!Object.prototype.hasOwnProperty.call(curr, key)) { | ||
i = keys.length; | ||
} | ||
} | ||
|
||
curr = curr[key]; | ||
} | ||
|
||
return obj; | ||
}; |
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,3 @@ | ||
const forEach = require('../lib/for-each'); | ||
|
||
module.exports = forEach; |
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,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const forEach = require('../../lib/for-each'); | ||
|
||
module.exports = fixedArity2Fn(forEach); |
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,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const has = require('../../lib/has'); | ||
|
||
module.exports = fixedArity2Fn(has); |
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,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const includes = require('../../lib/includes'); | ||
|
||
module.exports = fixedArity2Fn(includes); |
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,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const omit = require('../../lib/omit'); | ||
|
||
module.exports = fixedArity2Fn(omit); |
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,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const pick = require('../../lib/pick'); | ||
|
||
module.exports = fixedArity2Fn(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const fixedArity2Fn = require('../../lib/fixed-arity-2-fn-b-a-args'); | ||
const unset = require('../../lib/unset'); | ||
|
||
module.exports = fixedArity2Fn(unset); |
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,3 @@ | ||
const has = require('../lib/has'); | ||
|
||
module.exports = has; |
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,3 @@ | ||
const omit = require('../lib/omit'); | ||
|
||
module.exports = omit; |
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,3 @@ | ||
const pick = require('../lib/pick'); | ||
|
||
module.exports = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const unset = require('../lib/unset'); | ||
module.exports = unset; |
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,27 @@ | ||
const { | ||
d, | ||
expect, | ||
sinon: { spy }, | ||
tquire, | ||
} = deps; | ||
|
||
const me = __filename; | ||
|
||
d(me, () => { | ||
describe('given a normal require', () => { | ||
const forEach = tquire(me); | ||
const obj = { a: 1, b: 2, c: 3 }; | ||
|
||
const mockForEachFn = spy(); | ||
|
||
it('should call the forEachFn once per key', () => { | ||
forEach(obj, mockForEachFn); | ||
|
||
expect(mockForEachFn.args).to.deep.equal([ | ||
[1, 'a', obj], | ||
[2, 'b', obj], | ||
[3, 'c', obj], | ||
]); | ||
}); | ||
}); | ||
}); |
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,55 @@ | ||
const { d, expect, tquire, uuid } = deps; | ||
|
||
const has = tquire(__filename); | ||
const set = require('../../../src/lib/set'); | ||
|
||
d(__filename, () => { | ||
const val = Symbol(); | ||
|
||
describe('given a shallow key', () => { | ||
let key = null; | ||
let obj = null; | ||
|
||
beforeEach(() => { | ||
key = uuid(); | ||
obj = { [key]: val }; | ||
}); | ||
|
||
it('should return true if the key exists', () => | ||
expect(has(obj, key)).to.equal(true)); | ||
|
||
it('should return false if the key does not exist', () => | ||
expect(has(obj, Symbol())).to.equal(false)); | ||
|
||
it('should return false if the key does not exist', () => | ||
expect(has({}, Symbol())).to.equal(false)); | ||
|
||
it('should return false if the key does not exist', () => | ||
expect(has(obj, `gibberish-key-${uuid()}`)).to.equal(false)); | ||
|
||
it('should return false if the key does not exist', () => | ||
expect(has({}, key)).to.equal(false)); | ||
}); | ||
|
||
describe('given a nested key', () => { | ||
let key = null; | ||
let key1 = null; | ||
let key2 = null; | ||
|
||
beforeEach(() => { | ||
key1 = uuid(); | ||
key2 = uuid(); | ||
|
||
key = `${key1}.${key2}`; | ||
}); | ||
|
||
it('should return true if the key exists', () => | ||
expect(has(set({}, key, val), key)).to.equal(true)); | ||
|
||
it('should return false if a partial key exists but the full key does not', () => | ||
expect(has(set({}, key1, val), key)).to.equal(false)); | ||
|
||
it('should return false if the key does not exist', () => | ||
expect(has({}, key)).to.equal(false)); | ||
}); | ||
}); |
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.