From 84ce7fbcac9281238851ac188e2765ab1afcf066 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 15:23:03 +0100 Subject: [PATCH 1/9] chore: lintedstage eslint setup matching package.json to avoid confusion --- .lintstagedrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.lintstagedrc b/.lintstagedrc index 385afe9..624b617 100644 --- a/.lintstagedrc +++ b/.lintstagedrc @@ -1,5 +1,5 @@ { - "*.{js,json}": "eslint --quiet", + "*.{js,json}": "eslint --quiet src", "*.md": "markdownlint --ignore CHANGELOG.md", ".circleci/config.yml": "circleci config validate" } From 4ed5dbd6492706d0622c41964163842b92260312 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 15:30:22 +0100 Subject: [PATCH 2/9] chore: fix warning on tsconfig.json by excluding dist folder --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 4c6059e..861ca8f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "include": ["src", "types"], - "exclude": ["**/node_modules", "src/**/*.test-d.ts"], + "exclude": ["**/node_modules", "src/**/*.test-d.ts", "dist"], "compilerOptions": { "module": "node16", "moduleResolution": "node16", @@ -8,6 +8,7 @@ "declaration": false, "allowJs": true, "checkJs": false, + "outDir": "dist", "strict": true, "noImplicitReturns": true, From 064e66e8e0e37f351cbefce871142228d002e491 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 15:31:04 +0100 Subject: [PATCH 3/9] chore(eslint): in some tests we do want empty functions --- src/deep-equal/deep-equal.test.js | 1 + src/first/first.test.js | 1 + src/is-empty/is-empty.test.js | 1 + src/type/type.test.js | 1 + 4 files changed, 4 insertions(+) diff --git a/src/deep-equal/deep-equal.test.js b/src/deep-equal/deep-equal.test.js index 02db727..b6304c4 100644 --- a/src/deep-equal/deep-equal.test.js +++ b/src/deep-equal/deep-equal.test.js @@ -4,6 +4,7 @@ import test from "tape" import { isDeepEqual } from "./deep-equal.js" +// eslint-disable-next-line @typescript-eslint/no-empty-function const fn = () => {} test("isDeepEqual", t => { diff --git a/src/first/first.test.js b/src/first/first.test.js index b85106f..52919e5 100644 --- a/src/first/first.test.js +++ b/src/first/first.test.js @@ -9,6 +9,7 @@ test("first", t => { t.equal(first(2), undefined, "From number should return undefined") t.equal(first({}), undefined, "From object should return undefined") t.equal( + // eslint-disable-next-line @typescript-eslint/no-empty-function first(() => {}), undefined, "From function should return undefined" diff --git a/src/is-empty/is-empty.test.js b/src/is-empty/is-empty.test.js index 3bf92b2..7ae2922 100644 --- a/src/is-empty/is-empty.test.js +++ b/src/is-empty/is-empty.test.js @@ -16,6 +16,7 @@ test("isEmpty", t => { t.equal(isEmpty(null), true, "null should equal true") t.equal(isEmpty(), true, "undefined should equal true") t.equal( + // eslint-disable-next-line @typescript-eslint/no-empty-function isEmpty(() => {}), false, "() => {} should equal false" diff --git a/src/type/type.test.js b/src/type/type.test.js index 3a67476..a3ca29c 100644 --- a/src/type/type.test.js +++ b/src/type/type.test.js @@ -15,6 +15,7 @@ test("type", t => { t.equal(type({}), "Object", "{} should equal Object") t.equal(type(new Date()), "Date", "new Date() should equal Date") t.equal( + // eslint-disable-next-line @typescript-eslint/no-empty-function type(() => {}), "Function", "() => {} should equal Function" From c60a7d7ee16689e682a781b1245ecae26f66272b Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 15:49:37 +0100 Subject: [PATCH 4/9] chore: fix jsdoc linting errors by adding either an example or @internal tag --- src/drop-last/drop-last.js | 6 ++++-- src/hist/hist.js | 24 ++++++++++++++++++------ src/move/move.js | 1 + src/pick/pick.js | 1 + src/pluck/pluck.js | 2 ++ src/proto-chain/proto-chain.js | 3 +++ src/random/random.js | 3 +++ src/rename-file/rename-file.js | 7 +++++-- src/rename/rename.js | 2 ++ src/replace/replace.js | 26 ++++++++++++++++---------- src/same/same.js | 3 +++ src/spy/spy.js | 2 ++ 12 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/drop-last/drop-last.js b/src/drop-last/drop-last.js index dd94908..0acc6c2 100644 --- a/src/drop-last/drop-last.js +++ b/src/drop-last/drop-last.js @@ -8,13 +8,15 @@ const _dropLast = curry((count, input) => * Remove elements from end of array * * @param {number} count Number of element to remove (default 1) - * @param {Array} input Source array * - * @returns {Array} + * @returns {function(Array): Array} * * @tag Array * @signature (count: number, input: Array): Array * @signature (input: Array): Array + * @example + * dropLast(1, [1, 2, 3]) + * // => [1, 2] */ export const dropLast = count => { if (Array.isArray(count)) { diff --git a/src/hist/hist.js b/src/hist/hist.js index 588a5e2..263d9fb 100644 --- a/src/hist/hist.js +++ b/src/hist/hist.js @@ -2,11 +2,19 @@ import { type } from "../type/type.js" import { is } from "../is/is.js" /** + * @callback HistByArray * Count the number of occurances of each element * * @param {Array} input Source input * - * @returns {Object} + * @returns {function(Array): Object} + */ + +/** + * @type {HistByArray} + * + * @example + * byArray([1, 2, 3, 2, 3, 3]) // => { "1": 1, "2": 2, "3": 3 } */ const byArray = input => { const result = {} @@ -19,11 +27,16 @@ const byArray = input => { } /** + * @callback HistByKey * Count the number of occurances of each object by a field - * * @param {string} field The field - * - * @returns {Object} + * @returns {function(Object[]): Object} + */ + +/** + * @type {HistByKey} + * @example + * byKey("name")([{ name: "Bob" }, { name: "Alice" }, { name: "Bob" }]) // => { "Bob": 2, "Alice": 1 } */ const byKey = field => input => { const result = {} @@ -52,9 +65,8 @@ const byType = { * @signature (field: string)(source: Object[]): Object * * @param {string} field Field name to count - * @param {Object[]} source Array of objects * - * @returns {Object} + * @returns {HistByArray|HistByKey} a function of an Array * * @example * diff --git a/src/move/move.js b/src/move/move.js index 644b123..a77b4ed 100644 --- a/src/move/move.js +++ b/src/move/move.js @@ -1,4 +1,5 @@ /** + * @internal * @param {number} from * @param {number} to * @param {Array} input diff --git a/src/pick/pick.js b/src/pick/pick.js index 3969d17..0b5bdbc 100644 --- a/src/pick/pick.js +++ b/src/pick/pick.js @@ -1,4 +1,5 @@ /** + * @internal * @param {string} key Field name to extract values from * @param {Object[]} input Array of objects * diff --git a/src/pluck/pluck.js b/src/pluck/pluck.js index 4f839c1..d30b102 100644 --- a/src/pluck/pluck.js +++ b/src/pluck/pluck.js @@ -1,6 +1,7 @@ import { map } from "../map/map.js" /** + * @internal * @param {string[]} keys The properties to be filtered out * @param {Object} input The source object * @@ -22,6 +23,7 @@ const _pluckOne = (keys, input) => { } /** + * @internal * @param {string[]} keys * @param {Object | Object[]} input * diff --git a/src/proto-chain/proto-chain.js b/src/proto-chain/proto-chain.js index b4cac94..ffe6def 100644 --- a/src/proto-chain/proto-chain.js +++ b/src/proto-chain/proto-chain.js @@ -8,6 +8,9 @@ * * @tag Core * @signature (input: Object, acc: string[]): string[] + * + * @example + * protoChain({}) // => ["Object"] */ const protoChain = (input, acc = []) => { const proto = Object.getPrototypeOf(input) diff --git a/src/random/random.js b/src/random/random.js index bce7252..081bdf1 100644 --- a/src/random/random.js +++ b/src/random/random.js @@ -5,6 +5,9 @@ * @param {number} max Maximum value * * @returns {number} + * + * @example + * random(0, 10) // => 5 */ export const random = (min = 0, max = 1) => Math.floor(min + Math.random() * (max - min + 1)) diff --git a/src/rename-file/rename-file.js b/src/rename-file/rename-file.js index 6c64038..829d4a3 100644 --- a/src/rename-file/rename-file.js +++ b/src/rename-file/rename-file.js @@ -16,9 +16,12 @@ const removeTrailingSlash = input => * Rename a file * * @param {string} newName New file name - * @param {string} input Absolute file path * - * @returns {string} + * @returns {function(string): string } a function of the absolute file path + * + * @example + * renameFile("new-name.js", "/path/to/old-name.js") + * // => "/path/to/new-name.js" */ const renameFile = newName => pipe( diff --git a/src/rename/rename.js b/src/rename/rename.js index fa19267..b6b51a8 100644 --- a/src/rename/rename.js +++ b/src/rename/rename.js @@ -1,6 +1,7 @@ import { map } from "../map/map.js" /** + * @internal * @param {Object} mappings * @param {Object} input * @@ -23,6 +24,7 @@ const _renameOne = (mappings, input) => { } /** + * @internal * @param {Object} mappings * @param {Object | Object[]} input * diff --git a/src/replace/replace.js b/src/replace/replace.js index 2c68fea..6ef7761 100644 --- a/src/replace/replace.js +++ b/src/replace/replace.js @@ -5,23 +5,25 @@ import { type } from "../type/type.js" /** * Replace substring in string * + * @internal * @param {string} oldString The old string * @param {string} newString The new string * - * @returns {string} + * @returns {function(string): string} */ -const replaceString = (oldString, newString) => input => +const _replaceString = (oldString, newString) => input => String.prototype.replace.call(input, oldString, newString) /** * Replace element in array (shallow equal) * + * @internal * @param {any} oldElm * @param {any} newElm * - * @returns {Array} + * @returns {function(Array): Array} */ -const replaceArray = (oldElm, newElm) => input => { +const _replaceArray = (oldElm, newElm) => input => { const result = [] for (let i = 0, length = input.length - 1; i <= length; i++) { @@ -41,19 +43,24 @@ const replaceArray = (oldElm, newElm) => input => { * * @param {string|any} oldElm * @param {string|any} newElm - * @param {string|Array} source * - * @returns {string|Array} + * @returns {function(any): string|Array} * * @tag String,Array * @signature (oldElm: string|any, newElm: string|any) => (source: Array): Array * + * @example + * replace("foo", "bar")("foo bar baz") + * // => "bar bar baz" + * + * replace("foo", "wow")(["foo", "bar", "baz"]) + * // => ["wow", "bar", "baz"] */ const replace = (oldElm, newElm) => input => { const inputType = type(input) const byType = { - String: replaceString, - Array: replaceArray, + String: _replaceString, + Array: _replaceArray, } return byType[inputType](oldElm, newElm)(input) @@ -67,9 +74,8 @@ const replace = (oldElm, newElm) => input => { * * @param {Object} filter Filter object to match against each element * @param {Object} newValue Object to replace matching elements - * @param {Object[]} source * - * @returns {Array} + * @returns {function(Array): Array} * * @example * replaceWith( diff --git a/src/same/same.js b/src/same/same.js index ca7f794..8931500 100644 --- a/src/same/same.js +++ b/src/same/same.js @@ -4,5 +4,8 @@ * @param {any} input Something, anything * * @returns {any} + * + * @example + * same(42)() // => 42 */ export const same = input => () => input diff --git a/src/spy/spy.js b/src/spy/spy.js index 038af43..5c7250b 100644 --- a/src/spy/spy.js +++ b/src/spy/spy.js @@ -13,6 +13,8 @@ import { is } from "../is/is.js" * @signature (...props: any) => (source: any): any * * @example + * spy()([1, 2, 3]) + * // prints [1, 2, 3] in the console output */ export const spy = (props = {}) => From 30ff1f0d102b11269843ac771da57ab70d549138 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 16:34:15 +0100 Subject: [PATCH 5/9] chore: update swc dependencies in an attempt to make it work for Macs --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d58717d..b1394e2 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,6 @@ "release": "semantic-release" }, "dependencies": { - "@swc/helpers": "^0.4.12", "fast-deep-equal": "^3.1.3", "rfc-3986": "^1.0.1" }, @@ -82,7 +81,8 @@ "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", "@swc/cli": "^0.1.57", - "@swc/core": "^1.3.14", + "@swc/core": "^1.3.21", + "@swc/helpers": "^0.4.14", "@types/ramda": "^0.28.19", "@types/tape": "^4.13.2", "benchmark": "^2.1.4", From b4024e86bba1c757ba9d59dfd8a5a6a2a4871d71 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 16:35:27 +0100 Subject: [PATCH 6/9] chore: package-lock.json --- package-lock.json | 276 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 230 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6a3d77e..1891fb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "8.1.0", "license": "MIT", "dependencies": { - "@swc/helpers": "^0.4.12", + "@swc/helpers": "^0.4.14", "fast-deep-equal": "^3.1.3", "rfc-3986": "^1.0.1" }, @@ -22,7 +22,7 @@ "@semantic-release/changelog": "^6.0.1", "@semantic-release/git": "^10.0.1", "@swc/cli": "^0.1.57", - "@swc/core": "^1.3.14", + "@swc/core": "^1.3.21", "@types/ramda": "^0.28.19", "@types/tape": "^4.13.2", "benchmark": "^2.1.4", @@ -2521,9 +2521,9 @@ } }, "node_modules/@swc/core": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.14.tgz", - "integrity": "sha512-LpTTrXOGS7vnbR/rHrAux7GykUWbyVmI5NbICl9iF9yeqFdGm6JjaGBhbanmG8zrQL5aFx2kMxxb92V9D1KUiw==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.21.tgz", + "integrity": "sha512-RTmqkm5e5sb+Q+YbyqiE52xjvX+kcIVDgaSdSD7mNy2opgDfIdFMhExmB8UQStt3TLrlpAslWaFNWNmvaHP9rg==", "dev": true, "hasInstallScript": true, "bin": { @@ -2537,22 +2537,102 @@ "url": "https://opencollective.com/swc" }, "optionalDependencies": { - "@swc/core-darwin-arm64": "1.3.14", - "@swc/core-darwin-x64": "1.3.14", - "@swc/core-linux-arm-gnueabihf": "1.3.14", - "@swc/core-linux-arm64-gnu": "1.3.14", - "@swc/core-linux-arm64-musl": "1.3.14", - "@swc/core-linux-x64-gnu": "1.3.14", - "@swc/core-linux-x64-musl": "1.3.14", - "@swc/core-win32-arm64-msvc": "1.3.14", - "@swc/core-win32-ia32-msvc": "1.3.14", - "@swc/core-win32-x64-msvc": "1.3.14" + "@swc/core-darwin-arm64": "1.3.21", + "@swc/core-darwin-x64": "1.3.21", + "@swc/core-linux-arm-gnueabihf": "1.3.21", + "@swc/core-linux-arm64-gnu": "1.3.21", + "@swc/core-linux-arm64-musl": "1.3.21", + "@swc/core-linux-x64-gnu": "1.3.21", + "@swc/core-linux-x64-musl": "1.3.21", + "@swc/core-win32-arm64-msvc": "1.3.21", + "@swc/core-win32-ia32-msvc": "1.3.21", + "@swc/core-win32-x64-msvc": "1.3.21" + } + }, + "node_modules/@swc/core-darwin-arm64": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.21.tgz", + "integrity": "sha512-5dBrJyrCzdHOQ9evS9NBJm2geKcXffIuAvSrnwbMHkfTpl+pOM7crry2tolydFXdOE/Jbx8yyahAIXPne1fTHw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.21.tgz", + "integrity": "sha512-CAtzfsRoVZr7DLKOOWPua6npFdj06wRuv1us275CY2QS3mg1bPl9BxA3c94q3mMcu5Bf06+dzUOjJSGrsBD7Ig==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.21.tgz", + "integrity": "sha512-oPO7oFr89pjDFlHJ2aZvzGR6hwy5nmQyeiuqpTgfn+RFFLLbipFawJe/2NBWyD35bxuguW6a3/w9I6edKTpLUw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.21.tgz", + "integrity": "sha512-cgPw35T8HO4gB/tvPJMwjJuNNpydmw6U5hkxZ+7jiE+qA8hN8a71i+BBfXeSzlo60t4c44+zK4t+gK7UacZg2w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.21.tgz", + "integrity": "sha512-kwH+HHtcakSqR3gF5QJ7N7SPs96ilFiXuauB02Ct3UflaGbVYVoeFYj/VEIJ+ZJvlvvOEDByOiLyrk2bw0bG7A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" } }, "node_modules/@swc/core-linux-x64-gnu": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.14.tgz", - "integrity": "sha512-HtwwA1Z0tE2z9fgaR5ehgY5ULbnVLHj3tayyWhIElF4EWsi6aQfCyn/oCZAcjoPKfEnJiSNBYt5gMmfK8l4mJA==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.21.tgz", + "integrity": "sha512-/kLQLNxwdX6kO2R751uUrxXZsAhOkA1EeQzAqj+5Y+bzt3hA5asH5evkY0w0Aj1zCofX4p4o/Q35mandUPxMlw==", "cpu": [ "x64" ], @@ -2566,9 +2646,9 @@ } }, "node_modules/@swc/core-linux-x64-musl": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.14.tgz", - "integrity": "sha512-RPXilkTD8IVgpou4TNuqZJOB7kMrVJ7sm7GgHF4v1eV3xdIyvy4w5FWjXZRdwMW6iunLgQEckuOmVx0I4mrdNg==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.21.tgz", + "integrity": "sha512-s+l3LqUzDli6rbmIPR3IfO23IOLYBVxk97CDdcJWrRTVtCwUKFhFVJVZyErveriqLXSGJhy5+UL+aOuxC4dk8g==", "cpu": [ "x64" ], @@ -2581,10 +2661,58 @@ "node": ">=10" } }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.21.tgz", + "integrity": "sha512-59gWcdbZxvmyzh+J50yCCodKDYRUnMwNypzzfamF1Vusa4Np+IGMWEaE2KsZUq50OQIRo0PGHpBPMKVYkuGv8g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.21.tgz", + "integrity": "sha512-3gH86ffVAiCmeRy+xSxR5iWSbKy4nUddo4PIahD1zwGJx6LC5ahC/I6EpL1pvoX3KdJKVioUBn0KDfPDUYfqJw==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.21.tgz", + "integrity": "sha512-JKWLJdJ3oFc8fGBk4P6mGKhW8n+FmEjLLbsST+h94bZmelrSTeShBt3rr+pMMatFevlu/c9lM3OW2GHsZeZNkg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, "node_modules/@swc/helpers": { - "version": "0.4.12", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.12.tgz", - "integrity": "sha512-R6RmwS9Dld5lNvwKlPn62+piU+WDG1sMfsnfJioXCciyko/gZ0DQ4Mqglhq1iGU1nQ/RcGkAwfMH+elMSkJH3Q==", + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.14.tgz", + "integrity": "sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==", "dependencies": { "tslib": "^2.4.0" } @@ -21100,41 +21228,97 @@ } }, "@swc/core": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.14.tgz", - "integrity": "sha512-LpTTrXOGS7vnbR/rHrAux7GykUWbyVmI5NbICl9iF9yeqFdGm6JjaGBhbanmG8zrQL5aFx2kMxxb92V9D1KUiw==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.21.tgz", + "integrity": "sha512-RTmqkm5e5sb+Q+YbyqiE52xjvX+kcIVDgaSdSD7mNy2opgDfIdFMhExmB8UQStt3TLrlpAslWaFNWNmvaHP9rg==", "dev": true, "requires": { - "@swc/core-darwin-arm64": "1.3.14", - "@swc/core-darwin-x64": "1.3.14", - "@swc/core-linux-arm-gnueabihf": "1.3.14", - "@swc/core-linux-arm64-gnu": "1.3.14", - "@swc/core-linux-arm64-musl": "1.3.14", - "@swc/core-linux-x64-gnu": "1.3.14", - "@swc/core-linux-x64-musl": "1.3.14", - "@swc/core-win32-arm64-msvc": "1.3.14", - "@swc/core-win32-ia32-msvc": "1.3.14", - "@swc/core-win32-x64-msvc": "1.3.14" + "@swc/core-darwin-arm64": "1.3.21", + "@swc/core-darwin-x64": "1.3.21", + "@swc/core-linux-arm-gnueabihf": "1.3.21", + "@swc/core-linux-arm64-gnu": "1.3.21", + "@swc/core-linux-arm64-musl": "1.3.21", + "@swc/core-linux-x64-gnu": "1.3.21", + "@swc/core-linux-x64-musl": "1.3.21", + "@swc/core-win32-arm64-msvc": "1.3.21", + "@swc/core-win32-ia32-msvc": "1.3.21", + "@swc/core-win32-x64-msvc": "1.3.21" } }, + "@swc/core-darwin-arm64": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.21.tgz", + "integrity": "sha512-5dBrJyrCzdHOQ9evS9NBJm2geKcXffIuAvSrnwbMHkfTpl+pOM7crry2tolydFXdOE/Jbx8yyahAIXPne1fTHw==", + "dev": true, + "optional": true + }, + "@swc/core-darwin-x64": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.21.tgz", + "integrity": "sha512-CAtzfsRoVZr7DLKOOWPua6npFdj06wRuv1us275CY2QS3mg1bPl9BxA3c94q3mMcu5Bf06+dzUOjJSGrsBD7Ig==", + "dev": true, + "optional": true + }, + "@swc/core-linux-arm-gnueabihf": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.21.tgz", + "integrity": "sha512-oPO7oFr89pjDFlHJ2aZvzGR6hwy5nmQyeiuqpTgfn+RFFLLbipFawJe/2NBWyD35bxuguW6a3/w9I6edKTpLUw==", + "dev": true, + "optional": true + }, + "@swc/core-linux-arm64-gnu": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.21.tgz", + "integrity": "sha512-cgPw35T8HO4gB/tvPJMwjJuNNpydmw6U5hkxZ+7jiE+qA8hN8a71i+BBfXeSzlo60t4c44+zK4t+gK7UacZg2w==", + "dev": true, + "optional": true + }, + "@swc/core-linux-arm64-musl": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.21.tgz", + "integrity": "sha512-kwH+HHtcakSqR3gF5QJ7N7SPs96ilFiXuauB02Ct3UflaGbVYVoeFYj/VEIJ+ZJvlvvOEDByOiLyrk2bw0bG7A==", + "dev": true, + "optional": true + }, "@swc/core-linux-x64-gnu": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.14.tgz", - "integrity": "sha512-HtwwA1Z0tE2z9fgaR5ehgY5ULbnVLHj3tayyWhIElF4EWsi6aQfCyn/oCZAcjoPKfEnJiSNBYt5gMmfK8l4mJA==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.21.tgz", + "integrity": "sha512-/kLQLNxwdX6kO2R751uUrxXZsAhOkA1EeQzAqj+5Y+bzt3hA5asH5evkY0w0Aj1zCofX4p4o/Q35mandUPxMlw==", "dev": true, "optional": true }, "@swc/core-linux-x64-musl": { - "version": "1.3.14", - "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.14.tgz", - "integrity": "sha512-RPXilkTD8IVgpou4TNuqZJOB7kMrVJ7sm7GgHF4v1eV3xdIyvy4w5FWjXZRdwMW6iunLgQEckuOmVx0I4mrdNg==", + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.21.tgz", + "integrity": "sha512-s+l3LqUzDli6rbmIPR3IfO23IOLYBVxk97CDdcJWrRTVtCwUKFhFVJVZyErveriqLXSGJhy5+UL+aOuxC4dk8g==", + "dev": true, + "optional": true + }, + "@swc/core-win32-arm64-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.21.tgz", + "integrity": "sha512-59gWcdbZxvmyzh+J50yCCodKDYRUnMwNypzzfamF1Vusa4Np+IGMWEaE2KsZUq50OQIRo0PGHpBPMKVYkuGv8g==", + "dev": true, + "optional": true + }, + "@swc/core-win32-ia32-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.21.tgz", + "integrity": "sha512-3gH86ffVAiCmeRy+xSxR5iWSbKy4nUddo4PIahD1zwGJx6LC5ahC/I6EpL1pvoX3KdJKVioUBn0KDfPDUYfqJw==", + "dev": true, + "optional": true + }, + "@swc/core-win32-x64-msvc": { + "version": "1.3.21", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.21.tgz", + "integrity": "sha512-JKWLJdJ3oFc8fGBk4P6mGKhW8n+FmEjLLbsST+h94bZmelrSTeShBt3rr+pMMatFevlu/c9lM3OW2GHsZeZNkg==", "dev": true, "optional": true }, "@swc/helpers": { - "version": "0.4.12", - "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.12.tgz", - "integrity": "sha512-R6RmwS9Dld5lNvwKlPn62+piU+WDG1sMfsnfJioXCciyko/gZ0DQ4Mqglhq1iGU1nQ/RcGkAwfMH+elMSkJH3Q==", + "version": "0.4.14", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.4.14.tgz", + "integrity": "sha512-4C7nX/dvpzB7za4Ql9K81xK3HPxCpHMgwTZVyf+9JQ6VUbn9jjZVN7/Nkdz/Ugzs2CSjqnL/UPXroiVBVHUWUw==", "requires": { "tslib": "^2.4.0" } From b408eab3b823c95512f5d77b3ff33caa26224817 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 16:36:08 +0100 Subject: [PATCH 7/9] chore: autoformat eslintrc - hope that is fine --- .eslintrc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index abc96bf..d8cda0c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,18 +1,31 @@ { "root": true, - "extends": [ "@asd14/eslint-config/targets/node-ts" ], + "extends": [ + "@asd14/eslint-config/targets/node-ts" + ], "rules": { - "jsdoc/require-example": ["error", { "exemptedBy": ["internal"] }], - + "jsdoc/require-example": [ + "error", + { + "exemptedBy": [ + "internal" + ] + } + ], // disable until upstream issues fixed "jsdoc/check-line-alignment": "off", - // "jsdoc/check-line-alignment": ["error", "always", { // "tags": ["tags"] // }], - "jsdoc/check-tag-names": ["warn", { - "definedTags": ["tag", "signature"] - }] + "jsdoc/check-tag-names": [ + "warn", + { + "definedTags": [ + "tag", + "signature" + ] + } + ] }, "settings": { "import/cache": { From b1bc230f57043547ef0b441a49fe7a5f3845043f Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 16:45:56 +0100 Subject: [PATCH 8/9] chore: macos does not support cp --parents, add a cross-platoform command to be tested --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b1394e2..722d5ac 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "build.docs": "documentation build src/index.js --project-name m -f html -o docs -c documentation.yml", "build.js": "swc src -d 'dist/src'", "build.types": "cp --parents src/index.d.ts dist && cp -r --parents src/**/*.d.ts dist && cp -r --parents types dist", + "build.types.mac": "mkdir -p dist && cp src/index.d.ts dist/src/ && rsync -R types/** dist && rsync -R src/**/*.d.ts dist", "prebuild": "rm -rf dist && mkdir -p dist", "build": "npm run build.js && npm run build.types && npm run build.docs", "----LINT": "", From 556ade7389dc48113b813c58021cf6c4ef310365 Mon Sep 17 00:00:00 2001 From: David Gil <dgilperez@gmail.com> Date: Thu, 8 Dec 2022 16:56:21 +0100 Subject: [PATCH 9/9] feat: any gets types and type tests --- src/any/any.d.ts | 61 +++++++++++++++++++++++++++++++++ src/any/any.test-d.ts | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/any/any.d.ts create mode 100644 src/any/any.test-d.ts diff --git a/src/any/any.d.ts b/src/any/any.d.ts new file mode 100644 index 0000000..8425001 --- /dev/null +++ b/src/any/any.d.ts @@ -0,0 +1,61 @@ +import { UnaryPredicate, UnaryMorphism } from "../../types/function.js" + +declare function any<T>(fn: UnaryPredicate<T>, input: T[]): boolean +declare function any<T>(fn: UnaryPredicate<T>): (input: T[]) => boolean + +declare function any<T>(fns: [UnaryPredicate<T>], input: T[]): boolean +declare function any<T>(fns: [UnaryPredicate<T>]): (input: T[]) => boolean + +declare function any<T1, T2>( + fns: [UnaryMorphism<T1, T2>, UnaryPredicate<T2>], + input: T1[] +): boolean +declare function any<T1, T2>( + fns: [UnaryMorphism<T1, T2>, UnaryPredicate<T2>] +): (input: T1[]) => boolean + +declare function any<T1, T2, T3>( + fns: [UnaryMorphism<T1, T2>, UnaryMorphism<T2, T3>, UnaryPredicate<T3>], + input: T1[] +): boolean +declare function any<T1, T2, T3>( + fns: [UnaryMorphism<T1, T2>, UnaryMorphism<T2, T3>, UnaryPredicate<T3>] +): (input: T1[]) => boolean + +declare function any<T1, T2, T3, T4>( + fns: [ + UnaryMorphism<T1, T2>, + UnaryMorphism<T2, T3>, + UnaryMorphism<T3, T4>, + UnaryPredicate<T4> + ], + input: T1[] +): boolean +declare function any<T1, T2, T3, T4>( + fns: [ + UnaryMorphism<T1, T2>, + UnaryMorphism<T2, T3>, + UnaryMorphism<T3, T4>, + UnaryPredicate<T4> + ] +): (input: T1[]) => boolean + +declare function any<T1, T2, T3, T4, T5>( + fns: [ + UnaryMorphism<T1, T2>, + UnaryMorphism<T2, T3>, + UnaryMorphism<T3, T4>, + UnaryMorphism<T4, T5>, + UnaryPredicate<T5> + ], + input: T1[] +): boolean +declare function any<T1, T2, T3, T4, T5>( + fns: [ + UnaryMorphism<T1, T2>, + UnaryMorphism<T2, T3>, + UnaryMorphism<T3, T4>, + UnaryMorphism<T4, T5>, + UnaryPredicate<T5> + ] +): (input: T1[]) => boolean diff --git a/src/any/any.test-d.ts b/src/any/any.test-d.ts new file mode 100644 index 0000000..e970a0e --- /dev/null +++ b/src/any/any.test-d.ts @@ -0,0 +1,80 @@ +import { expectType, expectError } from "tsd" + +import { any } from "./any.js" +import { is } from "../is/is.js" + +const isEven = (input: number): boolean => input % 2 === 0 + +{ + /** + * Predicate signature is correctly inferred from input + */ + + const input = [1, 2, 3] + + expectType<boolean>( + any(item => { + expectType<number>(item) + + return isEven(item) + }, input) + ) + + /** + * When currying, predicate signature is not inferred and needs explicit typing + */ + + expectType<boolean>( + any(item => { + expectType<unknown>(item) + + return isEven(item as number) + })(input) + ) + + expectType<boolean>(any(isEven)(input)) +} + +{ + /** + * Predicate Pipe signature is also correctly inferred + */ + + const input = [{ id: "string" }, { id: 2 }, { id: 3 }] + + expectType<boolean>( + any( + [ + item => { + expectType<{ id: string } | { id: number }>(item) + + return item.id + }, + field => { + expectType<string | number>(field) + + return is(field) + }, + ], + input + ) + ) +} + +{ + const input = [1, "2", 3] + + /** + * When uncurried, predicate signature is checked against inferred input type + */ + + expectError(any(isEven, input)) + + /** + * When curried, input type is checked against predicate signature + */ + + const anyIsEven = any(isEven) + + expectError(anyIsEven(input)) +}