-
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
42 changed files
with
1,071 additions
and
566 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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
const isArray = require('./is-array'); | ||
const isObject = require('./is-object'); | ||
|
||
module.exports = inp => | ||
typeof inp === 'object' ? Object.assign({}, inp) : inp; | ||
isArray(inp) ? [].concat(inp) : isObject(inp) ? Object.assign({}, inp) : inp; |
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 isArray = require('./is-array'); | ||
const isBoolean = require('./is-boolean'); | ||
const isError = require('./is-error'); | ||
const isFunction = require('./is-function'); | ||
const isNull = require('./is-null'); | ||
const isNumber = require('./is-number'); | ||
const isObject = require('./is-object'); | ||
const isString = require('./is-string'); | ||
const isUndefined = require('./is-undefined'); | ||
|
||
const associations = [ | ||
{ fn: isUndefined, type: 'undefined' }, | ||
{ fn: isNull, type: 'null' }, | ||
{ fn: isBoolean, type: 'boolean' }, | ||
{ fn: isNumber, type: 'number' }, | ||
{ fn: isArray, type: 'array' }, | ||
{ fn: isFunction, type: 'function' }, | ||
{ fn: isError, type: 'error' }, | ||
{ fn: isString, type: 'string' }, | ||
{ fn: isObject, type: 'object' }, | ||
]; | ||
|
||
module.exports = item => | ||
associations.reduce( | ||
(acc, { fn, type }) => (acc !== false || !fn(item) ? acc : type), | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = item => Array.isArray(item); |
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 = item => | ||
item === true || item === false || item instanceof Boolean; |
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 = item => item instanceof Error; |
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 = item => typeof item === 'function'; |
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 = item => item === null; |
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 = item => typeof item === 'number' || item instanceof Number; |
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,5 @@ | ||
module.exports = item => { | ||
const type = typeof item; | ||
|
||
return item !== null && (type === 'object' || type === 'function'); | ||
}; |
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 = item => item === undefined; |
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 @@ | ||
module.exports = require('../lib/get-type'); |
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 = require('../lib/is-array'); |
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 = require('../lib/is-boolean'); |
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 = require('../lib/is-error'); |
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 = require('../lib/is-function'); |
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 = require('../lib/is-null'); |
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 = require('../lib/is-number'); |
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 = require('../lib/is-object'); |
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 = require('../lib/is-string'); |
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 = require('../lib/is-undefined'); |
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,19 @@ | ||
const runTestCreator = require('../../lib/run-lodash-parity-test-creator'); | ||
const runFpTestCreator = require('../../lib/run-lodash-fp-parity-test-creator'); | ||
|
||
const { d, nextInt } = deps; | ||
|
||
const me = __filename; | ||
|
||
d(me, () => { | ||
const runTest = runTestCreator('get'); | ||
const runFpTest = runFpTestCreator('get'); | ||
|
||
const obj = { a: undefined, b: null }; | ||
const r = () => nextInt(); | ||
|
||
const setsOfArgs = [[obj, 'a'], [obj, 'b'], [obj, r()]]; | ||
|
||
setsOfArgs.forEach(args => runTest(...args)); | ||
setsOfArgs.forEach(args => runFpTest(...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 |
---|---|---|
@@ -1,57 +0,0 @@ | ||
const lodash = require('lodash'); | ||
const lodashFp = require('lodash/fp'); | ||
const tinyPfp = require('../../../src/index'); | ||
|
||
const { d, testRunner } = deps; | ||
|
||
const me = __filename; | ||
|
||
const logIfTestingVerbose = obj => { | ||
if (process.env.TESTING_VERBOSE !== undefined) { | ||
console.error(obj); // eslint-disable-line no-console | ||
} | ||
|
||
return obj; | ||
}; | ||
|
||
d(me, () => { | ||
const runTestCreator = functionName => (...input) => | ||
describe(`tinyPfp.${functionName}`, () => | ||
testRunner( | ||
logIfTestingVerbose({ | ||
description: `should perform like lodash.${functionName}`, | ||
expected: lodash[functionName](...input), | ||
functionToTest: () => tinyPfp[functionName](...input), | ||
input: null, | ||
}), | ||
)); | ||
|
||
const runFpTestCreator = functionName => (...input) => | ||
describe(`tinyPfp.fp.${functionName}`, () => | ||
testRunner( | ||
logIfTestingVerbose({ | ||
description: `should perform like lodash.fp.${functionName}`, | ||
expected: lodashFp[functionName](...input), | ||
functionToTest: () => tinyPfp.fp[functionName](...input), | ||
input: null, | ||
}), | ||
)); | ||
|
||
const square = x => x * x; | ||
|
||
describe('array functions', () => { | ||
const setsOfArgs = [ | ||
[[], square], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], square], | ||
]; | ||
|
||
const rotateAToEnd = array => array.slice(1).concat([array[0]]); | ||
const runMapTest = runTestCreator('map'); | ||
const runFpMapTest = runFpTestCreator('map'); | ||
|
||
setsOfArgs.forEach(ea => { | ||
runMapTest(...ea); | ||
runFpMapTest(...rotateAToEnd(ea)); | ||
}); | ||
}); | ||
}); | ||
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 @@ | ||
const evaluatedSetOfEverything = require('../../lib/evaluated-set-of-everything'); | ||
|
||
const { _, d, expect } = deps; | ||
|
||
const me = __filename; | ||
|
||
d(me, () => { | ||
const tinyPfp = require('../../../src'); | ||
|
||
it('should have parity for all the `is-?` functions', () => | ||
[ | ||
'isArray', | ||
'isBoolean', | ||
'isError', | ||
'isFunction', | ||
'isNull', | ||
'isNumber', | ||
'isObject', | ||
'isString', | ||
'isUndefined', | ||
] | ||
.map(key => | ||
Object.assign({ | ||
ours: tinyPfp[key], | ||
theirs: _[key], | ||
key, | ||
}), | ||
) | ||
.forEach(({ key, ours, theirs }) => | ||
evaluatedSetOfEverything().forEach(({ evaluated, text }) => [ | ||
expect(ours, key).to.be.a('function'), | ||
expect(theirs, key).to.be.a('function'), | ||
expect(ours(evaluated), `${key} for ${text}`).to.equal( | ||
theirs(evaluated), | ||
), | ||
]), | ||
)); | ||
}); |
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,25 @@ | ||
const runTestCreator = require('../../lib/run-lodash-parity-test-creator'); | ||
const runFpTestCreator = require('../../lib/run-lodash-fp-parity-test-creator'); | ||
|
||
const { d } = deps; | ||
|
||
const me = __filename; | ||
|
||
d(me, () => { | ||
const square = x => x * x; | ||
|
||
describe('array functions', () => { | ||
const setsOfArgs = [ | ||
[[], square], | ||
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], square], | ||
]; | ||
|
||
const runMapTest = runTestCreator('map'); | ||
const runFpMapTest = runFpTestCreator('map'); | ||
|
||
setsOfArgs.forEach(ea => { | ||
runMapTest(...ea); | ||
runFpMapTest(...ea); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.