diff --git a/package-lock.json b/package-lock.json index 69a1813..b5563cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@asd14/eslint-config": { - "version": "5.19.0", - "resolved": "https://registry.npmjs.org/@asd14/eslint-config/-/eslint-config-5.19.0.tgz", - "integrity": "sha512-IF02/HJRFq84gZE6+JUw4jcp/REYeGJShLtDH4EdJ03rKYlmomGlCNEoKY/kYBSFRlzlXts+2DK/XCbvsCq+XQ==", + "version": "5.20.0", + "resolved": "https://registry.npmjs.org/@asd14/eslint-config/-/eslint-config-5.20.0.tgz", + "integrity": "sha512-vkWE0yrFep3rm2VISwJ94U428kkTDsP8KmFHclpa0AjwpL9rkoe7/0nr8OyAeydu+5XlBFIABXus4FroU2Y/bg==", "dev": true }, "@babel/cli": { @@ -7679,9 +7679,9 @@ "dev": true }, "eslint-plugin-unicorn": { - "version": "24.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-24.0.0.tgz", - "integrity": "sha512-NfLjIZas/ZUwc3S+pUtbTRqgCkODxPEkJBJ5ZR8wIu90BmX4jmXp10hoOZMScR2CR1NYTtrx0OX4BQvBnbzZzA==", + "version": "25.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-25.0.0.tgz", + "integrity": "sha512-RuhPUrsKuRj0YGz8lMuh5Z5DJoC/hmUR6omvlquLlY6SYY+oZXMFyp83ckpqLMhbafqUx+JttWOPOjfP4W9Y+Q==", "dev": true, "requires": { "ci-info": "^2.0.0", diff --git a/package.json b/package.json index d61c8e3..d9b66ee 100644 --- a/package.json +++ b/package.json @@ -46,11 +46,11 @@ "@babel/runtime-corejs3": "^7.12.5" }, "devDependencies": { - "@asd14/eslint-config": "^5.19.0", + "@asd14/eslint-config": "^5.20.0", "@babel/cli": "^7.12.10", "@babel/core": "^7.12.10", - "@babel/preset-env": "^7.12.11", "@babel/plugin-transform-runtime": "^7.12.10", + "@babel/preset-env": "^7.12.11", "@babel/register": "^7.12.10", "babel-eslint": "^10.1.0", "benchmark": "^2.1.4", @@ -65,7 +65,7 @@ "eslint-plugin-no-inferred-method-name": "^2.0.0", "eslint-plugin-prettier": "^3.3.0", "eslint-plugin-promise": "^4.2.1", - "eslint-plugin-unicorn": "^24.0.0", + "eslint-plugin-unicorn": "^25.0.0", "fast-deep-equal": "^3.1.3", "lodash": "^4.17.20", "markdownlint-cli": "^0.26.0", diff --git a/src/converge/converge.test.js b/src/converge/converge.test.js index 98d1a64..deec128 100644 --- a/src/converge/converge.test.js +++ b/src/converge/converge.test.js @@ -4,9 +4,10 @@ import { converge } from "./converge" import { reduce } from "../reduce/reduce" import { read } from "../read/read" +const sum = (...params) => reduce((acc, item) => acc + item, 0, params) + test("converge", t => { const source = [{ a: 1, b: 2 }] - const sum = (...params) => reduce((acc, item) => acc + item, 0, params) t.equals( converge(sum, [read([0, "a"], 0), read([0, "b"], 0)])(source), diff --git a/src/curry/curry.test.js b/src/curry/curry.test.js index 2c38d8a..22c0b23 100644 --- a/src/curry/curry.test.js +++ b/src/curry/curry.test.js @@ -1,10 +1,12 @@ import test from "tape" - import { curry } from "./curry" -test("curry", t => { - const sum = (a, b) => a + b +const sum = (a, b) => a + b + +// can curry multiple times and pass multiple parameters on each curry +const sumThree = (a, b, c) => a + b + c +test("curry", t => { // does nothing if there are enough parameters t.equal(curry(sum)(2, 3), 5) @@ -13,9 +15,6 @@ test("curry", t => { t.equal(addTwo(3), 5) - // can curry multiple times and pass multiple parameters on each curry - const sumThree = (a, b, c) => a + b + c - const addOne = curry(sumThree)(1) const addFourA = curry(addOne)(3) const addFourB = curry(sumThree)(2, 2) diff --git a/src/deep-equal/deep-equal.test.js b/src/deep-equal/deep-equal.test.js index 4185b9a..2d17e71 100644 --- a/src/deep-equal/deep-equal.test.js +++ b/src/deep-equal/deep-equal.test.js @@ -2,13 +2,13 @@ import test from "tape" import { isDeepEqual } from "./deep-equal" +const fn = () => {} + test("isDeepEqual", t => { t.equal(isDeepEqual(1, 1), true, "Primitives: 1 === 1") t.equal(isDeepEqual(1, "3"), false, 'Primitives: 1 !== "3"') - const fn = () => {} - t.equal(isDeepEqual(fn, fn), true, "Functions: fn === fn") t.equal( diff --git a/src/escapeHTML/escapeHTML.js b/src/escape-html/escape-html.js similarity index 100% rename from src/escapeHTML/escapeHTML.js rename to src/escape-html/escape-html.js diff --git a/src/escapeHTML/escapeHTML.test.js b/src/escape-html/escape-html.test.js similarity index 90% rename from src/escapeHTML/escapeHTML.test.js rename to src/escape-html/escape-html.test.js index a6b3839..28bfa07 100644 --- a/src/escapeHTML/escapeHTML.test.js +++ b/src/escape-html/escape-html.test.js @@ -1,6 +1,6 @@ import test from "tape" -import { escapeHTML } from "./escapeHTML" +import { escapeHTML } from "./escape-html" test("escapeHTML", t => { const actual = escapeHTML( diff --git a/src/escapeRegExp/escapeRegExp.js b/src/escape-reg-exp/escape-reg-exp.js similarity index 100% rename from src/escapeRegExp/escapeRegExp.js rename to src/escape-reg-exp/escape-reg-exp.js diff --git a/src/escapeRegExp/escapeRegExp.test.js b/src/escape-reg-exp/escape-reg-exp.test.js similarity index 91% rename from src/escapeRegExp/escapeRegExp.test.js rename to src/escape-reg-exp/escape-reg-exp.test.js index 027e3f6..5df2156 100644 --- a/src/escapeRegExp/escapeRegExp.test.js +++ b/src/escape-reg-exp/escape-reg-exp.test.js @@ -1,6 +1,6 @@ import test from "tape" -import { escapeRegExp } from "./escapeRegExp" +import { escapeRegExp } from "./escape-reg-exp" test("escapeRegExp", t => { const actualT1 = escapeRegExp("lorem. ipsum [dolor] (sit amet)?") diff --git a/src/index.js b/src/index.js index 0b07f53..6611f14 100644 --- a/src/index.js +++ b/src/index.js @@ -18,7 +18,7 @@ export { reduce } from "./reduce/reduce" export { converge } from "./converge/converge" export { forEach } from "./for-each/for-each" export { pipe } from "./pipe/pipe" -export { pipeP } from "./pipeP/pipeP" +export { pipeP } from "./pipe-p/pipe-p" export { read as get, read } from "./read/read" export { write as set, write } from "./write/write" export { same } from "./same/same" @@ -99,5 +99,5 @@ export { toUpper } from "./to-upper/to-upper" export { trim } from "./trim/trim" export { contains } from "./contains/contains" export { join } from "./join/join" -export { escapeHTML } from "./escapeHTML/escapeHTML" -export { escapeRegExp } from "./escapeRegExp/escapeRegExp" +export { escapeHTML } from "./escape-html/escape-html" +export { escapeRegExp } from "./escape-reg-exp/escape-reg-exp" diff --git a/src/map-matrix/map-matrix.test.js b/src/map-matrix/map-matrix.test.js index 06b86a9..a2e3ae5 100644 --- a/src/map-matrix/map-matrix.test.js +++ b/src/map-matrix/map-matrix.test.js @@ -2,9 +2,10 @@ import test from "tape" import { mapMatrix } from "./map-matrix" -test("mapMatrix", t => { - const square = value => value * value +const square = x => x * x +const inc = x => x + 1 +test("mapMatrix", t => { t.deepEqual( mapMatrix(square)([ [1, 2], @@ -29,8 +30,6 @@ test("mapMatrix", t => { "Uncurried (square, [[1, 2], [3, 4]]) // => [[1, 4], [9, 16]]" ) - const inc = x => x + 1 - t.deepEqual( mapMatrix( [square, inc], diff --git a/src/map/map.test.js b/src/map/map.test.js index 75a5e65..3271bb1 100644 --- a/src/map/map.test.js +++ b/src/map/map.test.js @@ -2,9 +2,9 @@ import test from "tape" import { map } from "./map" -test("map", t => { - const square = value => value * value +const square = value => value * value +test("map", t => { t.deepEqual( map(square, [1, 2, 3]), [1, 4, 9], diff --git a/src/max/max.test.js b/src/max/max.test.js index 491a05a..d321873 100644 --- a/src/max/max.test.js +++ b/src/max/max.test.js @@ -12,6 +12,8 @@ test("max", t => { t.end() }) +const toDate = element => new Date(element.time) + test("maxBy", t => { t.equals(maxBy(i, [1, 10, 3]), 10, "Find max in all positive numeric array") @@ -21,15 +23,12 @@ test("maxBy", t => { "Find max in empty array using transform function (=> undefined)" ) - const fn = element => new Date(element.time) - const source = [ - { time: "2018-05-15T11:20:07.754110Z" }, - { time: "2018-06-11T09:01:54.337344Z" }, - { time: "2018-06-08T08:26:12.711071Z" }, - ] - t.deepEquals( - maxBy(fn, source), + maxBy(toDate, [ + { time: "2018-05-15T11:20:07.754110Z" }, + { time: "2018-06-11T09:01:54.337344Z" }, + { time: "2018-06-08T08:26:12.711071Z" }, + ]), { time: "2018-06-11T09:01:54.337344Z" }, "Custom transform function" ) diff --git a/src/min/min.test.js b/src/min/min.test.js index adedc2f..c414349 100644 --- a/src/min/min.test.js +++ b/src/min/min.test.js @@ -15,6 +15,8 @@ test("min", t => { t.end() }) +const toDate = element => new Date(element.time) + test("minBy", t => { t.equals( minBy(i, []), @@ -22,15 +24,12 @@ test("minBy", t => { "Find min in empty array using transform function (=> undefined)" ) - const fn = element => new Date(element.time) - const source = [ - { time: "2018-06-11T09:01:54.337344Z" }, - { time: "2018-06-08T08:26:12.711071Z" }, - { time: "2018-05-15T11:20:07.754110Z" }, - ] - t.deepEquals( - minBy(fn, source), + minBy(toDate, [ + { time: "2018-06-11T09:01:54.337344Z" }, + { time: "2018-06-08T08:26:12.711071Z" }, + { time: "2018-05-15T11:20:07.754110Z" }, + ]), { time: "2018-05-15T11:20:07.754110Z" }, "Custom transform function" ) diff --git a/src/mutate/mutate.test.js b/src/mutate/mutate.test.js index cd42223..70b31fb 100644 --- a/src/mutate/mutate.test.js +++ b/src/mutate/mutate.test.js @@ -2,6 +2,8 @@ import test from "tape" import { mutate, mutateMany, mutateWith } from "./mutate" +const inc = x => x + 1 + test("mutate", t => { t.deepEqual( mutate({ test: "changed" }, { test: "Lorem Ipsum" }), @@ -9,8 +11,6 @@ test("mutate", t => { "Mutating existing property should return changed object" ) - const inc = x => x + 1 - t.deepEqual( mutate({ test: inc })({ test: 2 }), { test: 3 }, @@ -70,8 +70,6 @@ test("mutateMany", t => { }) test("mutateWith", t => { - const inc = x => x + 1 - t.deepEqual( mutateWith({ id: 2 }, { count: [inc], other: 2 }, [ { id: 1 }, diff --git a/src/partition/partition.test.js b/src/partition/partition.test.js index 8b03317..d17ee6c 100644 --- a/src/partition/partition.test.js +++ b/src/partition/partition.test.js @@ -4,9 +4,9 @@ import { is } from "../is/is" import { read } from "../read/read" import { partition, partitionWith } from "./partition" -test("partition", t => { - const equalsTwo = x => x === 2 +const equalsTwo = x => x === 2 +test("partition", t => { t.deepEqual( partition(equalsTwo)([2, 2, 1, 1, 2]), [ diff --git a/src/pipeP/pipeP.js b/src/pipe-p/pipe-p.js similarity index 100% rename from src/pipeP/pipeP.js rename to src/pipe-p/pipe-p.js diff --git a/src/pipeP/pipeP.test.js b/src/pipe-p/pipe-p.test.js similarity index 58% rename from src/pipeP/pipeP.test.js rename to src/pipe-p/pipe-p.test.js index 4ddf4c4..42064fd 100644 --- a/src/pipeP/pipeP.test.js +++ b/src/pipe-p/pipe-p.test.js @@ -1,15 +1,15 @@ import test from "tape" -import { pipeP } from ".." +import { pipeP } from "./pipe-p" -test("pipeP", t => { - const inc = input => input + 1 - const sum = (a = 0, b = 0) => - new Promise(resolve => { - setTimeout(() => { - resolve(a + b) - }, 100) - }) +const inc = input => input + 1 +const sum = (a = 0, b = 0) => + new Promise(resolve => { + setTimeout(() => { + resolve(a + b) + }, 100) + }) +test("pipeP", t => { return Promise.all([pipeP(sum, inc)(2), pipeP(sum, inc, inc)(2, 2)]).then( ([first, second]) => { t.equal(first, 3, "first input arity 1") diff --git a/src/pipe/pipe.test.js b/src/pipe/pipe.test.js index a425296..2b3419b 100644 --- a/src/pipe/pipe.test.js +++ b/src/pipe/pipe.test.js @@ -1,18 +1,10 @@ import test from "tape" import { pipe } from ".." -/** - * Performs left-to-right function composition. The leftmost function may have - * any arity, the remaining functions must be unary. - * - * @example - * pipe( inc, inc )( 2 ) - * // => 4 - */ -test("core::pipe", t => { - const inc = input => input + 1 - const sum = (a, b) => a + b +const inc = input => input + 1 +const sum = (a, b) => a + b +test("pipe", t => { t.deepEqual(pipe(inc, inc)(2), 4, "first input arity 1") t.deepEqual(pipe(sum, inc)(2, 2), 5, "first input arity 2") diff --git a/src/repeat/repeat.test.js b/src/repeat/repeat.test.js index 9d76d87..eca45b9 100644 --- a/src/repeat/repeat.test.js +++ b/src/repeat/repeat.test.js @@ -2,9 +2,9 @@ import test from "tape" import { repeat } from "./repeat" -test("repeat", t => { - const inc = x => x + 1 +const inc = x => x + 1 +test("repeat", t => { t.deepEqual(repeat(inc)(5), [1, 2, 3, 4, 5], "Repeat function curried") t.deepEqual(repeat(inc, 2), [1, 2], "Repeat function uncurried ") t.deepEqual(repeat([inc, inc], 2), [2, 3], "Repeat with function chain") diff --git a/src/trim/trim.js b/src/trim/trim.js index 530e83c..4a274a4 100644 --- a/src/trim/trim.js +++ b/src/trim/trim.js @@ -1,4 +1,4 @@ -import { escapeRegExp } from "../escapeRegExp/escapeRegExp" +import { escapeRegExp } from "../escape-reg-exp/escape-reg-exp" const _trim = (char = " ", source) => { const safeChar = escapeRegExp(char) diff --git a/src/update/update.test.js b/src/update/update.test.js index 2ae49b3..848a553 100644 --- a/src/update/update.test.js +++ b/src/update/update.test.js @@ -2,6 +2,8 @@ import test from "tape" import { update, updateMany, updateWith } from "./update" +const inc = x => x + 1 + test("update", t => { t.deepEqual( update({ test: "changed" }, { test: "Lorem Ipsum" }), @@ -9,8 +11,6 @@ test("update", t => { "Updating existing property should return changed object" ) - const inc = x => x + 1 - t.deepEqual( update({ test: inc })({ test: 2 }), { test: 3 }, @@ -59,8 +59,6 @@ test("updateMany", t => { }) test("updateWith", t => { - const inc = x => x + 1 - t.deepEqual( updateWith( {