From 173affe8839bf4967186dc589d5da0d70cea0e2d Mon Sep 17 00:00:00 2001 From: georapbox Date: Thu, 15 Sep 2022 14:48:38 +0300 Subject: [PATCH 01/17] Convert to ES6 --- .eslintrc.json | 10 +- package-lock.json | 686 +++++++++++------- package.json | 2 +- .../convertImageToBase64.js | 18 +- .../canvas/highResolutionCanvas/README.md | 4 +- .../highResolutionCanvas.js | 22 +- packages/function/after/README.md | 21 +- packages/function/after/after.js | 34 +- packages/function/after/test.js | 14 +- packages/function/ary/README.md | 10 +- packages/function/ary/ary.js | 27 +- packages/function/ary/test.js | 6 +- packages/function/before/README.md | 17 +- packages/function/before/before.js | 36 +- packages/function/before/test.js | 16 +- packages/function/compose/README.md | 22 +- packages/function/compose/compose.js | 38 +- packages/function/compose/test.js | 38 +- packages/function/curry/README.md | 26 +- packages/function/curry/curry.js | 44 +- packages/function/curry/test.js | 42 +- packages/function/debounce/README.md | 19 +- packages/function/debounce/debounce.js | 28 +- packages/function/debounce/test.js | 18 +- packages/function/flip/README.md | 16 +- packages/function/flip/flip.js | 24 +- packages/function/flip/test.js | 20 +- packages/function/negate/README.md | 38 +- packages/function/negate/negate.js | 47 +- packages/function/negate/test.js | 12 +- packages/function/once/README.md | 24 +- packages/function/once/once.js | 36 +- packages/function/once/test.js | 14 +- packages/function/partial/README.md | 33 +- packages/function/partial/partial.js | 49 +- packages/function/partial/test.js | 34 +- packages/function/partialRight/README.md | 21 +- .../function/partialRight/partialRight.js | 35 +- packages/function/partialRight/test.js | 20 +- packages/function/pipe/README.md | 22 +- packages/function/pipe/pipe.js | 38 +- packages/function/pipe/test.js | 40 +- packages/function/throttle/README.md | 11 +- packages/function/throttle/test.js | 6 +- packages/function/throttle/throttle.js | 26 +- packages/function/unary/README.md | 12 +- packages/function/unary/test.js | 6 +- packages/function/unary/unary.js | 18 +- 48 files changed, 891 insertions(+), 909 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ef3f4e2d..601b47d9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,11 +4,10 @@ "node": true, "jest": true, "amd": true, - "commonjs": true, - "es6": true + "commonjs": true }, "parserOptions": { - "ecmaVersion": 2017 + "ecmaVersion": "latest" }, "globals": { "Promise": false, @@ -63,6 +62,9 @@ "exceptions": { "Property": false } - }] + }], + "prefer-rest-params": ["warn"], + "prefer-const": ["warn"], + "no-var": ["warn"] } } diff --git a/package-lock.json b/package-lock.json index a1764f3f..6615626f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -389,23 +389,86 @@ } }, "@eslint/eslintrc": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.1.tgz", - "integrity": "sha512-XRUeBZ5zBWLYgSANMpThFddrZZkEbGHgUdt5UJjZfnlN9BGCiUBrf+nvbRupSjMvqzwnQN0qwCmOxITt1cfywA==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.2.tgz", + "integrity": "sha512-AXYd23w1S/bv3fTs3Lz0vjiYemS08jWkI3hYyS9I1ry+0f+Yjs1wm+sU0BS8qDOPrBIkp4qHYC16I8uVtpLajQ==", "dev": true, "requires": { "ajv": "^6.12.4", - "debug": "^4.1.1", - "espree": "^7.3.0", - "globals": "^12.1.0", - "ignore": "^4.0.6", + "debug": "^4.3.2", + "espree": "^9.4.0", + "globals": "^13.15.0", + "ignore": "^5.2.0", "import-fresh": "^3.2.1", - "js-yaml": "^3.13.1", - "lodash": "^4.17.19", - "minimatch": "^3.0.4", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "requires": { + "argparse": "^2.0.1" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + } } }, + "@humanwhocodes/config-array": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.10.4.tgz", + "integrity": "sha512-mXAIHxZT3Vcpg83opl1wGlVZ9xydbfZO3r5YfRSH6Gpp2J/PfdBP0wbDa2sO6/qRbcalpoevVyW6A/fI6LfeMw==", + "dev": true, + "requires": { + "@humanwhocodes/object-schema": "^1.2.1", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + } + }, + "@humanwhocodes/gitignore-to-minimatch": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@humanwhocodes/gitignore-to-minimatch/-/gitignore-to-minimatch-1.0.2.tgz", + "integrity": "sha512-rSqmMJDdLFUsyxR6FMtD00nfQKKLFb1kv+qBbOVKqErvloEIJLo5bDTJTQNTYgeyp78JsA7u/NPi5jT1GR/MuA==", + "dev": true + }, + "@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true + }, + "@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -636,6 +699,32 @@ "chalk": "^4.0.0" } }, + "@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + } + }, + "@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true + }, + "@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "requires": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + } + }, "@sinonjs/commons": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.1.tgz", @@ -802,9 +891,9 @@ } }, "acorn-jsx": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", - "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true }, "acorn-walk": { @@ -823,9 +912,9 @@ } }, "ajv": { - "version": "6.12.4", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.4.tgz", - "integrity": "sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ==", + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", @@ -834,12 +923,6 @@ "uri-js": "^4.2.2" } }, - "ansi-colors": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", - "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", - "dev": true - }, "ansi-escapes": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz", @@ -909,6 +992,12 @@ "integrity": "sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ=", "dev": true }, + "array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true + }, "array-unique": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/array-unique/-/array-unique-0.3.2.tgz", @@ -921,12 +1010,6 @@ "integrity": "sha1-WWZ/QfrdTyDMvCu5a41Pf3jsA2c=", "dev": true }, - "astral-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", - "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", - "dev": true - }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -1505,6 +1588,15 @@ "integrity": "sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q==", "dev": true }, + "dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "requires": { + "path-type": "^4.0.0" + } + }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -1537,12 +1629,6 @@ "integrity": "sha512-A8OG5SR/ij3SsJdWDJdkkSYUjQdCUx6APQXem0SaEePBSRg4eymGYwBkKo1Y6DU+af/Jn2dBQqDBvjnr9Vi8nQ==", "dev": true }, - "emoji-regex": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", - "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==", - "dev": true - }, "end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -1552,15 +1638,6 @@ "once": "^1.4.0" } }, - "enquirer": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", - "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", - "dev": true, - "requires": { - "ansi-colors": "^4.1.1" - } - }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -1577,98 +1654,187 @@ "dev": true }, "eslint": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.13.0.tgz", - "integrity": "sha512-uCORMuOO8tUzJmsdRtrvcGq5qposf7Rw0LwkTJkoDbOycVQtQjmnhZSuLQnozLE4TmAzlMVV45eCHmQ1OpDKUQ==", + "version": "8.23.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.23.1.tgz", + "integrity": "sha512-w7C1IXCc6fNqjpuYd0yPlcTKKmHlHHktRkzmBPZ+7cvNBQuiNjx0xaMTjAJGCafJhQkrFJooREv0CtrVzmHwqg==", "dev": true, "requires": { - "@babel/code-frame": "^7.0.0", - "@eslint/eslintrc": "^0.2.1", + "@eslint/eslintrc": "^1.3.2", + "@humanwhocodes/config-array": "^0.10.4", + "@humanwhocodes/gitignore-to-minimatch": "^1.0.2", + "@humanwhocodes/module-importer": "^1.0.1", "ajv": "^6.10.0", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", - "debug": "^4.0.1", + "debug": "^4.3.2", "doctrine": "^3.0.0", - "enquirer": "^2.3.5", - "eslint-scope": "^5.1.1", - "eslint-utils": "^2.1.0", - "eslint-visitor-keys": "^2.0.0", - "espree": "^7.3.0", - "esquery": "^1.2.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.1.1", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.3.0", + "espree": "^9.4.0", + "esquery": "^1.4.0", "esutils": "^2.0.2", - "file-entry-cache": "^5.0.1", - "functional-red-black-tree": "^1.0.1", - "glob-parent": "^5.0.0", - "globals": "^12.1.0", - "ignore": "^4.0.6", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "find-up": "^5.0.0", + "glob-parent": "^6.0.1", + "globals": "^13.15.0", + "globby": "^11.1.0", + "grapheme-splitter": "^1.0.4", + "ignore": "^5.2.0", "import-fresh": "^3.0.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "js-yaml": "^3.13.1", + "js-sdsl": "^4.1.4", + "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.19", - "minimatch": "^3.0.4", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.1", - "progress": "^2.0.0", - "regexpp": "^3.1.0", - "semver": "^7.2.1", - "strip-ansi": "^6.0.0", + "regexpp": "^3.2.0", + "strip-ansi": "^6.0.1", "strip-json-comments": "^3.1.0", - "table": "^5.2.3", - "text-table": "^0.2.0", - "v8-compile-cache": "^2.0.3" + "text-table": "^0.2.0" + }, + "dependencies": { + "argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "requires": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + } + }, + "js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "requires": { + "argparse": "^2.0.1" + } + }, + "locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "requires": { + "p-locate": "^5.0.0" + } + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "requires": { + "yocto-queue": "^0.1.0" + } + }, + "p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "requires": { + "p-limit": "^3.0.2" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.1" + } + } } }, "eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", + "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", "dev": true, "requires": { "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" + "estraverse": "^5.2.0" } }, "eslint-utils": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz", - "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", "dev": true, "requires": { - "eslint-visitor-keys": "^1.1.0" + "eslint-visitor-keys": "^2.0.0" }, "dependencies": { "eslint-visitor-keys": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", - "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true } } }, "eslint-visitor-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz", - "integrity": "sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", "dev": true }, "espree": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.0.tgz", - "integrity": "sha512-dksIWsvKCixn1yrEXO8UosNSxaDoSYpq9reEjZSbHLpT5hpaCAKTLBwq0RHtLrIr+c0ByiYzWT8KTMRzoRCNlw==", + "version": "9.4.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.4.0.tgz", + "integrity": "sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==", "dev": true, "requires": { - "acorn": "^7.4.0", - "acorn-jsx": "^5.2.0", - "eslint-visitor-keys": "^1.3.0" + "acorn": "^8.8.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" }, "dependencies": { - "eslint-visitor-keys": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", - "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", + "acorn": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", + "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==", "dev": true } } @@ -1680,20 +1846,12 @@ "dev": true }, "esquery": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.3.1.tgz", - "integrity": "sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", + "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", "dev": true, "requires": { "estraverse": "^5.1.0" - }, - "dependencies": { - "estraverse": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", - "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", - "dev": true - } } }, "esrecurse": { @@ -1703,20 +1861,12 @@ "dev": true, "requires": { "estraverse": "^5.2.0" - }, - "dependencies": { - "estraverse": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.2.0.tgz", - "integrity": "sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ==", - "dev": true - } } }, "estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true }, "esutils": { @@ -1976,6 +2126,46 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, + "fast-glob": { + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", + "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" + }, + "dependencies": { + "glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "requires": { + "is-glob": "^4.0.1" + } + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "dev": true, + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true + } + } + }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -1988,6 +2178,15 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fastq": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", + "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "dev": true, + "requires": { + "reusify": "^1.0.4" + } + }, "fb-watchman": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.1.tgz", @@ -1998,12 +2197,12 @@ } }, "file-entry-cache": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-5.0.1.tgz", - "integrity": "sha512-bCg29ictuBaKUwwArK4ouCaqDgLZcysCFLmM/Yn/FDoqndh/9vNuQfXRDvTuXKLxfD/JtZQGKFT8MGcJBK644g==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, "requires": { - "flat-cache": "^2.0.1" + "flat-cache": "^3.0.4" } }, "fill-range": { @@ -2026,20 +2225,19 @@ } }, "flat-cache": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-2.0.1.tgz", - "integrity": "sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", "dev": true, "requires": { - "flatted": "^2.0.0", - "rimraf": "2.6.3", - "write": "1.0.3" + "flatted": "^3.1.0", + "rimraf": "^3.0.2" } }, "flatted": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-2.0.2.tgz", - "integrity": "sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.7.tgz", + "integrity": "sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==", "dev": true }, "for-in": { @@ -2076,12 +2274,6 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, - "functional-red-black-tree": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", - "dev": true - }, "gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -2130,21 +2322,43 @@ } }, "glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, "requires": { - "is-glob": "^4.0.1" + "is-glob": "^4.0.3" } }, "globals": { - "version": "12.4.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", - "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", + "version": "13.17.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.17.0.tgz", + "integrity": "sha512-1C+6nQRb1GwGMKm2dH/E7enFAMxGTmGI7/dEdhy/DNelv85w9B72t3uc5frtMNXIbzrarJJ/lTCjcaZwbLJmyw==", "dev": true, "requires": { - "type-fest": "^0.8.1" + "type-fest": "^0.20.2" + }, + "dependencies": { + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + } + } + }, + "globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", + "dev": true, + "requires": { + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" } }, "graceful-fs": { @@ -2153,6 +2367,12 @@ "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", "dev": true }, + "grapheme-splitter": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", + "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", + "dev": true + }, "growly": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", @@ -2285,15 +2505,15 @@ } }, "ignore": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", - "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", "dev": true }, "import-fresh": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.2.tgz", - "integrity": "sha512-cTPNrlvJT6twpYy+YmKUKrTSjWFs3bjYjAhCwm+z4EOCubZxAuO+hHpRN64TqjEaYSHs7tJAE0w1CKMGmsG/lw==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, "requires": { "parent-module": "^1.0.0", @@ -2437,13 +2657,7 @@ "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true - }, - "is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true }, "is-generator-fn": { @@ -2453,9 +2667,9 @@ "dev": true }, "is-glob": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz", - "integrity": "sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg==", + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "requires": { "is-extglob": "^2.1.1" @@ -3092,6 +3306,12 @@ } } }, + "js-sdsl": { + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.4.tgz", + "integrity": "sha512-Y2/yD55y5jteOAmY50JbUZYwk3CP3wnLPEZnlR1w9oKhITrBEtAxwuWKebFf8hMrPMgbYwFoWK/lH2sBkErELw==", + "dev": true + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -3284,7 +3504,7 @@ "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, "json5": { @@ -3345,6 +3565,12 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, "lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", @@ -3398,6 +3624,12 @@ "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", "dev": true }, + "merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", + "dev": true + }, "micromatch": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", @@ -3465,15 +3697,6 @@ } } }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -3767,6 +3990,12 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", + "dev": true + }, "picomatch": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz", @@ -3841,12 +4070,6 @@ } } }, - "progress": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "dev": true - }, "prompts": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz", @@ -3879,6 +4102,12 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", + "dev": true + }, "react-is": { "version": "17.0.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.1.tgz", @@ -3927,9 +4156,9 @@ } }, "regexpp": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", - "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", "dev": true }, "remove-trailing-separator": { @@ -4007,10 +4236,16 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, + "reusify": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", + "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "dev": true + }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "dev": true, "requires": { "glob": "^7.1.3" @@ -4022,6 +4257,15 @@ "integrity": "sha512-nfMOlASu9OnRJo1mbEk2cz0D56a1MBNrJ7orjRZQG10XDyuvwksKbuXNp6qa+kbn839HwjwhBzhFmdsaEAfauA==", "dev": true }, + "run-parallel": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", + "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", + "dev": true, + "requires": { + "queue-microtask": "^1.2.2" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -4268,17 +4512,6 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true }, - "slice-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", - "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.0", - "astral-regex": "^1.0.0", - "is-fullwidth-code-point": "^2.0.0" - } - }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -4537,34 +4770,6 @@ "strip-ansi": "^6.0.0" } }, - "string-width": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", - "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", - "dev": true, - "requires": { - "emoji-regex": "^7.0.1", - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^5.1.0" - }, - "dependencies": { - "ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true - }, - "strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dev": true, - "requires": { - "ansi-regex": "^4.1.0" - } - } - } - }, "strip-ansi": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz", @@ -4640,18 +4845,6 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, - "table": { - "version": "5.4.6", - "resolved": "https://registry.npmjs.org/table/-/table-5.4.6.tgz", - "integrity": "sha512-wmEc8m4fjnob4gt5riFRtTu/6+4rSe12TpAELNSqHMfF3IqnA+CH37USM6/YR3qRZv7e56kAEAtd6nKZaxe0Ug==", - "dev": true, - "requires": { - "ajv": "^6.10.2", - "lodash": "^4.17.14", - "slice-ansi": "^2.1.0", - "string-width": "^3.0.0" - } - }, "terminal-link": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/terminal-link/-/terminal-link-2.1.1.tgz", @@ -4676,7 +4869,7 @@ "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, "throat": { @@ -4836,9 +5029,9 @@ } }, "uri-js": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz", - "integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "requires": { "punycode": "^2.1.0" @@ -4863,12 +5056,6 @@ "dev": true, "optional": true }, - "v8-compile-cache": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz", - "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==", - "dev": true - }, "v8-to-istanbul": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-7.0.0.tgz", @@ -5044,15 +5231,6 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "dev": true }, - "write": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz", - "integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==", - "dev": true, - "requires": { - "mkdirp": "^0.5.1" - } - }, "write-file-atomic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -5142,6 +5320,12 @@ "camelcase": "^5.0.0", "decamelize": "^1.2.0" } + }, + "yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true } } } diff --git a/package.json b/package.json index 60a2be47..9abe22f3 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint": "eslint packages/**/*.js" }, "devDependencies": { - "eslint": "~7.13.0", + "eslint": "~8.23.1", "jest": "~26.6.3" } } diff --git a/packages/canvas/convertImageToBase64/convertImageToBase64.js b/packages/canvas/convertImageToBase64/convertImageToBase64.js index aff3765d..8bd6be31 100644 --- a/packages/canvas/convertImageToBase64/convertImageToBase64.js +++ b/packages/canvas/convertImageToBase64/convertImageToBase64.js @@ -4,7 +4,7 @@ * Converts an image's content to Data URI scheme. * * @param {String} url The path of the image to be converted. - * @return {Object} A promise that when resolved, returns the Base64 string. + * @returns {Object} A promise that when resolved, returns the Base64 string. * @example * * convertImageToBase64('images/index.png').then(function (string64) { @@ -12,23 +12,23 @@ * }); * // -> data:image/png;base64,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 */ -function convertImageToBase64(url) { - var canvas = document.createElement('canvas'); - var ctx = canvas.getContext('2d'); - var image = new Image(); +const convertImageToBase64 = url => { + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + const image = new Image(); image.src = url; - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { image.onload = resolve; image.onerror = reject; - }).then(function () { + }).then(() => { canvas.width = image.width; canvas.height = image.height; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(image, 0, 0); return canvas.toDataURL(); }); -} +}; -module.exports = convertImageToBase64; \ No newline at end of file +module.exports = convertImageToBase64; diff --git a/packages/canvas/highResolutionCanvas/README.md b/packages/canvas/highResolutionCanvas/README.md index 7b154408..d2502ee2 100644 --- a/packages/canvas/highResolutionCanvas/README.md +++ b/packages/canvas/highResolutionCanvas/README.md @@ -17,9 +17,9 @@ Downsampling on the canvas is achieved by performing the following three actions **Example** ```js -var canvas = document.querySelector('canvas'); +const canvas = document.querySelector('canvas'); -var context = highResolutionCanvas(canvas); +const context = highResolutionCanvas(canvas); // Use the `context` variable from now on to access the `CanvasRenderingContext2D` interface. context.beginPath(); diff --git a/packages/canvas/highResolutionCanvas/highResolutionCanvas.js b/packages/canvas/highResolutionCanvas/highResolutionCanvas.js index 1f5e52d9..9c85104e 100644 --- a/packages/canvas/highResolutionCanvas/highResolutionCanvas.js +++ b/packages/canvas/highResolutionCanvas/highResolutionCanvas.js @@ -10,9 +10,9 @@ * @returns {CanvasRenderingContext2D} The 2D rendering context for the drawing surface of the `HTMLCanvasElement`. * @example * - * var canvas = document.querySelector('canvas'); + * const canvas = document.querySelector('canvas'); * - * var context = highResolutionCanvas(canvas); + * const context = highResolutionCanvas(canvas); * * // Use the `context` variable from now on to access the `CanvasRenderingContext2D` interface. * context.beginPath(); @@ -20,23 +20,22 @@ * context.fillStyle = "#ff0000"; * context.fill(); */ -function highResolutionCanvas(canvas) { - var ctx = canvas.getContext('2d'); - var devicePixelRatio = window.devicePixelRatio || 1; +const highResolutionCanvas = canvas => { + const ctx = canvas.getContext('2d'); + const devicePixelRatio = window.devicePixelRatio || 1; - var backingStoreRatio = ctx.webkitBackingStorePixelRatio + const backingStoreRatio = ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1; - var ratio = devicePixelRatio / backingStoreRatio; - var oldWidth, oldHeight; + const ratio = devicePixelRatio / backingStoreRatio; if (devicePixelRatio !== backingStoreRatio) { - oldWidth = canvas.width; - oldHeight = canvas.height; + const oldWidth = canvas.width; + const oldHeight = canvas.height; canvas.width = Math.round(oldWidth * ratio); canvas.height = Math.round(oldHeight * ratio); @@ -47,5 +46,6 @@ function highResolutionCanvas(canvas) { } return ctx; -} +}; + module.exports = highResolutionCanvas; diff --git a/packages/function/after/README.md b/packages/function/after/README.md index 5397fa16..03f5591b 100644 --- a/packages/function/after/README.md +++ b/packages/function/after/README.md @@ -1,26 +1,25 @@ -## after(n, func) ⇒ function -Creates a function that invokes `func` once it's called `n` or more times. -`func` is invoked with the this binding and arguments of the created function. +## after(n, fn) ⇒ function +Creates a function that invokes `fn` once it's called `n` or more times. +`fn` is invoked with the this binding and arguments of the created function. **Returns**: function - The new restricted function. **Throws**: - TypeError If `n` is not number. -- TypeError If `func` is not function. +- TypeError If `fn` is not function. + | Param | Type | Description | | --- | --- | --- | -| n | Number | The number of calls before `func` is invoked. A positive integer is expected. If a negative number or 0, `func` is invoked immediately. If `NaN`, `-Infinity` or `Infinity`, `func` is never invoked. | -| func | function | The function to restrict. | +| n | Number | The number of calls before `fn` is invoked. A positive integer is expected. If a negative number or 0, `fn` is invoked immediately. If `NaN`, `-Infinity` or `Infinity`, `fn` is never invoked. | +| fn | function | The function to restrict. | -**Example** +**Example** ```js -var doSomething = after(4, function () { - console.log('Do something...'); -}); +const doSomething = after(4, () => console.log('Do something...'); button.addEventListener('click', doSomething); -// -> logs "Do something..." after button is clicked at least 4 times. +// => logs "Do something..." after button is clicked at least 4 times. ``` diff --git a/packages/function/after/after.js b/packages/function/after/after.js index 9096bf2d..accc48d7 100644 --- a/packages/function/after/after.js +++ b/packages/function/after/after.js @@ -1,42 +1,40 @@ 'use strict'; /** - * Creates a function that invokes `func` once it's called `n` or more times. - * `func` is invoked with the this binding and arguments of the created function. + * Creates a function that invokes `fn` once it's called `n` or more times. + * `fn` is invoked with the this binding and arguments of the created function. * - * @param {Number} n The number of calls before `func` is invoked. - * A positive integer is expected. - * If a negative number or 0, `func` is invoked immediately. - * If `NaN`, `-Infinity` or `Infinity`, `func` is never invoked. - * @param {function} func The function to restrict. + * @param {Number} n The number of calls before `fn` is invoked. + * A positive integer is expected. + * If a negative number or 0, `fn` is invoked immediately. + * If `NaN`, `-Infinity` or `Infinity`, `fn` is never invoked. + * @param {function} fn The function to restrict. * @throws {TypeError} If `n` is not number. - * @throws {TypeError} If `func` is not function. + * @throws {TypeError} If `fn` is not function. * @return {function} The new restricted function. * @example * - * var doSomething = after(4, function () { - * console.log('Do something...'); - * }); + * const doSomething = after(4, () => console.log('Do something...'); * * button.addEventListener('click', doSomething); - * // -> logs "Do something..." after button is clicked at least 4 times. + * // => logs "Do something..." after button is clicked at least 4 times. */ -function after(n, func) { +const after = (n, fn) => { if (typeof n !== 'number') { throw new TypeError('Expected a number for first argument'); } - if (typeof func !== 'function') { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for second argument'); } n = parseInt(n, 10); - return function () { + return (...args) => { if (--n < 1) { - return func.apply(this, arguments); + return fn(...args); } }; -} +}; -module.exports = after; \ No newline at end of file +module.exports = after; diff --git a/packages/function/after/test.js b/packages/function/after/test.js index e12f3126..ceac62c0 100644 --- a/packages/function/after/test.js +++ b/packages/function/after/test.js @@ -1,16 +1,14 @@ -var after = require('./after'); +const after = require('./after'); describe('Function/after', function () { it('should invoke a function after it\'s been called n times', function () { - var count = 0; - var result; + let count = 0; + let result; - var doSomething = after(5, function () { - return count += 1; - }); + const doSomething = after(5, x => count += x); - for (var i = 0; i < 10; i += 1) { - result = doSomething(); + for (let i = 0; i < 10; i += 1) { + result = doSomething(1); } expect(result).toEqual(6); diff --git a/packages/function/ary/README.md b/packages/function/ary/README.md index d9e85e29..938f5ffe 100644 --- a/packages/function/ary/README.md +++ b/packages/function/ary/README.md @@ -1,25 +1,25 @@ -## ary(func, n) ⇒ function +## ary(fn, n) ⇒ function Creates a function that accepts up to `n` arguments, ignoring any additional arguments. **Returns**: function - Returns the new capped function. **Throws**: -- TypeError Throws if `func` is not function. +- TypeError Throws if `fn` is not function. - TypeError Throws if `n` is not number. | Param | Type | Description | | --- | --- | --- | -| func | function | The function to cap arguments for. | +| fn | function | The function to cap arguments for. | | n | Number | The arity cap. | **Example** ```js -var array = ['1', '2', '3']; +const array = ['1', '2', '3']; -var toInteger = ary(parseInt, 1); +const toInteger = ary(parseInt, 1); array.map(toInteger); // -> [1, 2, 3] ``` diff --git a/packages/function/ary/ary.js b/packages/function/ary/ary.js index 107df494..9270847c 100644 --- a/packages/function/ary/ary.js +++ b/packages/function/ary/ary.js @@ -3,21 +3,21 @@ /** * Creates a function that accepts up to `n` arguments, ignoring any additional arguments. * - * @param {function} func The function to cap arguments for. + * @param {function} fn The function to cap arguments for. * @param {Number} n The arity cap. - * @throws {TypeError} Throws if `func` is not function. + * @throws {TypeError} Throws if `fn` is not function. * @throws {TypeError} Throws if `n` is not number. * @returns {function} Returns the new capped function. * @example * - * var array = ['1', '2', '3']; + * const array = ['1', '2', '3']; * - * var toInteger = ary(parseInt, 1); + * const toInteger = ary(parseInt, 1); * * array.map(toInteger); // -> [1, 2, 3] */ -function ary(func, n) { - if (typeof func !== 'function') { +const ary = (fn, n) => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } @@ -25,18 +25,11 @@ function ary(func, n) { throw new TypeError('Expected a number for second argument'); } - return function (/* ...args */) { - var _len = arguments.length; - var _key = 0; - var args = new Array(_len); - var arityCap = n > 0 ? n : 0; + return (...args) => { + const arityCap = n > 0 ? n : 0; - for (; _key < _len; _key += 1) { - args[_key] = arguments[_key]; - } - - return func.apply(void 0, args.slice(0, arityCap)); + return fn(...args.slice(0, arityCap)); }; -} +}; module.exports = ary; diff --git a/packages/function/ary/test.js b/packages/function/ary/test.js index c29b1d47..20cb2229 100644 --- a/packages/function/ary/test.js +++ b/packages/function/ary/test.js @@ -1,9 +1,7 @@ -var ary = require('./ary.js'); +const ary = require('./ary.js'); describe('Function/ary', function () { - var fn = function (a, b) { - return [a, b]; - }; + const fn = (a, b) => ([a, b]); it('should create a function that accepts up to 1 argument, ignoring any additional arguments', function () { expect(ary(fn, 1)()).toStrictEqual([void 0, void 0]); diff --git a/packages/function/before/README.md b/packages/function/before/README.md index 92a183b1..f6294479 100644 --- a/packages/function/before/README.md +++ b/packages/function/before/README.md @@ -1,26 +1,25 @@ ## before(n, func) ⇒ function -Creates a function that invokes `func` while it’s called less than `n` times. -`func` is invoked with the this binding and arguments of the created function. +Creates a function that invokes `fn` while it’s called less than `n` times. +`fn` is invoked with the this binding and arguments of the created function. **Returns**: function - Returns the new restricted function. **Throws**: - TypeError If `n` is not number. -- TypeError If `func` is not function. +- TypeError If `fn` is not function. + | Param | Type | Description | | --- | --- | --- | -| n | Number | The number of calls before `func` is no longer invoked. A positive integer is expected. If a negative number or 0, `func` is never invoked. If `NaN`, `-Infinity` or `Infinity`, `func` is never invoked. | +| n | Number | The number of calls before `fn` is no longer invoked. A positive integer is expected. If a negative number or 0, `fn` is never invoked. If `NaN`, `-Infinity` or `Infinity`, `fn` is never invoked. | | func | function | The function to restrict. | -**Example** +**Example** ```js -var doSomething = before(6, function () { - console.log('Do something...'); -}); +const doSomething = before(6, () => console.log('Do something...')); button.addEventListener('click', doSomething); -// -> logs "Do something..." up to 5 times. +// => logs "Do something..." up to 5 times. ``` diff --git a/packages/function/before/before.js b/packages/function/before/before.js index 9c933635..620d7673 100644 --- a/packages/function/before/before.js +++ b/packages/function/before/before.js @@ -1,50 +1,48 @@ 'use strict'; /** - * Creates a function that invokes `func` while it’s called less than `n` times. - * `func` is invoked with the this binding and arguments of the created function. + * Creates a function that invokes `fn` while it’s called less than `n` times. + * `fn` is invoked with the this binding and arguments of the created function. * - * @param {Number} n The number of calls before `func` is no longer invoked. - * A positive integer is expected. - * If a negative number or 0, `func` is never invoked. - * If `NaN`, `-Infinity` or `Infinity`, `func` is never invoked. + * @param {Number} n The number of calls before `fn` is no longer invoked. + * A positive integer is expected. + * If a negative number or 0, `fn` is never invoked. + * If `NaN`, `-Infinity` or `Infinity`, `fn` is never invoked. * @param {function} func The function to restrict. * @throws {TypeError} If `n` is not number. - * @throws {TypeError} If `func` is not function. + * @throws {TypeError} If `fn` is not function. * @return {function} Returns the new restricted function. * @example * - * var doSomething = before(6, function () { - * console.log('Do something...'); - * }); + * const doSomething = before(6, () => console.log('Do something...')); * * button.addEventListener('click', doSomething); - * // -> logs "Do something..." up to 5 times. + * // => logs "Do something..." up to 5 times. */ -function before(n, func) { - var result; +const before = (n, fn) => { + let result; if (typeof n !== 'number') { throw new TypeError('Expected a number for first argument'); } - if (typeof func !== 'function') { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for second argument'); } n = parseInt(n, 10); - return function () { + return (...args) => { if (--n > 0) { - result = func.apply(this, arguments); + result = fn(...args); } if (n <= 1) { - func = void 0; + fn = void 0; } return result; }; -} +}; -module.exports = before; \ No newline at end of file +module.exports = before; diff --git a/packages/function/before/test.js b/packages/function/before/test.js index 65b7f77b..4d1ca0ec 100644 --- a/packages/function/before/test.js +++ b/packages/function/before/test.js @@ -1,18 +1,14 @@ -var before = require('./before'); +const before = require('./before'); describe('Function/before', function () { it('should invoke a function up to 5 times', function () { - var count = 0, - result; + let count = 0; + let result; - var doSomething = before(6, function () { - return count += 1; - }); + const doSomething = before(6, x => count += x); - var i = 0; - - for (i = 0; i < 10; i += 1) { - result = doSomething(); + for (let i = 0; i < 10; i += 1) { + result = doSomething(1); } expect(result).toEqual(5); diff --git a/packages/function/compose/README.md b/packages/function/compose/README.md index 5c6bba8c..3b41c3e0 100644 --- a/packages/function/compose/README.md +++ b/packages/function/compose/README.md @@ -4,22 +4,22 @@ Performs right-to-left function composition. The rightmost function may have any arity; the remaining functions must be unary. -**Returns**: function - A new function as the result of the composition +**Returns**: function - A new function as the result of the composition. | Param | Type | Description | | --- | --- | --- | -| ...fns | function | The functions to compose | +| ...fns | function | The functions to compose. | -**Example** +**Example** ```js -function inc(x) { - return x + 1; -} +const inc = x => x + 1; +const double = x => x * 2; -function double(x) { - return x * 2; -} +compose(inc, double)(3); // => 7 +compose(double, inc)(3); // => 8 -compose(inc, double)(3); // -> 7 -compose(double, inc)(3); // -> 8 +const capitalize = a => a.toUpperCase(); +const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; +const shoutGreeting = compose(capitalize, greeting); +shoutGreeting('John', 'Doe'); // => 'HELLO, MY NAME IS JOHN DOE.' ``` diff --git a/packages/function/compose/compose.js b/packages/function/compose/compose.js index e10b1420..8366a853 100644 --- a/packages/function/compose/compose.js +++ b/packages/function/compose/compose.js @@ -4,41 +4,31 @@ * Performs right-to-left function composition. * The rightmost function may have any arity; the remaining functions must be unary. * - * @param {...function} fns The functions to compose - * @returns {function} A new function as the result of the composition + * @param {function} ...fns The functions to compose. + * @returns {function} A new function as the result of the composition. * @example * - * function inc(x) { - * return x + 1; - * } + * const inc = x => x + 1; + * const double = x => x * 2; * - * function double(x) { - * return x * 2; - * } + * compose(inc, double)(3); // => 7 + * compose(double, inc)(3); // => 8 * - * compose(inc, double)(3); // -> 7 - * compose(double, inc)(3); // -> 8 + * const capitalize = a => a.toUpperCase(); + * const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; + * const shoutGreeting = compose(capitalize, greeting); + * shoutGreeting('John', 'Doe'); // => 'HELLO, MY NAME IS JOHN DOE.' */ -function compose(/* ...fns */) { - for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) { - fns[_key] = arguments[_key]; - } - +const compose = (...fns) => { if (fns.length === 0) { - return function (fn) { - return fn; - }; + return fn => fn; } if (fns.length === 1) { return fns[0]; } - return fns.reduce(function (a, b) { - return function () { - return a(b.apply(void 0, arguments)); - }; - }); -} + return fns.reduce((a, b) => (...args) => a(b(...args))); +}; module.exports = compose; diff --git a/packages/function/compose/test.js b/packages/function/compose/test.js index f9905273..4150d1ac 100644 --- a/packages/function/compose/test.js +++ b/packages/function/compose/test.js @@ -1,25 +1,11 @@ -var compose = require('./compose.js'); +const compose = require('./compose.js'); -describe('Function/compose', function () { - function capitalize(a) { - return a.toUpperCase(); - } - - function head(a) { - return a[0]; - } - - function reverse(a) { - return a.split('').reverse().join(''); - } - - function inc(x) { - return x + 1; - } - - function double(x) { - return x * 2; - } +describe('compose', () => { + const capitalize = a => a.toUpperCase(); + const head = a => a[0]; + const reverse = a => a.split('').reverse().join(''); + const inc = x => x + 1; + const double = x => x * 2; it('should perform right-to-left function composition', () => { expect(compose()()).toBeUndefined(); @@ -40,14 +26,12 @@ describe('Function/compose', function () { expect(compose(double, inc)(3)).toBe(8); - var reverseAndHead = compose(head, reverse); - var reverseHeadAndCapitalize = compose(capitalize, reverseAndHead); + const reverseAndHead = compose(head, reverse); + const reverseHeadAndCapitalize = compose(capitalize, reverseAndHead); expect(reverseHeadAndCapitalize('hello')).toBe('O'); - var greeting = function (firstName, lastName) { - return 'Hello, my name is ' + firstName + ' ' + lastName + '.'; - }; - var shoutGreeting = compose(capitalize, greeting); + const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; + const shoutGreeting = compose(capitalize, greeting); expect(shoutGreeting('John', 'Doe')).toBe('HELLO, MY NAME IS JOHN DOE.'); expect(compose(shoutGreeting('John', 'Doe'))).toBe('HELLO, MY NAME IS JOHN DOE.'); }); diff --git a/packages/function/curry/README.md b/packages/function/curry/README.md index ad523eec..6d805ea8 100644 --- a/packages/function/curry/README.md +++ b/packages/function/curry/README.md @@ -4,7 +4,7 @@ Transforms a function of N arguments in such a way that it can be called as a chain of N functions each with a single argument (arity: 1). -**Returns**: function - A curried equivalent of the provided function +**Returns**: function - A curried equivalent of the provided function. **Throws**: - TypeError Throws if `func` is not a function. @@ -16,21 +16,15 @@ be called as a chain of N functions each with a single argument (arity: 1). | func | function | | The initial function to be curried. | | [arity] | Number | func.length | The arity of the provided function. Useful in cases that arity cannot be determined by `func.length`. As of ES2015 when a function has a rest parameter or at least one parameter with default value, the `func.length` is not properly calculated. | -**Example** +**Example** ```js -var add = curry(function (a, b) { - return a + b; -}); - -var addOne = add(1); -addOne(2); // -> 3 +const add = curry((a, b) => a + b); +const addOne = add(1); +addOne(2); // => 3 // Provide arity as second argument in cases that it cannot be determined. -var add = curry(function (a = 0, ...args) { - return a + args[0] + args[1]; -}, 3); - -var addOne = add(1); -var addTwo = addOne(2); -addTwo(3); // -> 6 -``` \ No newline at end of file +const add = curry((a = 0, ...args) => a + args[0] + args[1], 3); +const addOne = add(1); +const addTwo = addOne(2); +addTwo(3); // => 6 +``` diff --git a/packages/function/curry/curry.js b/packages/function/curry/curry.js index 9171f52a..91dc6f63 100644 --- a/packages/function/curry/curry.js +++ b/packages/function/curry/curry.js @@ -11,26 +11,20 @@ * parameter with default value, the `func.length` is not properly calculated. * @throws {TypeError} Throws if `func` is not a function. * @throws {TypeError} Throws if `arity` is not a number but not undefined. - * @returns {function} A curried equivalent of the provided function + * @returns {function} A curried equivalent of the provided function. * @example * - * var add = curry(function (a, b) { - * return a + b; - * }); - * - * var addOne = add(1); - * addOne(2); // -> 3 + * const add = curry((a, b) => a + b); + * const addOne = add(1); + * addOne(2); // => 3 * * // Provide arity as second argument in cases that it cannot be determined. - * var add = curry(function (a = 0, ...args) { - * return a + args[0] + args[1]; - * }, 3); - * - * var addOne = add(1); - * var addTwo = addOne(2); - * addTwo(3); // -> 6 + * const add = curry((a = 0, ...args) => a + args[0] + args[1], 3); + * const addOne = add(1); + * const addTwo = addOne(2); + * addTwo(3); // => 6 */ -function curry(func, arity) { +const curry = (func, arity) => { if (typeof func !== 'function') { throw new TypeError('Expected a function for first argument'); } @@ -39,19 +33,11 @@ function curry(func, arity) { throw new TypeError('Expected a number for second argument'); } - return function curried(/* ...args_a */) { - for (var _len = arguments.length, args_a = new Array(_len), _key = 0; _key < _len; _key++) { - args_a[_key] = arguments[_key]; - } - - return args_a.length >= (arity || func.length) ? func.apply(void 0, args_a) : function (/* ...args_b */) { - for (var _len2 = arguments.length, args_b = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args_b[_key2] = arguments[_key2]; - } - - return curried.apply(void 0, args_a.concat(args_b)); - }; + return function curried(...args_a) { + return args_a.length >= (arity || func.length) + ? func(...args_a) + : (...args_b) => curried(...args_a, ...args_b); }; -} +}; -module.exports = curry; \ No newline at end of file +module.exports = curry; diff --git a/packages/function/curry/test.js b/packages/function/curry/test.js index 7545b2f3..708416b9 100644 --- a/packages/function/curry/test.js +++ b/packages/function/curry/test.js @@ -1,42 +1,22 @@ -var curry = require('./curry.js'); +const curry = require('./curry.js'); -describe('Function/curry', () => { +describe('curry', () => { it('should return a curried function until all expected arguments are satisfied', () => { - var add = curry(function (a, b, c) { - return a + b + c; - }); - - var addOne = add(1); - var addTwo = addOne(2); - var res = addTwo(3); + const add = curry((a, b, c) => a + b + c); + const addOne = add(1); + const addTwo = addOne(2); + const res = addTwo(3); expect(res).toEqual(6); }); it('providing arity when cannot be automatically calculated', () => { - var add = curry(function (a = 0, ...args) { - return a + args[0] + args[1]; - }, 3); - - var addOne = add(1); - var addTwo = addOne(2); - var res = addTwo(3); + const add = curry((a = 0, ...args) => a + args[0] + args[1], 3); + const addOne = add(1); + const addTwo = addOne(2); + const res = addTwo(3); - expect(add).toHaveLength(0); + expect(add.length).toBe(0); expect(res).toBe(6); }); - - it('throws if first argument is not a function', function () { - expect(function () { - return curry(); - }).toThrow(new TypeError('Expected a function for first argument')); - }); - - it('throws if second argument is not a number', function () { - expect(function () { - return curry(function (a, b) { - return a + b; - }, '2')(1)(2); - }).toThrow(new TypeError('Expected a number for second argument')); - }); }); diff --git a/packages/function/debounce/README.md b/packages/function/debounce/README.md index 88bce3cb..4fba2642 100644 --- a/packages/function/debounce/README.md +++ b/packages/function/debounce/README.md @@ -1,6 +1,6 @@ -## debounce(func, [n], [immediate]) ⇒ function +## debounce(fn, [wait], [immediate]) ⇒ function Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for 'n' milliseconds. If `immediate` is passed, trigger the function on the @@ -9,17 +9,18 @@ leading edge, instead of the trailing. **Returns**: function - A new debounced function. **Throws**: -- TypeError If `func` is not function. +- TypeError If `fn` is not function. -| Param | Type | Description | -| --- | --- | --- | -| func | function | The function to be executed. | -| [wait] | Number | Time of delay in milliseconds. It is required if `immediate` is used. | -| [immediate] | Boolean | If true or any truthy value, triggers the function on the leading edge. | -**Example** +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| fn | function | | The function to be executed. | +| [wait] | Number | 0 | Time of delay in milliseconds. It is required if `immediate` is used. | +| [immediate] | Boolean | false | If true or any truthy value, triggers the function on the leading edge. | + +**Example** ```js -var debouncedHandler = debounce(function () { +const debouncedHandler = debounce(() => { // Do your thing here... }, 250); diff --git a/packages/function/debounce/debounce.js b/packages/function/debounce/debounce.js index 0a780d60..2d309533 100644 --- a/packages/function/debounce/debounce.js +++ b/packages/function/debounce/debounce.js @@ -6,42 +6,40 @@ * 'n' milliseconds. If `immediate` is passed, trigger the function on the * leading edge, instead of the trailing. * - * @param {function} func The function to be executed. - * @param {Number} [wait] Time of delay in milliseconds. It is required if `immediate` is used. - * @param {Boolean} [immediate] If true or any truthy value, triggers the function on the leading edge. - * @throws {TypeError} If `func` is not function. + * @param {function} fn The function to be executed. + * @param {Number} [wait=0] Time of delay in milliseconds. It is required if `immediate` is used. + * @param {Boolean} [immediate=false] If true or any truthy value, triggers the function on the leading edge. + * @throws {TypeError} If `fn` is not function. * @returns {function} A new debounced function. * @example * - * var debouncedHandler = debounce(function () { + * const debouncedHandler = debounce(() => { * // Do your thing here... * }, 250); * * window.addEventListener('resize', debouncedHandler, false); */ -function debounce(func, wait, immediate) { - var timerId = null; +const debounce = (fn, wait = 0, immediate = false) => { + let timerId = null; - if (typeof func !== 'function') { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function debounced() { - var context = this; - var args = arguments; + return (...args) => { clearTimeout(timerId); if (immediate && !timerId) { - func.apply(context, args); + fn(...args); } - timerId = setTimeout(function () { + timerId = setTimeout(() => { timerId = null; if (!immediate) { - func.apply(context, args); + fn(...args); } }, wait); }; -} +}; module.exports = debounce; diff --git a/packages/function/debounce/test.js b/packages/function/debounce/test.js index e7520e08..de193fdf 100644 --- a/packages/function/debounce/test.js +++ b/packages/function/debounce/test.js @@ -1,4 +1,4 @@ -var debounce = require('./debounce'); +const debounce = require('./debounce'); describe('Function/debounce', function () { beforeEach(function () { @@ -10,16 +10,16 @@ describe('Function/debounce', function () { }); it('debounces a function; triggers the function on the trailing edge', function () { - var func = jest.fn(); - var delay = 1000; // ms - var debouncedFunc = debounce(func, delay); + const func = jest.fn(); + const delay = 1000; // ms + const debouncedFunc = debounce(func, delay); // Call it immediately debouncedFunc(); expect(func).toHaveBeenCalledTimes(0); // Call it several times with 500ms (< 1000ms) between each call - for (var i = 0; i < 5; i += 1) { + for (let i = 0; i < 5; i += 1) { jest.advanceTimersByTime(500); debouncedFunc(); } @@ -33,16 +33,16 @@ describe('Function/debounce', function () { }); it('debounces a function; triggers the function on the leading edge', function () { - var func = jest.fn(); - var delay = 1000; // ms - var debouncedFunc = debounce(func, delay, true); + const func = jest.fn(); + const delay = 1000; // ms + const debouncedFunc = debounce(func, delay, true); // Call it immediately debouncedFunc(); expect(func).toHaveBeenCalledTimes(1); // Call it several times with 500ms (< 1000ms) between each call - for (var i = 0; i < 5; i += 1) { + for (let i = 0; i < 5; i += 1) { jest.advanceTimersByTime(500); debouncedFunc(); } diff --git a/packages/function/flip/README.md b/packages/function/flip/README.md index 2349d34a..ed507b19 100644 --- a/packages/function/flip/README.md +++ b/packages/function/flip/README.md @@ -1,23 +1,21 @@ -## flip(func) ⇒ function +## flip(fn) ⇒ function Creates a function that invokes the original function with its parameters reversed. **Returns**: function - Returns the new flipped function. **Throws**: -- TypeError Throws if `func` is not a function. +- TypeError Throws if `fn` is not a function. | Param | Type | Description | | --- | --- | --- | -| func | function | The function to invoke with its parameters reversed. | +| fn | function | The function to invoke with its parameters reversed. | -**Example** +**Example** ```js -var flipped = flip(function () { - return Array.prototype.slice.call(arguments, 0); -}); +const flipped = flip((...args) => args); -flipped(1, 2, 3, 4); // -> [4, 3, 2, 1] -``` \ No newline at end of file +flipped(1, 2, 3, 4); // => [4, 3, 2, 1] +``` diff --git a/packages/function/flip/flip.js b/packages/function/flip/flip.js index 331a0aa1..9ff3363b 100644 --- a/packages/function/flip/flip.js +++ b/packages/function/flip/flip.js @@ -3,29 +3,21 @@ /** * Creates a function that invokes the original function with its parameters reversed. * - * @param {function} func The function to invoke with its parameters reversed. - * @throws {TypeError} Throws if `func` is not a function. + * @param {function} fn The function to invoke with its parameters reversed. + * @throws {TypeError} Throws if `fn` is not a function. * @returns {function} Returns the new flipped function. * @example * - * var flipped = flip(function () { - * return Array.prototype.slice.call(arguments, 0); - * }); + * const flipped = flip((...args) => args); * - * flipped(1, 2, 3, 4); // -> [4, 3, 2, 1] + * flipped(1, 2, 3, 4); // => [4, 3, 2, 1] */ -function flip(func) { - if (typeof func !== 'function') { +const flip = fn => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function flipped(/* ...args */) { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - - return func.apply(void 0, args.reverse()); - }; -} + return (...args) => fn(...args.reverse()); +}; module.exports = flip; diff --git a/packages/function/flip/test.js b/packages/function/flip/test.js index 39d3bcdf..514c78ec 100644 --- a/packages/function/flip/test.js +++ b/packages/function/flip/test.js @@ -1,24 +1,14 @@ -var flip = require('./flip.js'); - -describe('Function/flip', function () { - it('creates a new function that invokes the original function with its parameters reversed', function () { - var args = function () { - return Array.prototype.slice.call(arguments, 0); - }; +const flip = require('./flip.js'); +describe('flip', () => { + it('creates a new function that invokes the original function with its parameters reversed', () => { + const args = (...args) => args; expect(args(1, 2, 3, 4)).toEqual([1, 2, 3, 4]); expect(flip(args)(1, 2, 3, 4)).toEqual([4, 3, 2, 1]); expect(flip(args)()).toEqual([]); - var subtract = function (a, b) { - return a - b; - }; - + const subtract = (a, b) => a - b; expect(subtract(1, 2)).toBe(-1); expect(flip(subtract)(1, 2)).toBe(1); - - expect(function () { - return flip(null)(1, 2); - }).toThrow(new TypeError('Expected a function for first argument')); }); }); diff --git a/packages/function/negate/README.md b/packages/function/negate/README.md index 2cc4850a..5fd4925d 100644 --- a/packages/function/negate/README.md +++ b/packages/function/negate/README.md @@ -1,44 +1,40 @@ -## negate(func) ⇒ function -Creates a function that negates the result of the predicate `func`. -The `func` predicate is invoked with the this binding and arguments of the created function. +## negate(fn) ⇒ function +Creates a function that negates the result of the predicate `fn`. +The `fn` predicate is invoked with the this binding and arguments of the created function. **Returns**: function - Returns the new function. **Throws**: -- TypeError If `func` is not function. +- TypeError If `fn` is not function. + | Param | Type | Description | | --- | --- | --- | -| func | function | The predicate to negate. | -| [thisArg] | \* | Value to use as this when executing func. | +| fn | function | The predicate to negate. | -**Example** +**Example** ```js // Example 1 -var isString = function (val) { - return typeof val === 'string'; -}; +const isString = val => typeof val === 'string'; -var isNotString = negate(isString); +const isNotString = negate(isString); isString('lorem ipsum'); -// -> true +// => true isNotString('lorem ipsum'); -// -> false +// => false // Example 2 -var isEven = function (n) { - return n % 2 === 0; -}; +const isEven = n => n % 2 === 0; -var numbers = [1, 2, 3, 4, 5, 6]; +const numbers = [1, 2, 3, 4, 5, 6]; -var evens = numbers.filter(isEven); -// -> [2, 4, 6] +const evens = numbers.filter(isEven); +// => [2, 4, 6] -var odds = numbers.filter(negate(isEven)); -// -> [1, 3, 5] +const odds = numbers.filter(negate(isEven)); +// => [1, 3, 5] ``` diff --git a/packages/function/negate/negate.js b/packages/function/negate/negate.js index b74f382b..ac88a061 100644 --- a/packages/function/negate/negate.js +++ b/packages/function/negate/negate.js @@ -1,49 +1,42 @@ 'use strict'; /** - * Creates a function that negates the result of the predicate `func`. - * The `func` predicate is invoked with the this binding and arguments of the created function. + * Creates a function that negates the result of the predicate `fn`. + * The `fn` predicate is invoked with the arguments of the created function. * - * @param {function} func The predicate to negate. - * @param {*} [thisArg] Value to use as `this` when executing `func`. - * @throws {TypeError} If `func` is not function. - * @return {function} Returns the new function. + * @param {function} fn The predicate to negate. + * @throws {TypeError} If `fn` is not function. + * @returns {function} Returns the new function. * @example * * // Example 1 - * var isString = function (val) { - * return typeof val === 'string'; - * }; + * const isString = val => typeof val === 'string'; * - * var isNotString = negate(isString); + * const isNotString = negate(isString); * * isString('lorem ipsum'); - * // -> true + * // => true * * isNotString('lorem ipsum'); - * // -> false + * // => false * * // Example 2 - * var isEven = function (n) { - * return n % 2 === 0; - * }; + * const isEven = n => n % 2 === 0; * - * var numbers = [1, 2, 3, 4, 5, 6]; + * const numbers = [1, 2, 3, 4, 5, 6]; * - * var evens = numbers.filter(isEven); - * // -> [2, 4, 6] + * const evens = numbers.filter(isEven); + * // => [2, 4, 6] * - * var odds = numbers.filter(negate(isEven)); - * // -> [1, 3, 5] + * const odds = numbers.filter(negate(isEven)); + * // => [1, 3, 5] */ -function negate(func, thisArg) { - if (typeof func !== 'function') { +const negate = fn => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function () { - return !func.apply(thisArg, arguments); - }; -} + return (...args) => !fn(...args); +}; -module.exports = negate; \ No newline at end of file +module.exports = negate; diff --git a/packages/function/negate/test.js b/packages/function/negate/test.js index f4a00f8b..43247fcc 100644 --- a/packages/function/negate/test.js +++ b/packages/function/negate/test.js @@ -1,14 +1,12 @@ -var negate = require('./negate'); +const negate = require('./negate'); describe('Function/negate', function () { it('should negate the result of the predicate function', function () { - var isEven = function (n) { - return n % 2 === 0; - }; + const isEven = n => n % 2 === 0; - var numbers = [1, 2, 3, 4, 5, 6]; - var evens = numbers.filter(isEven); - var odds = numbers.filter(negate(isEven)); + const numbers = [1, 2, 3, 4, 5, 6]; + const evens = numbers.filter(isEven); + const odds = numbers.filter(negate(isEven)); expect(evens).toEqual([2, 4, 6]); diff --git a/packages/function/once/README.md b/packages/function/once/README.md index 1f2ac4c0..0b169f5a 100644 --- a/packages/function/once/README.md +++ b/packages/function/once/README.md @@ -1,25 +1,23 @@ -## once(func, [thisArg]) ⇒ function +## once(fn) ⇒ function Ensure a given functionality only runs once. **Returns**: function - Returns the new restricted function. +**Throws**: + +- TypeError If `fn` is not function. + | Param | Type | Description | | --- | --- | --- | -| func | function | The function to restrict. | -| [thisArg] | Object | Value to use as this when executing func. | +| fn | function | The function to restrict. | -**Example** +**Example** ```js -var num = 0; -var canOnlyFireOnce = once(function () { - return 'Number is now ' + (num += 1); -}); - -canOnlyFireOnce(); -// -> "Number is now 1" +let num = 0; +const canOnlyFireOnce = once(() => num += 1); -canOnlyFireOnce(); -// -> "Number is now 1" +canOnlyFireOnce(); // => 1 +canOnlyFireOnce(); // => 1 ``` diff --git a/packages/function/once/once.js b/packages/function/once/once.js index 028a45c4..7d0315ea 100644 --- a/packages/function/once/once.js +++ b/packages/function/once/once.js @@ -3,36 +3,32 @@ /** * Ensure a given functionality only runs once. * - * @param {function} func The function to restrict. - * @param {*} [thisArg] Value to use as this when executing `func`. + * @param {function} fn The function to restrict. + * @throws {TypeError} If `fn` is not function. * @return {function} Returns the new restricted function. * @example * - * var num = 0; - * var canOnlyFireOnce = once(function () { - * return 'Number is now ' + (num += 1); - * }); + * let num = 0; + * const canOnlyFireOnce = once(() => num += 1); * - * canOnlyFireOnce(); - * // -> "Number is now 1" - * - * canOnlyFireOnce(); - * // -> "Number is now 1" + * canOnlyFireOnce(); // => 1 + * canOnlyFireOnce(); // => 1 */ -function once(func, thisArg) { - var result; +const once = fn => { + let result; - if (typeof func !== 'function') { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function executeOnce() { - if (func) { - result = func.apply(thisArg || this, arguments); - func = null; + return (...args) => { + if (fn) { + result = fn(...args); + fn = null; } + return result; }; -} +}; -module.exports = once; \ No newline at end of file +module.exports = once; diff --git a/packages/function/once/test.js b/packages/function/once/test.js index 9d7258c2..91538ea7 100644 --- a/packages/function/once/test.js +++ b/packages/function/once/test.js @@ -1,15 +1,15 @@ -var once = require('./once'); +const once = require('./once'); describe('Function/once', function () { it('should execute a function only one time', function () { - var num = 0; - var canOnlyFireOnce = once(function () { - return num += 1; - }); + const fn = jest.fn(); + const canOnlyFireOnce = once(fn); - expect(canOnlyFireOnce()).toBe(1); + canOnlyFireOnce('foo'); + canOnlyFireOnce('bar'); - expect(canOnlyFireOnce()).toBe(1); + expect(fn).toHaveBeenCalledTimes(1); + expect(fn).toHaveBeenCalledWith('foo'); expect(function () { once(null)(); diff --git a/packages/function/partial/README.md b/packages/function/partial/README.md index c87a423f..3f275d12 100644 --- a/packages/function/partial/README.md +++ b/packages/function/partial/README.md @@ -1,34 +1,31 @@ -## partial(func) ⇒ function -Creates a new function that invokes the provided function `func` with `partials` prepended to the arguments it receives. +## partial(fn, ...args) ⇒ function +Creates a new function that invokes the provided function `fn` with `partials` prepended to the arguments it receives. **Returns**: function - Returns the new partially applied function. **Throws**: -- TypeError Throws if `func` is not a function. +- TypeError Throws if `fn` is not a function. | Param | Type | Description | | --- | --- | --- | -| func | function | The function to partially apply arguments to. | +| fn | function | The function to partially apply arguments to. | | [...args] | \* | The arguments to be partially applied. | -**Example** +**Example** ```js -var add = function (a, b, c) { - return a + b + c; -}; +const add = (a, b, c) => a + b + c; +const p1 = partial(add, 1); +p1(2, 3); // => 6 -var p1 = partial(add, 1); -p1(2, 3); // -> 6 +const p2 = partial(add, 10, 20); +p2(30); // => 60 -var p2 = partial(add, 10, 20); -p2(30); // -> 60 +const p3 = partial(add, 100, 200, 300); +p3(); // => 600 -var p3 = partial(add, 100, 200, 300); -p3(); // -> 600 - -var p4 = partial(add); -p4(5, 10, 15); // -> 30 -``` \ No newline at end of file +const p4 = partial(add); +p4(5, 10, 15); // => 30 +``` diff --git a/packages/function/partial/partial.js b/packages/function/partial/partial.js index 7e28c083..f28ee0eb 100644 --- a/packages/function/partial/partial.js +++ b/packages/function/partial/partial.js @@ -1,44 +1,33 @@ +'use strict'; + /** - * Creates a new function that invokes the provided function `func` with `partials` prepended to the arguments it receives. + * Creates a new function that invokes the provided function `fn` with `partials` prepended to the arguments it receives. * - * @param {function} func The function to partially apply arguments to. + * @param {function} fn The function to partially apply arguments to. * @param {*} [...args] The arguments to be partially applied. - * @throws {TypeError} Throws if `func` is not a function. + * @throws {TypeError} Throws if `fn` is not a function. * @returns {function} Returns the new partially applied function. * @example * - * var add = function (a, b, c) { - * return a + b + c; - * }; - * - * var p1 = partial(add, 1); - * p1(2, 3); // -> 6 + * const add = (a, b, c) => a + b + c; + * const p1 = partial(add, 1); + * p1(2, 3); // => 6 * - * var p2 = partial(add, 10, 20); - * p2(30); // -> 60 + * const p2 = partial(add, 10, 20); + * p2(30); // => 60 * - * var p3 = partial(add, 100, 200, 300); - * p3(); // -> 600 + * const p3 = partial(add, 100, 200, 300); + * p3(); // => 600 * - * var p4 = partial(add); - * p4(5, 10, 15); // -> 30 + * const p4 = partial(add); + * p4(5, 10, 15); // => 30 */ -function partial(func /* , ...args_a */) { - if (typeof func !== 'function') { +const partial = (fn, ...args_a) => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - for (var _len = arguments.length, args_a = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args_a[_key - 1] = arguments[_key]; - } - - return function (/* , ...args_b */) { - for (var _len2 = arguments.length, args_b = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args_b[_key2] = arguments[_key2]; - } - - return func.apply(void 0, args_a.concat(args_b)); - }; -} + return (...args_b) => fn(...args_a, ...args_b); +}; -module.exports = partial; \ No newline at end of file +module.exports = partial; diff --git a/packages/function/partial/test.js b/packages/function/partial/test.js index 7fa45517..7dd72e45 100644 --- a/packages/function/partial/test.js +++ b/packages/function/partial/test.js @@ -1,36 +1,28 @@ -var partial = require('./partial.js'); +const partial = require('./partial.js'); -describe('Function/partial', function () { - it('partially applies provided function to its arguments', function () { - var add = function (a, b, c) { - return a + b + c; - }; - var p1 = partial(add, 1); +describe('partial', () => { + it('partially applies provided function to its arguments', () => { + const add = (a, b, c) => a + b + c; + const p1 = partial(add, 1); expect(p1(2, 3)).toBe(6); - var p2 = partial(add, 10, 20); + const p2 = partial(add, 10, 20); expect(p2(30)).toBe(60); - var p3 = partial(add, 100, 200, 300); + const p3 = partial(add, 100, 200, 300); expect(p3()).toBe(600); - var p4 = partial(add); + const p4 = partial(add); expect(p4(5, 10, 15)).toBe(30); }); - it('providing more arguments than expected in the newly created function should have no effect', function () { - var add = (a, b) => a + b; - var p1 = partial(add, 1); + it('providing more arguments than expected in the newly created function should have no effect', () => { + const add = (a, b) => a + b; + const p1 = partial(add, 1); expect(p1(2, 4, 5, 6)).toBe(3); - var noop = () => void 0; - var p2 = partial(noop, 'foo', 'bar'); + const noop = () => void 0; + const p2 = partial(noop, 'foo', 'bar'); expect(p2()).toBeUndefined(); }); - - it('throws if first argument is not a function', function () { - expect(function () { - return partial(null, 'foo', 'bar'); - }).toThrow(new TypeError('Expected a function for first argument')); - }); }); diff --git a/packages/function/partialRight/README.md b/packages/function/partialRight/README.md index c3bea7f4..9d0e2e34 100644 --- a/packages/function/partialRight/README.md +++ b/packages/function/partialRight/README.md @@ -1,26 +1,23 @@ -## partialRight(func) ⇒ function -Creates a new function that invokes the provided function `func` with `partials` appended to the arguments it receives. +## partialRight(fn, ...args) ⇒ function +Creates a new function that invokes the provided function `fn` with `partials` appended to the arguments it receives. **Returns**: function - Returns the new partially applied function. **Throws**: -- TypeError Throws if `func` is not a function. +- TypeError Throws if `fn` is not a function. | Param | Type | Description | | --- | --- | --- | -| func | function | The function to partially apply arguments to. | +| fn | function | The function to partially apply arguments to. | | [...args] | \* | The arguments to be partially applied. | -**Example** +**Example** ```js -var greet = function (greeting, title, fname, lname) { - return greeting + ', ' + title + ' ' + fname + ' ' + lname + '.'; -}; +const greet = (greeting, title, fname, lname) => `${greeting}, ${title} ${fname} ${lname}.`; +const greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); -var greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); - -greetMrJoeBlack('Hello'); // -> Hello, Mr. Joe Black. -``` \ No newline at end of file +greetMrJoeBlack('Hello'); //=> Hello, Mr. Joe Black. +``` diff --git a/packages/function/partialRight/partialRight.js b/packages/function/partialRight/partialRight.js index 877f4900..572a085e 100644 --- a/packages/function/partialRight/partialRight.js +++ b/packages/function/partialRight/partialRight.js @@ -1,38 +1,25 @@ 'use strict'; /** - * Creates a new function that invokes the provided function `func` with `partials` appended to the arguments it receives. + * Creates a new function that invokes the provided function `fn` with `partials` appended to the arguments it receives. * - * @param {function} func The function to partially apply arguments to. + * @param {function} fn The function to partially apply arguments to. * @param {*} [...args] The arguments to be partially applied. - * @throws {TypeError} Throws if `func` is not a function. + * @throws {TypeError} Throws if `fn` is not a function. * @returns {function} Returns the new partially applied function. * @example * - * var greet = function (greeting, title, fname, lname) { - * return greeting + ', ' + title + ' ' + fname + ' ' + lname + '.'; - * }; + * const greet = (greeting, title, fname, lname) => `${greeting}, ${title} ${fname} ${lname}.`; + * const greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); * - * var greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); - * - * greetMrJoeBlack('Hello'); // -> Hello, Mr. Joe Black. + * greetMrJoeBlack('Hello'); //=> Hello, Mr. Joe Black. */ -function partialRight(func /* , ...args_a */) { - if (typeof func !== 'function') { +const partialRight = (fn, ...args_a) => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - for (var _len = arguments.length, args_a = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args_a[_key - 1] = arguments[_key]; - } - - return function (/* , ...args_b */) { - for (var _len2 = arguments.length, args_b = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args_b[_key2] = arguments[_key2]; - } - - return func.apply(void 0, args_b.concat(args_a)); - }; -} + return (...args_b) => fn(...args_b, ...args_a); +}; -module.exports = partialRight; \ No newline at end of file +module.exports = partialRight; diff --git a/packages/function/partialRight/test.js b/packages/function/partialRight/test.js index 745b8eae..f9baec8f 100644 --- a/packages/function/partialRight/test.js +++ b/packages/function/partialRight/test.js @@ -1,22 +1,14 @@ -var partialRight = require('./partialRight.js'); +const partialRight = require('./partialRight.js'); -describe('Function/partialRight', function () { - var greet = function (greeting, title, fname, lname) { - return greeting + ', ' + title + ' ' + fname + ' ' + lname + '.'; - }; - var greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); +describe('partialRight', () => { + const greet = (greeting, title, fname, lname) => `${greeting}, ${title} ${fname} ${lname}.`; + const greetMrJoeBlack = partialRight(greet, 'Mr.', 'Joe', 'Black'); - it('partially applies provided function to its arguments', function () { + it('partially applies provided function to its arguments', () => { expect(greetMrJoeBlack('Hello')).toBe('Hello, Mr. Joe Black.'); }); - it('providing more arguments than expected in the newly created function should affect the result', function () { + it('providing more arguments than expected in the newly created function should affect the result', () => { expect(greetMrJoeBlack('Hello', 'there')).toBe('Hello, there Mr. Joe.'); }); - - it('throws if first argument is not a function', function () { - expect(function () { - return partialRight(null, 'foo', 'bar'); - }).toThrow(new TypeError('Expected a function for first argument')); - }); }); diff --git a/packages/function/pipe/README.md b/packages/function/pipe/README.md index 285c88eb..7b6722f3 100644 --- a/packages/function/pipe/README.md +++ b/packages/function/pipe/README.md @@ -4,22 +4,22 @@ Performs left-to-right function composition. The leftmost function may have any arity; the remaining functions must be unary. -**Returns**: function - A new function as the result of the composition +**Returns**: function - A new function as the result of the composition. | Param | Type | Description | | --- | --- | --- | -| ...fns | function | The functions to compose | +| ...fns | function | The functions to compose. | -**Example** +**Example** ```js -function inc(x) { - return x + 1; -} +const inc = x => x + 1; +const double = x => x * 2; -function double(x) { - return x * 2; -} +pipe(inc, double)(3); // => 8 +pipe(double, inc)(3); // => 7 -pipe(inc, double)(3); // -> 8 -pipe(double, inc)(3); // -> 7 +const capitalize = a => a.toUpperCase(); +const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; +const shoutGreeting = pipe(greeting, capitalize); +shoutGreeting('John', 'Doe'); // => 'HELLO, MY NAME IS JOHN DOE.' ``` diff --git a/packages/function/pipe/pipe.js b/packages/function/pipe/pipe.js index 785edc3f..614793ae 100644 --- a/packages/function/pipe/pipe.js +++ b/packages/function/pipe/pipe.js @@ -4,41 +4,31 @@ * Performs left-to-right function composition. * The leftmost function may have any arity; the remaining functions must be unary. * - * @param {...function} fns The functions to compose - * @returns {function} A new function as the result of the composition + * @param {function} ...fns The functions to compose. + * @returns {function} A new function as the result of the composition. * @example * - * function inc(x) { - * return x + 1; - * } + * const inc = x => x + 1; + * const double = x => x * 2; * - * function double(x) { - * return x * 2; - * } + * pipe(inc, double)(3); // => 8 + * pipe(double, inc)(3); // => 7 * - * pipe(inc, double)(3); // -> 8 - * pipe(double, inc)(3); // -> 7 + * const capitalize = a => a.toUpperCase(); + * const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; + * const shoutGreeting = pipe(greeting, capitalize); + * shoutGreeting('John', 'Doe'); // => 'HELLO, MY NAME IS JOHN DOE.' */ -function pipe(/* ...fns */) { - for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) { - fns[_key] = arguments[_key]; - } - +const pipe = (...fns) => { if (fns.length === 0) { - return function (fn) { - return fn; - }; + return fn => fn; } if (fns.length === 1) { return fns[0]; } - return fns.reduceRight(function (a, b) { - return function () { - return a(b.apply(void 0, arguments)); - }; - }); -} + return fns.reduceRight((a, b) => (...args) => a(b(...args))); +}; module.exports = pipe; diff --git a/packages/function/pipe/test.js b/packages/function/pipe/test.js index 1436b236..0ea86670 100644 --- a/packages/function/pipe/test.js +++ b/packages/function/pipe/test.js @@ -1,27 +1,13 @@ -var pipe = require('./pipe.js'); +const pipe = require('./pipe.js'); -describe('Function/pipe', function () { - function capitalize(a) { - return a.toUpperCase(); - } +describe('pipe', () => { + const capitalize = a => a.toUpperCase(); + const head = a => a[0]; + const reverse = a => a.split('').reverse().join(''); + const inc = x => x + 1; + const double = x => x * 2; - function head(a) { - return a[0]; - } - - function reverse(a) { - return a.split('').reverse().join(''); - } - - function inc(x) { - return x + 1; - } - - function double(x) { - return x * 2; - } - - it('should perform left-to-right function composition', function () { + it('should perform left-to-right function composition', () => { expect(pipe()(1)).toBe(1); expect(pipe()(1, 2, 3)).toBe(1); @@ -38,14 +24,12 @@ describe('Function/pipe', function () { expect(pipe(double, inc)(3)).toBe(7); - var reverseAndHead = pipe(reverse, head); - var reverseHeadAndCapitalize = pipe(capitalize, reverseAndHead); + const reverseAndHead = pipe(reverse, head); + const reverseHeadAndCapitalize = pipe(capitalize, reverseAndHead); expect(reverseHeadAndCapitalize('hello')).toBe('O'); - var greeting = function (firstName, lastName) { - return 'Hello, my name is ' + firstName + ' ' + lastName + '.'; - }; - var shoutGreeting = pipe(greeting, capitalize); + const greeting = (firstName, lastName) => `Hello, my name is ${firstName} ${lastName}.`; + const shoutGreeting = pipe(greeting, capitalize); expect(shoutGreeting('John', 'Doe')).toBe('HELLO, MY NAME IS JOHN DOE.'); expect(pipe(shoutGreeting('John', 'Doe'))).toBe('HELLO, MY NAME IS JOHN DOE.'); }); diff --git a/packages/function/throttle/README.md b/packages/function/throttle/README.md index c17248b0..60c110c5 100644 --- a/packages/function/throttle/README.md +++ b/packages/function/throttle/README.md @@ -1,22 +1,23 @@ -## throttle(func, [n]) ⇒ function +## throttle(fn, [wait]) ⇒ function Limits the number of times a function can be called in a given period. **Returns**: function - The throttled function. **Throws**: -- TypeError If `func` is not function. +- TypeError If `fn` is not function. + | Param | Type | Default | Description | | --- | --- | --- | --- | -| func | function | | The function to be executed. | +| fn | function | | The function to be executed. | | [wait] | Number | 0 | Optional. Default value is 0. Time of delay in milliseconds. | -**Example** +**Example** ```js // A method that should be called no more than 4 times per second. -var throttledHandler = throttle(function () { +const throttledHandler = throttle(() => { // Do your thing here... }, 250); diff --git a/packages/function/throttle/test.js b/packages/function/throttle/test.js index c67ea978..21ce444f 100644 --- a/packages/function/throttle/test.js +++ b/packages/function/throttle/test.js @@ -1,4 +1,4 @@ -var throttle = require('./throttle'); +const throttle = require('./throttle'); describe('Function/throttle', function () { beforeEach(function () { @@ -10,9 +10,9 @@ describe('Function/throttle', function () { }); it('limits the number of times a function can be called in a given period', function () { - var func = jest.fn(); + const func = jest.fn(); - var throttled = throttle(func); + const throttled = throttle(func); throttled(); throttled(); diff --git a/packages/function/throttle/throttle.js b/packages/function/throttle/throttle.js index 2729bafa..450d1226 100644 --- a/packages/function/throttle/throttle.js +++ b/packages/function/throttle/throttle.js @@ -3,43 +3,41 @@ /** * Limits the number of times a function can be called in a given period. * - * @param {function} func The function to be executed. + * @param {function} fn The function to be executed. * @param {Number} [wait=0] Optional. Default value is 0. Time of delay in milliseconds. - * @throws {TypeError} If `func` is not function. + * @throws {TypeError} If `fn` is not function. * @returns {function} The throttled function. * @example * * // A method that should be called no more than 4 times per second. - * var throttledHandler = throttle(function () { + * const throttledHandler = throttle(() => { * // Do your thing here... * }, 250); * * window.addEventListener('resize', throttledHandler, false); */ -function throttle(func, wait) { - var timerId, lastRan; - - if (typeof func !== 'function') { +const throttle = (fn, wait = 0) => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function throttled() { - var context = this; - var args = arguments; + let timerId, lastRan; + return (...args) => { if (!lastRan) { - func.apply(context, args); + fn(...args); lastRan = Date.now(); } else { clearTimeout(timerId); - timerId = setTimeout(function () { + + timerId = setTimeout(() => { if ((Date.now() - lastRan) >= wait) { - func.apply(context, args); + fn(...args); lastRan = Date.now(); } }, (wait - (Date.now() - lastRan)) || 0); } }; -} +}; module.exports = throttle; diff --git a/packages/function/unary/README.md b/packages/function/unary/README.md index 3bffbbf4..f79daafb 100644 --- a/packages/function/unary/README.md +++ b/packages/function/unary/README.md @@ -1,23 +1,23 @@ -## unary(func) ⇒ function +## unary(fn) ⇒ function Creates a function that accepts up to one argument, ignoring any additional arguments. **Returns**: function - Returns the new capped function. **Throws**: -- TypeError Throws if `func` is not function. +- TypeError Throws if `fn` is not function. | Param | Type | Description | | --- | --- | --- | -| func | function | The function to cap arguments for. | +| fn | function | The function to cap arguments for. | -**Example** +**Example** ```js -var array = ['1', '2', '3']; +const array = ['1', '2', '3']; -var toInteger = unary(parseInt); +const toInteger = unary(parseInt); array.map(toInteger); // -> [1, 2, 3] ``` diff --git a/packages/function/unary/test.js b/packages/function/unary/test.js index c07f823a..c9388ee5 100644 --- a/packages/function/unary/test.js +++ b/packages/function/unary/test.js @@ -1,9 +1,7 @@ -var unary = require('./unary.js'); +const unary = require('./unary.js'); describe('Function/unary', function () { - var fn = function (a, b) { - return [a, b]; - }; + const fn = (a, b) => ([a, b]); it('should create a function that accepts up to 1 argument, ignoring any additional arguments', function () { expect(unary(fn)()).toStrictEqual([void 0, void 0]); diff --git a/packages/function/unary/unary.js b/packages/function/unary/unary.js index ecf5c3e5..be0e816f 100644 --- a/packages/function/unary/unary.js +++ b/packages/function/unary/unary.js @@ -3,25 +3,23 @@ /** * Creates a function that accepts up to one argument, ignoring any additional arguments. * - * @param {function} func The function to cap arguments for. - * @throws {TypeError} Throws if `func` is not function. + * @param {function} fn The function to cap arguments for. + * @throws {TypeError} Throws if `fn` is not function. * @returns {function} Returns the new capped function. * @example * - * var array = ['1', '2', '3']; + * const array = ['1', '2', '3']; * - * var toInteger = unary(parseInt); + * const toInteger = unary(parseInt); * * array.map(toInteger); // -> [1, 2, 3] */ -function unary(func) { - if (typeof func !== 'function') { +const unary = fn => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - return function (arg) { - return func(arg); - }; -} + return arg => fn(arg); +}; module.exports = unary; From 040e4ae54d8b8eb18df73525a6b2c5dc9bdd2f63 Mon Sep 17 00:00:00 2001 From: georapbox Date: Fri, 16 Sep 2022 10:04:07 +0300 Subject: [PATCH 02/17] Convert to ES6 --- README.md | 12 +- packages/dom/captureMouse/README.md | 42 ---- packages/dom/captureMouse/captureMouse.js | 90 ------- packages/dom/captureTouch/README.md | 42 ---- packages/dom/captureTouch/captureTouch.js | 105 -------- packages/dom/cookie/cookie.js | 21 +- packages/dom/cookie/test.js | 2 +- packages/dom/isEventSupported/README.md | 36 --- .../dom/isEventSupported/isEventSupported.js | 81 ------- packages/dom/isEventSupported/test.js | 44 ---- packages/dom/mediaQuery/README.md | 2 +- packages/dom/mediaQuery/mediaQuery.js | 20 +- packages/dom/mediaQuery/test.js | 6 +- packages/dom/preloadImages/preloadImages.js | 36 ++- packages/dom/scroll/README.md | 40 ---- packages/dom/scroll/scroll.js | 226 ------------------ packages/dom/whichAnimationEnd/README.md | 2 +- packages/dom/whichAnimationEnd/test.js | 6 +- .../whichAnimationEnd/whichAnimationEnd.js | 16 +- packages/dom/whichTransitionEnd/README.md | 2 +- packages/dom/whichTransitionEnd/test.js | 6 +- .../whichTransitionEnd/whichTransitionEnd.js | 12 +- packages/function/curry/README.md | 8 +- packages/function/curry/curry.js | 20 +- 24 files changed, 75 insertions(+), 802 deletions(-) delete mode 100644 packages/dom/captureMouse/README.md delete mode 100644 packages/dom/captureMouse/captureMouse.js delete mode 100644 packages/dom/captureTouch/README.md delete mode 100644 packages/dom/captureTouch/captureTouch.js delete mode 100644 packages/dom/isEventSupported/README.md delete mode 100644 packages/dom/isEventSupported/isEventSupported.js delete mode 100644 packages/dom/isEventSupported/test.js delete mode 100644 packages/dom/scroll/README.md delete mode 100644 packages/dom/scroll/scroll.js diff --git a/README.md b/README.md index 741e4c2f..6097d222 100755 --- a/README.md +++ b/README.md @@ -106,14 +106,14 @@ A collection of dependency-free JavaScript utility functions. |Name|Description| |--------|-----------| -|[after](https://github.com/georapbox/js-utils/tree/master/packages/function/after)|Creates a function that invokes `func` once it's called `n` or more times.| +|[after](https://github.com/georapbox/js-utils/tree/master/packages/function/after)|Creates a function that invokes `fn` once it's called `n` or more times.| |[ary](https://github.com/georapbox/js-utils/tree/master/packages/function/ary)|Creates a function that accepts up to `n` arguments, ignoring any additional arguments.| -|[before](https://github.com/georapbox/js-utils/tree/master/packages/function/before)|Creates a function that invokes `func` while it’s called less than `n` times.| +|[before](https://github.com/georapbox/js-utils/tree/master/packages/function/before)|Creates a function that invokes `fn` while it’s called less than `n` times.| |[compose](https://github.com/georapbox/js-utils/tree/master/packages/function/compose)|Performs right-to-left function composition.| |[curry](https://github.com/georapbox/js-utils/tree/master/packages/function/curry)|Returns a curried equivalent of the provided function.| |[debounce](https://github.com/georapbox/js-utils/tree/master/packages/function/debounce)|Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for 'n' milliseconds.| |[flip](https://github.com/georapbox/js-utils/tree/master/packages/function/flip)|Creates a function that invokes the original function with its parameters reversed.| -|[negate](https://github.com/georapbox/js-utils/tree/master/packages/function/negate)|Creates a function that negates the result of the predicate `func`.| +|[negate](https://github.com/georapbox/js-utils/tree/master/packages/function/negate)|Creates a function that negates the result of the predicate `fn`.| |[once](https://github.com/georapbox/js-utils/tree/master/packages/function/once)|Ensure a given functionality only runs once.| |[partial](https://github.com/georapbox/js-utils/tree/master/packages/function/partial)|Creates a new function that invokes the provided function with partials prepended to the arguments it receives.| |[partialRight](https://github.com/georapbox/js-utils/tree/master/packages/function/partialRight)|Creates a new function that invokes the provided function with partials appended to the arguments it receives.| @@ -191,13 +191,9 @@ A collection of dependency-free JavaScript utility functions. |Name|Description| |--------|-----------| -|[captureMouse](https://github.com/georapbox/js-utils/tree/master/packages/dom/captureMouse)|Captures the mouse position on a specific HTML element.| -|[captureTouch](https://github.com/georapbox/js-utils/tree/master/packages/dom/captureTouch)|Captures the touch position on a specific HTML element.| |[cookie](https://github.com/georapbox/js-utils/tree/master/packages/dom/cookie)|Create, read and delete cookies.| -|[preloadImages](https://github.com/georapbox/js-utils/tree/master/packages/dom/preloadImages)|Asynchronously load images to browser so that can be cached.| -|[isEventSupported](https://github.com/georapbox/js-utils/tree/master/packages/dom/isEventSupported)|Checks if an event is supported in a browser environment.| |[mediaQuery](https://github.com/georapbox/js-utils/tree/master/packages/dom/mediaQuery)|Determines if the document matches a media query string.| -|[scroll](https://github.com/georapbox/js-utils/tree/master/packages/dom/scroll)|Easing based scrolling to a specified y point inside page.| +|[preloadImages](https://github.com/georapbox/js-utils/tree/master/packages/dom/preloadImages)|Asynchronously load images to browser so that can be cached.| |[whichAnimationEnd](https://github.com/georapbox/js-utils/tree/master/packages/dom/whichAnimationEnd)|Detects the supported property name for the "animationend" event.| |[whichTransitionEnd](https://github.com/georapbox/js-utils/tree/master/packages/dom/whichTransitionEnd)|Detects the supported property name for the "transitionend" event.| diff --git a/packages/dom/captureMouse/README.md b/packages/dom/captureMouse/README.md deleted file mode 100644 index a91f2b6f..00000000 --- a/packages/dom/captureMouse/README.md +++ /dev/null @@ -1,42 +0,0 @@ - - -## captureMouse(element, [callback]) ⇒ Object -Captures the mouse position on a specific HTML element. - -**Returns**: Object - An object containing the position object (x, y) of mouse and an unbind method. -**Throws**: - -- TypeError If `element` is not a DOM element. -- TypeError If `callback` is defined but is not a function. - - -| Param | Type | Description | -| --- | --- | --- | -| element | HTMLElement | The HTML element to capture mouse position on. | -| [callback] | function | A callback function to be executed on mouse move taking the `position` object as argument. | - -**Example** -```js -var element = document.getElementById('some_element'); - -// Example 1 -var mouse = captureMouse(element); - -element.addEventListener('mousemove', function () { - var x = mouse.position.x; - var y = mouse.position.y; -}, false); - -// Example 2 - Utilizing the callback function -var mouse = captureMouse(element, function (position) { - var x = position.x; - var y = position.y; -}); - -// Unbinding capturing mouse move -var mouse = captureMouse(element); - -mouse.unbind(); // Unbind immediately. - -mouse.unbind(5000); // Unbind after 5 seconds. -``` diff --git a/packages/dom/captureMouse/captureMouse.js b/packages/dom/captureMouse/captureMouse.js deleted file mode 100644 index e5cd28b9..00000000 --- a/packages/dom/captureMouse/captureMouse.js +++ /dev/null @@ -1,90 +0,0 @@ -'use strict'; - -/** - * Captures the mouse position on a specific HTML element. - * - * @param {HTMLElement} element The HTML element to capture mouse position on. - * @param {function} [callback] A callback function to be executed on mouse move taking the `position` object as argument. - * @throws {TypeError} If `element` is not a DOM element. - * @throws {TypeError} If `callback` is defined but is not a function. - * @return {Object} An object containing the position object (x, y) of mouse and an unbind method. - * @example - * - * var element = document.getElementById('some_element'); - * - * // Example 1 - * var mouse = captureMouse(element); - * - * element.addEventListener('mousemove', function () { - * var x = mouse.position.x; - * var y = mouse.position.y; - * }, false); - * - * // Example 2 - Utilizing the callback function - * var mouse = captureMouse(element, function (position) { - * var x = position.x; - * var y = position.y; - * }); - * - * // Unbinding capturing mouse move - * var mouse = captureMouse(element); - * - * mouse.unbind(); // Unbind immediately. - * - * mouse.unbind(5000); // Unbind after 5 seconds. - */ -function captureMouse(element, callback) { - var position, onMouseMove; - - if (!element || element.nodeType !== 1 || element instanceof Element !== true) { - throw new TypeError('"element" must be a DOM element'); - } - - if (typeof callback !== 'undefined' && typeof callback !== 'function') { - throw new TypeError('"callback" must be a function'); - } - - position = { - x: 0, - y: 0 - }; - - onMouseMove = function (event) { - var x, y; - - if (event.pageX || event.pageY) { - x = event.pageX; - y = event.pageY; - } else { - x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; - y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop; - } - - x -= element.offsetLeft; - y -= element.offsetTop; - - position.x = x; - position.y = y; - - callback && callback.call(this, position); - }; - - element.addEventListener('mousemove', onMouseMove, false); - - return { - position: position, - unbind: function (timeout) { - if (timeout != null && typeof timeout === 'number') { - setTimeout(function () { - element.removeEventListener('mousemove', onMouseMove, false); - }, timeout); - } else { - element.removeEventListener('mousemove', onMouseMove, false); - } - - return this; - } - }; -} - -module.exports = captureMouse; diff --git a/packages/dom/captureTouch/README.md b/packages/dom/captureTouch/README.md deleted file mode 100644 index c3256800..00000000 --- a/packages/dom/captureTouch/README.md +++ /dev/null @@ -1,42 +0,0 @@ - - -## captureTouch(element, [callback]) ⇒ Object -Captures the touch position on a specific HTML element. - -**Returns**: Object - An object containing the position object (x, y) of touch and an unbind method. -**Throws**: - -- TypeError If `element` is not a DOM element. -- TypeError If `callback` is defined but is not a function. - - -| Param | Type | Description | -| --- | --- | --- | -| element | HTMLElement | The HTML element to capture touch position on. | -| [callback] | function | A callback function to be executed on touch move taking the `position` object as argument. | - -**Example** -```js -var element = document.getElementById('some_element'); - -// Example 1 -var touch = captureTouch(element); - -element.addEventListener('touchmove', function () { - var x = touch.position.x; - var y = touch.position.y; -}, false); - -// Example 2 - Utilizing the callback function -var touch = captureTouch(element, function (position) { - var x = position.x; - var y = position.y; -}); - -// Unbinding capturing touch move -var touch = captureTouch(element); - -touch.unbind(); // Unbind immediately. - -touch.unbind(5000); // Unbind after 5 seconds. -``` diff --git a/packages/dom/captureTouch/captureTouch.js b/packages/dom/captureTouch/captureTouch.js deleted file mode 100644 index 8067003d..00000000 --- a/packages/dom/captureTouch/captureTouch.js +++ /dev/null @@ -1,105 +0,0 @@ -'use strict'; - -/** - * Captures the touch position on a specific HTML element. - * - * @param {HTMLElement} element The HTML element to capture touch position on. - * @param {function} [callback] A callback function to be executed on touch move taking the `position` object as argument. - * @throws {TypeError} If `element` is not a DOM element. - * @throws {TypeError} If `callback` is defined but is not a function. - * @return {Object} An object containing the position object (x, y) of touch and an unbind method. - * @example - * - * var element = document.getElementById('some_element'); - * - * // Example 1 - * var touch = captureTouch(element); - * - * element.addEventListener('touchmove', function () { - * var x = touch.position.x; - * var y = touch.position.y; - * }, false); - * - * // Example 2 - Utilizing the callback function - * var touch = captureTouch(element, function (position) { - * var x = position.x; - * var y = position.y; - * }); - * - * // Unbinding capturing touch move - * var touch = captureTouch(element); - * - * touch.unbind(); // Unbind immediately. - * - * touch.unbind(5000); // Unbind after 5 seconds. - */ -function captureTouch(element, callback) { - var position, state, onTouchStart, onTouchEnd, onTouchMove; - - if (!element || element.nodeType !== 1 || element instanceof Element !== true) { - throw new TypeError('"element" must be a DOM element'); - } - - if (typeof callback !== 'undefined' && typeof callback !== 'function') { - throw new TypeError('"callback" must be a function'); - } - - position = { x: null, y: null }; - state = { isPressed: false }; - - onTouchStart = function () { - state.isPressed = true; - }; - - onTouchEnd = function () { - state.isPressed = false; - position.x = null; - position.y = null; - }; - - onTouchMove = function (event) { - var touch_event = event.touches[0], - x, y; - - if (touch_event.pageX || touch_event.pageY) { - x = touch_event.pageX; - y = touch_event.pageY; - } else { - x = touch_event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; - y = touch_event.clientY + document.body.scrollTop + document.documentElement.scrollTop; - } - - x -= element.offsetLeft; - y -= element.offsetTop; - - position.x = x; - position.y = y; - - callback && callback.call(this, position); - }; - - element.addEventListener('touchstart', onTouchStart, false); - element.addEventListener('touchend', onTouchEnd, false); - element.addEventListener('touchmove', onTouchMove, false); - - return { - position: position, - unbind: function (timeout) { - if (timeout != null && typeof timeout === 'number') { - setTimeout(function () { - element.removeEventListener('touchstart', onTouchStart, false); - element.removeEventListener('touchend', onTouchEnd, false); - element.removeEventListener('touchmove', onTouchMove, false); - }, timeout); - } else { - element.removeEventListener('touchstart', onTouchStart, false); - element.removeEventListener('touchend', onTouchEnd, false); - element.removeEventListener('touchmove', onTouchMove, false); - } - - return this; - } - }; -} - -module.exports = captureTouch; diff --git a/packages/dom/cookie/cookie.js b/packages/dom/cookie/cookie.js index f9445c25..1dca41be 100644 --- a/packages/dom/cookie/cookie.js +++ b/packages/dom/cookie/cookie.js @@ -29,24 +29,19 @@ module.exports = (function () { * }); * // -> undefined */ - function setCookie(name, value, options) { - var cookie, optionKey, optionValue; - + function setCookie(name, value, options = {}) { if (typeof name !== 'string' || typeof value !== 'string') { throw new TypeError('Expected a string for first and second argument'); } - if (!options || typeof options !== 'object') { - options = {}; - } - options.path = options.path || '/'; - cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value); + let cookie = encodeURIComponent(name) + '=' + encodeURIComponent(value); - for (optionKey in options) { + for (const optionKey in options) { if (Object.prototype.hasOwnProperty.call(options, optionKey)) { - optionValue = options[optionKey]; + const optionValue = options[optionKey]; + cookie += '; ' + optionKey; if (optionValue !== true) { @@ -74,13 +69,11 @@ module.exports = (function () { * // -> '' */ function getCookie(name) { - var matches; - if (typeof name !== 'string') { throw new TypeError('Expected a string for first argument'); } - matches = document.cookie.match( + const matches = document.cookie.match( new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + '=([^;]*)') ); @@ -114,4 +107,4 @@ module.exports = (function () { get: getCookie, remove: removeCookie }; -}()); \ No newline at end of file +}()); diff --git a/packages/dom/cookie/test.js b/packages/dom/cookie/test.js index 7a892681..fc24fd30 100644 --- a/packages/dom/cookie/test.js +++ b/packages/dom/cookie/test.js @@ -1,4 +1,4 @@ -var cookie = require('./cookie'); +const cookie = require('./cookie'); describe('dom/cookie', function () { it('should create, read and delete cookies', function () { diff --git a/packages/dom/isEventSupported/README.md b/packages/dom/isEventSupported/README.md deleted file mode 100644 index 541daea7..00000000 --- a/packages/dom/isEventSupported/README.md +++ /dev/null @@ -1,36 +0,0 @@ - - -## isEventSupported ⇒ Boolean -Checks if an event is supported in a browser environment. - -**Returns**: Boolean - True if event is supported, else false. -**Throws**: - -- TypeError If `eventName` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| eventName | String | The event name (without the `on` prefix) to check if is supported, eg `click`, `mouseover`, etc. | -| [element] | HTMLElement | An HTML node to check if an event is supported on. Some events are supported on specific elements, eg `online` is supported on `window` but not on a `div` element. If omitted the results are cached and next calls with the same `eventName` will return the results from cache. | - -**Example** -```js -isEventSupported('submit'); -// -> true - Checks on a `form` element - -isEventSupported('click'); -// -> true - Checks on a `div` element - -isEventSupported('resize'); -// -> false - Checks on a `div` element - -isEventSupported('resize', window); -// -> true - Checks on a `window` - -isEventSupported('keyup'); -// -> true - Checks on a `div` element - -isEventSupported('keyup', document.createElement('input')); -// -> true - Checks on an `input` element -``` diff --git a/packages/dom/isEventSupported/isEventSupported.js b/packages/dom/isEventSupported/isEventSupported.js deleted file mode 100644 index 78f474a2..00000000 --- a/packages/dom/isEventSupported/isEventSupported.js +++ /dev/null @@ -1,81 +0,0 @@ -'use strict'; - -/** - * Checks if an event is supported in a browser environment. - * - * @module isEventSupported - * @param {String} eventName The event name (without the `on` prefix) to check if is supported, eg `click`, `mouseover`, etc. - * @param {HTMLElement} [element] An HTML node to check if an event is supported on. - * Some events are supported on specific elements, eg `online` is supported on `window` but not on a `div` element. - * If omitted the results are cached and next calls with the same `eventName` will return the results from cache. - * @throws {TypeError} If `eventName` is not string. - * @return {Boolean} True if event is supported, else false. - * @example - * - * isEventSupported('submit'); - * // -> true - Checks on a `form` element - * - * isEventSupported('click'); - * // -> true - Checks on a `div` element - * - * isEventSupported('resize'); - * // -> false - Checks on a `div` element - * - * isEventSupported('resize', window); - * // -> true - Checks on a `window` - * - * isEventSupported('keyup'); - * // -> true - Checks on a `div` element - * - * isEventSupported('keyup', document.createElement('input')); - * // -> true - Checks on an `input` element - */ -module.exports = (function () { - var TAGNAMES = { - select: 'input', - change: 'input', - submit: 'form', - reset: 'form', - error: 'img', - load: 'img', - abort: 'img' - }; - var cache = {}; - - function isEventSupported(eventName, element) { - var canCache = !element; - var isSupported; - - if (typeof eventName !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - eventName = 'on' + eventName; - - // Return the cached result if exists. - if (canCache && cache[eventName]) { - return cache[eventName]; - } - - element = element || document.createElement(TAGNAMES[eventName] || 'div'); - isSupported = eventName in element; - - // Old Gecko based browsers create methods on an element when an attribute - // with the name corresponding to a “known” event is set on that element. - if (!isSupported) { - // If it has no `setAttribute` (i.e. doesn't implement Node interface), try a generic element like `div`. - if (!element.setAttribute) { - element = document.createElement('div'); - } - - element.setAttribute(eventName, 'return;'); - isSupported = typeof element[eventName] === 'function'; - } - - element = null; - - return canCache ? (cache[eventName] = isSupported) : isSupported; - } - - return isEventSupported; -}()); \ No newline at end of file diff --git a/packages/dom/isEventSupported/test.js b/packages/dom/isEventSupported/test.js deleted file mode 100644 index e7db4f9d..00000000 --- a/packages/dom/isEventSupported/test.js +++ /dev/null @@ -1,44 +0,0 @@ -var isEventSupported = require('./isEventSupported'); - -describe('dom/isEventSupported', function () { - it('checks if event is supported by browser', function () { - expect(isEventSupported('click')).toBe(true); - expect(isEventSupported('click', document.createElement('button'))).toBe(true); - - expect(isEventSupported('select')).toBe(true); - expect(isEventSupported('select', document.createElement('input'))).toBe(true); - - expect(isEventSupported('change')).toBe(true); - expect(isEventSupported('change', document.createElement('input'))).toBe(true); - - expect(isEventSupported('change')).toBe(true); - expect(isEventSupported('change', document.createElement('input'))).toBe(true); - - expect(isEventSupported('submit')).toBe(true); - expect(isEventSupported('submit', document.createElement('form'))).toBe(true); - - expect(isEventSupported('reset')).toBe(true); - expect(isEventSupported('reset', document.createElement('form'))).toBe(true); - - expect(isEventSupported('error')).toBe(true); - expect(isEventSupported('error', document.createElement('image'))).toBe(true); - - expect(isEventSupported('load')).toBe(true); - expect(isEventSupported('load', document.createElement('image'))).toBe(true); - - expect(isEventSupported('abort')).toBe(true); - expect(isEventSupported('abort', document.createElement('image'))).toBe(true); - - expect(isEventSupported('scroll')).toBe(true); - expect(isEventSupported('scroll', window)).toBe(true); - - expect(isEventSupported('keyup')).toBe(true); - expect(isEventSupported('keyup', document.createElement('input'))).toBe(true); - - expect(isEventSupported('something')).toBe(false); - - expect(function () { - return isEventSupported({}); - }).toThrow(new TypeError('Expected a string for first argument')); - }); -}); diff --git a/packages/dom/mediaQuery/README.md b/packages/dom/mediaQuery/README.md index aa085f71..366ff19e 100644 --- a/packages/dom/mediaQuery/README.md +++ b/packages/dom/mediaQuery/README.md @@ -19,7 +19,7 @@ Determines if the document matches a media query string. **Example** ```js // Start listening for media query status changes. -var unsubscribe = mediaQuery('(min-width: 480px) and (max-width: 768px)', function (matches) { +const unsubscribe = mediaQuery('(min-width: 480px) and (max-width: 768px)', matches => { document.body.style.backgroundColor = matches ? 'green' : 'red'; }); diff --git a/packages/dom/mediaQuery/mediaQuery.js b/packages/dom/mediaQuery/mediaQuery.js index 04a9278b..81225454 100644 --- a/packages/dom/mediaQuery/mediaQuery.js +++ b/packages/dom/mediaQuery/mediaQuery.js @@ -4,26 +4,20 @@ * @param {String} mediaQueryString A string specifying the media query to parse into a MediaQueryList. * @param {function} callback Callback function which is invoked whenever the media query status changes. * @param {Boolean} [immediate=true] If `true` the `callback` function is called immediately, otherwise is called only when the media query status changes. - * @returns {function} Returns a function that when called it will remove the event handler that listens for media query status changes. * @throws {TypeError} If `mediaQueryString` is not string. * @throws {TypeError} If `callback` is not function. + * @returns {function} Returns a function that when called it will remove the event handler that listens for media query status changes. * @example * * // Start listening for media query status changes. - * var unsubscribe = mediaQuery('(min-width: 480px) and (max-width: 768px)', function (matches) { + * const unsubscribe = mediaQuery('(min-width: 480px) and (max-width: 768px)', matches => { * document.body.style.backgroundColor = matches ? 'green' : 'red'; * }); * * // Stop listening for media query status changes. * unsubscribe(); */ -function mediaQuery(mediaQueryString, callback, immediate) { - var mqList; - - function onChange() { - callback(mqList.matches); - } - +const mediaQuery = (mediaQueryString, callback, immediate = true) => { if (typeof mediaQueryString !== 'string') { throw new TypeError('Expected a string for first argument'); } @@ -32,17 +26,19 @@ function mediaQuery(mediaQueryString, callback, immediate) { throw new TypeError('Expected a function for second argument'); } - mqList = window.matchMedia(mediaQueryString); + const mqList = window.matchMedia(mediaQueryString); - if (typeof immediate === 'undefined' || Boolean(immediate)) { + if (immediate) { callback(mqList.matches); } + const onChange = () => callback(mqList.matches); + mqList.addEventListener('change', onChange); return function unsubscribe() { mqList.removeEventListener('change', onChange); }; -} +}; module.exports = mediaQuery; diff --git a/packages/dom/mediaQuery/test.js b/packages/dom/mediaQuery/test.js index b794d92e..878f143e 100644 --- a/packages/dom/mediaQuery/test.js +++ b/packages/dom/mediaQuery/test.js @@ -1,4 +1,4 @@ -var mediaQuery = require('./mediaQuery'); +const mediaQuery = require('./mediaQuery'); describe('dom/mediaQuery', function () { function mockMediaQueryList(testQuery) { @@ -17,8 +17,8 @@ describe('dom/mediaQuery', function () { }); } - var mediaQueryString = '(min-width: 480px) and (max-width: 768px)'; - var matchMediaListener, unsubscribeMediaQuery; + const mediaQueryString = '(min-width: 480px) and (max-width: 768px)'; + let matchMediaListener, unsubscribeMediaQuery; beforeEach(function () { matchMediaListener = jest.fn().mockImplementation(function (matches) { diff --git a/packages/dom/preloadImages/preloadImages.js b/packages/dom/preloadImages/preloadImages.js index 8e44ae78..80539d60 100644 --- a/packages/dom/preloadImages/preloadImages.js +++ b/packages/dom/preloadImages/preloadImages.js @@ -11,7 +11,7 @@ * @return {undefined} * @example * - * var images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; + * const images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; * * function success(data) { * console.log(data.currentImage.src + ' -> loaded'); @@ -31,14 +31,16 @@ * * preloadImages(images, success, fail, always); */ -function preloadImages(images, successCallback, errorCallback, alwaysCallback) { - var list, i, len, img; +const preloadImages = (images, successCallback, errorCallback, alwaysCallback) => { + const list = []; - function onloadSuccess(image) { - var index; + if (!Array.isArray(images)) { + throw new TypeError('Expected an array for first argument'); + } + const onloadSuccess = image => { image.onload = function imagesLoadSuccess(event) { - index = list.indexOf(this); + const index = list.indexOf(this); if (index !== -1) { list.splice(index, 1); @@ -56,9 +58,9 @@ function preloadImages(images, successCallback, errorCallback, alwaysCallback) { currentImage: image }); }; - } + }; - function onLoadError(image) { + const onLoadError = image => { image.onerror = function imageLoadError(error) { errorCallback && errorCallback({ error: error, @@ -73,23 +75,15 @@ function preloadImages(images, successCallback, errorCallback, alwaysCallback) { currentImage: image }); }; - } - - if (!Array.isArray(images)) { - throw new TypeError('Expected an array for first argument'); - } - - list = []; - i = 0; - len = images.length; + }; - for (i; i < len; i += 1) { - img = new Image(); + for (let i = 0; i < images.length; i += 1) { + const img = new Image(); onloadSuccess(img); onLoadError(img); list.push(img); img.src = images[i]; } -} +}; -module.exports = preloadImages; \ No newline at end of file +module.exports = preloadImages; diff --git a/packages/dom/scroll/README.md b/packages/dom/scroll/README.md deleted file mode 100644 index e0f5aa35..00000000 --- a/packages/dom/scroll/README.md +++ /dev/null @@ -1,40 +0,0 @@ - - -## scroll -Easing based scrolling to a specified y point inside page. - - - -### scroll~to([options], [callback]) -Scrolls page to the y point with the specified duration and easing function. - -**Kind**: inner method of [scroll](#module_scroll) - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| [options] | Object | | User defined options, extending the default ones. | -| [options.y] | Number | 0 | The point the scroll ends. | -| [options.duration] | Number | 400 | The duration (milliseconds) of the scrolling animation. | -| [options.easing] | function | scroll.easing.linear | The animation's easing function.
Available easing methods: | -| [callback] | function | | A callback function to be executed after animation is done. | - -**Example** -```js -// Scroll page 500px from top -scroll.to({ - y: 500, - duration: 800, - easing: scroll.easing.easeInOutCubic -}, function () { - console.log('Finished scrolling.'); -}); - -// Scroll page to an element -scroll.to({ - y: document.getElementById('test').getBoundingClientRect().top + (document.documentElement.scrollTop || document.body.scrollTop), - duration: 600, - easing: scroll.easing.easeInOutCubic -}, function (y) { - console.log('Scrolled down ' + y + ' pixels.'); -}); -``` diff --git a/packages/dom/scroll/scroll.js b/packages/dom/scroll/scroll.js deleted file mode 100644 index 2e349d84..00000000 --- a/packages/dom/scroll/scroll.js +++ /dev/null @@ -1,226 +0,0 @@ -'use strict'; - -/** - * Easing based scrolling to a specified y point inside page. - * - * @module scroll - */ -(function (name, context, definition) { - if (typeof define === 'function' && define.amd) { - define(definition); - } else if (typeof module !== 'undefined' && module.exports) { - module.exports = definition(); - } else { - context[name] = definition(); - } -}('scroll', this, function () { // Change first argument ('scroll') if you need to export with different name. - /** - * Merges (deep copy) the contents of two or more objects together into the first object. - * - * @param {Object} target The object to extend. It will receive the new properties. - * @param {Object} object1 An object containing additional properties to merge in. - * @param {Object} objectN Additional objects containing properties to merge in. - * @example - * - * extend({}, obj1, objN) - */ - function extend() { - for (var i = 1, l = arguments.length; i < l; i++) { - for (var key in arguments[i]) { - if (Object.prototype.hasOwnProperty.call(arguments[i], key)) { - if ( - arguments[i][key] && arguments[i][key].constructor - && arguments[i][key].constructor === Object - ) { - arguments[0][key] = arguments[0][key] || {}; - extend(arguments[0][key], arguments[i][key]); - } else { - arguments[0][key] = arguments[i][key]; - } - } - } - } - return arguments[0]; - } - - var scroll = {}; - - /** - * Scrolls page to the y point with the specified duration and easing function. - * - * @function to - * @param {Object} [options] User defined options, extending the default ones. - * @param {Number} [options.y=0] The point the scroll ends. - * @param {Number} [options.duration=400] The duration (milliseconds) of the scrolling animation. - * @param {function} [options.easing=scroll.easing.linear] The animation's easing function. - *
Available easing methods: - * - * @param {function} [callback] A callback function to be executed after animation is done. - * @return {undefined} - * @example - * - * // Scroll page 500px from top - * scroll.to({ - * y: 500, - * duration: 800, - * easing: scroll.easing.easeInOutCubic - * }, function () { - * console.log('Finished scrolling.'); - * }); - * - * // Scroll page to an element - * scroll.to({ - * y: document.getElementById('test').getBoundingClientRect().top + (document.documentElement.scrollTop || document.body.scrollTop), - * duration: 600, - * easing: scroll.easing.easeInOutCubic - * }, function (y) { - * console.log('Scrolled down ' + y + ' pixels.'); - * }); - */ - scroll.to = function (options, callback) { - var defaults = { - y: 0, - duration: 400, - easing: scroll.easing.linear - }; - - // Handle case that options is not defined but callback is. - if (typeof options === 'function') { - callback = options; - } - - // Extend the default options. - options = extend({}, defaults, options); - - // Ugly hack for firefox, that wouldn't scroll if on top of page. - document.documentElement.scrollTop = document.documentElement.scrollTop + 1; - - var start = Date.now(), - elem = document.documentElement.scrollTop ? document.documentElement : document.body, - from = elem.scrollTop; - - // Prevent scrolling to the y point if already there. - if (from === options.y) { - callback && callback(options.y); - return; - } - - function min(a, b) { - return a < b ? a : b; - } - - function move() { - var currentTime = Date.now(), - time = min(1, (currentTime - start) / options.duration), - easedT = options.easing(time); - - elem.scrollTop = easedT * (options.y - from) + from; - - if (time < 1) { - requestAnimationFrame(move); - } else { - callback && callback(options.y); - } - } - - requestAnimationFrame(move); - }; - - /** - * Easing Functions - inspired from http://gizma.com/easing/ - * only considering the t value for the range [0, 1] => [0, 1] - */ - scroll.easing = { - linear: function (t) { // no easing, no acceleration - return t; - }, - easeInQuad: function (t) { // accelerating from zero velocity - return t * t; - }, - easeOutQuad: function (t) { // decelerating to zero velocity - return t * (2 - t); - }, - easeInOutQuad: function (t) { // acceleration until halfway, then deceleration - return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t; - }, - easeInCubic: function (t) { // accelerating from zero velocity - return t * t * t; - }, - easeOutCubic: function (t) { // decelerating to zero velocity - return --t * t * t + 1; - }, - easeInOutCubic: function (t) { // acceleration until halfway, then deceleration - return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1; - }, - easeInQuart: function (t) { // accelerating from zero velocity - return t * t * t * t; - }, - easeOutQuart: function (t) { // decelerating to zero velocity - return 1 - (--t) * t * t * t; - }, - easeInOutQuart: function (t) { // acceleration until halfway, then deceleration - return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t; - }, - easeInQuint: function (t) { // accelerating from zero velocity - return t * t * t * t * t; - }, - easeOutQuint: function (t) { // decelerating to zero velocity - return 1 + --t * t * t * t * t; - }, - easeInOutQuint: function (t) { // acceleration until halfway, then deceleration - return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t; - } - }; - - /** - * http://paulirish.com/2011/requestanimationframe-for-smart-animating/ - * http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating - * requestAnimationFrame polyfill by Erik Möller - * fixes from Paul Irish and Tino Zijdel - */ - (function () { - var lastTime = 0, - vendors = ['ms', 'moz', 'webkit', 'o']; - - for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { - window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; - window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] - || window[vendors[x] + 'CancelRequestAnimationFrame']; - } - - if (!window.requestAnimationFrame) { - window.requestAnimationFrame = function (callback) { - var currTime = new Date().getTime(), - timeToCall = Math.max(0, 16 - (currTime - lastTime)), - id = window.setTimeout(function () { - callback(currTime + timeToCall); - }, timeToCall); - - lastTime = currTime + timeToCall; - return id; - }; - } - - if (!window.cancelAnimationFrame) { - window.cancelAnimationFrame = function (id) { - clearTimeout(id); - }; - } - }()); - - return scroll; -})); \ No newline at end of file diff --git a/packages/dom/whichAnimationEnd/README.md b/packages/dom/whichAnimationEnd/README.md index a6c7c992..10595c7f 100644 --- a/packages/dom/whichAnimationEnd/README.md +++ b/packages/dom/whichAnimationEnd/README.md @@ -6,7 +6,7 @@ Detects the supported property name for the `animationend` event. **Returns**: String - The supported property name or `undefined` if not supported. **Example** ```js -var animEnd = whichAnimationEnd(); +const animEnd = whichAnimationEnd(); // -> eg 'animationend' element.addEventListener(animEnd, function () { diff --git a/packages/dom/whichAnimationEnd/test.js b/packages/dom/whichAnimationEnd/test.js index b8307f44..5d122bde 100644 --- a/packages/dom/whichAnimationEnd/test.js +++ b/packages/dom/whichAnimationEnd/test.js @@ -1,9 +1,9 @@ -var whichAnimationEnd = require('./whichAnimationEnd'); +const whichAnimationEnd = require('./whichAnimationEnd'); describe('dom/whichAnimationEnd', function () { it('returns the animation end event name', function () { - var values = ['animationend', 'oAnimationEnd', 'webkitAnimationEnd', undefined]; - var exists = values.indexOf(whichAnimationEnd()) !== -1; + const values = ['animationend', 'oAnimationEnd', 'webkitAnimationEnd', undefined]; + const exists = values.indexOf(whichAnimationEnd()) !== -1; expect(exists).toBe(true); }); diff --git a/packages/dom/whichAnimationEnd/whichAnimationEnd.js b/packages/dom/whichAnimationEnd/whichAnimationEnd.js index 173485b5..ed91de16 100644 --- a/packages/dom/whichAnimationEnd/whichAnimationEnd.js +++ b/packages/dom/whichAnimationEnd/whichAnimationEnd.js @@ -6,24 +6,24 @@ * @return {String} The supported property name or `undefined` if not supported. * @example * - * var animEnd = whichAnimationEnd(); + * const animEnd = whichAnimationEnd(); * // -> eg 'animationend' * * element.addEventListener(animEnd, function () { * // Do soething... * }); */ -function whichAnimationEnd() { - var key; - var el = document.createElement('div'); - var animations = { +const whichAnimationEnd = () => { + let el = document.createElement('div'); + + const animations = { 'animation': 'animationend', 'OAnimation': 'oAnimationEnd', 'MozAnimation': 'animationend', 'WebkitAnimation': 'webkitAnimationEnd' }; - for (key in animations) { + for (const key in animations) { if (Object.prototype.hasOwnProperty.call(animations, key)) { if (el.style[key] !== undefined) { el = null; @@ -31,6 +31,6 @@ function whichAnimationEnd() { } } } -} +}; -module.exports = whichAnimationEnd; \ No newline at end of file +module.exports = whichAnimationEnd; diff --git a/packages/dom/whichTransitionEnd/README.md b/packages/dom/whichTransitionEnd/README.md index 3264a472..538fdb4e 100644 --- a/packages/dom/whichTransitionEnd/README.md +++ b/packages/dom/whichTransitionEnd/README.md @@ -6,7 +6,7 @@ Detects the supported property name for the `transitionend` event. **Returns**: string - The supported property name or `undefined` if not supported. **Example** ```js -var transEnd = whichTransitionEnd(); +const transEnd = whichTransitionEnd(); // -> eg 'transitionend' element.addEventListener(transEnd, function () { diff --git a/packages/dom/whichTransitionEnd/test.js b/packages/dom/whichTransitionEnd/test.js index e85d55de..cddc0f16 100644 --- a/packages/dom/whichTransitionEnd/test.js +++ b/packages/dom/whichTransitionEnd/test.js @@ -1,9 +1,9 @@ -var whichTransitionEnd = require('./whichTransitionEnd'); +const whichTransitionEnd = require('./whichTransitionEnd'); describe('dom/whichTransitionEnd', function () { it('returns the transition end event name', function () { - var values = ['transitionend', 'oTransitionEnd', 'webkitTransitionEnd', undefined]; - var exists = values.indexOf(whichTransitionEnd()) !== -1; + const values = ['transitionend', 'oTransitionEnd', 'webkitTransitionEnd', undefined]; + const exists = values.indexOf(whichTransitionEnd()) !== -1; expect(exists).toBe(true); }); diff --git a/packages/dom/whichTransitionEnd/whichTransitionEnd.js b/packages/dom/whichTransitionEnd/whichTransitionEnd.js index 06ffc3f9..c68d78ee 100644 --- a/packages/dom/whichTransitionEnd/whichTransitionEnd.js +++ b/packages/dom/whichTransitionEnd/whichTransitionEnd.js @@ -6,7 +6,7 @@ * @return {String} The supported property name or `undefined` if not supported. * @example * - * var transEnd = whichTransitionEnd(); + * const transEnd = whichTransitionEnd(); * // -> eg 'transitionend' * * element.addEventListener(transEnd, function () { @@ -14,16 +14,16 @@ * }); */ function whichTransitionEnd() { - var key; - var el = document.createElement('div'); - var transitions = { + let el = document.createElement('div'); + + const transitions = { 'transition': 'transitionend', 'OTransition': 'oTransitionEnd', 'MozTransition': 'transitionend', 'WebkitTransition': 'webkitTransitionEnd' }; - for (key in transitions) { + for (const key in transitions) { if (Object.prototype.hasOwnProperty.call(transitions, key)) { if (el.style[key] !== undefined) { el = null; @@ -33,4 +33,4 @@ function whichTransitionEnd() { } } -module.exports = whichTransitionEnd; \ No newline at end of file +module.exports = whichTransitionEnd; diff --git a/packages/function/curry/README.md b/packages/function/curry/README.md index 6d805ea8..a9f75cf7 100644 --- a/packages/function/curry/README.md +++ b/packages/function/curry/README.md @@ -1,20 +1,20 @@ -## curry(func, [arity]) ⇒ function +## curry(fn, [arity]) ⇒ function Transforms a function of N arguments in such a way that it can be called as a chain of N functions each with a single argument (arity: 1). **Returns**: function - A curried equivalent of the provided function. **Throws**: -- TypeError Throws if `func` is not a function. +- TypeError Throws if `fn` is not a function. - TypeError Throws if `arity` is not a number but not undefined. | Param | Type | Default | Description | | --- | --- | --- | --- | -| func | function | | The initial function to be curried. | -| [arity] | Number | func.length | The arity of the provided function. Useful in cases that arity cannot be determined by `func.length`. As of ES2015 when a function has a rest parameter or at least one parameter with default value, the `func.length` is not properly calculated. | +| fn | function | | The initial function to be curried. | +| [arity] | Number | fn.length | The arity of the provided function. Useful in cases that arity cannot be determined by `fn.length`. As of ES2015 when a function has a rest parameter or at least one parameter with default value, the `fn.length` is not properly calculated. | **Example** ```js diff --git a/packages/function/curry/curry.js b/packages/function/curry/curry.js index 91dc6f63..db8bec90 100644 --- a/packages/function/curry/curry.js +++ b/packages/function/curry/curry.js @@ -4,12 +4,12 @@ * Transforms a function of N arguments in such a way that it can * be called as a chain of N functions each with a single argument (arity: 1). * - * @param {function} func The initial function to be curried. - * @param {Number} [arity=func.length] The arity of the provided function. - * Useful in cases that arity cannot be determined by `func.length`. + * @param {function} fn The initial function to be curried. + * @param {Number} [arity=fn.length] The arity of the provided function. + * Useful in cases that arity cannot be determined by `fn.length`. * As of ES2015 when a function has a rest parameter or at least one - * parameter with default value, the `func.length` is not properly calculated. - * @throws {TypeError} Throws if `func` is not a function. + * parameter with default value, the `fn.length` is not properly calculated. + * @throws {TypeError} Throws if `fn` is not a function. * @throws {TypeError} Throws if `arity` is not a number but not undefined. * @returns {function} A curried equivalent of the provided function. * @example @@ -24,18 +24,18 @@ * const addTwo = addOne(2); * addTwo(3); // => 6 */ -const curry = (func, arity) => { - if (typeof func !== 'function') { +const curry = (fn, arity = fn.length) => { + if (typeof fn !== 'function') { throw new TypeError('Expected a function for first argument'); } - if (typeof arity !== 'undefined' && typeof arity !== 'number') { + if (typeof arity !== 'number') { throw new TypeError('Expected a number for second argument'); } return function curried(...args_a) { - return args_a.length >= (arity || func.length) - ? func(...args_a) + return args_a.length >= arity + ? fn(...args_a) : (...args_b) => curried(...args_a, ...args_b); }; }; From 902fff14004636c11354a8cca1697432abd69bdc Mon Sep 17 00:00:00 2001 From: georapbox Date: Sat, 17 Sep 2022 23:47:59 +0300 Subject: [PATCH 03/17] Convert to ES6 --- .eslintrc.json | 9 ++--- packages/arrays/chunk/chunk.js | 17 ++++---- packages/arrays/chunk/test.js | 2 +- packages/arrays/compact/compact.js | 6 +-- packages/arrays/compact/test.js | 9 ++--- packages/arrays/diff/README.md | 6 +-- packages/arrays/diff/diff.js | 20 +++++----- packages/arrays/diff/test.js | 6 +-- packages/arrays/drop/drop.js | 18 ++++----- packages/arrays/drop/test.js | 4 +- packages/arrays/dropRight/dropRight.js | 19 +++++---- packages/arrays/dropRight/test.js | 4 +- packages/arrays/dropRightWhile/README.md | 2 +- .../arrays/dropRightWhile/dropRightWhile.js | 18 ++++----- packages/arrays/dropRightWhile/test.js | 4 +- packages/arrays/dropWhile/README.md | 2 +- packages/arrays/dropWhile/dropWhile.js | 16 ++++---- packages/arrays/dropWhile/test.js | 4 +- packages/arrays/fill/fill.js | 20 +++++----- packages/arrays/fill/test.js | 4 +- packages/arrays/find/README.md | 6 +-- packages/arrays/find/find.js | 22 +++++------ packages/arrays/find/test.js | 14 +++---- packages/arrays/findIndex/README.md | 13 ++++--- packages/arrays/findIndex/findIndex.js | 30 +++++++------- packages/arrays/findIndex/test.js | 17 ++++++-- packages/arrays/findLastIndex/README.md | 9 +++-- .../arrays/findLastIndex/findLastIndex.js | 31 ++++++++------- packages/arrays/findLastIndex/test.js | 19 +++++++-- packages/arrays/flat/README.md | 4 +- packages/arrays/flat/flat.js | 24 ++++++------ packages/arrays/flat/test.js | 6 +-- packages/arrays/fromPairs/fromPairs.js | 17 ++++---- packages/arrays/fromPairs/test.js | 4 +- packages/arrays/groupBy/groupBy.js | 6 +-- packages/arrays/groupBy/test.js | 14 +++---- packages/arrays/includes/README.md | 2 +- packages/arrays/includes/includes.js | 18 ++++----- packages/arrays/includes/test.js | 6 +-- packages/arrays/insert/README.md | 25 ++++++------ packages/arrays/insert/insert.js | 35 +++++++---------- packages/arrays/insert/test.js | 30 +++++++------- packages/arrays/intersect/README.md | 6 +-- packages/arrays/intersect/intersect.js | 32 ++++++--------- packages/arrays/intersect/test.js | 16 ++++---- packages/arrays/move/README.md | 2 +- packages/arrays/move/move.js | 19 +++++---- packages/arrays/move/test.js | 4 +- packages/arrays/partition/README.md | 14 +++---- packages/arrays/partition/partition.js | 33 +++++++--------- packages/arrays/partition/test.js | 22 ++++++----- packages/arrays/pluck/README.md | 2 +- packages/arrays/pluck/pluck.js | 20 ++++------ packages/arrays/pluck/test.js | 4 +- packages/arrays/remove/README.md | 25 +++++++----- packages/arrays/remove/remove.js | 31 ++++++++------- packages/arrays/remove/test.js | 36 ++++++++--------- packages/arrays/reverse/reverse.js | 8 ++-- packages/arrays/reverse/test.js | 6 +-- packages/arrays/shuffle/shuffle.js | 20 ++++------ packages/arrays/shuffle/test.js | 4 +- packages/arrays/sort/README.md | 2 +- packages/arrays/sort/sort.js | 33 ++++------------ packages/arrays/sort/test.js | 10 +++-- packages/arrays/sortBy/README.md | 6 +-- packages/arrays/sortBy/sortBy.js | 39 ++++++++++--------- packages/arrays/sortBy/test.js | 25 +++++++++++- packages/arrays/tail/tail.js | 8 ++-- packages/arrays/tail/test.js | 2 +- packages/arrays/take/take.js | 14 +++---- packages/arrays/take/test.js | 2 +- packages/arrays/takeRight/takeRight.js | 23 ++++++----- packages/arrays/takeRight/test.js | 2 +- packages/arrays/takeRightWhile/README.md | 2 +- .../arrays/takeRightWhile/takeRightWhile.js | 20 +++++----- packages/arrays/takeRightWhile/test.js | 8 ++-- packages/arrays/takeWhile/README.md | 2 +- packages/arrays/takeWhile/takeWhile.js | 17 ++++---- packages/arrays/takeWhile/test.js | 8 ++-- packages/arrays/uniq/test.js | 6 +-- packages/arrays/uniq/uniq.js | 17 ++++---- packages/arrays/uniqBy/README.md | 4 +- packages/arrays/uniqBy/test.js | 8 ++-- packages/arrays/uniqBy/uniqBy.js | 20 ++++------ packages/arrays/zip/test.js | 10 ++--- packages/arrays/zip/zip.js | 30 ++++---------- 86 files changed, 561 insertions(+), 603 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 601b47d9..70d0a775 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,8 @@ "node": true, "jest": true, "amd": true, - "commonjs": true + "commonjs": true, + "es6": true }, "parserOptions": { "ecmaVersion": "latest" @@ -15,14 +16,12 @@ }, "extends": "eslint:recommended", "rules": { - // Possible Errors "no-empty": ["error", { "allowEmptyCatch": true }], "no-use-before-define": ["error", { "functions": false }], - // Stylistic Issues "indent": ["warn", 2, { "SwitchCase": 1, "ignoredNodes": ["TemplateLiteral"] @@ -52,7 +51,6 @@ "asyncArrow": "always" }], "padded-blocks": ["warn", "never"], - // Best Practices "curly": ["warn"], "eqeqeq": ["error", "always", { "null": "ignore" @@ -65,6 +63,7 @@ }], "prefer-rest-params": ["warn"], "prefer-const": ["warn"], - "no-var": ["warn"] + "no-var": ["warn"], + "no-extra-parens": ["warn", "all"] } } diff --git a/packages/arrays/chunk/chunk.js b/packages/arrays/chunk/chunk.js index feda333e..61a00cd7 100644 --- a/packages/arrays/chunk/chunk.js +++ b/packages/arrays/chunk/chunk.js @@ -24,10 +24,7 @@ * chunk([1, 2, 3, 4], 2.7); * // -> [[1, 2], [3, 4]] */ -function chunk(array, size) { - var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - var len, result, index, resIndex; - +const chunk = (array, size) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -36,21 +33,23 @@ function chunk(array, size) { throw new TypeError('Expected a number for second argument'); } + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + if (size <= 0 || size > MAX_SAFE_INTEGER || size !== size) { throw new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument'); } size = Math.floor(size); - len = array.length; + const len = array.length; if (!len) { return []; } - index = 0; - resIndex = 0; - result = [Math.ceil(len / size)]; + let index = 0; + let resIndex = 0; + const result = [Math.ceil(len / size)]; while (index < len) { result[resIndex] = array.slice(index, index += size); @@ -58,6 +57,6 @@ function chunk(array, size) { } return result; -} +}; module.exports = chunk; diff --git a/packages/arrays/chunk/test.js b/packages/arrays/chunk/test.js index 94bf243a..078b0ab2 100644 --- a/packages/arrays/chunk/test.js +++ b/packages/arrays/chunk/test.js @@ -1,4 +1,4 @@ -var chunk = require('./chunk'); +const chunk = require('./chunk'); describe('Array/chunk', function () { it('creates an array of elements split into groups the length of size specified', function () { diff --git a/packages/arrays/compact/compact.js b/packages/arrays/compact/compact.js index 3b98c0f7..893afa9f 100755 --- a/packages/arrays/compact/compact.js +++ b/packages/arrays/compact/compact.js @@ -6,18 +6,18 @@ * * @param {Array} array The array to compact. * @throws {TypeError} If `array` is not array. - * @return {Array} Returns the new array of filtered values. + * @returns {Array} Returns the new array of filtered values. * @example * * compact([0, 1, false, 2, '', 3, null]); * // => [1, 2, 3] */ -function compact(array) { +const compact = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } return array.filter(Boolean); -} +}; module.exports = compact; diff --git a/packages/arrays/compact/test.js b/packages/arrays/compact/test.js index 41b6ae96..1c54e0de 100644 --- a/packages/arrays/compact/test.js +++ b/packages/arrays/compact/test.js @@ -1,12 +1,11 @@ -var compact = require('./compact'); +const compact = require('./compact'); describe('Array/compact', function () { - var arr = [0, 1, false, 2, '', 3, null]; - var ca = compact(arr); - var i, l; + const arr = [0, 1, false, 2, '', 3, null]; + const ca = compact(arr); it('compacts array (removes falsy values)', function () { - for (i = 0, l = ca.length; i < l; i++) { + for (let i = 0; i < ca.length; i += 1) { expect(ca[i]).toBeTruthy(); } diff --git a/packages/arrays/diff/README.md b/packages/arrays/diff/README.md index 872ad250..894876ff 100644 --- a/packages/arrays/diff/README.md +++ b/packages/arrays/diff/README.md @@ -17,12 +17,12 @@ by excluding all values from the second array using strict equality for comparis **Example** ```js -var obj = { +const obj = { foo: 'bar' }; -var a = [1, 2, 3, 4, 5, obj]; -var b = [5, 2, 10, obj]; +const a = [1, 2, 3, 4, 5, obj]; +const b = [5, 2, 10, obj]; diff(a, b); // -> [1, 3, 4] diff --git a/packages/arrays/diff/diff.js b/packages/arrays/diff/diff.js index 16eab9ff..5522778a 100644 --- a/packages/arrays/diff/diff.js +++ b/packages/arrays/diff/diff.js @@ -7,15 +7,15 @@ * @param {Array} arrayA The array to process. * @param {Array} arrayB The values to exclude from `arrayA`. * @throws {TypeError} If any of the arguments passed are not arrays. - * @return {Array} Array of values not included in the exclusion set. + * @returns {Array} Array of values not included in the exclusion set. * @example * - * var obj = { + * const obj = { * foo: 'bar' * }; * - * var a = [1, 2, 3, 4, 5, obj]; - * var b = [5, 2, 10, obj]; + * const a = [1, 2, 3, 4, 5, obj]; + * const b = [5, 2, 10, obj]; * * diff(a, b); * // -> [1, 3, 4] @@ -23,15 +23,13 @@ * diff(a, []); * // -> [1, 2, 3, 4, 5, obj] */ -function diff(arrayA, arrayB) { - var len, arr; - +const diff = (arrayA, arrayB) => { if (!Array.isArray(arrayA) || !Array.isArray(arrayB)) { throw new TypeError('Expected both arguments to be arrays'); } - len = arrayA.length; - arr = []; + let len = arrayA.length; + const arr = []; while (len--) { if (arrayB.indexOf(arrayA[len]) === -1) { @@ -40,6 +38,6 @@ function diff(arrayA, arrayB) { } return arr; -} +}; -module.exports = diff; \ No newline at end of file +module.exports = diff; diff --git a/packages/arrays/diff/test.js b/packages/arrays/diff/test.js index ff7018d8..bd0713cf 100644 --- a/packages/arrays/diff/test.js +++ b/packages/arrays/diff/test.js @@ -1,8 +1,8 @@ -var diff = require('./diff'); +const diff = require('./diff'); describe('Array/diff', function () { - var a = [1, 2, 3, 4, {}]; - var b = [5, 2, 10]; + const a = [1, 2, 3, 4, {}]; + const b = [5, 2, 10]; it('diffs two arrays', function () { expect(diff(a, b)).toEqual([1, 3, 4, {}]); diff --git a/packages/arrays/drop/drop.js b/packages/arrays/drop/drop.js index cf669354..77c9c237 100644 --- a/packages/arrays/drop/drop.js +++ b/packages/arrays/drop/drop.js @@ -7,7 +7,7 @@ * @param {Number} [n=1] The number of elements to drop. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `n` is not number but not if is `undefined`. - * @return {Array} The slice of the array. + * @returns {Array} The slice of the array. * @example * * drop([1, 2, 3, 4, 5]); @@ -40,9 +40,7 @@ * drop({}, 2); * // -> Throws TypeError */ -function drop(array, n) { - var MAX_SAFE_INTEGER, length; - +const drop = (array, n) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -51,14 +49,14 @@ function drop(array, n) { throw new TypeError('Expected a number for second argument'); } - MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - length = array.length; + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const len = array.length; n = n > MAX_SAFE_INTEGER - ? length + ? len : n == null || n !== n ? 1 : Math.floor(n); - return array.slice(n < 0 ? 0 : n, length); -} + return array.slice(n < 0 ? 0 : n, len); +}; -module.exports = drop; \ No newline at end of file +module.exports = drop; diff --git a/packages/arrays/drop/test.js b/packages/arrays/drop/test.js index 3927b850..727ac3df 100644 --- a/packages/arrays/drop/test.js +++ b/packages/arrays/drop/test.js @@ -1,8 +1,8 @@ -var drop = require('./drop'); +const drop = require('./drop'); describe('Array/drop', function () { it('creates a slice of array with n elements dropped from the beginning', function () { - var arr = [1, 2, 3, 4, 5]; + const arr = [1, 2, 3, 4, 5]; expect(drop(arr)).toEqual([2, 3, 4, 5]); diff --git a/packages/arrays/dropRight/dropRight.js b/packages/arrays/dropRight/dropRight.js index 02209984..00481abe 100644 --- a/packages/arrays/dropRight/dropRight.js +++ b/packages/arrays/dropRight/dropRight.js @@ -7,7 +7,7 @@ * @param {Number} [n=1] The number of elements to drop. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `n` is not number but not if is `undefined`. - * @return {Array} The slice of the array. + * @returns {Array} The slice of the array. * @example * * dropRight([1, 2, 3, 4, 5]); @@ -40,9 +40,7 @@ * dropRight({}, 2); * // -> Throws TypeError */ -function dropRight(array, n) { - var MAX_SAFE_INTEGER, length; - +const dropRight = (array, n) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -51,12 +49,13 @@ function dropRight(array, n) { throw new TypeError('Expected a number for second argument'); } - MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - length = array.length; - n = n > MAX_SAFE_INTEGER ? length : n == null || n !== n ? 1 : Math.floor(n); - n = length - n; + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const len = array.length; + + n = n > MAX_SAFE_INTEGER ? len : n == null || n !== n ? 1 : Math.floor(n); + n = len - n; return array.slice(0, n < 0 ? 0 : n); -} +}; -module.exports = dropRight; \ No newline at end of file +module.exports = dropRight; diff --git a/packages/arrays/dropRight/test.js b/packages/arrays/dropRight/test.js index b7670e6f..1affb4b0 100644 --- a/packages/arrays/dropRight/test.js +++ b/packages/arrays/dropRight/test.js @@ -1,8 +1,8 @@ -var dropRight = require('./dropRight'); +const dropRight = require('./dropRight'); describe('Array/dropRight', function () { it('creates a slice of array with n elements dropped from the end', function () { - var arr = [1, 2, 3, 4, 5]; + const arr = [1, 2, 3, 4, 5]; expect(dropRight(arr)).toEqual([1, 2, 3, 4]); diff --git a/packages/arrays/dropRightWhile/README.md b/packages/arrays/dropRightWhile/README.md index 323ccaf8..37b5bc64 100644 --- a/packages/arrays/dropRightWhile/README.md +++ b/packages/arrays/dropRightWhile/README.md @@ -18,7 +18,7 @@ The `predicate` is invoked with three arguments: (`value`, `index`, `array`). **Example** ```js -var books = [ +const books = [ {title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}, {title: 'JavaScript The Good Parts', read: false}, diff --git a/packages/arrays/dropRightWhile/dropRightWhile.js b/packages/arrays/dropRightWhile/dropRightWhile.js index bad42190..3042d4e3 100644 --- a/packages/arrays/dropRightWhile/dropRightWhile.js +++ b/packages/arrays/dropRightWhile/dropRightWhile.js @@ -8,10 +8,10 @@ * @param {function} predicate The function invoked per iteration. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `predicate` is not function but not if is `undefined`. - * @return {Array} The slice of `array`. + * @returns {Array} The slice of `array`. * @example * - * var books = [ + * const books = [ * {title: 'Javascript Design Patterns', read: false}, * {title: 'Programming Javascript Applications', read: true}, * {title: 'JavaScript The Good Parts', read: false}, @@ -24,9 +24,7 @@ * // -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}] * */ -function dropRightWhile(array, predicate) { - var index, length; - +const dropRightWhile = (array, predicate) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -35,14 +33,14 @@ function dropRightWhile(array, predicate) { throw new TypeError('Expected a function for second argument'); } - length = array.length; - index = length; + const len = array.length; + let index = len; - while (--index < length && index >= 0 && predicate(array[index], index, array)) { + while (--index < len && index >= 0 && predicate(array[index], index, array)) { continue; } return array.slice(0, index + 1); -} +}; -module.exports = dropRightWhile; \ No newline at end of file +module.exports = dropRightWhile; diff --git a/packages/arrays/dropRightWhile/test.js b/packages/arrays/dropRightWhile/test.js index 6c88192f..c1323cb1 100644 --- a/packages/arrays/dropRightWhile/test.js +++ b/packages/arrays/dropRightWhile/test.js @@ -1,8 +1,8 @@ -var dropRightWhile = require('./dropRightWhile'); +const dropRightWhile = require('./dropRightWhile'); describe('Array/dropRightWhile', function () { it('creates a slice of `array` excluding elements dropped from the beginning, until `predicate` returns falsy', function () { - var books = [ + const books = [ { title: 'Javascript Design Patterns', read: false diff --git a/packages/arrays/dropWhile/README.md b/packages/arrays/dropWhile/README.md index 6d59c1bb..e9414800 100644 --- a/packages/arrays/dropWhile/README.md +++ b/packages/arrays/dropWhile/README.md @@ -18,7 +18,7 @@ The predicate is invoked with three arguments: (`value`, `index`, `array`). **Example** ```js -var books = [ +const books = [ {title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}, {title: 'JavaScript The Good Parts', read: true}, diff --git a/packages/arrays/dropWhile/dropWhile.js b/packages/arrays/dropWhile/dropWhile.js index f73d2da9..1365e307 100644 --- a/packages/arrays/dropWhile/dropWhile.js +++ b/packages/arrays/dropWhile/dropWhile.js @@ -23,9 +23,7 @@ * }); * // -> [{title: 'JavaScript The Good Parts', read: true}, {title: 'Eloquent Javascript', read: false}] */ -function dropWhile(array, predicate) { - var index, length; - +const dropWhile = (array, predicate) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -34,14 +32,14 @@ function dropWhile(array, predicate) { throw new TypeError('Expected a function for second argument'); } - index = -1; - length = array.length; + let index = -1; + const len = array.length; - while (++index < length && predicate(array[index], index, array)) { + while (++index < len && predicate(array[index], index, array)) { continue; } - return array.slice(index, length); -} + return array.slice(index, len); +}; -module.exports = dropWhile; \ No newline at end of file +module.exports = dropWhile; diff --git a/packages/arrays/dropWhile/test.js b/packages/arrays/dropWhile/test.js index eebd786e..34d1a2c6 100644 --- a/packages/arrays/dropWhile/test.js +++ b/packages/arrays/dropWhile/test.js @@ -1,8 +1,8 @@ -var dropWhile = require('./dropWhile'); +const dropWhile = require('./dropWhile'); describe('Array/dropWhile', function () { it('creates a slice of `array` excluding elements dropped from the beginning, until `predicate` returns falsy', function () { - var books = [ + const books = [ { title: 'Javascript Design Patterns', read: false diff --git a/packages/arrays/fill/fill.js b/packages/arrays/fill/fill.js index 93c5126b..d2ea1903 100644 --- a/packages/arrays/fill/fill.js +++ b/packages/arrays/fill/fill.js @@ -29,9 +29,7 @@ * fill(['a', 'b', 'c']); * // -> [undefined, undefined, undefined] */ -function fill(array, value, start, end) { - var resultArray, length; - +const fill = (array, value, start = 0, end = array.length) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -40,23 +38,23 @@ function fill(array, value, start, end) { return array.fill(value, start, end); } - resultArray = array.slice(0); - length = resultArray.length; + const resultArray = array.slice(0); + const len = resultArray.length; - if (length === 0) { + if (len === 0) { return []; } start = parseInt(start, 10) || 0; if (start < 0) { - start = -start > length ? 0 : length + start; + start = -start > len ? 0 : len + start; } - end = typeof end === 'undefined' || end > length ? length : parseInt(end, 10); + end = end > len ? len : parseInt(end, 10); if (end < 0) { - end += length; + end += len; } if (start > end) { @@ -68,6 +66,6 @@ function fill(array, value, start, end) { } return resultArray; -} +}; -module.exports = fill; \ No newline at end of file +module.exports = fill; diff --git a/packages/arrays/fill/test.js b/packages/arrays/fill/test.js index 2597ca9e..2e9d3aff 100644 --- a/packages/arrays/fill/test.js +++ b/packages/arrays/fill/test.js @@ -1,4 +1,4 @@ -var fill = require('./fill'); +const fill = require('./fill'); describe('Array/fill', function () { function runTests() { @@ -36,7 +36,7 @@ describe('Array/fill', function () { }); it('fills elements of array with value from start up to end (not including end) (Array.prototype.fill is not supported)', function () { - var nativeCode = Array.prototype.fill; + const nativeCode = Array.prototype.fill; Array.prototype.fill = null; runTests(); Array.prototype.fill = nativeCode; diff --git a/packages/arrays/find/README.md b/packages/arrays/find/README.md index 35fda671..ebeba36f 100644 --- a/packages/arrays/find/README.md +++ b/packages/arrays/find/README.md @@ -19,11 +19,11 @@ it is not invoked for indexes which have been deleted or which have never been a | --- | --- | --- | | array | Array | The array to process. | | predicate | function | Function to execute on each value in the array, taking three arguments: - `{*}` element: The current element being processed in the array. - `{Number}` index: The index of the current element being processed in the array. - `{Array}` array: The array find was called upon. | -| [thisArg] | Object | Object to use as `this` when executing predicate. | +| [thisArg] | * | Optional object to use as `this` when executing the predicate function. | -**Example** +**Example** ```js -var fruits = [ +const fruits = [ {name: 'apples', quantity: 2}, {name: 'bananas', quantity: 0}, {name: 'cherries', quantity: 5}, diff --git a/packages/arrays/find/find.js b/packages/arrays/find/find.js index a8fb3924..72e5b4b7 100644 --- a/packages/arrays/find/find.js +++ b/packages/arrays/find/find.js @@ -13,13 +13,13 @@ * - `{*}` element: The current element being processed in the array. * - `{Number}` index: The index of the current element being processed in the array. * - `{Array}` array: The array find was called upon. - * @param {Object} [thisArg] Object to use as `this` when executing predicate. + * @param {*} [thisArg] Optional object to use as `this` when executing the predicate function. * @throws {TypeError} If `array` is not an array. * @throws {TypeError} If `predicate` is not a function. - * @return {*} A value in the array if an element passes the test, else, `undefined`. + * @returns {*} A value in the array if an element passes the test, else, `undefined`. * @example * - * var fruits = [ + * const fruits = [ * {name: 'apples', quantity: 2}, * {name: 'bananas', quantity: 0}, * {name: 'cherries', quantity: 5}, @@ -46,9 +46,7 @@ * }); * // -> undefined */ -function find(array, predicate, thisArg) { - var index, element, length; - +const find = (array, predicate, thisArg) => { if (!Array.isArray(array)) { throw new TypeError('Expected an an array for first argument'); } @@ -61,17 +59,15 @@ function find(array, predicate, thisArg) { return array.find(predicate, thisArg); } - length = array.length >>> 0; - - for (index = 0; index < length; index += 1) { - element = array[index]; + for (let index = 0; index < array.length; index += 1) { + const element = array[index]; if (predicate.call(thisArg, element, index, array)) { return element; } } - return undefined; -} + return; +}; -module.exports = find; \ No newline at end of file +module.exports = find; diff --git a/packages/arrays/find/test.js b/packages/arrays/find/test.js index a74ffe4c..22aa9fe2 100644 --- a/packages/arrays/find/test.js +++ b/packages/arrays/find/test.js @@ -1,27 +1,27 @@ -var find = require('./find'); +const find = require('./find'); describe('Array/find', function () { function runTests() { - var fruits = [ + const fruits = [ { name: 'apples', quantity: 2 }, { name: 'bananas', quantity: 0 }, { name: 'cherries', quantity: 5 }, { name: 'melons', quantity: 0 } ]; - var cherries = find(fruits, function (element) { + const cherries = find(fruits, function (element) { return element.name === 'cherries'; }); - var bananas = find(fruits, function (element) { + const bananas = find(fruits, function (element) { return element.quantity === 0; }); - var three = find([1, 2, 3, 4, 5], function (element) { + const three = find([1, 2, 3, 4, 5], function (element) { return element === 3; }); - var undef = find([1, 2, 3, 4, 5], function (element) { + const undef = find([1, 2, 3, 4, 5], function (element) { return element === 10; }); @@ -58,7 +58,7 @@ describe('Array/find', function () { }); it('returns a value in the array, if an element in the array satisfies the provided testing function (Array.prototype.find is not supported)', function () { - var nativeCode = Array.prototype.find; + const nativeCode = Array.prototype.find; Array.prototype.find = null; runTests(); Array.prototype.find = nativeCode; diff --git a/packages/arrays/findIndex/README.md b/packages/arrays/findIndex/README.md index 2e8a6f68..8edad883 100644 --- a/packages/arrays/findIndex/README.md +++ b/packages/arrays/findIndex/README.md @@ -1,6 +1,6 @@ -## findIndex(array, callback) ⇒ Number +## findIndex(array, callback, [thisArg]) ⇒ Number Returns the index of the first element that passes the callback check. If no element passes the callback check, returns -1. @@ -15,17 +15,18 @@ If no element passes the callback check, returns -1. | --- | --- | --- | | array | Array | The array to check. | | callback | function | The function called per iteration. | +| [thisArg] | * | Optional object to use as `this` when executing the callback function. | -**Example** +**Example** ```js -var heroes = [ +const heroes = [ {name: 'Bruce Wayne', hero: 'Batman'}, {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} ]; -var characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; -var numbers = [1, 2, 3]; +const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; +const numbers = [1, 2, 3]; findIndex(characters, function (chr, index, array) { return chr === 'E'; @@ -39,7 +40,7 @@ findIndex(heroes, function (hero, index, array) { findIndex(heroes, function (hero, index, array) { if (hero.specialPowers) { - for (var i = 0; i < hero.specialPowers.length; i++) { + for (let i = 0; i < hero.specialPowers.length; i++) { if (hero.specialPowers[i] === 'climbing') return true; } } diff --git a/packages/arrays/findIndex/findIndex.js b/packages/arrays/findIndex/findIndex.js index 0a6d09ab..bf1290fd 100644 --- a/packages/arrays/findIndex/findIndex.js +++ b/packages/arrays/findIndex/findIndex.js @@ -7,19 +7,20 @@ * * @param {Array} array The array to check. * @param {function} callback The function called per iteration. + * @param {*} [thisArg] Optional object to use as `this` when executing the callback function. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `callback` is not function. - * @return {Number} Returns the index of the first element that matches the callback check. + * @returns {Number} Returns the index of the first element that matches the callback check. * @example * - * var heroes = [ + * const heroes = [ * {name: 'Bruce Wayne', hero: 'Batman'}, * {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, * {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} * ]; * - * var characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; - * var numbers = [1, 2, 3]; + * const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; + * const numbers = [1, 2, 3]; * * findIndex(characters, function (chr, index, array) { * return chr === 'E'; @@ -33,7 +34,7 @@ * * findIndex(heroes, function (hero, index, array) { * if (hero.specialPowers) { - * for (var i = 0; i < hero.specialPowers.length; i++) { + * for (let i = 0; i < hero.specialPowers.length; i++) { * if (hero.specialPowers[i] === 'climbing') return true; * } * } @@ -45,9 +46,7 @@ * }); * // -> -1 */ -function findIndex(array, callback) { - var index, length; - +const findIndex = (array, callback, thisArg) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -56,16 +55,19 @@ function findIndex(array, callback) { throw new TypeError('Expected a function for second argument'); } - index = -1; - length = array.length; + if (Array.prototype.findIndex) { + return array.findIndex(callback, thisArg); + } + + let index = -1; - while (++index < length) { - if (callback(array[index], index, array) === true) { + while (++index < array.length) { + if (callback.call(thisArg, array[index], index, array)) { return index; } } return -1; -} +}; -module.exports = findIndex; \ No newline at end of file +module.exports = findIndex; diff --git a/packages/arrays/findIndex/test.js b/packages/arrays/findIndex/test.js index 21e6ddfa..2449d89b 100644 --- a/packages/arrays/findIndex/test.js +++ b/packages/arrays/findIndex/test.js @@ -1,9 +1,9 @@ -var findIndex = require('./findIndex'); +const findIndex = require('./findIndex'); describe('Array/findIndex', function () { - var arr = ['a', 'b', 'c', 'd', 'e']; + function runTests() { + const arr = ['a', 'b', 'c', 'd', 'e']; - it('returns the index in the array', function () { expect(findIndex(arr, function (chr) { return chr === 'b'; })).toBe(1); @@ -21,5 +21,16 @@ describe('Array/findIndex', function () { expect(function () { return findIndex(arr); }).toThrow(new TypeError('Expected a function for second argument')); + } + + it('returns the index in the array ((Array.prototype.findIndex is supported))', function () { + runTests(); + }); + + it('returns the index in the array ((Array.prototype.findIndex is not supported))', function () { + const nativeCode = Array.prototype.findIndex; + Array.prototype.findIndex = null; + runTests(); + Array.prototype.findIndex = nativeCode; }); }); diff --git a/packages/arrays/findLastIndex/README.md b/packages/arrays/findLastIndex/README.md index 8e1cf0e2..3c10797d 100644 --- a/packages/arrays/findLastIndex/README.md +++ b/packages/arrays/findLastIndex/README.md @@ -14,17 +14,18 @@ Returns the index of the last element of a collection that passes the callback c | --- | --- | --- | | array | Array | The array to check. | | callback | function | The function called per iteration. | +| [thisArg] | * | Optional object to use as `this` when executing the callback function. | **Example** ```js -var heroes = [ +const heroes = [ {name: 'Bruce Wayne', hero: 'Batman'}, {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} ]; -var characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; -var numbers = [1, 2, 3]; +const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; +const numbers = [1, 2, 3]; findLastIndex(characters, function (chr, index, array) { return chr === 'E'; @@ -38,7 +39,7 @@ findLastIndex(heroes, function (hero, index, array) { findLastIndex(heroes, function (hero, index, array) { if (hero.specialPowers) { - for (var i = 0; i < hero.specialPowers.length; i++) { + for (let i = 0; i < hero.specialPowers.length; i++) { if (hero.specialPowers[i] === 'climbing') return true; } } diff --git a/packages/arrays/findLastIndex/findLastIndex.js b/packages/arrays/findLastIndex/findLastIndex.js index acee5708..a7998b83 100644 --- a/packages/arrays/findLastIndex/findLastIndex.js +++ b/packages/arrays/findLastIndex/findLastIndex.js @@ -5,19 +5,20 @@ * * @param {Array} array The array to check. * @param {function} callback The function called per iteration. + * @param {*} [thisArg] Optional object to use as `this` when executing the callback function. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `callback` is not function. - * @return {Number} Returns the index of the last element that matches the callback check. + * @returns {Number} Returns the index of the last element that matches the callback check. * @example * - * var heroes = [ + * const heroes = [ * {name: 'Bruce Wayne', hero: 'Batman'}, * {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, * {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} * ]; * - * var characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; - * var numbers = [1, 2, 3]; + * const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; + * const numbers = [1, 2, 3]; * * findLastIndex(characters, function (chr, index, array) { * return chr === 'E'; @@ -31,7 +32,7 @@ * * findLastIndex(heroes, function (hero, index, array) { * if (hero.specialPowers) { - * for (var i = 0; i < hero.specialPowers.length; i++) { + * for (let i = 0; i < hero.specialPowers.length; i++) { * if (hero.specialPowers[i] === 'climbing') return true; * } * } @@ -43,9 +44,7 @@ * }); * // -> -1 */ -function findLastIndex(array, callback) { - var length; - +const findLastIndex = (array, callback, thisArg) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -54,15 +53,19 @@ function findLastIndex(array, callback) { throw new TypeError('Expected a function for second argument'); } - length = array.length; + if (Array.prototype.findLastIndex) { + return array.findLastIndex(callback, thisArg); + } + + let len = array.length; - while (length--) { - if (callback(array[length], length, array)) { - return length; + while (len--) { + if (callback.call(thisArg, array[len], len, array)) { + return len; } } return -1; -} +}; -module.exports = findLastIndex; \ No newline at end of file +module.exports = findLastIndex; diff --git a/packages/arrays/findLastIndex/test.js b/packages/arrays/findLastIndex/test.js index 6ac9f568..1c36cbdb 100644 --- a/packages/arrays/findLastIndex/test.js +++ b/packages/arrays/findLastIndex/test.js @@ -1,10 +1,10 @@ -var findLastIndex = require('./findLastIndex'); +const findLastIndex = require('./findLastIndex'); describe('Array/findLastIndex', function () { - var letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; - var numbers = [1, 2, 3, 4]; + function runTests() { + const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; + const numbers = [1, 2, 3, 4]; - it('returns the last index in the array', function () { expect(findLastIndex(letters, function (chr) { return chr === 'E'; })).toBe(7); @@ -22,5 +22,16 @@ describe('Array/findLastIndex', function () { expect(function () { return findLastIndex(letters); }).toThrow(new TypeError('Expected a function for second argument')); + } + + it('returns the last index in the array (Array.prototype.findLastIndex is supported)', function () { + runTests(); }); + + it('returns the last index in the array (Array.prototype.findLastIndex is not supported', function () { + const nativeCode = Array.prototype.findLastIndex; + Array.prototype.findLastIndex = null; + runTests(); + Array.prototype.findLastIndex = nativeCode; + }) }); diff --git a/packages/arrays/flat/README.md b/packages/arrays/flat/README.md index 67fedf3a..ec25c7c5 100644 --- a/packages/arrays/flat/README.md +++ b/packages/arrays/flat/README.md @@ -16,7 +16,7 @@ Creates a new array with all sub-array elements concatenated into it recursively **Example** ```js -var arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; +const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; flat(arr); // -> [1, 2, 3, 4, [5, 6, [7, 8]]] @@ -32,4 +32,4 @@ flat(arr, Infinity); flat(arr, 0); // -> [1, 2, [3, 4, [5, 6, [7, 8]]]] -``` \ No newline at end of file +``` diff --git a/packages/arrays/flat/flat.js b/packages/arrays/flat/flat.js index a37ad96a..2775fb2c 100644 --- a/packages/arrays/flat/flat.js +++ b/packages/arrays/flat/flat.js @@ -9,7 +9,7 @@ * @returns {Array} Returns a new array with the sub-array elements concatenated into it. * @example * - * var arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; + * const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; * * flat(arr); * // -> [1, 2, 3, 4, [5, 6, [7, 8]]] @@ -26,9 +26,7 @@ * flat(arr, 0); * // -> [1, 2, [3, 4, [5, 6, [7, 8]]]] */ -function flat(array, depth) { - var result, length, element, index; - +const flat = (array, depth = 1) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -37,25 +35,25 @@ function flat(array, depth) { return array.flat(depth); } - result = []; - length = array.length; - depth = typeof depth !== 'undefined' ? Math.floor(depth) : 1; + let result = []; + + depth = Math.floor(depth); - for (index = 0; index < length; index += 1) { - element = array[index]; + for (let index = 0; index < array.length; index += 1) { + const element = array[index]; if (depth > 0) { if (Array.isArray(element)) { - result.push.apply(result, flat(element, depth - 1)); + result.push(...flat(element, depth - 1)); } else { result.push(element); } } else { - result = Array.prototype.slice.call(array, 0); + result = [...array]; } } return result; -} +}; -module.exports = flat; \ No newline at end of file +module.exports = flat; diff --git a/packages/arrays/flat/test.js b/packages/arrays/flat/test.js index 0e08733a..ea6714f3 100644 --- a/packages/arrays/flat/test.js +++ b/packages/arrays/flat/test.js @@ -1,8 +1,8 @@ -var flat = require('./flat'); +const flat = require('./flat'); describe('Array/flat', function () { function runTests() { - var arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; + const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; expect(flat(arr)).toEqual([1, 2, 3, 4, [5, 6, [7, 8]]]); @@ -40,7 +40,7 @@ describe('Array/flat', function () { }); it('flattens recursively up to the specified depth (Array.prototype.flat is not supported)', function () { - var nativeCode = Array.prototype.flat; + const nativeCode = Array.prototype.flat; Array.prototype.flat = null; runTests(); Array.prototype.flat = nativeCode; diff --git a/packages/arrays/fromPairs/fromPairs.js b/packages/arrays/fromPairs/fromPairs.js index 2c06d841..2c5f71d1 100644 --- a/packages/arrays/fromPairs/fromPairs.js +++ b/packages/arrays/fromPairs/fromPairs.js @@ -11,24 +11,21 @@ * fromPairs([['Javascript', 10], ['PHP', 3], ['Java', 4]]); * // -> { 'Javascript': 10, 'PHP': 3, 'Java': 4 } */ -function fromPairs(array) { - var index, length, result, pair; - +const fromPairs = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - index = 0; - length = array.length; - result = {}; + const result = {}; + let index = 0; - while (index < length) { - pair = array[index]; + while (index < array.length) { + const pair = array[index]; result[pair[0]] = pair[1]; index += 1; } return result; -} +}; -module.exports = fromPairs; \ No newline at end of file +module.exports = fromPairs; diff --git a/packages/arrays/fromPairs/test.js b/packages/arrays/fromPairs/test.js index 8ee1e842..f9af1d38 100644 --- a/packages/arrays/fromPairs/test.js +++ b/packages/arrays/fromPairs/test.js @@ -1,8 +1,8 @@ -var fromPairs = require('./fromPairs'); +const fromPairs = require('./fromPairs'); describe('Array/fromPairs', function () { it('creates an object composed from key-value pairs', function () { - var pairs = [ + const pairs = [ ['Javascript', 10], ['PHP', 3], ['Java', 4] diff --git a/packages/arrays/groupBy/groupBy.js b/packages/arrays/groupBy/groupBy.js index 1f0bc1fd..fd4bbfd7 100644 --- a/packages/arrays/groupBy/groupBy.js +++ b/packages/arrays/groupBy/groupBy.js @@ -26,17 +26,17 @@ * ], 'name'); * // -> { 'John': [{'name': 'John'}, {'name': 'John'}], 'George': [{'name': 'George'}, {'name': 'George'}], 'Helen': [{'name': 'Helen'}, {'name': 'Helen'}], 'Alex': [{'name': 'Alex'}] } */ -function groupBy(array, iteratee) { +const groupBy = (array, iteratee) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } return array.reduce(function arrayAggregator(accumulator, item) { - var group = typeof iteratee === 'function' ? iteratee(item) : item[iteratee]; + const group = typeof iteratee === 'function' ? iteratee(item) : item[iteratee]; accumulator[group] = accumulator[group] || []; accumulator[group].push(item); return accumulator; }, {}); -} +}; module.exports = groupBy; diff --git a/packages/arrays/groupBy/test.js b/packages/arrays/groupBy/test.js index b53a2880..68104003 100644 --- a/packages/arrays/groupBy/test.js +++ b/packages/arrays/groupBy/test.js @@ -1,10 +1,10 @@ -var groupBy = require('./groupBy'); +const groupBy = require('./groupBy'); describe('Array/groupBy', function () { it('Creates an object composed of keys generated from the results of running each element of array through iteratee', function () { - var arr1 = ['one', 'two', 'three', 'four', 'five']; + const arr1 = ['one', 'two', 'three', 'four', 'five']; - var arr2 = [ + const arr2 = [ { name: 'John' }, { name: 'George' }, { name: 'Helen' }, @@ -14,22 +14,22 @@ describe('Array/groupBy', function () { { name: 'George' } ]; - var arr3 = [9.5, 6.3, 4.9, 6.8, 9.0, 9.3]; + const arr3 = [9.5, 6.3, 4.9, 6.8, 9.0, 9.3]; - var exp1 = { + const exp1 = { 3: ['one', 'two'], 4: ['four', 'five'], 5: ['three'] }; - var exp2 = { + const exp2 = { John: [{ name: 'John' }, { name: 'John' }], George: [{ name: 'George' }, { name: 'George' }], Helen: [{ name: 'Helen' }, { name: 'Helen' }], Alex: [{ name: 'Alex' }] }; - var exp3 = { + const exp3 = { 4: [4.9], 6: [6.3, 6.8], 9: [9.5, 9.0, 9.3] diff --git a/packages/arrays/includes/README.md b/packages/arrays/includes/README.md index af2f596b..a23fb8e9 100644 --- a/packages/arrays/includes/README.md +++ b/packages/arrays/includes/README.md @@ -14,7 +14,7 @@ returning true or false as appropriate. | --- | --- | --- | --- | | array | Array | | The array to search. | | searchElement | \* | | The element to search for. | -| [fromIndex] | Number | 0 | The position in the array at which to begin searching for `searchElement`. A negative value searches from the index of `array.length + fromIndex` by ascending. | +| [fromIndex] | Number | 0 | The position in the array at which to begin searching for `searchElement`. A negative value searches from the index of `array.length + fromIndex` by ascending. | **Example** ```js diff --git a/packages/arrays/includes/includes.js b/packages/arrays/includes/includes.js index 68663522..2546413f 100644 --- a/packages/arrays/includes/includes.js +++ b/packages/arrays/includes/includes.js @@ -7,9 +7,9 @@ * @param {Array} array The array to search. * @param {*} searchElement The element to search for. * @param {Number} [fromIndex=0] The position in the array at which to begin searching for `searchElement`. - * A negative value searches from the index of `array.length + fromIndex` by ascending. + * A negative value searches from the index of `array.length + fromIndex` by ascending. * @throws {TypeError} If `array` is not array. - * @return {Boolean} True if array includes `searchElement`, else false. + * @returns {Boolean} True if array includes `searchElement`, else false. * @example * * includes([1, 2, 3], 2); @@ -39,14 +39,12 @@ * includes([1, 2, 0], -0); * // -> true */ -function includes(array, searchElement, fromIndex) { - var arrayLength, currentIndex, currentElement; - +const includes = (array, searchElement, fromIndex = 0) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - arrayLength = array.length; + const arrayLength = array.length; if (arrayLength === 0) { return false; @@ -58,6 +56,8 @@ function includes(array, searchElement, fromIndex) { fromIndex = parseInt(fromIndex, 10) || 0; + let currentIndex; + if (fromIndex >= 0) { currentIndex = fromIndex; } else { @@ -69,7 +69,7 @@ function includes(array, searchElement, fromIndex) { } while (currentIndex < arrayLength) { - currentElement = array[currentIndex]; + const currentElement = array[currentIndex]; if ( searchElement === currentElement @@ -82,6 +82,6 @@ function includes(array, searchElement, fromIndex) { } return false; -} +}; -module.exports = includes; \ No newline at end of file +module.exports = includes; diff --git a/packages/arrays/includes/test.js b/packages/arrays/includes/test.js index 8f49a511..be51a810 100644 --- a/packages/arrays/includes/test.js +++ b/packages/arrays/includes/test.js @@ -1,8 +1,8 @@ -var includes = require('./includes'); +const includes = require('./includes'); describe('Array/includes', function () { function runTests() { - var obj = { foo: 'bar' }; + const obj = { foo: 'bar' }; expect(includes([1, 2, 3], 2)).toBe(true); @@ -38,7 +38,7 @@ describe('Array/includes', function () { }); it('determines whether an array includes a certain element (Array.prototype.includes is not supported)', function () { - var nativeCode = Array.prototype.includes; + const nativeCode = Array.prototype.includes; Array.prototype.includes = null; runTests(); Array.prototype.includes = nativeCode; diff --git a/packages/arrays/insert/README.md b/packages/arrays/insert/README.md index a2d91db2..aff21a99 100644 --- a/packages/arrays/insert/README.md +++ b/packages/arrays/insert/README.md @@ -1,6 +1,6 @@ -## insert(array, start, elements) ⇒ Array +## insert(array, start) ⇒ Array Inserts one or more elements to array at a specific index. **Returns**: Array - A new array including the new elements. @@ -8,40 +8,39 @@ Inserts one or more elements to array at a specific index. - TypeError If `array` is not array. - TypeError If `start` is not number. -- TypeError If `elements` is not array. | Param | Type | Description | | --- | --- | --- | | array | Array | The array to insert elements to. | | start | Number | The index to insert elements. If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end. If a float number is passed, it is implicitly converted to integers using `Math.floor()`. | -| elements | Array | The elements to insert to the array. | +| ...elements | \* | The elements to insert to the array. | -**Example** +**Example** ```js -var arr = [1, 2, 3]; +const arr = [1, 2, 3]; -insert(arr, 0, ['a']); +insert(arr, 0, 'a'); // -> ['a', 1, 2, 3] -insert(arr, 2, ['a']); +insert(arr, 2, 'a'); // -> [1, 2, 'a', 3] -insert(arr, -1, ['a']); +insert(arr, -1, 'a'); // -> [1, 2, 'a', 3] -insert(arr, 0.9, ['a']); +insert(arr, 0.9, 'a'); // -> ['a', 1, 2, 3]; -insert(arr, arr.length + 1, ['a']); +insert(arr, arr.length + 1, 'a'); // -> [1, 2, 3, 'a'] -insert(arr, 1, ['a', 'b', 'c']); +insert(arr, 1, 'a', 'b', 'c'); // -> [1, 'a', 'b', 'c', 2, 3] -insert(arr, 2, [undefined]); +insert(arr, 2, undefined); // -> [1, 2, undefined, 3] -insert(arr, 2, []); +insert(arr, 2); // -> [1, 2, 3] ``` diff --git a/packages/arrays/insert/insert.js b/packages/arrays/insert/insert.js index 2c7233ad..c2c07704 100644 --- a/packages/arrays/insert/insert.js +++ b/packages/arrays/insert/insert.js @@ -8,42 +8,39 @@ * If greater than the length of the array, actual starting index will be set to the length of the array. * If negative, will begin that many elements from the end. * If a float number is passed, it is implicitly converted to integers using `Math.floor()`. - * @param {Array} elements The elements to insert to the array. + * @param {*} ...elements The elements to insert to the array. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `start` is not number. - * @throws {TypeError} If `elements` is not array. * @returns {Array} A new array including the new elements. * @example * - * var arr = [1, 2, 3]; + * const arr = [1, 2, 3]; * - * insert(arr, 0, ['a']); + * insert(arr, 0, 'a'); * // -> ['a', 1, 2, 3] * - * insert(arr, 2, ['a']); + * insert(arr, 2, 'a'); * // -> [1, 2, 'a', 3] * - * insert(arr, -1, ['a']); + * insert(arr, -1, 'a'); * // -> [1, 2, 'a', 3] * - * insert(arr, 0.9, ['a']); + * insert(arr, 0.9, 'a'); * // -> ['a', 1, 2, 3]; * - * insert(arr, arr.length + 1, ['a']); + * insert(arr, arr.length + 1, 'a'); * // -> [1, 2, 3, 'a'] * - * insert(arr, 1, ['a', 'b', 'c']); + * insert(arr, 1, 'a', 'b', 'c'); * // -> [1, 'a', 'b', 'c', 2, 3] * - * insert(arr, 2, [undefined]); + * insert(arr, 2, undefined); * // -> [1, 2, undefined, 3] * - * insert(arr, 2, []); + * insert(arr, 2); * // -> [1, 2, 3] */ -function insert(array, start, elements) { - var result; - +const insert = (array, start, ...elements) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -52,15 +49,11 @@ function insert(array, start, elements) { throw new TypeError('Expected a number for second argument'); } - if (!Array.isArray(elements)) { - throw new TypeError('Expected an array for third argument'); - } - - result = array.slice(0); + const result = [...array]; - result.splice.apply(result, [start, 0].concat(elements)); + result.splice(start, 0, ...elements); return result; -} +}; module.exports = insert; diff --git a/packages/arrays/insert/test.js b/packages/arrays/insert/test.js index 14526c10..3b4ca2bc 100644 --- a/packages/arrays/insert/test.js +++ b/packages/arrays/insert/test.js @@ -1,30 +1,30 @@ -var insert = require('./insert'); +const insert = require('./insert'); describe('Array/insert', function () { it('inserts elements to array at specific index', function () { - var arr = [1, 2, 3]; + const arr = [1, 2, 3]; - expect(insert(arr, 0, ['a'])).toEqual(['a', 1, 2, 3]); + expect(insert(arr, 0, 'a')).toEqual(['a', 1, 2, 3]); - expect(insert(arr, 0.9, ['a'])).toEqual(['a', 1, 2, 3]); + expect(insert(arr, 0.9, 'a')).toEqual(['a', 1, 2, 3]); - expect(insert(arr, 1.2, ['a'])).toEqual([1, 'a', 2, 3]); + expect(insert(arr, 1.2, 'a')).toEqual([1, 'a', 2, 3]); - expect(insert(arr, -1.2, ['a'])).toEqual([1, 2, 'a', 3]); + expect(insert(arr, -1.2, 'a')).toEqual([1, 2, 'a', 3]); - expect(insert(arr, -0, ['a'])).toEqual(['a', 1, 2, 3]); + expect(insert(arr, -0, 'a')).toEqual(['a', 1, 2, 3]); - expect(insert(arr, 2, ['a'])).toEqual([1, 2, 'a', 3]); + expect(insert(arr, 2, 'a')).toEqual([1, 2, 'a', 3]); - expect(insert(arr, -1, ['a'])).toEqual([1, 2, 'a', 3]); + expect(insert(arr, -1, 'a')).toEqual([1, 2, 'a', 3]); - expect(insert(arr, arr.length + 1, ['a'])).toEqual([1, 2, 3, 'a']); + expect(insert(arr, arr.length + 1, 'a')).toEqual([1, 2, 3, 'a']); - expect(insert(arr, 1, ['a', 'b', 'c'])).toEqual([1, 'a', 'b', 'c', 2, 3]); + expect(insert(arr, 1, 'a', 'b', 'c')).toEqual([1, 'a', 'b', 'c', 2, 3]); - expect(insert(arr, 2, [])).toEqual([1, 2, 3]); + expect(insert(arr, 2)).toEqual([1, 2, 3]); - expect(insert(arr, 2, [undefined])).toEqual([1, 2, undefined, 3]); + expect(insert(arr, 2, undefined)).toEqual([1, 2, undefined, 3]); expect(function () { return insert({ foo: 'bar' }, 0, ['a', 'b']); @@ -33,9 +33,5 @@ describe('Array/insert', function () { expect(function () { return insert(arr, '0', ['a', 'b']); }).toThrow(new TypeError('Expected a number for second argument')); - - expect(function () { - return insert(arr, 0, 'a'); - }).toThrow(new TypeError('Expected an array for third argument')); }); }); diff --git a/packages/arrays/intersect/README.md b/packages/arrays/intersect/README.md index 004eb441..4cd4182d 100644 --- a/packages/arrays/intersect/README.md +++ b/packages/arrays/intersect/README.md @@ -15,9 +15,9 @@ The order of result values is determined by the order they occur in the first ar **Example** ```js -var arrA = [NaN, 3, 8, 'foo', 'bar']; -var arrB = [2, 7, 'foo', NaN, 3]; -var arrC = [1, 2, 3, NaN]; +const arrA = [NaN, 3, 8, 'foo', 'bar']; +const arrB = [2, 7, 'foo', NaN, 3]; +const arrC = [1, 2, 3, NaN]; intersect(arrA, arrB); // -> [NaN, 3, 'foo'] diff --git a/packages/arrays/intersect/intersect.js b/packages/arrays/intersect/intersect.js index 23b7777c..3418ae65 100644 --- a/packages/arrays/intersect/intersect.js +++ b/packages/arrays/intersect/intersect.js @@ -6,12 +6,12 @@ * * @param {...Array} arrays The arrays to intersect. * @throws {TypeError} If any of the arguments is not array. - * @return {Array} The array of intersecting values. + * @returns {Array} The array of intersecting values. * @example * - * var arrA = [NaN, 3, 8, 'foo', 'bar']; - * var arrB = [2, 7, 'foo', NaN, 3]; - * var arrC = [1, 2, 3, NaN]; + * const arrA = [NaN, 3, 8, 'foo', 'bar']; + * const arrB = [2, 7, 'foo', NaN, 3]; + * const arrC = [1, 2, 3, NaN]; * * intersect(arrA, arrB); * // -> [NaN, 3, 'foo'] @@ -19,32 +19,24 @@ * intersect(arrA, arrB, arrC); * // -> [NaN, 3] */ -function intersect(/* ...arrays */) { - var _len = arguments.length; - var _key = 0; - var arrays = new Array(_len); +const intersect = (...arrays) => { + let len = arrays.length; - for (; _key < _len; _key += 1) { - arrays[_key] = arguments[_key]; - } - - while (_len--) { - if (!Array.isArray(arrays[_len])) { + while (len--) { + if (!Array.isArray(arrays[len])) { throw new TypeError('Expected all arguments to be arrays'); } } - return arrays.reduce(function (accumArray, currentArray) { + return arrays.reduce((accumArray, currentArray) => { return accumArray.filter(function (element) { - var index, currentElement; - if (Array.prototype.includes) { return currentArray.includes(element); } else { - index = 0; + let index = 0; while (index < currentArray.length) { - currentElement = currentArray[index]; + const currentElement = currentArray[index]; if ( element === currentElement @@ -60,6 +52,6 @@ function intersect(/* ...arrays */) { } }); }); -} +}; module.exports = intersect; diff --git a/packages/arrays/intersect/test.js b/packages/arrays/intersect/test.js index d69b0351..c9394a85 100644 --- a/packages/arrays/intersect/test.js +++ b/packages/arrays/intersect/test.js @@ -1,13 +1,13 @@ -var intersect = require('./intersect'); +const intersect = require('./intersect'); describe('Array/intersect', function () { function runTests() { - var arrA = [NaN, 3, 8, 'foo', 'bar']; - var arrB = [2, 7, 'foo', NaN, 3]; - var arrC = [1, 2, 3, NaN]; - var arrD = [4, 5, 6]; - var arrE = [1, null, 2, NaN, 3, void 0]; - var arrF = ['1', void 0, '2', null, '3', NaN]; + const arrA = [NaN, 3, 8, 'foo', 'bar']; + const arrB = [2, 7, 'foo', NaN, 3]; + const arrC = [1, 2, 3, NaN]; + const arrD = [4, 5, 6]; + const arrE = [1, null, 2, NaN, 3, void 0]; + const arrF = ['1', void 0, '2', null, '3', NaN]; expect(intersect(arrA, arrB)).toEqual([NaN, 3, 'foo']); @@ -31,7 +31,7 @@ describe('Array/intersect', function () { }); it('creates an array of unique values that are included in all given arrays (Array.prototype.includes is not supported)', function () { - var nativeCode = Array.prototype.includes; + const nativeCode = Array.prototype.includes; Array.prototype.includes = null; runTests(); Array.prototype.includes = nativeCode; diff --git a/packages/arrays/move/README.md b/packages/arrays/move/README.md index 7b1ab1ba..af37082c 100644 --- a/packages/arrays/move/README.md +++ b/packages/arrays/move/README.md @@ -18,7 +18,7 @@ Move an array element to a different position. **Example** ```js -var array = ['A', 'B', 'C', 'D', 'E']; +const array = ['A', 'B', 'C', 'D', 'E']; move(array, 0, 1); // -> ['B', 'A', 'C', 'D', 'E'] diff --git a/packages/arrays/move/move.js b/packages/arrays/move/move.js index e8734b43..fd8874a2 100644 --- a/packages/arrays/move/move.js +++ b/packages/arrays/move/move.js @@ -11,7 +11,7 @@ * @returns {Array} The new array with the element moved to a new position. * @example * - * var array = ['A', 'B', 'C', 'D', 'E']; + * const array = ['A', 'B', 'C', 'D', 'E']; * * move(array, 0, 1); * // -> ['B', 'A', 'C', 'D', 'E'] @@ -25,9 +25,7 @@ * move(array, -1, -3); * // -> ['A', 'B', 'E', 'C', 'D'] */ -function move(array, fromIndex, toIndex) { - var resultArray, startIndex, endIndex, elementToMove; - +const move = (array, fromIndex, toIndex) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -36,21 +34,22 @@ function move(array, fromIndex, toIndex) { throw new TypeError('Expected a number for second and third arguments'); } - resultArray = Array.prototype.slice.call(array, 0); + const resultArray = [...array]; if (fromIndex === toIndex) { return resultArray; } - startIndex = fromIndex < 0 ? resultArray.length + fromIndex : fromIndex; + const startIndex = fromIndex < 0 ? resultArray.length + fromIndex : fromIndex; if (startIndex >= 0 && startIndex < resultArray.length) { - endIndex = toIndex < 0 ? resultArray.length + toIndex : toIndex; - elementToMove = resultArray.splice(fromIndex, 1)[0]; + const endIndex = toIndex < 0 ? resultArray.length + toIndex : toIndex; + const elementToMove = resultArray.splice(fromIndex, 1)[0]; + resultArray.splice(endIndex, 0, elementToMove); } return resultArray; -} +}; -module.exports = move; \ No newline at end of file +module.exports = move; diff --git a/packages/arrays/move/test.js b/packages/arrays/move/test.js index 10462779..3b5f6d7a 100644 --- a/packages/arrays/move/test.js +++ b/packages/arrays/move/test.js @@ -1,8 +1,8 @@ -var move = require('./move'); +const move = require('./move'); describe('Array/move', function () { it('moves an array element to a different position', function () { - var array = ['A', 'B', 'C', 'D', 'E']; + const array = ['A', 'B', 'C', 'D', 'E']; expect(move(array, 0, 1)).toEqual(['B', 'A', 'C', 'D', 'E']); diff --git a/packages/arrays/partition/README.md b/packages/arrays/partition/README.md index f84e3b49..a8d1e19a 100644 --- a/packages/arrays/partition/README.md +++ b/packages/arrays/partition/README.md @@ -9,6 +9,8 @@ The predicate is invoked with three arguments: (value, index, collection). **Throws**: - TypeError If `array` is not array. +- TypeError If `predicate` is defined but not a function. + | Param | Type | Default | Description | | --- | --- | --- | --- | @@ -17,7 +19,7 @@ The predicate is invoked with three arguments: (value, index, collection). **Example** ```js -var users = [{ +const users = [{ name: 'John', isAdmin: true }, { @@ -28,15 +30,11 @@ var users = [{ isAdmin: true }]; -partition(users, function (element) { - return element.isAdmin -}); +partition(users, user => user.isAdmin); // -> [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] -var numbers = [1, 3, 5, -4, 6, -2]; +const numbers = [1, 3, 5, -4, 6, -2]; -partition(numbers, function (element) { - return element > 0; -}); +partition(numbers, num => num > 0); // -> [[1, 3, 5, 6], [-4, -2]] ``` diff --git a/packages/arrays/partition/partition.js b/packages/arrays/partition/partition.js index 0dd0ad14..4fb15b13 100644 --- a/packages/arrays/partition/partition.js +++ b/packages/arrays/partition/partition.js @@ -8,10 +8,11 @@ * @param {Array} array The array to iterate over. * @param {Function} [predicate=Identity] The function invoked per iteration. * @throws {TypeError} If `array` is not array. + * @throws {TypeError} If `predicate` is defined but not a function. * @returns {Array} Returns the array of grouped elements. * @example * - * var users = [{ + * const users = [{ * name: 'John', * isAdmin: true * }, { @@ -22,40 +23,32 @@ * isAdmin: true * }]; * - * partition(users, function (element) { - * return element.isAdmin - * }); + * partition(users, user => user.isAdmin); * // -> [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] * + * const numbers = [1, 3, 5, -4, 6, -2]; * - * var numbers = [1, 3, 5, -4, 6, -2]; - * - * partition(numbers, function (element) { - * return element > 0; - * }); + * partition(numbers, num => num > 0); * // -> [[1, 3, 5, 6], [-4, -2]] */ -function partition(array, predicate) { - var part1 = []; - var part2 = []; - var index, value; +const partition = (array, predicate = x => x) => { + const part1 = []; + const part2 = []; if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } if (typeof predicate !== 'function') { - predicate = function (x) { - return x; - }; + throw new TypeError('Expected a function for second argument'); } - for (index = 0; index < array.length; index += 1) { - value = array[index]; + for (let index = 0; index < array.length; index += 1) { + const value = array[index]; predicate(value, index, array) ? part1.push(value) : part2.push(value); } return [part1, part2]; -} +}; -module.exports = partition; \ No newline at end of file +module.exports = partition; diff --git a/packages/arrays/partition/test.js b/packages/arrays/partition/test.js index f6525f2a..a81e27c8 100644 --- a/packages/arrays/partition/test.js +++ b/packages/arrays/partition/test.js @@ -1,8 +1,8 @@ -var partition = require('./partition'); +const partition = require('./partition'); describe('Array/partition', function () { it('creates an array of elements split into two groups', function () { - var users = [{ + const users = [{ name: 'John', isAdmin: true }, { @@ -13,22 +13,22 @@ describe('Array/partition', function () { isAdmin: true }]; - var numbers = [1, 3, 5, -4, 6, -2]; + const numbers = [1, 3, 5, -4, 6, -2]; - var partitionedNumbers = partition(numbers, function (element) { + const partitionedNumbers = partition(numbers, function (element) { return element > 0; }); - var positive = partitionedNumbers[0]; - var nonPositive = partitionedNumbers[1]; + const positive = partitionedNumbers[0]; + const nonPositive = partitionedNumbers[1]; expect(positive).toEqual([1, 3, 5, 6]); expect(nonPositive).toEqual([-4, -2]); - var partitionedUsers = partition(users, function (element) { + const partitionedUsers = partition(users, function (element) { return element.isAdmin; }); - var admins = partitionedUsers[0]; - var nonAdmins = partitionedUsers[1]; + const admins = partitionedUsers[0]; + const nonAdmins = partitionedUsers[1]; expect(admins).toEqual([{ name: 'John', @@ -54,5 +54,9 @@ describe('Array/partition', function () { return element.isAdmin; }); }).toThrow(new TypeError('Expected an array for first argument')); + + expect(function () { + return partition(users, null); + }).toThrow(new TypeError('Expected a function for second argument')); }); }); diff --git a/packages/arrays/pluck/README.md b/packages/arrays/pluck/README.md index 19dd3110..0fd73a2f 100755 --- a/packages/arrays/pluck/README.md +++ b/packages/arrays/pluck/README.md @@ -16,7 +16,7 @@ Retrieves the value of a specified property from all elements in an array. **Example** ```js -var books = [ +const books = [ {title: 'Around the World in Eighty Days', author: 'Jules Verne'}, {title: 'The Mist', author: 'Stephen King'}, {title: 'Journey to the Center of the Earth', author: 'Jules Verne'}, diff --git a/packages/arrays/pluck/pluck.js b/packages/arrays/pluck/pluck.js index 155d2a34..96852e57 100755 --- a/packages/arrays/pluck/pluck.js +++ b/packages/arrays/pluck/pluck.js @@ -9,7 +9,7 @@ * @returns {Array} Returns the result array. * @example * - * var books = [ + * const books = [ * {title: 'Around the World in Eighty Days', author: 'Jules Verne'}, * {title: 'The Mist', author: 'Stephen King'}, * {title: 'Journey to the Center of the Earth', author: 'Jules Verne'}, @@ -22,20 +22,16 @@ * pluck(books, 'author'); * // -> ["Jules Verne", "Stephen King", "Jules Verne", "Stephen King"] */ -function pluck(array, key) { - var arr, index, len, arrItem; - +const pluck = (array, key) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - arr = []; - index = -1; - len = array.length; - arrItem; + const arr = []; + let index = -1; - while (++index < len) { - arrItem = array[index]; + while (++index < array.length) { + const arrItem = array[index]; if (Object.prototype.hasOwnProperty.call(arrItem, key)) { arr[arr.length] = arrItem[key]; @@ -43,6 +39,6 @@ function pluck(array, key) { } return arr; -} +}; -module.exports = pluck; \ No newline at end of file +module.exports = pluck; diff --git a/packages/arrays/pluck/test.js b/packages/arrays/pluck/test.js index f9e9e8d2..47aba1cf 100644 --- a/packages/arrays/pluck/test.js +++ b/packages/arrays/pluck/test.js @@ -1,7 +1,7 @@ -var pluck = require('./pluck'); +const pluck = require('./pluck'); describe('Array/pluck', function () { - var books = [ + const books = [ { title: 'Around the World in Eighty Days', author: 'Jules Verne' }, { title: 'The Mist', author: 'Stephen King' }, { title: 'Journey to the Center of the Earth', author: 'Jules Verne' }, diff --git a/packages/arrays/remove/README.md b/packages/arrays/remove/README.md index 708a02dd..f9269366 100644 --- a/packages/arrays/remove/README.md +++ b/packages/arrays/remove/README.md @@ -1,36 +1,41 @@ -## remove(array, indexes) ⇒ Array +## remove(array) ⇒ Array Removes one or more elements from an array at the specified index(es). **Returns**: Array - The result array with the elements specified removed. **Throws**: - TypeError If `array` is not array. -- TypeError If `indexes` is not array. | Param | Type | Description | | --- | --- | --- | | array | Array | The initial array to remove elements from. | -| indexes | Array.<Number> | An array with the index(es) of the elements to be removed. Non numbers are ignored. | +| ...indexes | Number | The index(es) of the elements to be removed. Non numbers are ignored. | -**Example** +**Example** ```js -var arr = [1, 2, 3, 4, 5]; +const arr = [1, 2, 3, 4, 5]; -remove(arr, [0]); +remove(arr, 0); // -> [2, 3, 4, 5] -remove(arr, [0, 1]); +remove(arr, 0, 1); // -> [3, 4, 5] -remove(arr, [0, 4]); +remove(arr, 0, 4); // -> [2, 3, 4] -remove(arr, []); +remove(arr); // -> [1, 2, 3, 4, 5] -remove(arr, [arr.length]); +remove(arr, arr.length); +// -> [1, 2, 3, 4, 5] + +remove(arr, arr.length - 1); +// -> [1, 2, 3, 4] + +remove(arr, NaN); // -> [1, 2, 3, 4, 5] ``` diff --git a/packages/arrays/remove/remove.js b/packages/arrays/remove/remove.js index a951d3d4..784e73da 100644 --- a/packages/arrays/remove/remove.js +++ b/packages/arrays/remove/remove.js @@ -4,43 +4,44 @@ * Removes one or more elements from an array at the specified index(es). * * @param {Array} array The initial array to remove elements from. - * @param {Array.} indexes An array with the index(es) of the elements to be removed. Non numbers are ignored. + * @param {Number} ...indexes The index(es) of the elements to be removed. Non numbers are ignored. * @throws {TypeError} If `array` is not array. - * @throws {TypeError} If `indexes` is not array. * @returns {Array} The result array with the elements specified removed. * @example * - * var arr = [1, 2, 3, 4, 5]; + * const arr = [1, 2, 3, 4, 5]; * - * remove(arr, [0]); + * remove(arr, 0); * // -> [2, 3, 4, 5] * - * remove(arr, [0, 1]); + * remove(arr, 0, 1); * // -> [3, 4, 5] * - * remove(arr, [0, 4]); + * remove(arr, 0, 4); * // -> [2, 3, 4] * - * remove(arr, []); + * remove(arr); * // -> [1, 2, 3, 4, 5] * - * remove(arr, [arr.length]); + * remove(arr, arr.length); + * // -> [1, 2, 3, 4, 5] + * + * remove(arr, arr.length - 1); + * // -> [1, 2, 3, 4] + * + * remove(arr, NaN); * // -> [1, 2, 3, 4, 5] */ -function remove(array, indexes) { +const remove = (array, ...indexes) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - if (!Array.isArray(indexes)) { - throw new TypeError('Expected an array for second argument'); - } - - return array.filter(function (_, index) { + return array.filter((_, index) => { return typeof index === 'number' && index === index // check if number and not NaN ? indexes.indexOf(index) === -1 : false; }); -} +}; module.exports = remove; diff --git a/packages/arrays/remove/test.js b/packages/arrays/remove/test.js index 51ba28ef..396ec2c1 100644 --- a/packages/arrays/remove/test.js +++ b/packages/arrays/remove/test.js @@ -1,39 +1,39 @@ -var remove = require('./remove'); +const remove = require('./remove'); describe('Array/remove', function () { it('removes elements from array at specific index(es)', function () { - var arr = [1, 2, 3, 4, 5]; + const arr = [1, 2, 3, 4, 5]; - expect(remove(arr, [0])).toEqual([2, 3, 4, 5]); + expect(remove(arr, 0)).toEqual([2, 3, 4, 5]); - expect(remove(arr, [0, 1])).toEqual([3, 4, 5]); + expect(remove(arr, 0, 1)).toEqual([3, 4, 5]); - expect(remove(arr, [1, 0])).toEqual([3, 4, 5]); + expect(remove(arr, 1, 0)).toEqual([3, 4, 5]); - expect(remove(arr, [0, 4])).toEqual([2, 3, 4]); + expect(remove(arr, 0, 4)).toEqual([2, 3, 4]); - expect(remove(arr, [4, 0])).toEqual([2, 3, 4]); + expect(remove(arr, 4, 0)).toEqual([2, 3, 4]); - expect(remove(arr, [0, 0])).toEqual([2, 3, 4, 5]); + expect(remove(arr, 0, 0)).toEqual([2, 3, 4, 5]); - expect(remove(arr, [arr.length])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr, arr.length)).toEqual([1, 2, 3, 4, 5]); - expect(remove(arr, [])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr, arr.length - 1)).toEqual([1, 2, 3, 4]); - expect(remove(arr, [NaN])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr)).toEqual([1, 2, 3, 4, 5]); - expect(remove(arr, [undefined])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr, NaN)).toEqual([1, 2, 3, 4, 5]); - expect(remove(arr, [null])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr, undefined)).toEqual([1, 2, 3, 4, 5]); - expect(remove(arr, ['0', '1'])).toEqual([1, 2, 3, 4, 5]); + expect(remove(arr, null)).toEqual([1, 2, 3, 4, 5]); + + expect(remove(arr, null, undefined, NaN)).toEqual([1, 2, 3, 4, 5]); + + expect(remove(arr, '0', '1')).toEqual([1, 2, 3, 4, 5]); expect(function () { return remove({ foo: 'bar' }, [0]); }).toThrow(new TypeError('Expected an array for first argument')); - - expect(function () { - return remove(arr, 0); - }).toThrow(new TypeError('Expected an array for second argument')); }); }); diff --git a/packages/arrays/reverse/reverse.js b/packages/arrays/reverse/reverse.js index a213e909..50aa4196 100644 --- a/packages/arrays/reverse/reverse.js +++ b/packages/arrays/reverse/reverse.js @@ -12,12 +12,12 @@ * reverse([1, 2, 3]); * // -> [3, 2, 1] */ -function reverse(array) { +const reverse = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - return array.slice(0).reverse(); -} + return [...array].reverse(); +}; -module.exports = reverse; \ No newline at end of file +module.exports = reverse; diff --git a/packages/arrays/reverse/test.js b/packages/arrays/reverse/test.js index 38204b94..11df9fa5 100644 --- a/packages/arrays/reverse/test.js +++ b/packages/arrays/reverse/test.js @@ -1,9 +1,9 @@ -var reverse = require('./reverse'); +const reverse = require('./reverse'); describe('Array/reverse', function () { it('returns a new reversed array', function () { - var numbers = [1, 2, 3]; - var revNumbers = reverse(numbers); + const numbers = [1, 2, 3]; + const revNumbers = reverse(numbers); expect(numbers).toEqual([1, 2, 3]); diff --git a/packages/arrays/shuffle/shuffle.js b/packages/arrays/shuffle/shuffle.js index 437aa740..b061fab7 100644 --- a/packages/arrays/shuffle/shuffle.js +++ b/packages/arrays/shuffle/shuffle.js @@ -6,34 +6,30 @@ * * @param {Array} array The array to shuffle. * @throws {TypeError} If `array` is not array. - * @return {Array} Returns a new array with its elements randomised. + * @returns {Array} Returns a new array with its elements randomised. * @example * * shuffle(arr); * // -> ['b', 'f', 'h', 'e', 'd', 'c', 'g', 'a'] */ -function shuffle(array) { - var newArray, currentIndex, temporaryValue, randomIndex; - +const shuffle = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - newArray = array.slice(0); // Ensure that original array stays intact. - currentIndex = newArray.length; + const newArray = [...array]; + let currentIndex = newArray.length; // While remaining elements to shuffle... while (currentIndex) { - // Pick a remaining element... - randomIndex = Math.random() * currentIndex-- | 0; + const randomIndex = Math.random() * currentIndex-- | 0; // Pick a remaining element... + const temporaryValue = newArray[currentIndex]; // And swap it with the current element. - // And swap it with the current element. - temporaryValue = newArray[currentIndex]; newArray[currentIndex] = newArray[randomIndex]; newArray[randomIndex] = temporaryValue; } return newArray; -} +}; -module.exports = shuffle; \ No newline at end of file +module.exports = shuffle; diff --git a/packages/arrays/shuffle/test.js b/packages/arrays/shuffle/test.js index 2464513b..87d2aec3 100644 --- a/packages/arrays/shuffle/test.js +++ b/packages/arrays/shuffle/test.js @@ -1,8 +1,8 @@ -var shuffle = require('./shuffle'); +const shuffle = require('./shuffle'); describe('Array/shuffle', function () { it('shuffles an array', function () { - var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; + const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']; expect(shuffle(arr)).toHaveLength(8); diff --git a/packages/arrays/sort/README.md b/packages/arrays/sort/README.md index 2f117df0..c8d09e58 100644 --- a/packages/arrays/sort/README.md +++ b/packages/arrays/sort/README.md @@ -15,7 +15,7 @@ If array values are of different type, the result is not guaranteed to be correc | Param | Type | Default | Description | | --- | --- | --- | --- | | array | Array | | The array to sort. | -| [ascending] | Boolean | true | Defines the sort order. Default is true (ascending). | +| [ascending] | Boolean | true | Defines the sort order. Falsy values will assume descending. | **Example** ```js diff --git a/packages/arrays/sort/sort.js b/packages/arrays/sort/sort.js index 72b19056..d31a6b04 100644 --- a/packages/arrays/sort/sort.js +++ b/packages/arrays/sort/sort.js @@ -7,9 +7,9 @@ * * @Note: For legacy browsers use the `Array.prototype.map` and `Array.prototype.filter` polyfills. * @param {Array} array The array to sort. - * @param {Boolean} [ascending=true] Defines the sort order. Default is true (ascending). + * @param {Boolean} [ascending=true] Defines the sort order. Falsy values will assume descending. * @throws {TypeError} If `array` is not array. - * @return {Array} The new sorted array. + * @returns {Array} The new sorted array. * @example * * sort(['Delta', 'Omega', 'alpha', 'CHARLIE', 'lorem', 'bravo']); @@ -30,31 +30,14 @@ * sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], false); * // -> [321, 100, 99, 9, 6, 4, 2, -2, -10] */ -function sort(array, ascending) { - // Remove any `null`, `undefined` or `NaN` values. - var filtered; - +const sort = (array, ascending = true) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - filtered = array.filter(function (el) { - return el != null && el === el; - }); - - return filtered.map(function (el, idx) { - return { - index: idx, - value: typeof el === 'string' ? el.toLowerCase() : el - }; - }).sort(function (a, b) { - if (ascending == null) { - ascending = true; - } - return (a.value < b.value ? -1 : a.value > b.value ? 1 : 0) * [-1, 1][+!!ascending]; - }).map(function (el) { - return filtered[el.index]; - }); -} + return array.filter(el => el != null && el === el) // Remove any `null`, `undefined` or `NaN` values. + .map(el => typeof el === 'string' ? el.toLowerCase() : el) + .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0) * [-1, 1][+!!ascending]); +}; -module.exports = sort; \ No newline at end of file +module.exports = sort; diff --git a/packages/arrays/sort/test.js b/packages/arrays/sort/test.js index 5f6272e9..cf07b65e 100644 --- a/packages/arrays/sort/test.js +++ b/packages/arrays/sort/test.js @@ -1,8 +1,8 @@ -var sort = require('./sort'); +const sort = require('./sort'); describe('Array/sort', function () { - var numbers = [1, 2, 3, 10, 4, 9]; - var drinks = ['martini', 'coffee', 'wine', 'tequila']; + const numbers = [1, 2, 3, 10, 4, 9]; + const drinks = ['martini', 'coffee', 'wine', 'tequila']; it('sorts an array', function () { expect(sort(numbers)).toEqual([1, 2, 3, 4, 9, 10]); @@ -11,8 +11,12 @@ describe('Array/sort', function () { expect(sort(drinks)).toEqual(['coffee', 'martini', 'tequila', 'wine']); + expect(sort(drinks, 1)).toEqual(['coffee', 'martini', 'tequila', 'wine']); + expect(sort(drinks, false)).toEqual(['wine', 'tequila', 'martini', 'coffee']); + expect(sort(drinks, NaN)).toEqual(['wine', 'tequila', 'martini', 'coffee']); + expect(sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], true)) .toEqual([-10, -2, 2, 4, 6, 9, 99, 100, 321]); diff --git a/packages/arrays/sortBy/README.md b/packages/arrays/sortBy/README.md index d77d1888..432225ac 100644 --- a/packages/arrays/sortBy/README.md +++ b/packages/arrays/sortBy/README.md @@ -1,7 +1,7 @@ ## sortBy(array, field, [ascending], [primer]) ⇒ Array -Sorts an array of objects (not in place) by property. +Sorts an array of plain objects (not in place) by property. **Returns**: Array - Returns the new sorted array. **Throws**: @@ -13,12 +13,12 @@ Sorts an array of objects (not in place) by property. | --- | --- | --- | --- | | array | Array | | The array to sort. | | field | String | | The field to sort the array by. | -| [ascending] | Boolean | true | Defines the sort order. This is not optional if `primer` is required. | +| [ascending] | Boolean | true | Defines the sort order. This is not optional if `primer` is required. | | [primer] | function | | Manipulates the field to sort by. | **Example** ```js -var homes = [ +const homes = [ {h_id: 8, city: 'Dallas', price: '162500'}, {h_id: 4, city: 'Beverly Hills', price: '162500.5'}, {h_id: 5, city: 'new York', price: '162500.1'} diff --git a/packages/arrays/sortBy/sortBy.js b/packages/arrays/sortBy/sortBy.js index 26769914..0a7b5579 100755 --- a/packages/arrays/sortBy/sortBy.js +++ b/packages/arrays/sortBy/sortBy.js @@ -1,18 +1,17 @@ 'use strict'; /** - * Sorts an array of objects (not in place) by property. + * Sorts an array of plain objects (not in place) by property. * * @param {Array} array The array to sort. * @param {String} field The field to sort the array by. - * @param {Boolean} [ascending=true] Defines the sort order. - * This is not optional if `primer` is required. + * @param {Boolean} [ascending=true] Defines the sort order. Falsy values will assume descending. This is not optional if `primer` is required. * @param {function} [primer] Manipulates the field to sort by. * @throws {TypeError} If `array` is not array. - * @return {Array} Returns the new sorted array. + * @returns {Array} Returns the new sorted array. * @example * - * var homes = [ + * const homes = [ * {h_id: 8, city: 'Dallas', price: '162500'}, * {h_id: 4, city: 'Beverly Hills', price: '162500.5'}, * {h_id: 5, city: 'new York', price: '162500.1'} @@ -32,27 +31,29 @@ * }); * // -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"}]" */ -function sortBy(array, field, ascending, primer) { - var key; - +const sortBy = (array, field, ascending = true, primer) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - key = function (x) { - return primer ? primer(x[field]) : x[field]; - }; - - return array.slice().sort(function (a, b) { - var A = key(a); - var B = key(b); + const key = x => typeof primer === 'function' ? primer(x[field]) : x[field]; - if (typeof ascending !== 'boolean') { - ascending = true; + const isPlainObject = value => { + if (Object.prototype.toString.call(value) !== '[object Object]') { + return false; } + const proto = Object.getPrototypeOf(value); + + return proto === null || proto === Object.prototype; + }; + + return array.filter(isPlainObject).sort((a, b) => { + const A = key(a); + const B = key(b); + return (A < B ? -1 : A > B ? 1 : 0) * [-1, 1][+!!ascending]; }); -} +}; -module.exports = sortBy; \ No newline at end of file +module.exports = sortBy; diff --git a/packages/arrays/sortBy/test.js b/packages/arrays/sortBy/test.js index 3c2e734d..f54b9611 100644 --- a/packages/arrays/sortBy/test.js +++ b/packages/arrays/sortBy/test.js @@ -1,7 +1,7 @@ -var sortBy = require('./sortBy'); +const sortBy = require('./sortBy'); describe('Array/sortBy', function () { - var people = [ + const people = [ { name: 'Elena', age: '2' }, { name: 'George', age: '33' }, { name: 'Vasiliki', age: '32' }, @@ -23,6 +23,13 @@ describe('Array/sortBy', function () { { name: 'Elena', age: '2' } ]); + expect(sortBy(people, 'name', null)).toEqual([ + { name: 'Vasiliki', age: '32' }, + { name: 'Vaggelis', age: '30' }, + { name: 'George', age: '33' }, + { name: 'Elena', age: '2' } + ]); + expect(sortBy(people, 'age', true, function (age) { return age * 2; })).toEqual([ @@ -32,6 +39,20 @@ describe('Array/sortBy', function () { { name: 'George', age: '33' } ]); + expect(sortBy(people, 'age', true, {})).toEqual([ + { name: 'Elena', age: '2' }, + { name: 'Vaggelis', age: '30' }, + { name: 'Vasiliki', age: '32' }, + { name: 'George', age: '33' } + ]); + + expect(sortBy([...people, undefined, null, NaN, 'foo', 100, [1, 2, 3], () => void 0, new Set(), new Map(), Symbol('foo'), new Date()], 'age')).toEqual([ + { name: 'Elena', age: '2' }, + { name: 'Vaggelis', age: '30' }, + { name: 'Vasiliki', age: '32' }, + { name: 'George', age: '33' }, + ]); + expect(sortBy(people, 'nonExistentProperty')).toEqual([ { name: 'Elena', age: '2' }, { name: 'George', age: '33' }, diff --git a/packages/arrays/tail/tail.js b/packages/arrays/tail/tail.js index 1f08a23c..4f9ecbba 100644 --- a/packages/arrays/tail/tail.js +++ b/packages/arrays/tail/tail.js @@ -5,7 +5,7 @@ * * @param {Array} array The array to process. * @throws {TypeError} If `array` is not array. - * @return {Array} The new tailed array. + * @returns {Array} The new tailed array. * @example * * tail([1, 2, 3,]); @@ -17,12 +17,12 @@ * tail([]); * // -> [] */ -function tail(array) { +const tail = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } return array.slice(1); -} +}; -module.exports = tail; \ No newline at end of file +module.exports = tail; diff --git a/packages/arrays/tail/test.js b/packages/arrays/tail/test.js index 8d21b637..349adbe3 100644 --- a/packages/arrays/tail/test.js +++ b/packages/arrays/tail/test.js @@ -1,4 +1,4 @@ -var tail = require('./tail'); +const tail = require('./tail'); describe('Array/tail', function () { it('Gets all but the first element of array', function () { diff --git a/packages/arrays/take/take.js b/packages/arrays/take/take.js index 7145faaf..02184ac9 100644 --- a/packages/arrays/take/take.js +++ b/packages/arrays/take/take.js @@ -7,7 +7,7 @@ * @param {Number} [n=1] The number of items to take. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `n` is not number but not if is `undefined`. - * @return {Array} The slice of the array. + * @returns {Array} The slice of the array. * @example * * take([1, 2, 3, 4, 5]); @@ -37,24 +37,22 @@ * take({}, 2); * // -> Throws TypeError */ -function take(array, n) { - var MAX_SAFE_INTEGER; - +const take = (array, n = 1) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - if (typeof n !== 'number' && typeof n !== 'undefined') { + if (typeof n !== 'number') { throw new TypeError('Expected a number for second argument'); } - MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; n = n > MAX_SAFE_INTEGER ? array.length : n == null || n !== n ? 1 : Math.floor(n); return array.slice(0, n < 0 ? 0 : n); -} +}; -module.exports = take; \ No newline at end of file +module.exports = take; diff --git a/packages/arrays/take/test.js b/packages/arrays/take/test.js index dc51f728..21acd37b 100644 --- a/packages/arrays/take/test.js +++ b/packages/arrays/take/test.js @@ -1,4 +1,4 @@ -var take = require('./take'); +const take = require('./take'); describe('Array/take', function () { it('creates a slice of array with n items taken from the beginning', function () { diff --git a/packages/arrays/takeRight/takeRight.js b/packages/arrays/takeRight/takeRight.js index da74dc51..6c617aa6 100644 --- a/packages/arrays/takeRight/takeRight.js +++ b/packages/arrays/takeRight/takeRight.js @@ -7,7 +7,7 @@ * @param {Number} [n=1] The number of items to take. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `n` is not number but not if is `undefined`. - * @return {Array} The slice of the array. + * @returns {Array} The slice of the array. * @example * * takeRight([1, 2, 3, 4, 5]); @@ -37,23 +37,22 @@ * takeRight({}, 2); * // -> Throws TypeError */ -function takeRight(array, n) { - var MAX_SAFE_INTEGER, length; - +const takeRight = (array, n = 1) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - if (typeof n !== 'number' && typeof n !== 'undefined') { + if (typeof n !== 'number') { throw new TypeError('Expected a number for second argument'); } - MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - length = array.length; - n = n > MAX_SAFE_INTEGER ? length : n == null || n !== n ? 1 : Math.floor(n); - n = length - n; + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const len = array.length; + + n = n > MAX_SAFE_INTEGER ? len : n == null || n !== n ? 1 : Math.floor(n); + n = len - n; - return array.slice(n < 0 ? 0 : n, length); -} + return array.slice(n < 0 ? 0 : n, len); +}; -module.exports = takeRight; \ No newline at end of file +module.exports = takeRight; diff --git a/packages/arrays/takeRight/test.js b/packages/arrays/takeRight/test.js index 6022b84c..c83e2d44 100644 --- a/packages/arrays/takeRight/test.js +++ b/packages/arrays/takeRight/test.js @@ -1,4 +1,4 @@ -var takeRight = require('./takeRight'); +const takeRight = require('./takeRight'); describe('Array/takeRight', function () { it('creates a slice of array with n items taken from the end', function () { diff --git a/packages/arrays/takeRightWhile/README.md b/packages/arrays/takeRightWhile/README.md index 223a80a1..7bba0034 100644 --- a/packages/arrays/takeRightWhile/README.md +++ b/packages/arrays/takeRightWhile/README.md @@ -18,7 +18,7 @@ The `predicate` is invoked with three arguments: (`value`, `index`, `array`). **Example** ```js -var books = [ +const books = [ {title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}, {title: 'JavaScript The Good Parts', read: false}, diff --git a/packages/arrays/takeRightWhile/takeRightWhile.js b/packages/arrays/takeRightWhile/takeRightWhile.js index 3870ac57..3ab8e882 100644 --- a/packages/arrays/takeRightWhile/takeRightWhile.js +++ b/packages/arrays/takeRightWhile/takeRightWhile.js @@ -8,10 +8,10 @@ * @param {function} predicate The function invoked per iteration. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `predicate` is not function but not if is `undefined`. - * @return {Array} The slice of `array`. + * @returns {Array} The slice of `array`. * @example * - * var books = [ + * const books = [ * {title: 'Javascript Design Patterns', read: false}, * {title: 'Programming Javascript Applications', read: true}, * {title: 'JavaScript The Good Parts', read: false}, @@ -23,9 +23,7 @@ * }); * // -> [{title: 'JavaScript The Good Parts', read: false}, {title: 'Eloquent Javascript', read: false}] */ -function takeRightWhile(array, predicate) { - var index, length; - +const takeRightWhile = (array, predicate) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -34,14 +32,14 @@ function takeRightWhile(array, predicate) { throw new TypeError('Expected a function for second argument'); } - length = array.length; - index = length; + const len = array.length; + let index = len; - while (--index < length && index >= 0 && predicate(array[index], index, array)) { + while (--index < len && index >= 0 && predicate(array[index], index, array)) { continue; } - return array.slice(index + 1, length); -} + return array.slice(index + 1, len); +}; -module.exports = takeRightWhile; \ No newline at end of file +module.exports = takeRightWhile; diff --git a/packages/arrays/takeRightWhile/test.js b/packages/arrays/takeRightWhile/test.js index f2dc5559..7b337d20 100644 --- a/packages/arrays/takeRightWhile/test.js +++ b/packages/arrays/takeRightWhile/test.js @@ -1,19 +1,19 @@ -var takeRightWhile = require('./takeRightWhile'); +const takeRightWhile = require('./takeRightWhile'); describe('Array/takeRightWhile', function () { it('creates a slice of array with n items taken from the end', function () { - var books = [ + const books = [ { title: 'Javascript Design Patterns', read: false }, { title: 'Programming Javascript Applications', read: true }, { title: 'JavaScript The Good Parts', read: false }, { title: 'Eloquent Javascript', read: false } ]; - var unread = takeRightWhile(books, function (book) { + const unread = takeRightWhile(books, function (book) { return !book.read; }); - var read = takeRightWhile(books, function (book) { + const read = takeRightWhile(books, function (book) { return book.read; }); diff --git a/packages/arrays/takeWhile/README.md b/packages/arrays/takeWhile/README.md index 9739b3d4..a93821c2 100644 --- a/packages/arrays/takeWhile/README.md +++ b/packages/arrays/takeWhile/README.md @@ -18,7 +18,7 @@ The `predicate` is invoked with three arguments: (`value`, `index`, `array`). **Example** ```js -var books = [ +const books = [ {title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}, {title: 'JavaScript: The Good Parts', read: true}, diff --git a/packages/arrays/takeWhile/takeWhile.js b/packages/arrays/takeWhile/takeWhile.js index 073a7810..da7f49bf 100644 --- a/packages/arrays/takeWhile/takeWhile.js +++ b/packages/arrays/takeWhile/takeWhile.js @@ -8,10 +8,10 @@ * @param {function} predicate The function invoked per iteration. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `predicate` is not function but not if is `undefined`. - * @return {Array} The slice of `array`. + * @returns {Array} The slice of `array`. * @example * - * var books = [ + * const books = [ * {title: 'Javascript Design Patterns', read: false}, * {title: 'Programming Javascript Applications', read: false}, * {title: 'JavaScript: The Good Parts', read: true}, @@ -23,9 +23,7 @@ * }); * // -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}] */ -function takeWhile(array, predicate) { - var index, length; - +const takeWhile = (array, predicate) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } @@ -34,14 +32,13 @@ function takeWhile(array, predicate) { throw new TypeError('Expected a function for second argument'); } - index = -1; - length = array.length; + let index = -1; - while (++index < length && predicate(array[index], index, array)) { + while (++index < array.length && predicate(array[index], index, array)) { continue; } return array.slice(0, index); -} +}; -module.exports = takeWhile; \ No newline at end of file +module.exports = takeWhile; diff --git a/packages/arrays/takeWhile/test.js b/packages/arrays/takeWhile/test.js index 6730e61a..13510a89 100644 --- a/packages/arrays/takeWhile/test.js +++ b/packages/arrays/takeWhile/test.js @@ -1,19 +1,19 @@ -var takeWhile = require('./takeWhile'); +const takeWhile = require('./takeWhile'); describe('Array/takeWhile', function () { it('creates a slice of array with elements taken from the beginning, until predicate returns falsy', function () { - var books = [ + const books = [ { title: 'Javascript Design Patterns', read: false }, { title: 'Programming Javascript Applications', read: false }, { title: 'JavaScript The Good Parts', read: true }, { title: 'Eloquent Javascript', read: false } ]; - var firstUnread = takeWhile(books, function (book) { + const firstUnread = takeWhile(books, function (book) { return !book.read; }); - var firstRead = takeWhile(books, function (book) { + const firstRead = takeWhile(books, function (book) { return book.read; }); diff --git a/packages/arrays/uniq/test.js b/packages/arrays/uniq/test.js index fc7af001..7d141431 100644 --- a/packages/arrays/uniq/test.js +++ b/packages/arrays/uniq/test.js @@ -1,10 +1,10 @@ -var uniq = require('./uniq'); +const uniq = require('./uniq'); describe('Array/uniq', function () { - var arr = ['a', 'a', 'b', true, '2', 2, false, true]; + const arr = ['a', 'a', 'b', true, '2', 2, false, true]; it('removes duplicate primitive values from an array', function () { - var result = uniq(arr); + const result = uniq(arr); expect(result).toEqual(['a', 'b', true, '2', 2, false]); diff --git a/packages/arrays/uniq/uniq.js b/packages/arrays/uniq/uniq.js index 21683fda..0b686d55 100755 --- a/packages/arrays/uniq/uniq.js +++ b/packages/arrays/uniq/uniq.js @@ -5,26 +5,23 @@ * * @param {Array} array The array to process. * @throws {TypeError} If `array` is not array. - * @return {Array} Returns the result (duplicates-free) array. + * @returns {Array} Returns the result (duplicates-free) array. * @example * * uniq(['a', 'a', 'b', true, '2', 2, false, true]); * // -> ['a', 'b', true, '2', 2, false] */ -function uniq(array) { - var duplicates, len, i, j, found; - +const uniq = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - duplicates = []; - len = array.length; + const duplicates = []; - for (i = 0; i < len; i += 1) { - found = false; + for (let i = 0; i < array.length; i += 1) { + let found = false; - for (j = 0; j < duplicates.length; j += 1) { + for (let j = 0; j < duplicates.length; j += 1) { if (array[i] === duplicates[j]) { found = true; break; @@ -37,6 +34,6 @@ function uniq(array) { } return duplicates; -} +}; module.exports = uniq; diff --git a/packages/arrays/uniqBy/README.md b/packages/arrays/uniqBy/README.md index 3db80358..85b88241 100644 --- a/packages/arrays/uniqBy/README.md +++ b/packages/arrays/uniqBy/README.md @@ -17,13 +17,13 @@ The `iteratee` is invoked with one argument (each element in the array). **Example** ```js -var arr1 = [ +const arr1 = [ { id: 1, name: 'John' }, { id: 2, name: 'George' }, { id: 1, name: 'Helen' } ]; -var arr2 = [ +const arr2 = [ { v: 1.6 }, { v: 2.1 }, { v: 1.1 } diff --git a/packages/arrays/uniqBy/test.js b/packages/arrays/uniqBy/test.js index b31c6e7b..1749d670 100644 --- a/packages/arrays/uniqBy/test.js +++ b/packages/arrays/uniqBy/test.js @@ -1,21 +1,21 @@ -var uniqBy = require('./uniqBy'); +const uniqBy = require('./uniqBy'); describe('Array/uniqBy', function () { it('Creates an object composed of keys generated from the results of running each element of array through iteratee', function () { - var arr1 = [ + const arr1 = [ { id: 1, name: 'John' }, { id: 2, name: 'George' }, { id: 1, name: 'Helen' }, { id: 3, name: 'Helen' } ]; - var arr2 = [ + const arr2 = [ { v: 1.6 }, { v: 2.1 }, { v: 1.1 } ]; - var arr3 = [ + const arr3 = [ { x: '0', y: '1', z: '2' }, { x: '1', y: '0', z: '2' }, { x: '0', y: '1', z: '2' }, diff --git a/packages/arrays/uniqBy/uniqBy.js b/packages/arrays/uniqBy/uniqBy.js index 9f33fe60..f843629b 100644 --- a/packages/arrays/uniqBy/uniqBy.js +++ b/packages/arrays/uniqBy/uniqBy.js @@ -10,13 +10,13 @@ * @returns {Array} The duplicate free array. * @example * - * var arr1 = [ + * const arr1 = [ * { id: 1, name: 'John' }, * { id: 2, name: 'George' }, * { id: 1, name: 'Helen' } * ]; * - * var arr2 = [ + * const arr2 = [ * { v: 1.6 }, * { v: 2.1 }, * { v: 1.1 } @@ -30,26 +30,22 @@ * }); * // -> [{ v: 1.6 }, { v: 2.1 }] */ -function uniqBy(array, iteratee) { +const uniqBy = (array, iteratee) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - var cb = typeof iteratee === 'function' ? iteratee : function (o) { - return o[iteratee]; - }; + const cb = typeof iteratee === 'function' ? iteratee : (o) => o[iteratee]; - return array.reduce(function (acc, current) { - var found = acc.find(function (item) { - return cb(item) === cb(current); - }); + return array.reduce((acc, current) => { + const found = acc.find(item => cb(item) === cb(current)); if (!found) { - return acc.concat([current]); + return [...acc, current]; } else { return acc; } }, []); -} +}; module.exports = uniqBy; diff --git a/packages/arrays/zip/test.js b/packages/arrays/zip/test.js index 68eb7e49..13e323fe 100644 --- a/packages/arrays/zip/test.js +++ b/packages/arrays/zip/test.js @@ -1,11 +1,11 @@ -var zip = require('./zip'); +const zip = require('./zip'); describe('Array/zip', function () { it('creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on', function () { - var arr1 = [1, 2, 3]; - var arr2 = [11, 22]; - var arr3 = [111]; - var zipped = zip(arr1, arr2, arr3); + const arr1 = [1, 2, 3]; + const arr2 = [11, 22]; + const arr3 = [111]; + const zipped = zip(arr1, arr2, arr3); expect(zipped).toHaveLength(3); diff --git a/packages/arrays/zip/zip.js b/packages/arrays/zip/zip.js index 564c0a62..875e78c1 100644 --- a/packages/arrays/zip/zip.js +++ b/packages/arrays/zip/zip.js @@ -25,32 +25,18 @@ * zip(); * // -> [] */ -function zip(/* ...arrays */) { - var _len = arguments.length; - var arrays = new Array(_len); - var _key = 0; - var longest; +const zip = (...arrays) => { + let len = arrays.length; - for (; _key < _len; _key += 1) { - arrays[_key] = arguments[_key]; - } - - while (_len--) { - if (!Array.isArray(arrays[_len])) { + while (len--) { + if (!Array.isArray(arrays[len])) { throw new TypeError('Expected all arguments passed to be arrays'); } } - // Find the longest of the arrays, to begin mapping from this one. - longest = arrays.reduce(function (a, b) { - return a.length > b.length ? a : b; - }, []); - - return longest.map(function (item, index) { - return arrays.map(function (array) { - return array[index]; - }); - }); -} + return arrays + .reduce((a, b) => a.length > b.length ? a : b, []) // Find the longest of the arrays, to begin mapping from this one. + .map((_, index) => arrays.map(array => array[index])); +}; module.exports = zip; From febf7703f0bbf57aa75b07a757432cc96a2923f3 Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 11:08:08 +0300 Subject: [PATCH 04/17] Convert to ES6 --- .eslintrc.json | 7 +++-- README.md | 2 +- packages/arrays/sort/README.md | 2 -- packages/arrays/sort/sort.js | 1 - packages/arrays/uniq/README.md | 10 +++++-- packages/arrays/uniq/test.js | 10 +++---- packages/arrays/uniq/uniq.js | 30 ++++++------------- packages/arrays/zip/README.md | 2 -- packages/arrays/zip/zip.js | 1 - packages/objects/schemaValidate/README.md | 2 -- .../objects/schemaValidate/schemaValidate.js | 3 +- 11 files changed, 28 insertions(+), 42 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 70d0a775..297add91 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -42,7 +42,9 @@ "operator-linebreak": ["warn", "before"], "brace-style": ["warn"], "keyword-spacing": ["warn"], - "object-curly-spacing": ["warn", "always"], + "object-curly-spacing": ["warn", "never"], + "array-bracket-spacing": ["warn", "never"], + "computed-property-spacing": ["warn", "never"], "space-before-blocks": ["warn", "always"], "spaced-comment": ["warn", "always"], "space-before-function-paren": ["warn", { @@ -64,6 +66,7 @@ "prefer-rest-params": ["warn"], "prefer-const": ["warn"], "no-var": ["warn"], - "no-extra-parens": ["warn", "all"] + "no-extra-parens": ["warn", "all"], + "space-in-parens": ["warn", "never"] } } diff --git a/README.md b/README.md index 6097d222..58ceaa84 100755 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ A collection of dependency-free JavaScript utility functions. |[takeWhile](https://github.com/georapbox/js-utils/tree/master/packages/arrays/takeWhile)|Creates a slice of `array` with elements taken from the beginning, until `predicate` returns falsy.| |[sort](https://github.com/georapbox/js-utils/tree/master/packages/arrays/sort)|Sorts an **array of primitive values**.| |[sortBy](https://github.com/georapbox/js-utils/tree/master/packages/arrays/sortBy)|Sorts an **array of objects** by a property.| -|[uniq](https://github.com/georapbox/js-utils/tree/master/packages/arrays/uniq)|Removes duplicate primitive values from an array.| +|[uniq](https://github.com/georapbox/js-utils/tree/master/packages/arrays/uniq)|Creates a duplicate-free version of an array, using SameValueZero for equality comparisons.| |[uniqBy](https://github.com/georapbox/js-utils/tree/master/packages/arrays/uniqBy)|Creates a dupliate free array by accepting an `iteratee` which is invoked for each element in array.| |[zip](https://github.com/georapbox/js-utils/tree/master/packages/arrays/zip)|Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.| diff --git a/packages/arrays/sort/README.md b/packages/arrays/sort/README.md index c8d09e58..650f55c4 100644 --- a/packages/arrays/sort/README.md +++ b/packages/arrays/sort/README.md @@ -10,8 +10,6 @@ If array values are of different type, the result is not guaranteed to be correc - TypeError If `array` is not array. -**Note:**: For legacy browsers use the `Array.prototype.map` and `Array.prototype.filter` polyfills. - | Param | Type | Default | Description | | --- | --- | --- | --- | | array | Array | | The array to sort. | diff --git a/packages/arrays/sort/sort.js b/packages/arrays/sort/sort.js index d31a6b04..934c18c6 100644 --- a/packages/arrays/sort/sort.js +++ b/packages/arrays/sort/sort.js @@ -5,7 +5,6 @@ * Any `null`, `undefined` or `NaN` values are removed from the result array. * If array values are of different type, the result is not guaranteed to be correct. * - * @Note: For legacy browsers use the `Array.prototype.map` and `Array.prototype.filter` polyfills. * @param {Array} array The array to sort. * @param {Boolean} [ascending=true] Defines the sort order. Falsy values will assume descending. * @throws {TypeError} If `array` is not array. diff --git a/packages/arrays/uniq/README.md b/packages/arrays/uniq/README.md index a7bd14b7..a4375620 100755 --- a/packages/arrays/uniq/README.md +++ b/packages/arrays/uniq/README.md @@ -1,7 +1,7 @@ ## uniq(array) ⇒ Array -Removes duplicate primitive values from an array. +Creates a duplicate-free version of an array, using [SameValueZero](https://262.ecma-international.org/7.0/#sec-samevaluezero) for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. **Returns**: Array - Returns the result (duplicates-free) array. **Throws**: @@ -15,6 +15,10 @@ Removes duplicate primitive values from an array. **Example** ```js -uniq(['a', 'a', 'b', true, '2', 2, false, true]); -// -> ['a', 'b', true, '2', 2, false] +const obj = {foo: 'bar'}; +const arr = ['foo', 'bar']; +const values = ['a', 'a', 'b', '2', 2, obj, obj, arr, arr, true, true, false, false, NaN, NaN]; + +uniq(values); +// -> ['a', 'b', '2', 2, obj, arr, true, false, NaN] ``` diff --git a/packages/arrays/uniq/test.js b/packages/arrays/uniq/test.js index 7d141431..7320fdb3 100644 --- a/packages/arrays/uniq/test.js +++ b/packages/arrays/uniq/test.js @@ -1,12 +1,12 @@ const uniq = require('./uniq'); describe('Array/uniq', function () { - const arr = ['a', 'a', 'b', true, '2', 2, false, true]; + it('removes duplicate values from an array', function () { + const obj = {foo: 'bar'}; + const arr = ['foo', 'bar']; + const values = ['a', 'a', 'b', '2', 2, obj, obj, arr, arr, true, true, false, false, NaN, NaN]; - it('removes duplicate primitive values from an array', function () { - const result = uniq(arr); - - expect(result).toEqual(['a', 'b', true, '2', 2, false]); + expect(uniq(values)).toEqual(['a', 'b', '2', 2, obj, arr, true, false, NaN]); expect(function () { return uniq({}); diff --git a/packages/arrays/uniq/uniq.js b/packages/arrays/uniq/uniq.js index 0b686d55..8545dcb0 100755 --- a/packages/arrays/uniq/uniq.js +++ b/packages/arrays/uniq/uniq.js @@ -1,39 +1,27 @@ 'use strict'; /** - * Removes duplicate primitive values from an array. + * Creates a duplicate-free version of an array, using [SameValueZero](https://262.ecma-international.org/7.0/#sec-samevaluezero) for equality comparisons, + * in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array. * * @param {Array} array The array to process. * @throws {TypeError} If `array` is not array. * @returns {Array} Returns the result (duplicates-free) array. * @example * - * uniq(['a', 'a', 'b', true, '2', 2, false, true]); - * // -> ['a', 'b', true, '2', 2, false] + * const obj = {foo: 'bar'}; + * const arr = ['foo', 'bar']; + * const values = ['a', 'a', 'b', '2', 2, obj, obj, arr, arr, true, true, false, false, NaN, NaN]; + * + * uniq(values); + * // -> ['a', 'b', '2', 2, obj, arr, true, false, NaN] */ const uniq = array => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - const duplicates = []; - - for (let i = 0; i < array.length; i += 1) { - let found = false; - - for (let j = 0; j < duplicates.length; j += 1) { - if (array[i] === duplicates[j]) { - found = true; - break; - } - } - - if (!found) { - duplicates.push(array[i]); - } - } - - return duplicates; + return Array.from(new Set(array)); }; module.exports = uniq; diff --git a/packages/arrays/zip/README.md b/packages/arrays/zip/README.md index cfdbddf3..878a9b3b 100644 --- a/packages/arrays/zip/README.md +++ b/packages/arrays/zip/README.md @@ -9,8 +9,6 @@ the second of which contains the second elements of the given arrays, and so on. - TypeError If any of the arguments is not array. -**Note**: To support legacy browsers, use `Array.prototype.map` and `Array.prototype.reduce` polyfills. - | Param | Type | Description | | --- | --- | --- | | ...arrays | Array | The arrays to process. | diff --git a/packages/arrays/zip/zip.js b/packages/arrays/zip/zip.js index 875e78c1..cf0f49d8 100644 --- a/packages/arrays/zip/zip.js +++ b/packages/arrays/zip/zip.js @@ -4,7 +4,6 @@ * Creates an array of grouped elements, the first of which contains the first elements of the given arrays, * the second of which contains the second elements of the given arrays, and so on. * - * @NOTE To support legacy browsers, use `Array.prototype.map` and `Array.prototype.reduce` polyfills. * @param {...Array} arrays The arrays to process. * @throws {TypeError} If any of the arguments is not array. * @return {Array} Returns the new array of grouped elements. diff --git a/packages/objects/schemaValidate/README.md b/packages/objects/schemaValidate/README.md index c8147360..bae37ae7 100644 --- a/packages/objects/schemaValidate/README.md +++ b/packages/objects/schemaValidate/README.md @@ -8,8 +8,6 @@ Validates a plain object against a provided schema object. - TypeError If any of the schema validators are not function. -**Note**: To support legacy browsers, use `Array.prototype.map`, `Array.prototype.reduce` and `Object.keys()` polyfills. - | Param | Type | Description | | --- | --- | --- | | object | Object | The object to validate. | diff --git a/packages/objects/schemaValidate/schemaValidate.js b/packages/objects/schemaValidate/schemaValidate.js index a4b6c04d..c7eabebe 100644 --- a/packages/objects/schemaValidate/schemaValidate.js +++ b/packages/objects/schemaValidate/schemaValidate.js @@ -3,7 +3,6 @@ /** * Validates a plain object against a provided schema object. * - * @NOTE To support legacy browsers, use `Array.prototype.map`, `Array.prototype.reduce` and `Object.keys()` polyfills. * @param {Object} object The object to validate. * @param {Object.} [schema] A plain object with validator functions. If `undefined` validation always passes. * @throws {TypeError} If any of the schema validators are not function. @@ -87,4 +86,4 @@ function schemaValidate(object, schema) { }; } -module.exports = schemaValidate; \ No newline at end of file +module.exports = schemaValidate; From 0b598479cbcdc289fda63e2c46acee0f7e3e3e2c Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 11:36:09 +0300 Subject: [PATCH 05/17] Remove utils where native solutions exist --- README.md | 19 --- packages/arrays/fill/README.md | 37 ------ packages/arrays/fill/fill.js | 71 ----------- packages/arrays/fill/test.js | 44 ------- packages/arrays/find/README.md | 52 --------- packages/arrays/find/find.js | 73 ------------ packages/arrays/find/test.js | 66 ----------- packages/arrays/findIndex/README.md | 54 --------- packages/arrays/findIndex/findIndex.js | 73 ------------ packages/arrays/findIndex/test.js | 36 ------ packages/arrays/findLastIndex/README.md | 53 --------- .../arrays/findLastIndex/findLastIndex.js | 71 ----------- packages/arrays/findLastIndex/test.js | 37 ------ packages/arrays/flat/README.md | 35 ------ packages/arrays/flat/flat.js | 59 ---------- packages/arrays/flat/test.js | 48 -------- packages/arrays/fromPairs/README.md | 20 ---- packages/arrays/fromPairs/fromPairs.js | 31 ----- packages/arrays/fromPairs/test.js | 25 ---- packages/arrays/includes/README.md | 47 -------- packages/arrays/includes/includes.js | 87 -------------- packages/arrays/includes/test.js | 46 -------- packages/arrays/reverse/README.md | 21 ---- packages/arrays/reverse/reverse.js | 23 ---- packages/arrays/reverse/test.js | 16 --- packages/dom/preloadImages/README.md | 4 +- packages/dom/preloadImages/preloadImages.js | 4 +- packages/strings/contains/README.md | 34 ------ packages/strings/contains/contains.js | 55 --------- packages/strings/contains/test.js | 40 ------- packages/strings/endsWith/README.md | 30 ----- packages/strings/endsWith/endsWith.js | 56 --------- packages/strings/endsWith/test.js | 30 ----- packages/strings/pad/README.md | 32 ----- packages/strings/pad/pad.js | 54 --------- packages/strings/pad/test.js | 21 ---- packages/strings/padLeft/README.md | 26 ----- packages/strings/padLeft/padLeft.js | 44 ------- packages/strings/padLeft/test.js | 21 ---- packages/strings/padRight/README.md | 26 ----- packages/strings/padRight/padRight.js | 44 ------- packages/strings/padRight/test.js | 21 ---- packages/strings/repeat/README.md | 27 ----- packages/strings/repeat/repeat.js | 64 ---------- packages/strings/repeat/test.js | 43 ------- packages/strings/startsWith/README.md | 39 ------- packages/strings/startsWith/startsWith.js | 52 --------- packages/strings/startsWith/test.js | 34 ------ packages/strings/trim/README.md | 22 ---- packages/strings/trim/test.js | 36 ------ packages/strings/trim/trim.js | 26 ----- packages/strings/trimLeft/README.md | 20 ---- packages/strings/trimLeft/test.js | 38 ------ packages/strings/trimLeft/trimLeft.js | 24 ---- packages/strings/trimRight/README.md | 20 ---- packages/strings/trimRight/test.js | 38 ------ packages/strings/trimRight/trimRight.js | 24 ---- packages/strings/urlSearchParams/README.md | 82 ------------- packages/strings/urlSearchParams/test.js | 27 ----- .../urlSearchParams/urlSearchParams.js | 110 ------------------ 60 files changed, 4 insertions(+), 2408 deletions(-) delete mode 100644 packages/arrays/fill/README.md delete mode 100644 packages/arrays/fill/fill.js delete mode 100644 packages/arrays/fill/test.js delete mode 100644 packages/arrays/find/README.md delete mode 100644 packages/arrays/find/find.js delete mode 100644 packages/arrays/find/test.js delete mode 100644 packages/arrays/findIndex/README.md delete mode 100644 packages/arrays/findIndex/findIndex.js delete mode 100644 packages/arrays/findIndex/test.js delete mode 100644 packages/arrays/findLastIndex/README.md delete mode 100644 packages/arrays/findLastIndex/findLastIndex.js delete mode 100644 packages/arrays/findLastIndex/test.js delete mode 100644 packages/arrays/flat/README.md delete mode 100644 packages/arrays/flat/flat.js delete mode 100644 packages/arrays/flat/test.js delete mode 100644 packages/arrays/fromPairs/README.md delete mode 100644 packages/arrays/fromPairs/fromPairs.js delete mode 100644 packages/arrays/fromPairs/test.js delete mode 100644 packages/arrays/includes/README.md delete mode 100644 packages/arrays/includes/includes.js delete mode 100644 packages/arrays/includes/test.js delete mode 100644 packages/arrays/reverse/README.md delete mode 100644 packages/arrays/reverse/reverse.js delete mode 100644 packages/arrays/reverse/test.js delete mode 100755 packages/strings/contains/README.md delete mode 100755 packages/strings/contains/contains.js delete mode 100644 packages/strings/contains/test.js delete mode 100755 packages/strings/endsWith/README.md delete mode 100755 packages/strings/endsWith/endsWith.js delete mode 100644 packages/strings/endsWith/test.js delete mode 100644 packages/strings/pad/README.md delete mode 100644 packages/strings/pad/pad.js delete mode 100644 packages/strings/pad/test.js delete mode 100644 packages/strings/padLeft/README.md delete mode 100644 packages/strings/padLeft/padLeft.js delete mode 100644 packages/strings/padLeft/test.js delete mode 100644 packages/strings/padRight/README.md delete mode 100644 packages/strings/padRight/padRight.js delete mode 100644 packages/strings/padRight/test.js delete mode 100644 packages/strings/repeat/README.md delete mode 100644 packages/strings/repeat/repeat.js delete mode 100644 packages/strings/repeat/test.js delete mode 100755 packages/strings/startsWith/README.md delete mode 100755 packages/strings/startsWith/startsWith.js delete mode 100644 packages/strings/startsWith/test.js delete mode 100755 packages/strings/trim/README.md delete mode 100644 packages/strings/trim/test.js delete mode 100755 packages/strings/trim/trim.js delete mode 100644 packages/strings/trimLeft/README.md delete mode 100644 packages/strings/trimLeft/test.js delete mode 100644 packages/strings/trimLeft/trimLeft.js delete mode 100644 packages/strings/trimRight/README.md delete mode 100644 packages/strings/trimRight/test.js delete mode 100644 packages/strings/trimRight/trimRight.js delete mode 100644 packages/strings/urlSearchParams/README.md delete mode 100644 packages/strings/urlSearchParams/test.js delete mode 100644 packages/strings/urlSearchParams/urlSearchParams.js diff --git a/README.md b/README.md index 58ceaa84..2f08d32b 100755 --- a/README.md +++ b/README.md @@ -17,14 +17,7 @@ A collection of dependency-free JavaScript utility functions. |[dropRight](https://github.com/georapbox/js-utils/tree/master/packages/arrays/dropRight)|Creates a slice of `array` with `n` elements dropped from the end.| |[dropRightWhile](https://github.com/georapbox/js-utils/tree/master/packages/arrays/dropRightWhile)|Creates a slice of `array` excluding elements dropped from the end, until `predicate` returns falsy.| |[dropWhile](https://github.com/georapbox/js-utils/tree/master/packages/arrays/dropWhile)|Creates a slice of `array` excluding elements dropped from the beginning, until `predicate` returns falsy.| -|[fill](https://github.com/georapbox/js-utils/tree/master/packages/arrays/fill)|Fills elements of array with value from start up to end (not including end).| -|[find](https://github.com/georapbox/js-utils/tree/master/packages/arrays/find)|Returns a value in the array, if an element in the array satisfies the provided testing function.| -|[findIndex](https://github.com/georapbox/js-utils/tree/master/packages/arrays/findIndex)|Returns the index of the first element of a collection that passes the callback check.| -|[findLastIndex](https://github.com/georapbox/js-utils/tree/master/packages/arrays/findLastIndex)|Returns the index of the first element of a collection that passes the callback check, iterating from right to left.| -|[flat](https://github.com/georapbox/js-utils/tree/master/packages/arrays/flat)|Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.| -|[fromPairs](https://github.com/georapbox/js-utils/tree/master/packages/arrays/fromPairs)|Creates an object composed from key-value pairs.| |[groupBy](https://github.com/georapbox/js-utils/tree/master/packages/arrays/groupBy)|Creates an object composed of keys generated from the results of running each element of `array` through `iteratee`.| -|[includes](https://github.com/georapbox/js-utils/tree/master/packages/arrays/includes)|Determines whether an array includes a certain element.| |[intersect](https://github.com/georapbox/js-utils/tree/master/packages/arrays/intersect)|Creates an array of unique values that are included in all given arrays.| |[insert](https://github.com/georapbox/js-utils/tree/master/packages/arrays/insert)|Inserts one or more elements to array at specific index.| |[move](https://github.com/georapbox/js-utils/tree/master/packages/arrays/move)|Move an array element to a different position.| @@ -32,7 +25,6 @@ A collection of dependency-free JavaScript utility functions. |[pluck](https://github.com/georapbox/js-utils/tree/master/packages/arrays/pluck)|Retrieves the value of a specified property from all elements in an array.| |[remove](https://github.com/georapbox/js-utils/tree/master/packages/arrays/remove)|Removes one or more elements from an array at the specified index(es).| |[shuffle](https://github.com/georapbox/js-utils/tree/master/packages/arrays/shuffle)|Returns a new array with its elements' order randomized, using the Fisher-Yates (aka Knuth) Shuffle algorithm.| -|[reverse](https://github.com/georapbox/js-utils/tree/master/packages/arrays/reverse)|Reverses an array (not in place). The first array element becomes the last and the last becomes the first.| |[tail](https://github.com/georapbox/js-utils/tree/master/packages/arrays/tail)|Gets all but the first element of array.| |[take](https://github.com/georapbox/js-utils/tree/master/packages/arrays/take)|Creates a slice of array with `n` items taken from the beginning.| |[takeRight](https://github.com/georapbox/js-utils/tree/master/packages/arrays/takeRight)|Creates a slice of array with `n` items taken from the end.| @@ -53,36 +45,25 @@ A collection of dependency-free JavaScript utility functions. |[capitalize](https://github.com/georapbox/js-utils/tree/master/packages/strings/capitalize)|Capitalizes the first character of a string (Optionally, converts the rest of the string to lower case).| |[classnames](https://github.com/georapbox/js-utils/tree/master/packages/strings/classnames)|Creates a string by conditionally joining classNames together.| |[collapseWhitespace](https://github.com/georapbox/js-utils/tree/master/packages/strings/collapseWhitespace)|Converts all adjacent whitespace characters to a single space.| -|[contains](https://github.com/georapbox/js-utils/tree/master/packages/strings/contains)|Determines whether one string may be found within another string, returning true or false as appropriate.| |[deburr](https://github.com/georapbox/js-utils/tree/master/packages/strings/deburr)|Deburrs a string by converting latin-1 supplementary letters to basic latin letters and removing combining diacritical marks.| -|[endsWith](https://github.com/georapbox/js-utils/tree/master/packages/strings/endsWith)|Determines whether a string ends with the characters of another string, returning true or false as appropriate.| |[escapeHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/escapeHTML)|Escapes a HTML string.| |[kebabCase](https://github.com/georapbox/js-utils/tree/master/packages/strings/kebabCase)|Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles), eg `'the-quick-brown-fox-jumps-over-the-lazy-dog'`.| |[lines](https://github.com/georapbox/js-utils/tree/master/packages/strings/lines)|Returns an array with the lines of a a string.| |[numberFormat](https://github.com/georapbox/js-utils/tree/master/packages/strings/numberFormat)|Formats a number based on the number of decimal points, the decimal separator and the thousands separator.| -|[pad](https://github.com/georapbox/js-utils/tree/master/packages/strings/pad)|Pad `subjectString` on **both** sides to the given `len`, with optional `chars` defaulting to a space.| -|[padLeft](https://github.com/georapbox/js-utils/tree/master/packages/strings/padLeft)|Pad `subjectString` on **left** side to the given `len`, with optional `chars` defaulting to a space.| -|[padRight](https://github.com/georapbox/js-utils/tree/master/packages/strings/padRight)|Pad `subjectString` on **right** side to the given `len`, with optional `chars` defaulting to a space.| |[pascalCase](https://github.com/georapbox/js-utils/tree/master/packages/strings/pascalCase)|Converts a string to [pascal case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles), eg `'TheQuickBrownFoxJumpsOverTheLazyDog'`.| |[randomString](https://github.com/georapbox/js-utils/tree/master/packages/strings/randomString)|Generates a pseudo-random string of specific `length` allowing a set of characters specified by `chars`.| |[removePrefix](https://github.com/georapbox/js-utils/tree/master/packages/strings/removePrefix)|Removes substring (prefix) from start of a string.| |[removeSuffix](https://github.com/georapbox/js-utils/tree/master/packages/strings/removeSuffix)|Removes substring (suffix) from end of a string.| -|[repeat](https://github.com/georapbox/js-utils/tree/master/packages/strings/repeat)|Constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.| |[snakeCase](https://github.com/georapbox/js-utils/tree/master/packages/strings/snakeCase)|Converts a string to [snake case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles), eg `'the_quick_brown_fox_jumps_over_the_lazy_dog'`.| |[squash](https://github.com/georapbox/js-utils/tree/master/packages/strings/squash)|Removes all spaces from a string; optionally removes any escape sequences such as `\t`, `\n`, `\f`, `\r` and `\v`.| -|[startsWith](https://github.com/georapbox/js-utils/tree/master/packages/strings/startsWith)|Returns true if string begins with substring (prefix).| |[strip](https://github.com/georapbox/js-utils/tree/master/packages/strings/strip)|Returns a new string with all occurrences of arguments passed removed.| |[stripHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/stripHTML)|Returns a new string with all HTML tags removed.| |[stripPunctuation](https://github.com/georapbox/js-utils/tree/master/packages/strings/stripPunctuation)|Returns a new string with all of punctuation removed.| |[substringAfter](https://github.com/georapbox/js-utils/tree/master/packages/strings/substringAfter)|Returns a substring after a specific sequence of character(s).| |[substringBefore](https://github.com/georapbox/js-utils/tree/master/packages/strings/substringBefore)|Returns a substring before a specific sequence of character(s).| |[supplant](https://github.com/georapbox/js-utils/tree/master/packages/strings/supplant)|supplant() does variable substitution on a string. It scans through the string looking for expressions enclosed in {{ }} braces. If an expression is found, use it as a key on the object, and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.| -|[trim](https://github.com/georapbox/js-utils/tree/master/packages/strings/trim)|Removes whitespace from both ends of a string.| -|[trimLeft](https://github.com/georapbox/js-utils/tree/master/packages/strings/trimLeft)|Removes whitespace from the left end of a string.| -|[trimRight](https://github.com/georapbox/js-utils/tree/master/packages/strings/trimRight)|Removes whitespace from the right end of a string.| |[truncate](https://github.com/georapbox/js-utils/tree/master/packages/strings/truncate)|Truncates a string based on character count.| |[unescapeHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/unescapeHTML)|Unescapes a HTML string.| -|[urlSearchParams](https://github.com/georapbox/js-utils/tree/master/packages/strings/urlSearchParams)|Factory to access the URL search parameters.| |[words](https://github.com/georapbox/js-utils/tree/master/packages/strings/words)|Splits string into an array of its words.| |[wrapHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/wrapHTML)|Wraps a string with a HTML tag with attributes if specified.| diff --git a/packages/arrays/fill/README.md b/packages/arrays/fill/README.md deleted file mode 100644 index 9aaf3229..00000000 --- a/packages/arrays/fill/README.md +++ /dev/null @@ -1,37 +0,0 @@ - - -## fill(array, value, [start], [end]) ⇒ Array -Fills elements of array with value from start up to end (not including end). - -**Returns**: Array - The new array. -**Throws**: - -- TypeError If `array` is not an array. - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| array | Array | | The array to fill. | -| value | \* | | The value to fill array with. | -| [start] | Number | 0 | The start position. | -| [end] | Number | array.length | The end position. | - -**Example** -```js -fill(['a', 'b', 'c'], '*'); -// -> ['*', '*', '*'] - -fill(['a', 'b', 'c'], '*', 0, 2); -// -> ['*', '*', 'c'] - -fill(['a', 'b', 'c'], '*', -1, 3); -// -> ['a', 'b', '*'] - -fill(['a', 'b', 'c'], '*', -1, 2); -// -> ['a', 'b', 'c'] - -fill(['a', 'b', 'c'], '*', 0, -2); -// -> ['*', 'b', 'c'] - -fill(['a', 'b', 'c']); -// -> [undefined, undefined, undefined] -``` diff --git a/packages/arrays/fill/fill.js b/packages/arrays/fill/fill.js deleted file mode 100644 index d2ea1903..00000000 --- a/packages/arrays/fill/fill.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -/** - * Fills elements of array with value from start up to end (not including end). - * - * @param {Array} array The array to fill. - * @param {*} value The value to fill array with. - * @param {Number} [start=0] The start position. - * @param {Number} [end=array.length] The end position. - * @throws {TypeError} If `array` is not an array. - * @returns {Array} The new array. - * @example - * - * fill(['a', 'b', 'c'], '*'); - * // -> ['*', '*', '*'] - * - * fill(['a', 'b', 'c'], '*', 0, 2); - * // -> ['*', '*', 'c'] - * - * fill(['a', 'b', 'c'], '*', -1, 3); - * // -> ['a', 'b', '*'] - * - * fill(['a', 'b', 'c'], '*', -1, 2); - * // -> ['a', 'b', 'c'] - * - * fill(['a', 'b', 'c'], '*', 0, -2); - * // -> ['*', 'b', 'c'] - * - * fill(['a', 'b', 'c']); - * // -> [undefined, undefined, undefined] - */ -const fill = (array, value, start = 0, end = array.length) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - if (Array.prototype.fill) { - return array.fill(value, start, end); - } - - const resultArray = array.slice(0); - const len = resultArray.length; - - if (len === 0) { - return []; - } - - start = parseInt(start, 10) || 0; - - if (start < 0) { - start = -start > len ? 0 : len + start; - } - - end = end > len ? len : parseInt(end, 10); - - if (end < 0) { - end += len; - } - - if (start > end) { - end = 0; - } - - while (start < end) { - resultArray[start++] = value; - } - - return resultArray; -}; - -module.exports = fill; diff --git a/packages/arrays/fill/test.js b/packages/arrays/fill/test.js deleted file mode 100644 index 2e9d3aff..00000000 --- a/packages/arrays/fill/test.js +++ /dev/null @@ -1,44 +0,0 @@ -const fill = require('./fill'); - -describe('Array/fill', function () { - function runTests() { - expect(fill(['a', 'b', 'c'], '*')).toEqual(['*', '*', '*']); - - expect(fill(['a', 'b', 'c'], '*', 0, 2)).toEqual(['*', '*', 'c']); - - expect(fill(['a', 'b', 'c'], '*', -1, 3)).toEqual(['a', 'b', '*']); - - expect(fill(['a', 'b', 'c'], '*', -1, 2)).toEqual(['a', 'b', 'c']); - - expect(fill(['a', 'b', 'c'], '*', 0, -2)).toEqual(['*', 'b', 'c']); - - expect(fill(['a', 'b', 'c'])).toEqual([undefined, undefined, undefined]); - - expect(fill([])).toEqual([]); - - expect(fill([1, 2, 3, 4, 5], '*', 3, 2)).toEqual([1, 2, 3, 4, 5]); - - expect(fill([1, 2, 3], 4, NaN, NaN)).toEqual([1, 2, 3]); - - expect(fill([1, 2, 3], 4, NaN, 2)).toEqual([4, 4, 3]); - - expect(fill([1, 2, 3], 4, 0, NaN)).toEqual([1, 2, 3]); - - expect(function () { - return fill({ - foo: 'bar' - }, '*'); - }).toThrow(new TypeError('Expected an array for first argument')); - } - - it('fills elements of array with value from start up to end (not including end) (Array.prototype.fill is supported)', function () { - runTests(); - }); - - it('fills elements of array with value from start up to end (not including end) (Array.prototype.fill is not supported)', function () { - const nativeCode = Array.prototype.fill; - Array.prototype.fill = null; - runTests(); - Array.prototype.fill = nativeCode; - }); -}); diff --git a/packages/arrays/find/README.md b/packages/arrays/find/README.md deleted file mode 100644 index ebeba36f..00000000 --- a/packages/arrays/find/README.md +++ /dev/null @@ -1,52 +0,0 @@ - - -## find(array, predicate, [thisArg]) ⇒ \* -Returns a value in the array, if an element in the array satisfies the provided testing function. -Executes the callback function once for each element present in the array until it finds one -where `predicate` returns a true value. If such an element is found, `find` immediately returns -the value of that element, otherwise, `find` returns `undefined`. -`predicate` is invoked only for indexes of the array which have assigned values; -it is not invoked for indexes which have been deleted or which have never been assigned values. - -**Returns**: \* - A value in the array if an element passes the test, else, `undefined`. -**Throws**: - -- TypeError If `array` is not an array. -- TypeError If `predicate` is not a function. - - -| Param | Type | Description | -| --- | --- | --- | -| array | Array | The array to process. | -| predicate | function | Function to execute on each value in the array, taking three arguments: - `{*}` element: The current element being processed in the array. - `{Number}` index: The index of the current element being processed in the array. - `{Array}` array: The array find was called upon. | -| [thisArg] | * | Optional object to use as `this` when executing the predicate function. | - -**Example** -```js -const fruits = [ - {name: 'apples', quantity: 2}, - {name: 'bananas', quantity: 0}, - {name: 'cherries', quantity: 5}, - {name: 'melons', quantity: 0} -]; - -find(fruits, function (element, index, array) { - return element.name === 'cherries'; -}); -// -> {name: 'cherries', quantity: 5} - -find(fruits, function (element, index, array) { - return element.quantity === 0; -}); -// -> {name: 'bananas', quantity: 0} - -find([1, 2, 3, 4, 5], function (element) { - return element === 3; -}); -// -> 3 - -find([1, 2, 3, 4, 5], function (element) { - return element === 10; -}); -// -> undefined -``` diff --git a/packages/arrays/find/find.js b/packages/arrays/find/find.js deleted file mode 100644 index 72e5b4b7..00000000 --- a/packages/arrays/find/find.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -/** - * Returns a value in the array, if an element in the array satisfies the provided testing function. - * Executes the callback function once for each element present in the array until it finds one - * where `predicate` returns a true value. If such an element is found, `find` immediately returns - * the value of that element, otherwise, `find` returns `undefined`. - * `predicate` is invoked only for indexes of the array which have assigned values; - * it is not invoked for indexes which have been deleted or which have never been assigned values. - * - * @param {Array} array The array to process. - * @param {function} predicate Function to execute on each value in the array, taking three arguments: - * - `{*}` element: The current element being processed in the array. - * - `{Number}` index: The index of the current element being processed in the array. - * - `{Array}` array: The array find was called upon. - * @param {*} [thisArg] Optional object to use as `this` when executing the predicate function. - * @throws {TypeError} If `array` is not an array. - * @throws {TypeError} If `predicate` is not a function. - * @returns {*} A value in the array if an element passes the test, else, `undefined`. - * @example - * - * const fruits = [ - * {name: 'apples', quantity: 2}, - * {name: 'bananas', quantity: 0}, - * {name: 'cherries', quantity: 5}, - * {name: 'melons', quantity: 0} - * ]; - * - * find(fruits, function (element, index, array) { - * return element.name === 'cherries'; - * }); - * // -> {name: 'cherries', quantity: 5} - * - * find(fruits, function (element, index, array) { - * return element.quantity === 0; - * }); - * // -> {name: 'bananas', quantity: 0} - * - * find([1, 2, 3, 4, 5], function (element) { - * return element === 3; - * }); - * // -> 3 - * - * find([1, 2, 3, 4, 5], function (element) { - * return element === 10; - * }); - * // -> undefined - */ -const find = (array, predicate, thisArg) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an an array for first argument'); - } - - if (typeof predicate !== 'function') { - throw new TypeError('Expected a function for second argument'); - } - - if (Array.prototype.find) { - return array.find(predicate, thisArg); - } - - for (let index = 0; index < array.length; index += 1) { - const element = array[index]; - - if (predicate.call(thisArg, element, index, array)) { - return element; - } - } - - return; -}; - -module.exports = find; diff --git a/packages/arrays/find/test.js b/packages/arrays/find/test.js deleted file mode 100644 index 22aa9fe2..00000000 --- a/packages/arrays/find/test.js +++ /dev/null @@ -1,66 +0,0 @@ -const find = require('./find'); - -describe('Array/find', function () { - function runTests() { - const fruits = [ - { name: 'apples', quantity: 2 }, - { name: 'bananas', quantity: 0 }, - { name: 'cherries', quantity: 5 }, - { name: 'melons', quantity: 0 } - ]; - - const cherries = find(fruits, function (element) { - return element.name === 'cherries'; - }); - - const bananas = find(fruits, function (element) { - return element.quantity === 0; - }); - - const three = find([1, 2, 3, 4, 5], function (element) { - return element === 3; - }); - - const undef = find([1, 2, 3, 4, 5], function (element) { - return element === 10; - }); - - expect(cherries).toEqual({ - name: 'cherries', - quantity: 5 - }); - - expect(bananas).toEqual({ - name: 'bananas', - quantity: 0 - }); - - expect(three).toEqual(3); - - expect(undef).toEqual(undefined); - - expect(function () { - return find({ - name: 'cherries', - quantity: 5 - }, function (element) { - return element.name === 'cherries'; - }); - }).toThrow(new TypeError('Expected an an array for first argument')); - - expect(function () { - return find(fruits); - }).toThrow(new TypeError('Expected a function for second argument')); - } - - it('returns a value in the array, if an element in the array satisfies the provided testing function (Array.prototype.find is supported)', function () { - runTests(); - }); - - it('returns a value in the array, if an element in the array satisfies the provided testing function (Array.prototype.find is not supported)', function () { - const nativeCode = Array.prototype.find; - Array.prototype.find = null; - runTests(); - Array.prototype.find = nativeCode; - }); -}); diff --git a/packages/arrays/findIndex/README.md b/packages/arrays/findIndex/README.md deleted file mode 100644 index 8edad883..00000000 --- a/packages/arrays/findIndex/README.md +++ /dev/null @@ -1,54 +0,0 @@ - - -## findIndex(array, callback, [thisArg]) ⇒ Number -Returns the index of the first element that passes the callback check. -If no element passes the callback check, returns -1. - -**Returns**: Number - Returns the index of the first element that matches the callback check. -**Throws**: - -- TypeError If `array` is not array. -- TypeError If `callback` is not function. - - -| Param | Type | Description | -| --- | --- | --- | -| array | Array | The array to check. | -| callback | function | The function called per iteration. | -| [thisArg] | * | Optional object to use as `this` when executing the callback function. | - -**Example** -```js -const heroes = [ - {name: 'Bruce Wayne', hero: 'Batman'}, - {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, - {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} -]; - -const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; -const numbers = [1, 2, 3]; - -findIndex(characters, function (chr, index, array) { - return chr === 'E'; -}); -// -> 4 - -findIndex(heroes, function (hero, index, array) { - return hero.name === 'Clark Kent'; -}); -// -> 1 - -findIndex(heroes, function (hero, index, array) { - if (hero.specialPowers) { - for (let i = 0; i < hero.specialPowers.length; i++) { - if (hero.specialPowers[i] === 'climbing') return true; - } - } -}); -// -> 2 - -findIndex(numbers, function (n) { - return n > 10; -}); -// -> -1 -``` diff --git a/packages/arrays/findIndex/findIndex.js b/packages/arrays/findIndex/findIndex.js deleted file mode 100644 index bf1290fd..00000000 --- a/packages/arrays/findIndex/findIndex.js +++ /dev/null @@ -1,73 +0,0 @@ - -'use strict'; - -/** - * Returns the index of the first element that passes the callback check. - * If no element passes the callback check, returns -1. - * - * @param {Array} array The array to check. - * @param {function} callback The function called per iteration. - * @param {*} [thisArg] Optional object to use as `this` when executing the callback function. - * @throws {TypeError} If `array` is not array. - * @throws {TypeError} If `callback` is not function. - * @returns {Number} Returns the index of the first element that matches the callback check. - * @example - * - * const heroes = [ - * {name: 'Bruce Wayne', hero: 'Batman'}, - * {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, - * {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} - * ]; - * - * const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G']; - * const numbers = [1, 2, 3]; - * - * findIndex(characters, function (chr, index, array) { - * return chr === 'E'; - * }); - * // -> 4 - * - * findIndex(heroes, function (hero, index, array) { - * return hero.name === 'Clark Kent'; - * }); - * // -> 1 - * - * findIndex(heroes, function (hero, index, array) { - * if (hero.specialPowers) { - * for (let i = 0; i < hero.specialPowers.length; i++) { - * if (hero.specialPowers[i] === 'climbing') return true; - * } - * } - * }); - * // -> 2 - * - * findIndex(numbers, function (n) { - * return n > 10; - * }); - * // -> -1 - */ -const findIndex = (array, callback, thisArg) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - if (typeof callback !== 'function') { - throw new TypeError('Expected a function for second argument'); - } - - if (Array.prototype.findIndex) { - return array.findIndex(callback, thisArg); - } - - let index = -1; - - while (++index < array.length) { - if (callback.call(thisArg, array[index], index, array)) { - return index; - } - } - - return -1; -}; - -module.exports = findIndex; diff --git a/packages/arrays/findIndex/test.js b/packages/arrays/findIndex/test.js deleted file mode 100644 index 2449d89b..00000000 --- a/packages/arrays/findIndex/test.js +++ /dev/null @@ -1,36 +0,0 @@ -const findIndex = require('./findIndex'); - -describe('Array/findIndex', function () { - function runTests() { - const arr = ['a', 'b', 'c', 'd', 'e']; - - expect(findIndex(arr, function (chr) { - return chr === 'b'; - })).toBe(1); - - expect(findIndex(arr, function (chr) { - return chr === 'Hello'; - })).toBe(-1); - - expect(function () { - return findIndex({}, function (chr) { - return chr === 'b'; - }); - }).toThrow(new TypeError('Expected an array for first argument')); - - expect(function () { - return findIndex(arr); - }).toThrow(new TypeError('Expected a function for second argument')); - } - - it('returns the index in the array ((Array.prototype.findIndex is supported))', function () { - runTests(); - }); - - it('returns the index in the array ((Array.prototype.findIndex is not supported))', function () { - const nativeCode = Array.prototype.findIndex; - Array.prototype.findIndex = null; - runTests(); - Array.prototype.findIndex = nativeCode; - }); -}); diff --git a/packages/arrays/findLastIndex/README.md b/packages/arrays/findLastIndex/README.md deleted file mode 100644 index 3c10797d..00000000 --- a/packages/arrays/findLastIndex/README.md +++ /dev/null @@ -1,53 +0,0 @@ - - -## findLastIndex(array, callback) ⇒ Number -Returns the index of the last element of a collection that passes the callback check. - -**Returns**: Number - Returns the index of the last element that matches the callback check. -**Throws**: - -- TypeError If `array` is not array. -- TypeError If `callback` is not function. - - -| Param | Type | Description | -| --- | --- | --- | -| array | Array | The array to check. | -| callback | function | The function called per iteration. | -| [thisArg] | * | Optional object to use as `this` when executing the callback function. | - -**Example** -```js -const heroes = [ - {name: 'Bruce Wayne', hero: 'Batman'}, - {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, - {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} -]; - -const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; -const numbers = [1, 2, 3]; - -findLastIndex(characters, function (chr, index, array) { - return chr === 'E'; -}); -// -> 7 - -findLastIndex(heroes, function (hero, index, array) { - return hero.name === 'Clark Kent'; -}); -// -> 1 - -findLastIndex(heroes, function (hero, index, array) { - if (hero.specialPowers) { - for (let i = 0; i < hero.specialPowers.length; i++) { - if (hero.specialPowers[i] === 'climbing') return true; - } - } -}); -// -> 2 - -findLastIndex(numbers, function (n) { - return n > 10; -}); -// -> -1 -``` diff --git a/packages/arrays/findLastIndex/findLastIndex.js b/packages/arrays/findLastIndex/findLastIndex.js deleted file mode 100644 index a7998b83..00000000 --- a/packages/arrays/findLastIndex/findLastIndex.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; - -/** - * Returns the index of the last element of a collection that passes the callback check. - * - * @param {Array} array The array to check. - * @param {function} callback The function called per iteration. - * @param {*} [thisArg] Optional object to use as `this` when executing the callback function. - * @throws {TypeError} If `array` is not array. - * @throws {TypeError} If `callback` is not function. - * @returns {Number} Returns the index of the last element that matches the callback check. - * @example - * - * const heroes = [ - * {name: 'Bruce Wayne', hero: 'Batman'}, - * {name: 'Clark Kent', hero: 'Superman', specialPowers: ['speed', 'flying', 'strength']}, - * {name: 'Peter Parker', hero: 'Spiderman', specialPowers: ['climbing']} - * ]; - * - * const characters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; - * const numbers = [1, 2, 3]; - * - * findLastIndex(characters, function (chr, index, array) { - * return chr === 'E'; - * }); - * // -> 7 - * - * findLastIndex(heroes, function (hero, index, array) { - * return hero.name === 'Clark Kent'; - * }); - * // -> 1 - * - * findLastIndex(heroes, function (hero, index, array) { - * if (hero.specialPowers) { - * for (let i = 0; i < hero.specialPowers.length; i++) { - * if (hero.specialPowers[i] === 'climbing') return true; - * } - * } - * }); - * // -> 2 - * - * findLastIndex(numbers, function (n) { - * return n > 10; - * }); - * // -> -1 - */ -const findLastIndex = (array, callback, thisArg) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - if (typeof callback !== 'function') { - throw new TypeError('Expected a function for second argument'); - } - - if (Array.prototype.findLastIndex) { - return array.findLastIndex(callback, thisArg); - } - - let len = array.length; - - while (len--) { - if (callback.call(thisArg, array[len], len, array)) { - return len; - } - } - - return -1; -}; - -module.exports = findLastIndex; diff --git a/packages/arrays/findLastIndex/test.js b/packages/arrays/findLastIndex/test.js deleted file mode 100644 index 1c36cbdb..00000000 --- a/packages/arrays/findLastIndex/test.js +++ /dev/null @@ -1,37 +0,0 @@ -const findLastIndex = require('./findLastIndex'); - -describe('Array/findLastIndex', function () { - function runTests() { - const letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'E']; - const numbers = [1, 2, 3, 4]; - - expect(findLastIndex(letters, function (chr) { - return chr === 'E'; - })).toBe(7); - - expect(findLastIndex(numbers, function (chr) { - return chr > 10; - })).toBe(-1); - - expect(function () { - return findLastIndex({}, function (chr) { - return chr > 10; - }); - }).toThrow(new TypeError('Expected an array for first argument')); - - expect(function () { - return findLastIndex(letters); - }).toThrow(new TypeError('Expected a function for second argument')); - } - - it('returns the last index in the array (Array.prototype.findLastIndex is supported)', function () { - runTests(); - }); - - it('returns the last index in the array (Array.prototype.findLastIndex is not supported', function () { - const nativeCode = Array.prototype.findLastIndex; - Array.prototype.findLastIndex = null; - runTests(); - Array.prototype.findLastIndex = nativeCode; - }) -}); diff --git a/packages/arrays/flat/README.md b/packages/arrays/flat/README.md deleted file mode 100644 index ec25c7c5..00000000 --- a/packages/arrays/flat/README.md +++ /dev/null @@ -1,35 +0,0 @@ - - -## flat(array, [depth]) ⇒ Array -Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. - -**Returns**: Array - Returns a new array with the sub-array elements concatenated into it. -**Throws**: - -- TypeError Throws if `array` is not array. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| array | Array | | The initial array to be flattened. | -| [depth] | Number | 1 | The depth level specifying how deep a nested array structure should be flattened. Defaults to 1. If unsure of how nested the array is, use `Infinity` to deeply flatten the array. If a number less thatn 1 is provided, it will return a shallow copy of the original array. | - -**Example** -```js -const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; - -flat(arr); -// -> [1, 2, 3, 4, [5, 6, [7, 8]]] - -flat(arr, 2); -// -> [1, 2, 3, 4, 5, 6, [7, 8]] - -flat(arr, 3); -// -> [1, 2, 3, 4, 5, 6, 7, 8] - -flat(arr, Infinity); -// -> [1, 2, 3, 4, 5, 6, 7, 8] - -flat(arr, 0); -// -> [1, 2, [3, 4, [5, 6, [7, 8]]]] -``` diff --git a/packages/arrays/flat/flat.js b/packages/arrays/flat/flat.js deleted file mode 100644 index 2775fb2c..00000000 --- a/packages/arrays/flat/flat.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. - * - * @param {Array} array The initial array to be flattened. - * @param {Number} [depth=1] The depth level specifying how deep a nested array structure should be flattened. Defaults to 1. - * If unsure of how nested the array is, use `Infinity` to deeply flatten the array. - * If a number less thatn 1 is provided, it will return a shallow copy of the original array. - * @throws {TypeError} Throws if `array` is not array. - * @returns {Array} Returns a new array with the sub-array elements concatenated into it. - * @example - * - * const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; - * - * flat(arr); - * // -> [1, 2, 3, 4, [5, 6, [7, 8]]] - * - * flat(arr, 2); - * // -> [1, 2, 3, 4, 5, 6, [7, 8]] - * - * flat(arr, 3); - * // -> [1, 2, 3, 4, 5, 6, 7, 8] - * - * flat(arr, Infinity); - * // -> [1, 2, 3, 4, 5, 6, 7, 8] - * - * flat(arr, 0); - * // -> [1, 2, [3, 4, [5, 6, [7, 8]]]] - */ -const flat = (array, depth = 1) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - if (Array.prototype.flat) { - return array.flat(depth); - } - - let result = []; - - depth = Math.floor(depth); - - for (let index = 0; index < array.length; index += 1) { - const element = array[index]; - - if (depth > 0) { - if (Array.isArray(element)) { - result.push(...flat(element, depth - 1)); - } else { - result.push(element); - } - } else { - result = [...array]; - } - } - - return result; -}; - -module.exports = flat; diff --git a/packages/arrays/flat/test.js b/packages/arrays/flat/test.js deleted file mode 100644 index ea6714f3..00000000 --- a/packages/arrays/flat/test.js +++ /dev/null @@ -1,48 +0,0 @@ -const flat = require('./flat'); - -describe('Array/flat', function () { - function runTests() { - const arr = [1, 2, [3, 4, [5, 6, [7, 8]]]]; - - expect(flat(arr)).toEqual([1, 2, 3, 4, [5, 6, [7, 8]]]); - - expect(flat(arr, 1)).toEqual([1, 2, 3, 4, [5, 6, [7, 8]]]); - - expect(flat(arr, 2)).toEqual([1, 2, 3, 4, 5, 6, [7, 8]]); - - expect(flat(arr, '2')).toEqual([1, 2, 3, 4, 5, 6, [7, 8]]); - - expect(flat(arr, 3)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - - expect(flat(arr, '3.6')).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - - expect(flat(arr, Infinity)).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - - expect(flat(arr, -Infinity)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(flat(arr, 0)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(flat(arr, +0)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(flat(arr, -0)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(flat(arr, NaN)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(flat(arr, 0.5)).toEqual([1, 2, [3, 4, [5, 6, [7, 8]]]]); - - expect(function () { - return flat({}); - }).toThrow(new TypeError('Expected an array for first argument')); - } - - it('flattens recursively up to the specified depth (Array.prototype.flat is supported)', function () { - runTests(); - }); - - it('flattens recursively up to the specified depth (Array.prototype.flat is not supported)', function () { - const nativeCode = Array.prototype.flat; - Array.prototype.flat = null; - runTests(); - Array.prototype.flat = nativeCode; - }); -}); diff --git a/packages/arrays/fromPairs/README.md b/packages/arrays/fromPairs/README.md deleted file mode 100644 index 191c8ac6..00000000 --- a/packages/arrays/fromPairs/README.md +++ /dev/null @@ -1,20 +0,0 @@ - - -## fromPairs(array) ⇒ Object -Creates an object composed from key-value pairs. - -**Returns**: Object - Returns the result object. -**Throws**: - -- TypeError If `array` is not array. - - -| Param | Type | Description | -| --- | --- | --- | -| array | Array.<Array> | The key-value pairs array. | - -**Example** -```js -fromPairs([['Javascript', 10], ['PHP', 3], ['Java', 4]]); -// -> { 'Javascript': 10, 'PHP': 3, 'Java': 4 } -``` diff --git a/packages/arrays/fromPairs/fromPairs.js b/packages/arrays/fromPairs/fromPairs.js deleted file mode 100644 index 2c5f71d1..00000000 --- a/packages/arrays/fromPairs/fromPairs.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -/** - * Creates an object composed from key-value pairs. - * - * @param {Array.} array The key-value pairs array. - * @throws {TypeError} If `array` is not array. - * @returns {Object} Returns the result object. - * @example - * - * fromPairs([['Javascript', 10], ['PHP', 3], ['Java', 4]]); - * // -> { 'Javascript': 10, 'PHP': 3, 'Java': 4 } - */ -const fromPairs = array => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - const result = {}; - let index = 0; - - while (index < array.length) { - const pair = array[index]; - result[pair[0]] = pair[1]; - index += 1; - } - - return result; -}; - -module.exports = fromPairs; diff --git a/packages/arrays/fromPairs/test.js b/packages/arrays/fromPairs/test.js deleted file mode 100644 index f9af1d38..00000000 --- a/packages/arrays/fromPairs/test.js +++ /dev/null @@ -1,25 +0,0 @@ -const fromPairs = require('./fromPairs'); - -describe('Array/fromPairs', function () { - it('creates an object composed from key-value pairs', function () { - const pairs = [ - ['Javascript', 10], - ['PHP', 3], - ['Java', 4] - ]; - - expect(fromPairs(pairs)).toEqual({ - 'Javascript': 10, - 'PHP': 3, - 'Java': 4 - }); - - expect(function () { - return fromPairs({ - 'Javascript': 10, - 'PHP': 3, - 'Java': 4 - }); - }).toThrow(new TypeError('Expected an array for first argument')); - }); -}); diff --git a/packages/arrays/includes/README.md b/packages/arrays/includes/README.md deleted file mode 100644 index a23fb8e9..00000000 --- a/packages/arrays/includes/README.md +++ /dev/null @@ -1,47 +0,0 @@ - - -## includes(array, searchElement, [fromIndex]) ⇒ Boolean -Determines whether an array includes a certain element, -returning true or false as appropriate. - -**Returns**: Boolean - True if array includes `searchElement`, else false. -**Throws**: - -- TypeError If `array` is not array. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| array | Array | | The array to search. | -| searchElement | \* | | The element to search for. | -| [fromIndex] | Number | 0 | The position in the array at which to begin searching for `searchElement`. A negative value searches from the index of `array.length + fromIndex` by ascending. | - -**Example** -```js -includes([1, 2, 3], 2); -// -> true - -includes([1, 2, 3], 4); -// -> false - -includes([1, 2, 3], 3, 3); -// -> false - -includes([1, 2, 3], 3, -1); -// -> true - -includes([1, 2, NaN, 3], NaN); -// -> true - -includes([1, 2, null], null); -// -> true - -includes([1, 2, undefined]); -// -> true - -includes([1, 2, 0], 0); -// -> true - -includes([1, 2, 0], -0); -// -> true -``` diff --git a/packages/arrays/includes/includes.js b/packages/arrays/includes/includes.js deleted file mode 100644 index 2546413f..00000000 --- a/packages/arrays/includes/includes.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -/** - * Determines whether an array includes a certain element, - * returning true or false as appropriate. - * - * @param {Array} array The array to search. - * @param {*} searchElement The element to search for. - * @param {Number} [fromIndex=0] The position in the array at which to begin searching for `searchElement`. - * A negative value searches from the index of `array.length + fromIndex` by ascending. - * @throws {TypeError} If `array` is not array. - * @returns {Boolean} True if array includes `searchElement`, else false. - * @example - * - * includes([1, 2, 3], 2); - * // -> true - * - * includes([1, 2, 3], 4); - * // -> false - * - * includes([1, 2, 3], 3, 3); - * // -> false - * - * includes([1, 2, 3], 3, -1); - * // -> true - * - * includes([1, 2, NaN, 3], NaN); - * // -> true - * - * includes([1, 2, null], null); - * // -> true - * - * includes([1, 2, undefined]); - * // -> true - * - * includes([1, 2, 0], 0); - * // -> true - * - * includes([1, 2, 0], -0); - * // -> true - */ -const includes = (array, searchElement, fromIndex = 0) => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - const arrayLength = array.length; - - if (arrayLength === 0) { - return false; - } - - if (Array.prototype.includes) { - return array.includes(searchElement, fromIndex); - } - - fromIndex = parseInt(fromIndex, 10) || 0; - - let currentIndex; - - if (fromIndex >= 0) { - currentIndex = fromIndex; - } else { - currentIndex = arrayLength + fromIndex; - - if (currentIndex < 0) { - currentIndex = 0; - } - } - - while (currentIndex < arrayLength) { - const currentElement = array[currentIndex]; - - if ( - searchElement === currentElement - || (searchElement !== searchElement && currentElement !== currentElement) // Check for NaN values - ) { - return true; - } - - currentIndex += 1; - } - - return false; -}; - -module.exports = includes; diff --git a/packages/arrays/includes/test.js b/packages/arrays/includes/test.js deleted file mode 100644 index be51a810..00000000 --- a/packages/arrays/includes/test.js +++ /dev/null @@ -1,46 +0,0 @@ -const includes = require('./includes'); - -describe('Array/includes', function () { - function runTests() { - const obj = { foo: 'bar' }; - - expect(includes([1, 2, 3], 2)).toBe(true); - - expect(includes([1, 2, 3], 4)).toBe(false); - - expect(includes([1, 2, 3], 3, 3)).toBe(false); - - expect(includes([1, 2, 3], 3, -1)).toBe(true); - - expect(includes([1, 2, NaN, 3], NaN)).toBe(true); - - expect(includes([1, 2, null], null)).toBe(true); - - expect(includes([1, 2, undefined])).toBe(true); - - expect(includes([1, 2, 0], 0)).toBe(true); - - expect(includes([1, 2, 0], -0)).toBe(true); - - expect(includes([1, 2, obj, 0], obj)).toBe(true); - - expect(includes([], 1)).toBe(false); - - expect(includes([1, 2, 3], 3, -5)).toBe(true); - - expect(function () { - return includes({ foo: 'bar' }, 'bar'); - }).toThrow(new TypeError('Expected an array for first argument')); - } - - it('determines whether an array includes a certain element (Array.prototype.includes is supported)', function () { - runTests(); - }); - - it('determines whether an array includes a certain element (Array.prototype.includes is not supported)', function () { - const nativeCode = Array.prototype.includes; - Array.prototype.includes = null; - runTests(); - Array.prototype.includes = nativeCode; - }); -}); diff --git a/packages/arrays/reverse/README.md b/packages/arrays/reverse/README.md deleted file mode 100644 index 2b36b070..00000000 --- a/packages/arrays/reverse/README.md +++ /dev/null @@ -1,21 +0,0 @@ - - -## reverse(array) ⇒ Array -Reverses an array (not in place). -The first array element becomes the last and the last becomes the first. - -**Returns**: Array - Returns a new array reversed. -**Throws**: - -- TypeError If `array` is not array. - - -| Param | Type | Description | -| --- | --- | --- | -| array | Array | The array to reverse. | - -**Example** -```js -reverse([1, 2, 3]); -// -> [3, 2, 1] -``` diff --git a/packages/arrays/reverse/reverse.js b/packages/arrays/reverse/reverse.js deleted file mode 100644 index 50aa4196..00000000 --- a/packages/arrays/reverse/reverse.js +++ /dev/null @@ -1,23 +0,0 @@ -'use strict'; - -/** - * Reverses an array (not in place). - * The first array element becomes the last and the last becomes the first. - * - * @param {Array} array The array to reverse. - * @throws {TypeError} If `array` is not array. - * @return {Array} Returns a new array reversed. - * @example - * - * reverse([1, 2, 3]); - * // -> [3, 2, 1] - */ -const reverse = array => { - if (!Array.isArray(array)) { - throw new TypeError('Expected an array for first argument'); - } - - return [...array].reverse(); -}; - -module.exports = reverse; diff --git a/packages/arrays/reverse/test.js b/packages/arrays/reverse/test.js deleted file mode 100644 index 11df9fa5..00000000 --- a/packages/arrays/reverse/test.js +++ /dev/null @@ -1,16 +0,0 @@ -const reverse = require('./reverse'); - -describe('Array/reverse', function () { - it('returns a new reversed array', function () { - const numbers = [1, 2, 3]; - const revNumbers = reverse(numbers); - - expect(numbers).toEqual([1, 2, 3]); - - expect(revNumbers).toEqual([3, 2, 1]); - - expect(function () { - return reverse({ a: '1', b: '2' }); - }).toThrow(new TypeError('Expected an array for first argument')); - }); -}); diff --git a/packages/dom/preloadImages/README.md b/packages/dom/preloadImages/README.md index cf3934c0..49477e71 100644 --- a/packages/dom/preloadImages/README.md +++ b/packages/dom/preloadImages/README.md @@ -20,12 +20,12 @@ Load images to browser asynchronously so that can be cached. var images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; function success(data) { - console.log(data.currentImage.src + ' -> loaded'); + console.log(data.currentImage.src, 'loaded'); } function fail(data) { console.error(data.error); - console.log(data.currentImage.src + ' -> failed'); + console.log(data.currentImage.src, 'failed'); } function always(data) { diff --git a/packages/dom/preloadImages/preloadImages.js b/packages/dom/preloadImages/preloadImages.js index 80539d60..552f147b 100644 --- a/packages/dom/preloadImages/preloadImages.js +++ b/packages/dom/preloadImages/preloadImages.js @@ -14,12 +14,12 @@ * const images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; * * function success(data) { - * console.log(data.currentImage.src + ' -> loaded'); + * console.log(data.currentImage.src, 'loaded'); * } * * function fail(data) { * console.error(data.error); - * console.log(data.currentImage.src + ' -> failed'); + * console.log(data.currentImage.src, 'failed'); * } * * function always(data) { diff --git a/packages/strings/contains/README.md b/packages/strings/contains/README.md deleted file mode 100755 index 28483a04..00000000 --- a/packages/strings/contains/README.md +++ /dev/null @@ -1,34 +0,0 @@ - - -## contains(subjectString, searchString, [position]) ⇒ Boolean -Determines whether one string may be found within another string, returning true or false as appropriate. - -**Returns**: Boolean - True if searchString is found within subjectString, else false. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| searchString | String | | A string to be searched for within the original string. | -| [position] | Number | 0 | The position in the original string at which to begin searching for searchString; defaults to 0. | - -**Example** -```js -contains(str, 'To be'); -// -> true - -contains(str, 'question'); -// -> true - -contains(str, 'nonexistent'); -// -> false - -contains(str, 'To be', 1); -// -> false - -contains(str, 'TO BE'); -// -> false -``` diff --git a/packages/strings/contains/contains.js b/packages/strings/contains/contains.js deleted file mode 100755 index fe6e0ed4..00000000 --- a/packages/strings/contains/contains.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -/** - * Determines whether one string may be found within another string, returning true or false as appropriate. - * - * @param {String} subjectString The string to process. - * @param {String} searchString A string to be searched for within the original string. - * @param {Number} [position=0] The position in the original string at which to begin searching for searchString; defaults to 0. - * @throws {TypeError} If `subjectString` is not string. - * @return {Boolean} True if searchString is found within subjectString, else false. - * @example - * - * contains(str, 'To be'); - * // -> true - * - * contains(str, 'question'); - * // -> true - * - * contains(str, 'nonexistent'); - * // -> false - * - * contains(str, 'To be', 1); - * // -> false - * - * contains(str, 'TO BE'); - * // -> false - */ -function contains(subjectString, searchString, position) { - var subjectLength, searchLength; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (String.prototype.includes) { - return subjectString.includes(searchString, position); - } - - if (searchString == null) { - return false; - } - - subjectString = subjectString.toString(); - searchString = searchString.toString(); - - position = parseInt(position, 10) || 0; - subjectLength = subjectString.length; - searchLength = searchString.length; - - return position + searchLength <= subjectLength - ? subjectString.indexOf(searchString, position) !== -1 - : false; -} - -module.exports = contains; \ No newline at end of file diff --git a/packages/strings/contains/test.js b/packages/strings/contains/test.js deleted file mode 100644 index 604890f6..00000000 --- a/packages/strings/contains/test.js +++ /dev/null @@ -1,40 +0,0 @@ -var contains = require('./contains'); - -describe('String/contains', function () { - function runTests() { - var str = 'To be, or not to be, that is the question.'; - - expect(contains(str, 'To be')).toBe(true); - - expect(contains(str, 'question')).toBe(true); - - expect(contains(str, 'nonexistent')).toBe(false); - - expect(contains(str, 'To be', 1)).toBe(false); - - expect(contains(str, 'TO BE')).toBe(false); - - expect(contains(str, void 0)).toBe(false); - - expect(contains(str, null)).toBe(false); - - expect(contains('Hello', 'Hello', 1)).toBe(false); - - expect(contains('Hello', 'ello', 1)).toBe(true); - - expect(function () { - return contains(123456, '123'); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('String should contain the specified search string (String.prototype.includes is supported)', function () { - runTests(); - }); - - it('String should contain the specified search string (String.prototype.includes is not supported)', function () { - var nativeCode = String.prototype.includes; - String.prototype.includes = null; - runTests(); - String.prototype.includes = nativeCode; - }); -}); diff --git a/packages/strings/endsWith/README.md b/packages/strings/endsWith/README.md deleted file mode 100755 index c46335ee..00000000 --- a/packages/strings/endsWith/README.md +++ /dev/null @@ -1,30 +0,0 @@ - - -## endsWith(subjectString, searchString, [position]) ⇒ Boolean -Determines whether a string ends with the characters of another string. - -**Returns**: Boolean - True if `subjectString` ends with `searchString`, else false. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| searchString | String | | The characters to be searched for at the end of the original string. | -| [position] | Number | subjectString.length | Search within this string as if this string were only this long; defaults to the original string's actual length, clamped within the range established by this string's length. | - -**Example** -```js -var str = 'To be, or not to be, that is the question.'; - -endsWith(str, 'question.'); -// -> true - -endsWith(str, 'to be'); -// -> false - -endsWith(str, 'to be', 19); -// -> true -``` diff --git a/packages/strings/endsWith/endsWith.js b/packages/strings/endsWith/endsWith.js deleted file mode 100755 index 9fcf1d65..00000000 --- a/packages/strings/endsWith/endsWith.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -/** - * Determines whether a string ends with the characters of another string. - * - * @param {String} subjectString The string to process. - * @param {String} searchString The characters to be searched for at the end of the original string. - * @param {Number} [position=subjectString.length] Search within this string as if this string were only this long; - * defaults to the original string's actual length, clamped within the range established by this string's length. - * @throws {TypeError} If `subjectString` is not string. - * @return {Boolean} True if `subjectString` ends with `searchString`, else false. - * @example - * - * var str = 'To be, or not to be, that is the question.'; - * - * endsWith(str, 'question.'); - * // -> true - * - * endsWith(str, 'to be'); - * // -> false - * - * endsWith(str, 'to be', 19); - * // -> true - */ -function endsWith(subjectString, searchString, position) { - var lastIndex; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (String.prototype.endsWith) { - return subjectString.endsWith(searchString, position); - } - - if (searchString == null) { - return false; - } - - subjectString = subjectString.toString(); - searchString = searchString.toString(); - - if ( - typeof position !== 'number' || !isFinite(position) - || Math.floor(position) !== position || position > subjectString.length - ) { - position = subjectString.length; - } - - position -= searchString.length; - lastIndex = subjectString.indexOf(searchString, position); - - return lastIndex !== -1 && lastIndex === position; -} - -module.exports = endsWith; \ No newline at end of file diff --git a/packages/strings/endsWith/test.js b/packages/strings/endsWith/test.js deleted file mode 100644 index dcd4dcb3..00000000 --- a/packages/strings/endsWith/test.js +++ /dev/null @@ -1,30 +0,0 @@ -var endsWith = require('./endsWith'); - -describe('String/endsWith', function () { - function runTests() { - expect(endsWith('To be, or not to be, that is the question.', 'question.')).toBe(true); - - expect(endsWith('To be, or not to be, that is the question.', 'question')).toBe(false); - - expect(endsWith('To be, or not to be, that is the question.', 'to be', 19)).toBe(true); - - expect(endsWith('Hello world')).toBe(false); - - expect(endsWith('Hello world', null)).toBe(false); - - expect(function () { - return endsWith(123455, '123'); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('String should end with specified search string (using native String.prototype.endsWith)', function () { - runTests(); - }); - - it('String should end with specified search string (using native String.prototype.endsWith)', function () { - var nativeCode = String.prototype.endsWith; - String.prototype.endsWith = null; - runTests(); - String.prototype.endsWith = nativeCode; - }); -}); diff --git a/packages/strings/pad/README.md b/packages/strings/pad/README.md deleted file mode 100644 index de200a18..00000000 --- a/packages/strings/pad/README.md +++ /dev/null @@ -1,32 +0,0 @@ - - -## pad(subjectString, len, [chars]) ⇒ String -Pad `subjectString` on both sides to the given `len`, with optional `chars` defaulting to a space. - -**Returns**: String - The result padded string. -**Throws**: - -- TypeError If `subjectString` is not string. -- TypeError If `len` is not number. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| len | Number | | The length to pad the string. | -| [chars] | String | ' ' | The character(s) to use for padding. | - -**Example** -```js -pad('Hello', 9); -// -> " Hello " - -pad('Hello', 9, '-'); -// -> "--Hello--" - -pad('Hello', 6, '-'); -// -> '-Hello' - -pad('Hello', 5, '-'); -// -> 'Hello' (len is the same as str.length) -``` diff --git a/packages/strings/pad/pad.js b/packages/strings/pad/pad.js deleted file mode 100644 index cd5b4ef9..00000000 --- a/packages/strings/pad/pad.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; - -/** - * Pad `subjectString` on both sides to the given `len`, with optional `chars` defaulting to a space. - * - * @param {String} subjectString The string to process. - * @param {Number} len The length to pad the string. - * @param {String} [chars=' '] The character(s) to use for padding. - * @throws {TypeError} If `subjectString` is not string. - * @throws {TypeError} If `len` is not number. - * @return {String} The result padded string. - * @example - * - * pad('Hello', 9); - * // -> " Hello " - * - * pad('Hello', 9, '-'); - * // -> "--Hello--" - * - * pad('Hello', 6, '-'); - * // -> '-Hello' - * - * pad('Hello', 5, '-'); - * // -> 'Hello' (len is the same as str.length) - */ -function pad(subjectString, len, chars) { - var left, right; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (typeof len !== 'number') { - throw new TypeError('Expected a number for second argument'); - } - - chars = chars || ' '; // Set default character. - - if (subjectString.length >= len) { - return subjectString; - } - - len = len - subjectString.length; - left = []; - right = []; - left.length = Math.ceil(len / 2) + 1; - right.length = Math.floor(len / 2) + 1; - left = left.join(chars); - right = right.join(chars); - - return left + subjectString + right; -} - -module.exports = pad; \ No newline at end of file diff --git a/packages/strings/pad/test.js b/packages/strings/pad/test.js deleted file mode 100644 index e5c76817..00000000 --- a/packages/strings/pad/test.js +++ /dev/null @@ -1,21 +0,0 @@ -var pad = require('./pad'); - -describe('String/pad', function () { - it('pads a string on both sides to the given length', function () { - expect(pad('Hello', 9, ' ')).toBe(' Hello '); - - expect(pad('Hello', 9)).toBe(' Hello '); - - expect(pad('Hello', 9, '-')).toBe('--Hello--'); - - expect(pad('Hello', 3, '-')).toBe('Hello'); - - expect(function () { - return pad(123456, 3); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return pad('Hello', '9'); - }).toThrow(new TypeError('Expected a number for second argument')); - }); -}); diff --git a/packages/strings/padLeft/README.md b/packages/strings/padLeft/README.md deleted file mode 100644 index 807c07a4..00000000 --- a/packages/strings/padLeft/README.md +++ /dev/null @@ -1,26 +0,0 @@ - - -## padLeft(subjectString, len, [chars]) ⇒ String -Pad `subjectString` on left side to the given `len`, with optional `chars` defaulting to a space. - -**Returns**: String - The result padded string. -**Throws**: - -- TypeError If `subjectString` is not string. -- TypeError If `len` is not number. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| len | Number | | The length to pad the string. | -| [chars] | String | ' ' | The character(s) to use for padding. | - -**Example** -```js -padLeft('Hello', 10); -// -> ' Hello' - -padLeft('Hello', 5, '-'); -// -> '-----Hello' -``` diff --git a/packages/strings/padLeft/padLeft.js b/packages/strings/padLeft/padLeft.js deleted file mode 100644 index 99faac20..00000000 --- a/packages/strings/padLeft/padLeft.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -/** - * Pad `subjectString` on left side to the given `len`, with optional `chars` defaulting to a space. - * - * @param {String} subjectString The string to process. - * @param {Number} len The length to pad the string. - * @param {String} [chars=' '] The character(s) to use for padding. - * @throws {TypeError} If `subjectString` is not string. - * @throws {TypeError} If `len` is not number. - * @return {String} The result padded string. - * @example - * - * padLeft('Hello', 10); - * // -> ' Hello' - * - * padLeft('Hello', 5, '-'); - * // -> '-----Hello' - */ -function padLeft(subjectString, len, chars) { - var left; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (typeof len !== 'number') { - throw new TypeError('Expected a number for second argument'); - } - - chars = chars || ' '; // Set default character. - - if (subjectString.length >= len) { - return subjectString; - } - - left = []; - left.length = len - subjectString.length + 1; - left = left.join(chars); - - return left + subjectString; -} - -module.exports = padLeft; \ No newline at end of file diff --git a/packages/strings/padLeft/test.js b/packages/strings/padLeft/test.js deleted file mode 100644 index 7f9e6c5e..00000000 --- a/packages/strings/padLeft/test.js +++ /dev/null @@ -1,21 +0,0 @@ -var padLeft = require('./padLeft'); - -describe('String/padLeft', function () { - it('pads a string on the left side to the given length', function () { - expect(padLeft('Hello', 10, ' ')).toBe(' Hello'); - - expect(padLeft('Hello', 10)).toBe(' Hello'); - - expect(padLeft('Hello', 10, '-')).toBe('-----Hello'); - - expect(padLeft('Hello', 3, '-')).toBe('Hello'); - - expect(function () { - return padLeft(123456, 3); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return padLeft('Hello', '10'); - }).toThrow(new TypeError('Expected a number for second argument')); - }); -}); diff --git a/packages/strings/padRight/README.md b/packages/strings/padRight/README.md deleted file mode 100644 index d9500303..00000000 --- a/packages/strings/padRight/README.md +++ /dev/null @@ -1,26 +0,0 @@ - - -## padRight(subjectString, len, [chars]) ⇒ String -Pad `subjectString` on right side to the given `len`, with optional `chars` defaulting to a space. - -**Returns**: String - The result padded string. -**Throws**: - -- TypeError If `subjectString` is not string. -- TypeError If `len` is not number. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| len | Number | | The length to pad the string. | -| [chars] | String | ' ' | The character(s) to use for padding. | - -**Example** -```js -padRight('Hello', 10); -// -> 'Hello ' - -padRight('Hello', 5, '-'); -// -> 'Hello-----' -``` diff --git a/packages/strings/padRight/padRight.js b/packages/strings/padRight/padRight.js deleted file mode 100644 index 995177ad..00000000 --- a/packages/strings/padRight/padRight.js +++ /dev/null @@ -1,44 +0,0 @@ -'use strict'; - -/** - * Pad `subjectString` on right side to the given `len`, with optional `chars` defaulting to a space. - * - * @param {String} subjectString The string to process. - * @param {Number} len The length to pad the string. - * @param {String} [chars=' '] The character(s) to use for padding. - * @throws {TypeError} If `subjectString` is not string. - * @throws {TypeError} If `len` is not number. - * @return {String} The result padded string. - * @example - * - * padRight('Hello', 10); - * // -> 'Hello ' - * - * padRight('Hello', 5, '-'); - * // -> 'Hello-----' - */ -function padRight(subjectString, len, chars) { - var right; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (typeof len !== 'number') { - throw new TypeError('Expected a number for second argument'); - } - - chars = chars || ' '; // Set default character. - - if (subjectString.length >= len) { - return subjectString; - } - - right = []; - right.length = len - subjectString.length + 1; - right = right.join(chars); - - return subjectString + right; -} - -module.exports = padRight; \ No newline at end of file diff --git a/packages/strings/padRight/test.js b/packages/strings/padRight/test.js deleted file mode 100644 index 22f0b9c4..00000000 --- a/packages/strings/padRight/test.js +++ /dev/null @@ -1,21 +0,0 @@ -var padRight = require('./padRight'); - -describe('String/padRight', function () { - it('pads a string on the right side to the given length', function () { - expect(padRight('Hello', 10, ' ')).toBe('Hello '); - - expect(padRight('Hello', 10)).toBe('Hello '); - - expect(padRight('Hello', 10, '-')).toBe('Hello-----'); - - expect(padRight('Hello', 3, '-')).toBe('Hello'); - - expect(function () { - return padRight(123456, 3); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return padRight('Hello', '10'); - }).toThrow(new TypeError('Expected a number for second argument')); - }); -}); diff --git a/packages/strings/repeat/README.md b/packages/strings/repeat/README.md deleted file mode 100644 index 2a1d02c9..00000000 --- a/packages/strings/repeat/README.md +++ /dev/null @@ -1,27 +0,0 @@ - - -## repeat(subjectString, [count]) ⇒ String -Constructs and returns a new string which contains the specified number -of copies of the string on which it was called, concatenated together. - -**Returns**: String - A new string containing the specified number of copies of the given string. -**Throws**: - -- TypeError If `subjectString` is not string. -- TypeError If `count` is not number. -- RangeError If `count` is a negative or zero number or is greater than `Number.MAX_SAFE_INTEGER`. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The string to process. | -| count | Number | An integer indicating the number of times to repeat the string. | - -**Example** -```js -repeat('a', 4); -// -> 'aaaa' - -repeat('a', 2.5); -// -> 'aa' (count will be converted to integer) -``` diff --git a/packages/strings/repeat/repeat.js b/packages/strings/repeat/repeat.js deleted file mode 100644 index a815c42a..00000000 --- a/packages/strings/repeat/repeat.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; - -/** - * Constructs and returns a new string which contains the specified number - * of copies of the string on which it was called, concatenated together. - * - * @param {String} subjectString The string to process. - * @param {Number} count An integer indicating the number of times to repeat the string. - * @throws {TypeError} If `subjectString` is not string. - * @throws {TypeError} If `count` is not number. - * @throws {RangeError} If `count` is a negative or zero number or is greater than `Number.MAX_SAFE_INTEGER`. - * @return {String} A new string containing the specified number of copies of the given string. - * @example - * - * repeat('a', 4); - * // -> 'aaaa' - * - * repeat('a', 2.5); - * // -> 'aa' (count will be converted to integer) - */ -function repeat(subjectString, count) { - var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - var str, repeated; - - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (typeof count !== 'number') { - throw new TypeError('Expected a number for second argument'); - } - - str = '' + subjectString; - - if (count <= 0 || count > MAX_SAFE_INTEGER || count !== count) { - throw new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument'); - } - - count = Math.floor(count); - - if (str.length === 0 || count === 0) { - return ''; - } - - repeated = ''; - - for (;;) { - if ((count & 1) === 1) { - repeated += str; - } - - count >>>= 1; - - if (count === 0) { - break; - } - - str += str; - } - - return repeated; -} - -module.exports = repeat; diff --git a/packages/strings/repeat/test.js b/packages/strings/repeat/test.js deleted file mode 100644 index 78a41a6b..00000000 --- a/packages/strings/repeat/test.js +++ /dev/null @@ -1,43 +0,0 @@ -var repeat = require('./repeat'); - -describe('String/repeat', function () { - it('should repeat a string n times', function () { - expect(repeat('a', 3)).toBe('aaa'); - - expect(repeat('a', 3.8)).toBe('aaa'); - - expect(repeat('', 3)).toBe(''); - - expect(function () { - return repeat('a'); - }).toThrow(new TypeError('Expected a number for second argument')); - - expect(function () { - return repeat('a', 0); - }).toThrow(new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument')); - - expect(function () { - return repeat('a', NaN); - }).toThrow(new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument')); - - expect(function () { - return repeat('a', Infinity); - }).toThrow(new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument')); - - expect(function () { - return repeat('a', -2); - }).toThrow(new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument')); - - expect(function () { - return repeat('a', 1 / 0); - }).toThrow(new RangeError('Expected a positive number lower than Number.MAX_SAFE_INTEGER for second argument')); - - expect(function () { - return repeat(null, 0); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return repeat('a', '3'); - }).toThrow(new TypeError('Expected a number for second argument')); - }); -}); diff --git a/packages/strings/startsWith/README.md b/packages/strings/startsWith/README.md deleted file mode 100755 index 816fb1d0..00000000 --- a/packages/strings/startsWith/README.md +++ /dev/null @@ -1,39 +0,0 @@ - - -## startsWith(subjectString, searchString, [position]) ⇒ Boolean -Determines whether a string begins with the characters of another string. - -**Returns**: Boolean - Returns `true` if `subjectString` starts with `searchString`; otherwise `false`. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| subjectString | String | | The string to process. | -| searchString | String | | The characters to be searched for at the start of the string. | -| [position] | Number | 0 | The position in the original string at which to begin searching for `prefix`. | - -**Example** -```js -var str = 'Lorem ipsum dolor sit amet'; - -startsWith(str, 'Lorem'); -// -> true - -startsWith(str, 'Lorem', 0); -// -> true - -startsWith(str, 'ipsum'); -// -> false - -startsWith(str, 'orem', 1); -// -> true - -startsWith('🍏 🍎 🍐 🍊 🍋', '🍏'); -// -> true - -startsWith('🍏 🍎 🍐 🍊 🍋', '🍎'); -// -> false -``` diff --git a/packages/strings/startsWith/startsWith.js b/packages/strings/startsWith/startsWith.js deleted file mode 100755 index 36bd3fde..00000000 --- a/packages/strings/startsWith/startsWith.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -/** - * Determines whether a string begins with the characters of another string. - * - * @param {String} subjectString The string to process. - * @param {String} searchString The characters to be searched for at the start of the string. - * @param {Number} [position=0] The position in the original string at which to begin searching for `prefix`. - * @throws {TypeError} If `subjectString` is not string. - * @return {Boolean} Returns `true` if `subjectString` starts with `searchString`; otherwise `false`. - * - * @example - * - * var str = 'Lorem ipsum dolor sit amet'; - * - * startsWith(str, 'Lorem'); - * // -> true - * - * startsWith(str, 'Lorem', 0); - * // -> true - * - * startsWith(str, 'ipsum'); - * // -> false - * - * startsWith(str, 'orem', 1); - * // -> true - * - * startsWith('🍏 🍎 🍐 🍊 🍋', '🍏'); - * // -> true - * - * startsWith('🍏 🍎 🍐 🍊 🍋', '🍎'); - * // -> false - */ -function startsWith(subjectString, searchString, position) { - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (searchString == null) { - return false; - } - - if (String.prototype.startsWith) { - return subjectString.startsWith(searchString, position); - } - - var pos = position > 0 ? position | 0 : 0; - - return subjectString.substring(pos, pos + searchString.length) === searchString; -} - -module.exports = startsWith; diff --git a/packages/strings/startsWith/test.js b/packages/strings/startsWith/test.js deleted file mode 100644 index 570cc18a..00000000 --- a/packages/strings/startsWith/test.js +++ /dev/null @@ -1,34 +0,0 @@ -var startsWith = require('./startsWith'); - -describe('String/startsWith', function () { - function runTests() { - expect(startsWith('Hello world', 'Hello')).toBe(true); - - expect(startsWith('Hello world', 'world')).toBe(false); - - expect(startsWith('Hello world', 'ello', 1)).toBe(true); - - expect(startsWith('Hello world')).toBe(false); - - expect(startsWith('Hello world', null)).toBe(false); - - expect(startsWith('🍏 🍎 🍐 🍊 🍋', '🍏')).toBe(true); - - expect(startsWith('🍏 🍎 🍐 🍊 🍋', '🍎')).toBe(false); - - expect(function () { - return startsWith(123455, '123'); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('checks if subject string starts with string specified (String.prototype.startsWith is supported)', function () { - runTests(); - }); - - it('checks if subject string starts with string specified (String.prototype.startsWith is not supported)', function () { - var nativeCode = String.prototype.startsWith; - String.prototype.startsWith = null; - runTests(); - String.prototype.startsWith = nativeCode; - }); -}); diff --git a/packages/strings/trim/README.md b/packages/strings/trim/README.md deleted file mode 100755 index 4b55e974..00000000 --- a/packages/strings/trim/README.md +++ /dev/null @@ -1,22 +0,0 @@ - - -## trim(subjectString) ⇒ String -Removes whitespace from both ends of a string. -Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) -and all the line terminator characters (LF, CR, etc.). - -**Returns**: String - The result string. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The string to trim. | - -**Example** -```js -trim(' Lorem ipsum dolor si amet. '); -// -> 'Lorem ipsum dolor si amet.' -``` diff --git a/packages/strings/trim/test.js b/packages/strings/trim/test.js deleted file mode 100644 index e635a0a5..00000000 --- a/packages/strings/trim/test.js +++ /dev/null @@ -1,36 +0,0 @@ -var trim = require('./trim'); - -describe('String/trim', function () { - function runTests() { - expect(trim(' Hello ')).toBe('Hello'); - - expect(trim('\t Hello \t')).toBe('Hello'); - - expect(trim('\n Hello \n')).toBe('Hello'); - - expect(trim('\v Hello \v')).toBe('Hello'); - - expect(trim('\r Hello \r')).toBe('Hello'); - - expect(trim('\t\n\v\r Hello \t\n\v\r')).toBe('Hello'); - - expect(function () { - return trim(null); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return trim(123); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('trims string both ends (String.prototype.trim is uspported)', function () { - runTests(); - }); - - it('trims string both ends (String.prototype.trim is not uspported)', function () { - var nativeCode = String.prototype.trim; - String.prototype.trim = null; - runTests(); - String.prototype.trim = nativeCode; - }); -}); diff --git a/packages/strings/trim/trim.js b/packages/strings/trim/trim.js deleted file mode 100755 index 11a3d82b..00000000 --- a/packages/strings/trim/trim.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -/** - * Removes whitespace from both ends of a string. - * Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) - * and all the line terminator characters (LF, CR, etc.). - * - * @param {String} subjectString The string to trim. - * @throws {TypeError} If `subjectString` is not string. - * @return {String} The result string. - * @example - * - * trim(' Lorem ipsum dolor si amet. '); - * // -> 'Lorem ipsum dolor si amet.' - */ -function trim(subjectString) { - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - return String.prototype.trim - ? subjectString.trim() - : subjectString.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); -} - -module.exports = trim; \ No newline at end of file diff --git a/packages/strings/trimLeft/README.md b/packages/strings/trimLeft/README.md deleted file mode 100644 index 137b4e8e..00000000 --- a/packages/strings/trimLeft/README.md +++ /dev/null @@ -1,20 +0,0 @@ - - -## trimLeft(subjectString) ⇒ String -Removes whitespace from the left end of a string. - -**Returns**: String - The result string. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The string to left trim. | - -**Example** -```js -trimLeft(' Lorem ipsum dolor si amet.'); -// -> 'Lorem ipsum dolor si amet.' -``` diff --git a/packages/strings/trimLeft/test.js b/packages/strings/trimLeft/test.js deleted file mode 100644 index d00b4a48..00000000 --- a/packages/strings/trimLeft/test.js +++ /dev/null @@ -1,38 +0,0 @@ -var trimLeft = require('./trimLeft'); - -describe('String/trimLeft', function () { - function runTests() { - expect(trimLeft(' Hello')).toBe('Hello'); - - expect(trimLeft('\t Hello')).toBe('Hello'); - - expect(trimLeft('\n Hello')).toBe('Hello'); - - expect(trimLeft('\v Hello')).toBe('Hello'); - - expect(trimLeft('\r Hello')).toBe('Hello'); - - expect(trimLeft('\t\n\v\r Hello')).toBe('Hello'); - - expect(trimLeft('\t\n\v\r Hello \t\n\v\r')).toBe('Hello \t\n\v\r'); - - expect(function () { - return trimLeft(null); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return trimLeft(123); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('trims string from left end (String.prototype.trimStart is supported)', function () { - runTests(); - }); - - it('trims string from left end (String.prototype.trimStart is not supported)', function () { - var nativeCode = String.prototype.trimStart; - String.prototype.trimStart = null; - runTests(); - String.prototype.trimStart = nativeCode; - }); -}); diff --git a/packages/strings/trimLeft/trimLeft.js b/packages/strings/trimLeft/trimLeft.js deleted file mode 100644 index ae7d66b0..00000000 --- a/packages/strings/trimLeft/trimLeft.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -/** - * Removes whitespace from the left end of a string. - * - * @param {String} subjectString The string to left trim. - * @throws {TypeError} If `subjectString` is not string. - * @return {String} The result string. - * @example - * - * trimLeft(' Lorem ipsum dolor si amet.'); - * // -> 'Lorem ipsum dolor si amet.' - */ -function trimLeft(subjectString) { - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - return String.prototype.trimStart - ? subjectString.trimStart() - : subjectString.replace(/^\s+/, ''); -} - -module.exports = trimLeft; \ No newline at end of file diff --git a/packages/strings/trimRight/README.md b/packages/strings/trimRight/README.md deleted file mode 100644 index 215b9bbf..00000000 --- a/packages/strings/trimRight/README.md +++ /dev/null @@ -1,20 +0,0 @@ - - -## trimRight(subjectString) ⇒ String -Removes whitespace from the right end of a string. - -**Returns**: String - The result string. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The string to right trim. | - -**Example** -```js -trimLeft('Lorem ipsum dolor si amet. '); -// -> 'Lorem ipsum dolor si amet.' -``` diff --git a/packages/strings/trimRight/test.js b/packages/strings/trimRight/test.js deleted file mode 100644 index d5f68b00..00000000 --- a/packages/strings/trimRight/test.js +++ /dev/null @@ -1,38 +0,0 @@ -var trimRight = require('./trimRight'); - -describe('String/trimRight', function () { - function runTests() { - expect(trimRight('Hello ')).toBe('Hello'); - - expect(trimRight('Hello\t ')).toBe('Hello'); - - expect(trimRight('Hello\n ')).toBe('Hello'); - - expect(trimRight('Hello\v ')).toBe('Hello'); - - expect(trimRight('Hello\r ')).toBe('Hello'); - - expect(trimRight('Hello\t\n\v\r ')).toBe('Hello'); - - expect(trimRight('\t\n\v\r Hello \t\n\v\r')).toBe('\t\n\v\r Hello'); - - expect(function () { - return trimRight(null); - }).toThrow(new TypeError('Expected a string for first argument')); - - expect(function () { - return trimRight(123); - }).toThrow(new TypeError('Expected a string for first argument')); - } - - it('trims string from right end (String.prototype.trimEnd is supported)', function () { - runTests(); - }); - - it('trims string from right end (String.prototype.trimEnd is not supported)', function () { - var nativeCode = String.prototype.trimEnd; - String.prototype.trimEnd = null; - runTests(); - String.prototype.trimEnd = nativeCode; - }); -}); diff --git a/packages/strings/trimRight/trimRight.js b/packages/strings/trimRight/trimRight.js deleted file mode 100644 index b8af2fe2..00000000 --- a/packages/strings/trimRight/trimRight.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -/** - * Removes whitespace from the right end of a string. - * - * @param {String} subjectString The string to right trim. - * @throws {TypeError} If `subjectString` is not string. - * @return {String} The result string. - * @example - * - * trimLeft('Lorem ipsum dolor si amet. '); - * // -> 'Lorem ipsum dolor si amet.' - */ -function trimRight(subjectString) { - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - return String.prototype.trimEnd - ? subjectString.trimEnd() - : subjectString.replace(/\s+$/, ''); -} - -module.exports = trimRight; \ No newline at end of file diff --git a/packages/strings/urlSearchParams/README.md b/packages/strings/urlSearchParams/README.md deleted file mode 100644 index 2bbece77..00000000 --- a/packages/strings/urlSearchParams/README.md +++ /dev/null @@ -1,82 +0,0 @@ - - -## urlSearchParams(searchString) ⇒ Object -Factory function that returns methods that access the URL search parameters. - -**Returns**: Object - A plain object that holds methods to access the URL search parameters. -**Throws**: - -- TypeError If `searchString` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| searchString | String | The URL search string. eg "?id=1&fname=Foo&lname=Bar" | - -**Example** -```js -urlSearchParams('?id=1&fname=Foo&lname=Bar'); -// -> {get: get(), keys: keys(), values: values()} -``` - -* [urlSearchParams(searchString)](#urlSearchParams) ⇒ Object - * [~get([param])](#urlSearchParams..get) ⇒ Array - * [~keys()](#urlSearchParams..keys) ⇒ Array - * [~values()](#urlSearchParams..values) ⇒ Array - - - -### urlSearchParams~get([param]) ⇒ Array -Get all search parameters or the value of the one specified. - -**Kind**: inner method of [urlSearchParams](#urlSearchParams) -**Returns**: Array - If `param` is `undefined`, returns an array of plain objects that represent - the search parameters as key/value pairs. If `param` is specified, returns an array - of string(s) which is/are the value(s) of the specified parameter key. If the parameter - specified is not found in the original search query string, an empty array is returned. - -| Param | Type | Description | -| --- | --- | --- | -| [param] | String | The parameter's key we want to access its value. | - -**Example** -```js -urlSearchParams('?id=1&fname=Foo&lname=Bar').get(); -// -> [{id: '1'}, {fname: 'Foo'}, {lname: 'Bar'}] - -urlSearchParams('?id=1&fname=Foo&lname=Bar').get('id'); -// -> ['1'] - -urlSearchParams('?id=1&fname=Foo&lname=Bar').get('fname'); -// -> ['Foo'] - -urlSearchParams('?id=1&fname=Foo&lname=Bar').get('lname'); -// -> ['Bar'] - -urlSearchParams('?id=1&fname=Foo&lname=Bar').get('something'); -// -> [] -``` - - -### urlSearchParams~keys() ⇒ Array -Get all "keys" from the URL search string. - -**Kind**: inner method of [urlSearchParams](#urlSearchParams) -**Returns**: Array - An array holding the "keys" found in the search string. -**Example** -```js -urlSearchParams('?id=1&fname=Foo&lname=Bar').keys(); -// -> ['id', 'fname', 'lname'] -``` - - -### urlSearchParams~values() ⇒ Array -Get all "values" for each "key" from the URL search string. - -**Kind**: inner method of [urlSearchParams](#urlSearchParams) -**Returns**: Array - An array holding the "values" for each "key(s)" that is found in the search string. -**Example** -```js -urlSearchParams('?id=1&fname=Foo&lname=Bar').values(); -// -> ['1', 'Foo', 'Bar'] -``` diff --git a/packages/strings/urlSearchParams/test.js b/packages/strings/urlSearchParams/test.js deleted file mode 100644 index c6191a42..00000000 --- a/packages/strings/urlSearchParams/test.js +++ /dev/null @@ -1,27 +0,0 @@ -var urlSearchParams = require('./urlSearchParams'); - -describe('String/urlSearchParams', function () { - it('accesses parameters of a URL search string', function () { - var search = '?id=1&fname=Foo&lname=Bar'; - var params = urlSearchParams(search); - - expect(params.get()).toHaveLength(3); - expect(params.get('id')[0]).toEqual('1'); - expect(params.get('fname')[0]).toEqual('Foo'); - expect(params.get('lname')[0]).toEqual('Bar'); - - expect(params.keys()).toHaveLength(3); - expect(params.keys()[0]).toEqual('id'); - expect(params.keys()[1]).toEqual('fname'); - expect(params.keys()[2]).toEqual('lname'); - - expect(params.values()).toHaveLength(3); - expect(params.values()[0]).toEqual('1'); - expect(params.values()[1]).toEqual('Foo'); - expect(params.values()[2]).toEqual('Bar'); - - expect(function () { - return urlSearchParams(); - }).toThrow(new TypeError('Expected a string for first argument')); - }); -}); diff --git a/packages/strings/urlSearchParams/urlSearchParams.js b/packages/strings/urlSearchParams/urlSearchParams.js deleted file mode 100644 index f1f511ba..00000000 --- a/packages/strings/urlSearchParams/urlSearchParams.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -/** - * Factory function that returns methods that access the URL search parameters. - * - * @param {String} searchString The URL search string. eg "?id=1&fname=Foo&lname=Bar" - * @throws {TypeError} If `searchString` is not string. - * @return {Object} A plain object that holds methods to access the URL search parameters. - * @example - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar'); - * // -> {get: get(), keys: keys(), values: values()} - */ -function urlSearchParams(searchString) { - var queryParams, regex, isValidQuery, tempObj, tokens; - - if (typeof searchString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - queryParams = []; - regex = /[?&]?([^=]+)=([^&]*)/g; - isValidQuery = typeof searchString === 'string'; - - /** - * Get all search parameters or the value of the one specified. - * - * @param {String} [param] The parameter's key we want to access its value. - * @return {Array} If `param` is `undefined`, returns an array of plain objects that represent - * the search parameters as key/value pairs. If `param` is specified, returns an array - * of string(s) which is/are the value(s) of the specified parameter key. If the parameter - * specified is not found in the original search query string, an empty array is returned. - * @example - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').get(); - * // -> [{id: '1'}, {fname: 'Foo'}, {lname: 'Bar'}] - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').get('id'); - * // -> ['1'] - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').get('fname'); - * // -> ['Foo'] - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').get('lname'); - * // -> ['Bar'] - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').get('something'); - * // -> [] - */ - function get(param) { - return typeof param !== 'string' - ? queryParams - : queryParams.filter(function (item) { - return Object.keys(item)[0] === param; - }).reduce(function (accum, current) { - accum.push(current[param]); - return accum; - }, []); - } - - /** - * Get all "keys" from the URL search string. - * - * @return {Array} An array holding the "keys" found in the search string. - * @example - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').keys(); - * // -> ['id', 'fname', 'lname'] - */ - function keys() { - return queryParams.reduce(function (accum, current) { - accum.push(Object.keys(current)[0]); - return accum; - }, []); - } - - /** - * Get all "values" for each "key" from the URL search string. - * - * @return {Array} An array holding the "values" for each "key(s)" that is found in the search string. - * @example - * - * urlSearchParams('?id=1&fname=Foo&lname=Bar').values(); - * // -> ['1', 'Foo', 'Bar'] - */ - function values() { - return queryParams.reduce(function (accum, current) { - accum.push(current[Object.keys(current)[0]]); - return accum; - }, []); - } - - searchString = isValidQuery ? searchString.split('+').join(' ') : ''; - - while (tokens = regex.exec(searchString)) { // eslint-disable-line no-cond-assign - tempObj = {}; - tempObj[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); - queryParams.push(tempObj); - } - - tokens = tempObj = regex = isValidQuery = null; - - return { - get: get, - keys: keys, - values: values - }; -} - -module.exports = urlSearchParams; \ No newline at end of file From 4f8b18394d418a5b574dcd360e3bfcbcc0d366f0 Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 12:48:50 +0300 Subject: [PATCH 06/17] Convert to ES6 --- packages/math/average/README.md | 2 +- packages/math/average/average.js | 33 ++++++++----------- packages/math/average/test.js | 2 +- packages/math/clamp/clamp.js | 6 ++-- packages/math/clamp/test.js | 2 +- .../math/degreesToRadians/degreesToRadians.js | 4 +-- packages/math/degreesToRadians/test.js | 2 +- packages/math/inRange/inRange.js | 6 ++-- packages/math/inRange/test.js | 2 +- packages/math/lerp/lerp.js | 6 ++-- packages/math/lerp/test.js | 2 +- packages/math/max/README.md | 8 ++--- packages/math/max/max.js | 20 +++++------ packages/math/max/test.js | 2 +- packages/math/min/README.md | 8 ++--- packages/math/min/min.js | 18 +++++----- packages/math/min/test.js | 2 +- packages/math/normalize/normalize.js | 6 ++-- packages/math/normalize/test.js | 2 +- .../math/radiansToDegrees/radiansToDegrees.js | 6 ++-- packages/math/radiansToDegrees/test.js | 2 +- packages/math/randomDist/randomDist.js | 12 +++---- packages/math/randomDist/test.js | 6 ++-- packages/math/randomInt/randomInt.js | 6 ++-- packages/math/randomInt/test.js | 6 ++-- packages/math/randomRange/randomRange.js | 6 ++-- packages/math/randomRange/test.js | 6 ++-- .../math/roundToNearest/roundToNearest.js | 21 ++++++------ packages/math/roundToNearest/test.js | 8 +++-- packages/math/roundToPlaces/roundToPlaces.js | 12 +++---- packages/math/roundToPlaces/test.js | 4 +-- 31 files changed, 110 insertions(+), 118 deletions(-) diff --git a/packages/math/average/README.md b/packages/math/average/README.md index 87fcebe7..4063375a 100644 --- a/packages/math/average/README.md +++ b/packages/math/average/README.md @@ -9,7 +9,7 @@ Ommits any non number value. | Param | Type | Description | | --- | --- | --- | -| [...args] | Number | Array | A set of numbers or an array of numbers. | +| [...nums] | Number | Array | A set of numbers or an array of numbers. | **Example** ```js diff --git a/packages/math/average/average.js b/packages/math/average/average.js index da1a7519..b7331b57 100644 --- a/packages/math/average/average.js +++ b/packages/math/average/average.js @@ -5,8 +5,8 @@ * Accepts any number of numbers as parameters, or an array of numbers. * Ommits any non number value. * - * @param {Number|Array} [...args] A set of numbers or an array of numbers. - * @return {Number} The average number of the set of data provided. + * @param {Number|Array} [...nums] A set of numbers or an array of numbers. + * @returns {Number} The average number of the set of data provided. * @example * * average(5, 10, 50, -45, 6, 7); // -> 5.5 @@ -30,33 +30,26 @@ * average(5, 4, null, true, '12', Infinity); // -> 0 * average([5, 4, null, true, '12', Infinity]); // -> 0 */ -function average(/* ...args */) { - var sum = 0; - var count = 0; - var len = arguments.length; - var args = new Array(len); - var index = 0; - var arg; +const average = (...nums) => { + let sum = 0; + let count = 0; + let len = nums.length; - for (; index < len; index += 1) { - args[index] = arguments[index]; - } - - if (len === 1 && Array.isArray(args[0])) { - args = args[0]; - len = args.length; + if (len === 1 && Array.isArray(nums[0])) { + nums = nums[0]; + len = nums.length; } while (len--) { - arg = args[len]; + const num = nums[len]; - if (isFinite(arg) && typeof arg === 'number') { // equivalent of Number.isFinite - sum += arg; + if (Number.isFinite(num)) { // equivalent of + sum += num; count += 1; } } return count > 0 ? sum / count : 0; -} +}; module.exports = average; diff --git a/packages/math/average/test.js b/packages/math/average/test.js index ae4b8266..84691914 100644 --- a/packages/math/average/test.js +++ b/packages/math/average/test.js @@ -1,4 +1,4 @@ -var average = require('./average'); +const average = require('./average'); describe('Math/average', function () { it('calculates the average of a set of numbers', function () { diff --git a/packages/math/clamp/clamp.js b/packages/math/clamp/clamp.js index d0824570..69a355cf 100644 --- a/packages/math/clamp/clamp.js +++ b/packages/math/clamp/clamp.js @@ -9,7 +9,7 @@ * @param {Number} min The lower bound. * @param {Number} max The upper bound. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Number} The clamped number. + * @returns {Number} The clamped number. * @example * * clamp(10, -5, 5); @@ -30,7 +30,7 @@ * clamp(120, 100, 0); // The order of lower and upper bounds is reversed (100 > 0) * // -> 100 */ -function clamp(value, lower, upper) { +const clamp = (value, lower, upper) => { if (typeof value !== 'number' || typeof lower !== 'number' || typeof upper !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } @@ -44,6 +44,6 @@ function clamp(value, lower, upper) { } return Math.min(Math.max(value, Math.min(lower, upper)), Math.max(lower, upper)); -} +}; module.exports = clamp; diff --git a/packages/math/clamp/test.js b/packages/math/clamp/test.js index 93cfcb92..686753a8 100644 --- a/packages/math/clamp/test.js +++ b/packages/math/clamp/test.js @@ -1,4 +1,4 @@ -var clamp = require('./clamp'); +const clamp = require('./clamp'); describe('Math/clamp', function () { it('clamps number within the inclusive lower and upper bounds', function () { diff --git a/packages/math/degreesToRadians/degreesToRadians.js b/packages/math/degreesToRadians/degreesToRadians.js index a89c9f68..992bb00c 100644 --- a/packages/math/degreesToRadians/degreesToRadians.js +++ b/packages/math/degreesToRadians/degreesToRadians.js @@ -5,7 +5,7 @@ * * @param {Number} degrees A number representing the degrees to convert. * @throws {TypeError} If `degrees` is not a number. - * @return {Number} The result in radiands, after conversion. + * @returns {Number} The result in radiands, after conversion. * @example * * degreesToRadians(0); @@ -23,7 +23,7 @@ * degreesToRadians(360); * // -> 6.283185307179586 (2π) */ -function degreesToRadians(degrees) { +const degreesToRadians = degrees => { if (typeof degrees !== 'number') { throw new TypeError('Expected a number for first argument'); } diff --git a/packages/math/degreesToRadians/test.js b/packages/math/degreesToRadians/test.js index 8e921aac..ac228663 100644 --- a/packages/math/degreesToRadians/test.js +++ b/packages/math/degreesToRadians/test.js @@ -1,4 +1,4 @@ -var degreesToRadians = require('./degreesToRadians'); +const degreesToRadians = require('./degreesToRadians'); describe('Math/degreesToRadians', function () { it('converts degrees to radians', function () { diff --git a/packages/math/inRange/inRange.js b/packages/math/inRange/inRange.js index 136e9297..58449d89 100644 --- a/packages/math/inRange/inRange.js +++ b/packages/math/inRange/inRange.js @@ -8,7 +8,7 @@ * @param {Number} min The minimum value of the range. * @param {Number} max The maximum value of the range. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Boolean} True if number is in the range; otherwise false. + * @returns {Boolean} True if number is in the range; otherwise false. * @example * * inRange(3, 2, 4); @@ -26,12 +26,12 @@ * inRange(4.5, 8.2, 2.1); * // -> true */ -function inRange(value, min, max) { +const inRange = (value, min, max) => { if (typeof value !== 'number' || typeof min !== 'number' || typeof max !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } return value >= Math.min(min, max) && value <= Math.max(min, max); -} +}; module.exports = inRange; diff --git a/packages/math/inRange/test.js b/packages/math/inRange/test.js index 96a83c5f..19316d80 100644 --- a/packages/math/inRange/test.js +++ b/packages/math/inRange/test.js @@ -1,4 +1,4 @@ -var inRange = require('./inRange'); +const inRange = require('./inRange'); describe('Math/inRange', function () { it('should test if number is in range', function () { diff --git a/packages/math/lerp/lerp.js b/packages/math/lerp/lerp.js index f1d40ee8..cc4f390c 100644 --- a/packages/math/lerp/lerp.js +++ b/packages/math/lerp/lerp.js @@ -8,7 +8,7 @@ * @param {Number} min The minimum value of the range of values. * @param {Number} max The maximum value of the range of values. * @throws {TypeError} If any of the arguments passed is not a number. - * @return {Number} The value that the normalized value points to. + * @returns {Number} The value that the normalized value points to. * @example * * lerp(0.75, 0, 365); @@ -26,12 +26,12 @@ * lerp(-0.5, 0, 500); * // -> -250 */ -function lerp(norm, min, max) { +const lerp = (norm, min, max) => { if (typeof norm !== 'number' || typeof min !== 'number' || typeof max !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } return (max - min) * norm + min; -} +}; module.exports = lerp; diff --git a/packages/math/lerp/test.js b/packages/math/lerp/test.js index 963b2e8d..037007c4 100644 --- a/packages/math/lerp/test.js +++ b/packages/math/lerp/test.js @@ -1,4 +1,4 @@ -var lerp = require('./lerp'); +const lerp = require('./lerp'); describe('Math/lerp', function () { it('converts a normalized value to the value that the normalized value points to', function () { diff --git a/packages/math/max/README.md b/packages/math/max/README.md index 1f71f1f0..4806da76 100644 --- a/packages/math/max/README.md +++ b/packages/math/max/README.md @@ -3,16 +3,14 @@ ## max() ⇒ Number Finds the largest of zero or more numbers. -NOTE: The following function uses `Function.prototype.apply` to get the maximum of an array. -This should be avoided for arrays with relatively many elements. See links below for more details: -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#using_apply_and_built-in_functions +NOTE: Prefer using an array of numbers if you want to compare a relatively large amount of numbers. +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array **Returns**: Number - The largest number from the arguments provided. | Param | Type | Description | | --- | --- | --- | -| [...args] | Number \| Array | A set of numbers as arguments, or an array of numbers as the only argument. | +| [...nums] | Number \| Array | A set of numbers, or an array of numbers. | **Example** ```js diff --git a/packages/math/max/max.js b/packages/math/max/max.js index f15aab42..e8d844ed 100644 --- a/packages/math/max/max.js +++ b/packages/math/max/max.js @@ -3,13 +3,11 @@ /** * Finds the largest of zero or more numbers. * - * NOTE: The following function uses `Function.prototype.apply` to get the maximum of an array. - * This should be avoided for arrays with relatively many elements. See links below for more details: + * NOTE: Prefer using an array of numbers if you want to compare a relatively large amount of numbers. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#using_apply_and_built-in_functions * - * @param {...Number|Array} [...args] A set of numbers as arguments, or an array of numbers as the only argument. - * @return {Number} The largest number from the arguments provided. + * @param {...Number|Array} [...nums] A set of numbers as arguments, or an array of numbers as the only argument. + * @returns {Number} The largest number from the arguments provided. * @example * * max(5); @@ -36,10 +34,12 @@ * max(); * // -> -Infinity */ -function max() { - return arguments.length === 1 && Array.isArray(arguments[0]) - ? Math.max.apply(null, arguments[0]) - : Math.max.apply(null, arguments); -} +const max = (...nums) => { + if (nums.length === 1 && Array.isArray(nums[0])) { + nums = nums[0]; + } + + return nums.reduce((a, b) => Math.max(a, b), -Infinity); +}; module.exports = max; diff --git a/packages/math/max/test.js b/packages/math/max/test.js index da49e4a3..7a172591 100644 --- a/packages/math/max/test.js +++ b/packages/math/max/test.js @@ -1,4 +1,4 @@ -var max = require('./max'); +const max = require('./max'); describe('Math/max', function () { it('finds the largest of zero or more numbers', function () { diff --git a/packages/math/min/README.md b/packages/math/min/README.md index d11f4baa..c42b3dcc 100644 --- a/packages/math/min/README.md +++ b/packages/math/min/README.md @@ -3,16 +3,14 @@ ## min() ⇒ Number Finds the smallest of zero or more numbers. -NOTE: The following function uses `Function.prototype.apply` to get the maximum of an array. -This should be avoided for arrays with relatively many elements. See links below for more details: -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array -https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#using_apply_and_built-in_functions +NOTE: Prefer using an array of numbers if you want to compare a relatively large amount of numbers. +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array **Returns**: Number - The smallest number from the arguments provided. | Param | Type | Description | | --- | --- | --- | -| [...args] | Number \| Array | A set of numbers as arguments, or an array of numbers as the only argument. | +| [...nums] | Number \| Array | A set of numbers as arguments, or an array of numbers as the only argument. | **Example** ```js diff --git a/packages/math/min/min.js b/packages/math/min/min.js index 06bc3a36..c6fcc9f4 100644 --- a/packages/math/min/min.js +++ b/packages/math/min/min.js @@ -3,12 +3,10 @@ /** * Finds the smallest of zero or more numbers. * - * NOTE: The following function uses `Function.prototype.apply` to get the maximum of an array. - * This should be avoided for arrays with relatively many elements. See links below for more details: + * NOTE: Prefer using an array of numbers if you want to compare a relatively large amount of numbers. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max#getting_the_maximum_element_of_an_array - * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#using_apply_and_built-in_functions * - * @param {...Number|Array} [...args] A set of numbers as arguments, or an array of numbers as the only argument. + * @param {...Number|Array} [...nums] A set of numbers as arguments, or an array of numbers as the only argument. * @returns {Number} The smallest number from the arguments provided. * @example * @@ -39,10 +37,12 @@ * min(); * // -> Infinity */ -function min() { - return arguments.length === 1 && Array.isArray(arguments[0]) - ? Math.min.apply(null, arguments[0]) - : Math.min.apply(null, arguments); -} +const min = (...nums) => { + if (nums.length === 1 && Array.isArray(nums[0])) { + nums = nums[0]; + } + + return nums.reduce((a, b) => Math.min(a, b), Infinity); +}; module.exports = min; diff --git a/packages/math/min/test.js b/packages/math/min/test.js index 197b0d6d..0aa2939e 100644 --- a/packages/math/min/test.js +++ b/packages/math/min/test.js @@ -1,4 +1,4 @@ -var min = require('./min'); +const min = require('./min'); describe('Math/min', function () { it('finds the smallest of zero or more numbers', function () { diff --git a/packages/math/normalize/normalize.js b/packages/math/normalize/normalize.js index 9e46e170..b63e918d 100644 --- a/packages/math/normalize/normalize.js +++ b/packages/math/normalize/normalize.js @@ -8,7 +8,7 @@ * @param {Number} min The minimum value of the range of values. * @param {Number} max The maximum value of the range of values. * @throws {TypeError} If any of the arguments passed is not a number. - * @return {Number} The normalized value. + * @returns {Number} The normalized value. * @example * * normalize(23, 0, 33); @@ -29,12 +29,12 @@ * normalize(-5, -5, 33); * // -> 0 */ -function normalize(value, min, max) { +const normalize = (value, min, max) => { if (typeof value !== 'number' || typeof min !== 'number' || typeof max !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } return (value - min) / (max - min); -} +}; module.exports = normalize; diff --git a/packages/math/normalize/test.js b/packages/math/normalize/test.js index 9a4fa75f..3f98624b 100644 --- a/packages/math/normalize/test.js +++ b/packages/math/normalize/test.js @@ -1,4 +1,4 @@ -var normalize = require('./normalize'); +const normalize = require('./normalize'); describe('Math/normalize', function () { it('converts a numeical value from 0 to 1 indicating where it lies within a range of values', function () { diff --git a/packages/math/radiansToDegrees/radiansToDegrees.js b/packages/math/radiansToDegrees/radiansToDegrees.js index f607f365..facff505 100644 --- a/packages/math/radiansToDegrees/radiansToDegrees.js +++ b/packages/math/radiansToDegrees/radiansToDegrees.js @@ -5,7 +5,7 @@ * * @param {Number} radians A number representing the radians to convert. * @throws {TypeError} If `radians` is not a number. - * @return {Number} The result in degrees, after conversion. + * @returns {Number} The result in degrees, after conversion. * @example * * radiansToDegrees(0); @@ -23,12 +23,12 @@ * radiansToDegrees(6.283185307179586); // 2π * // -> 360 */ -function radiansToDegrees(radians) { +const radiansToDegrees = radians => { if (typeof radians !== 'number') { throw new TypeError('Expected a number for first argument'); } return radians * 180 / Math.PI; -} +}; module.exports = radiansToDegrees; diff --git a/packages/math/radiansToDegrees/test.js b/packages/math/radiansToDegrees/test.js index ccffc2bc..b813a531 100644 --- a/packages/math/radiansToDegrees/test.js +++ b/packages/math/radiansToDegrees/test.js @@ -1,4 +1,4 @@ -var radiansToDegrees = require('./radiansToDegrees'); +const radiansToDegrees = require('./radiansToDegrees'); describe('Math/radiansToDegrees', function () { it('converts radians to degrees', function () { diff --git a/packages/math/randomDist/randomDist.js b/packages/math/randomDist/randomDist.js index 273727d1..0582e614 100644 --- a/packages/math/randomDist/randomDist.js +++ b/packages/math/randomDist/randomDist.js @@ -15,10 +15,8 @@ * randomDist(0, 100, 200); * // -> 49.27716133759931 */ -function randomDist(min, max, iterations) { - var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - var total = 0; - var i = 0; +const randomDist = (min, max, iterations) => { + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; if (typeof min !== 'number' || typeof max !== 'number' || typeof iterations !== 'number') { throw new TypeError('Expected all arguments to be numbers'); @@ -30,11 +28,13 @@ function randomDist(min, max, iterations) { iterations = Math.floor(iterations); - for (i; i < iterations; i += 1) { + let total = 0; + + for (let i = 0; i < iterations; i += 1) { total += Math.min(min, max) + Math.random() * (Math.max(min, max) - Math.min(min, max)); } return total / iterations; -} +}; module.exports = randomDist; diff --git a/packages/math/randomDist/test.js b/packages/math/randomDist/test.js index ff064910..b9fda73b 100644 --- a/packages/math/randomDist/test.js +++ b/packages/math/randomDist/test.js @@ -1,12 +1,12 @@ -var randomDist = require('./randomDist'); +const randomDist = require('./randomDist'); describe('Math/randomDist', function () { it('should return a weighted random number that tends to center', function () { - var r0 = randomDist(0, 100, 100); + const r0 = randomDist(0, 100, 100); expect(r0 >= 0 && r0 <= 100).toBe(true); // Test that min and max can be inverted. - var r1 = randomDist(100, 0, 100); + const r1 = randomDist(100, 0, 100); expect(r1 >= 0 && r1 <= 100).toBe(true); expect(function () { diff --git a/packages/math/randomInt/randomInt.js b/packages/math/randomInt/randomInt.js index 0d0df2a3..a2cbc27c 100644 --- a/packages/math/randomInt/randomInt.js +++ b/packages/math/randomInt/randomInt.js @@ -7,13 +7,13 @@ * @param {Number} min The minimum value of the range. * @param {Number} max The maximum value of the range. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Number} The pseudo-random integer number. + * @returns {Number} The pseudo-random integer number. * @example * * randomInt(3, 8); * // -> Any integer number between 3 (inclusive) and 8 (inclusive). eg 6 */ -function randomInt(min, max) { +const randomInt = (min, max) => { if (typeof min !== 'number' || typeof max !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } @@ -21,6 +21,6 @@ function randomInt(min, max) { return Math.floor( Math.min(min, max) + Math.random() * (Math.max(min, max) - Math.min(min, max) + 1) ); -} +}; module.exports = randomInt; diff --git a/packages/math/randomInt/test.js b/packages/math/randomInt/test.js index b095e951..876f1d81 100644 --- a/packages/math/randomInt/test.js +++ b/packages/math/randomInt/test.js @@ -1,9 +1,9 @@ -var randomInt = require('./randomInt'); +const randomInt = require('./randomInt'); describe('Math/randomInt', function () { it('returns a pseudo-random integer number between a min (inclusive) and a max (inclusive) value.', function () { - var r0 = randomInt(0, 2); - var r1 = randomInt(2, 0); + const r0 = randomInt(0, 2); + const r1 = randomInt(2, 0); expect(r0 >= 0 && r0 <= 2).toBe(true); diff --git a/packages/math/randomRange/randomRange.js b/packages/math/randomRange/randomRange.js index 8702f293..d2e1eeb6 100644 --- a/packages/math/randomRange/randomRange.js +++ b/packages/math/randomRange/randomRange.js @@ -7,18 +7,18 @@ * @param {Number} min The minimum value of the range. * @param {Number} max The maximum value of the range. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Number} The pseudo-random number. + * @returns {Number} The pseudo-random number. * @example * * randomRange(3, 8); * // -> Any number between 3 (inclusive) and 8 (exclusive). eg 5.3304674779064953 */ -function randomRange(min, max) { +const randomRange = (min, max) => { if (typeof min !== 'number' || typeof max !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } return Math.min(min, max) + Math.random() * (Math.max(min, max) - Math.min(min, max)); -} +}; module.exports = randomRange; diff --git a/packages/math/randomRange/test.js b/packages/math/randomRange/test.js index ecc0a666..753a0a76 100644 --- a/packages/math/randomRange/test.js +++ b/packages/math/randomRange/test.js @@ -1,9 +1,9 @@ -var randomRange = require('./randomRange'); +const randomRange = require('./randomRange'); describe('Math/randomRange', function () { it('returns a pseudo-random number between a min (inclusive) and a max (exclusive) value.', function () { - var r0 = randomRange(0, 2); - var r1 = randomRange(2, 0); + const r0 = randomRange(0, 2); + const r1 = randomRange(2, 0); expect(r0 >= 0 && r0 < 2).toBe(true); diff --git a/packages/math/roundToNearest/roundToNearest.js b/packages/math/roundToNearest/roundToNearest.js index 001c0f4d..b8b997af 100644 --- a/packages/math/roundToNearest/roundToNearest.js +++ b/packages/math/roundToNearest/roundToNearest.js @@ -4,9 +4,9 @@ * Rounds a number to the nearest multiple of a value provided. * * @param {Number} value The number to be rounded. - * @param {Number} nearest=1 The value to be used in order to find the nearest multiple of. + * @param {Number} nearest The value to be used in order to find the nearest multiple of. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Number} The rounded number. + * @returns {Number} The rounded number. * @example * * roundToNearest(100, 40); @@ -18,20 +18,21 @@ * roundToNearest(180, 40); * // -> 200 * - * roundToNearest(113, 0); - * // -> 113 (0 is converted to 1) + * roundToNearest(100, 0); + * // -> NaN * - * roundToNearest(113, NaN); - * // -> 113 (NaN is converted to 1) + * roundToNearest(100, NaN); + * // -> NaN + * + * roundToNearest(100); + * // -> NaN */ -function roundToNearest(value, nearest) { +const roundToNearest = (value, nearest) => { if (typeof value !== 'number' || typeof nearest !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } - nearest = nearest || 1; - return Math.round(value / nearest) * nearest; -} +}; module.exports = roundToNearest; diff --git a/packages/math/roundToNearest/test.js b/packages/math/roundToNearest/test.js index 0e199f47..f12a0a05 100644 --- a/packages/math/roundToNearest/test.js +++ b/packages/math/roundToNearest/test.js @@ -1,4 +1,4 @@ -var roundToNearest = require('./roundToNearest'); +const roundToNearest = require('./roundToNearest'); describe('Math/roundToNearest', function () { it('rounds a number to the nearest multiple of a value provided', function () { @@ -8,7 +8,11 @@ describe('Math/roundToNearest', function () { expect(roundToNearest(180, 40)).toBe(200); - expect(roundToNearest(100, 0)).toBe(100); + expect(roundToNearest(100, 0)).toBe(NaN); + + expect(roundToNearest(100, NaN)).toBe(NaN); + + expect(roundToNearest(100, Infinity)).toBe(NaN); expect(function () { return roundToNearest('100', '40'); diff --git a/packages/math/roundToPlaces/roundToPlaces.js b/packages/math/roundToPlaces/roundToPlaces.js index dc51c8cb..dc2fb629 100644 --- a/packages/math/roundToPlaces/roundToPlaces.js +++ b/packages/math/roundToPlaces/roundToPlaces.js @@ -7,10 +7,10 @@ * @param {Number} value The number to be rounded. * @param {Number} places The places that the `value` is rounded to. * @throws {TypeError} If one or more of the arguments passed is not a number. - * @return {Number} The rounded number. + * @returns {Number} The rounded number. * @example * - * var PI = Math.PI + * const PI = Math.PI * // -> 3.141592653589793 * * roundToPlaces(PI, 0); @@ -40,16 +40,14 @@ * roundToPlaces(123456789, -3); * // -> 123457000 */ -function roundToPlaces(value, places) { - var mult; - +const roundToPlaces = (value, places) => { if (typeof value !== 'number' || typeof places !== 'number') { throw new TypeError('Expected all arguments to be numbers'); } - mult = Math.pow(10, parseInt(places, 10)); + const mult = Math.pow(10, parseInt(places, 10)); return Math.round(value * mult) / mult; -} +}; module.exports = roundToPlaces; diff --git a/packages/math/roundToPlaces/test.js b/packages/math/roundToPlaces/test.js index 1f21bdf7..954763e8 100644 --- a/packages/math/roundToPlaces/test.js +++ b/packages/math/roundToPlaces/test.js @@ -1,8 +1,8 @@ -var roundToPlaces = require('./roundToPlaces'); +const roundToPlaces = require('./roundToPlaces'); describe('Math/roundToPlaces', function () { it('rounds a number to a number of desired places', function () { - var PI = Math.PI; + const PI = Math.PI; expect(roundToPlaces(PI, 0)).toBe(3); From cd551ab3bc19f63a846f37c208674922500d6163 Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 12:53:25 +0300 Subject: [PATCH 07/17] Remove utils that native solutions exist --- packages/objects/deepClone/README.md | 23 --- packages/objects/deepClone/deepClone.js | 42 ----- packages/objects/deepClone/test.js | 23 --- packages/objects/extend/README.md | 77 -------- packages/objects/extend/extend.js | 173 ------------------ packages/objects/extend/test.js | 92 ---------- packages/objects/schemaValidate/README.md | 62 ------- .../objects/schemaValidate/schemaValidate.js | 89 --------- packages/objects/schemaValidate/test.js | 102 ----------- 9 files changed, 683 deletions(-) delete mode 100644 packages/objects/deepClone/README.md delete mode 100644 packages/objects/deepClone/deepClone.js delete mode 100644 packages/objects/deepClone/test.js delete mode 100755 packages/objects/extend/README.md delete mode 100755 packages/objects/extend/extend.js delete mode 100644 packages/objects/extend/test.js delete mode 100644 packages/objects/schemaValidate/README.md delete mode 100644 packages/objects/schemaValidate/schemaValidate.js delete mode 100644 packages/objects/schemaValidate/test.js diff --git a/packages/objects/deepClone/README.md b/packages/objects/deepClone/README.md deleted file mode 100644 index 42539f56..00000000 --- a/packages/objects/deepClone/README.md +++ /dev/null @@ -1,23 +0,0 @@ - - -## deepClone(obj) ⇒ \* -Creates a deep clone of a given value. It supports cloning arrays, objects and dates. -All other types are just passed by reference. For more sophisticated deep cloning, use -[structuredClone()](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) that -creates a deep clone using the structured clone algorithm and covers more cases. - -**Returns**: \* - Returns the deep cloned value. - -| Param | Type | Description | -| --- | --- | --- | -| obj | \* | The value to recursively clone. | - -**Example** -```js -var original = [{ 'a': 1 }, { 'b': 2 }]; - -var clone = deeClone(original); - -console.log(clone[0] === original[0]); -// -> false -``` diff --git a/packages/objects/deepClone/deepClone.js b/packages/objects/deepClone/deepClone.js deleted file mode 100644 index ca5ac22f..00000000 --- a/packages/objects/deepClone/deepClone.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -/** - * Creates a deep clone of a given value. It supports cloning arrays, objects and dates. - * All other types are just passed by reference. For more sophisticated deep cloning, use - * [structuredClone()](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) that - * creates a deep clone using the structured clone algorithm and covers more cases. - * - * @param {*} obj The value to recursively clone. - * @returns {*} Returns the deep cloned value. - * @example - * - * var original = [{ 'a': 1 }, { 'b': 2 }]; - * - * var clone = deeClone(original); - * - * console.log(clone[0] === original[0]); - * // -> false - */ -function deepClone(obj) { - var key, copy; - - if (Array.isArray(obj)) { - copy = []; - for (key in obj) { - copy[key] = deepClone(obj[key]); - } - return copy; - } else if (Object.prototype.toString.call(obj) === '[object Object]') { - copy = {}; - for (key in obj) { - copy[key] = deepClone(obj[key]); - } - return copy; - } else if (Object.prototype.toString.call(obj) === '[object Date]') { - return new Date(obj.getTime()); - } else { - return obj; - } -} - -module.exports = deepClone; diff --git a/packages/objects/deepClone/test.js b/packages/objects/deepClone/test.js deleted file mode 100644 index ba144ef0..00000000 --- a/packages/objects/deepClone/test.js +++ /dev/null @@ -1,23 +0,0 @@ -var deepClone = require('./deepClone'); - -describe('Object/deepClone', function () { - it('Clones deeply arrays, objects and dates.', function () { - var original = { - obj: { a: 'a' }, - arr: [ { n: 1 } ], - date: new Date('2021-05-28') - }; - - original.obj._proto_ = { foo: 'bar' }; - original.arr.foobar = { foo: 'bar' }; - - var copy = deepClone(original); - - expect(original.obj === copy.obj).toBe(false); - expect(original.obj._proto_ === copy.obj._proto_).toBe(false); - expect(original.arr === copy.arr).toBe(false); - expect(original.arr[0] === copy.arr[0]).toBe(false); - expect(original.arr.foobar === copy.arr.foobar).toBe(false); - expect(original.date === copy.date).toBe(false); - }); -}); diff --git a/packages/objects/extend/README.md b/packages/objects/extend/README.md deleted file mode 100755 index 64bc3e93..00000000 --- a/packages/objects/extend/README.md +++ /dev/null @@ -1,77 +0,0 @@ - - -## extend([deep], target, object1, [objectN]) ⇒ Object -Merge the contents of two or more objects together into the first object. - -Keep in mind that the target object (first argument) will be modified, and will also be returned from `extend()`. -If, however, you want to preserve both of the original objects, you can do so by passing an empty object as the target: - -`var object = extend({}, object1, object2);` - -The merge performed by `extend()` is not recursive by default; if a property of the first object -is itself an object or array, it will be completely overwritten by a property with the same key -in the second or subsequent object. The values are not merged. -However, by passing true for the first function argument, objects will be recursively merged. - -**Warning:** Passing false for the first argument is not supported. - -Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over. -Properties that are an object constructed via new MyCustomObject(args), or built-in JavaScript types such as -Date or RegExp, are not re-constructed and will appear as plain Objects in the resulting object or array. - -On a deep extend, Object and Array are extended, but object wrappers on primitive types such as -String, Boolean, and Number are not. Deep-extending a cyclical data structure will result in an error. - -**Returns**: Object - The merged object. - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| [deep] | Boolean | false | If true, the merge becomes recursive (aka. deep copy). | -| target | Object | | An object that will receive the new properties if additional objects are passed. | -| object1 | Object | | An object containing additional properties to merge in. | -| [objectN] | Object | | Additional objects containing properties to merge in. | - -**Example** -```js -// EXAMPLE 1 -// Merge two objects, modifying the first. -var object1 = { - apple: 0, - banana: {weight: 52, price: 100}, - cherry: 97 -}; - -var object2 = { - banana: {price: 200}, - durian: 100 -}; - -extend(object1, object2); -// -> {"apple": 0, "banana": {"price": 200}, "cherry": 97, "durian": 100} - -// EXAMPLE 2 -// Merge two objects recursively, modifying the first. -var object1 = { - apple: 0, - banana: {weight: 52, price: 100}, - cherry: 97 -}; -var object2 = { - banana: {price: 200}, - durian: 100 -}; - -extend(true, object1, object2); -// -> {"apple": 0, "banana": {"weight": 52, "price": 200}, "cherry": 97, "durian": 100} - -// EXAMPLE 3 -var defaults = {validate: false, limit: 5, name: "foo"}; -var options = {validate: true, name: "bar"}; - -// Merge defaults and options, without modifying defaults -var settings = extend({}, defaults, options); - -// -> defaults -- {"validate": false, "limit": 5, "name": "foo"} -// -> options -- {"validate": true, "name": "bar"} -// -> settings -- {"validate": true, "limit": 5, "name": "bar"} -``` diff --git a/packages/objects/extend/extend.js b/packages/objects/extend/extend.js deleted file mode 100755 index 10691f03..00000000 --- a/packages/objects/extend/extend.js +++ /dev/null @@ -1,173 +0,0 @@ -'use strict'; - -/** - * Merge the contents of two or more objects together into the first object. - * - * Keep in mind that the target object (first argument) will be modified, and will also be returned from `extend()`. - * If, however, you want to preserve both of the original objects, you can do so by passing an empty object as the target: - * - * `var object = extend({}, object1, object2);` - * - * The merge performed by `extend()` is not recursive by default; if a property of the first object - * is itself an object or array, it will be completely overwritten by a property with the same key - * in the second or subsequent object. The values are not merged. - * However, by passing true for the first function argument, objects will be recursively merged. - * - * **Warning:** Passing false for the first argument is not supported. - * - * Undefined properties are not copied. However, properties inherited from the object's prototype will be copied over. - * Properties that are an object constructed via new MyCustomObject(args), or built-in JavaScript types such as - * Date or RegExp, are not re-constructed and will appear as plain Objects in the resulting object or array. - * - * On a deep extend, Object and Array are extended, but object wrappers on primitive types such as - * String, Boolean, and Number are not. Deep-extending a cyclical data structure will result in an error. - * - * @function extend - * @param {Boolean} [deep=false] If true, the merge becomes recursive (aka. deep copy). - * @param {Object} target An object that will receive the new properties if additional objects are passed. - * @param {Object} object1 An object containing additional properties to merge in. - * @param {Object} [objectN] Additional objects containing properties to merge in. - * @return {Object} The merged object. - * @example - * - * // EXAMPLE 1 - * // Merge two objects, modifying the first. - * var object1 = { - * apple: 0, - * banana: {weight: 52, price: 100}, - * cherry: 97 - * }; - * - * var object2 = { - * banana: {price: 200}, - * durian: 100 - * }; - * - * extend(object1, object2); - * // -> {"apple": 0, "banana": {"price": 200}, "cherry": 97, "durian": 100} - * - * // EXAMPLE 2 - * // Merge two objects recursively, modifying the first. - * var object1 = { - * apple: 0, - * banana: {weight: 52, price: 100}, - * cherry: 97 - * }; - * var object2 = { - * banana: {price: 200}, - * durian: 100 - * }; - * - * extend(true, object1, object2); - * // -> {"apple": 0, "banana": {"weight": 52, "price": 200}, "cherry": 97, "durian": 100} - * - * // EXAMPLE 3 - * var defaults = {validate: false, limit: 5, name: "foo"}; - * var options = {validate: true, name: "bar"}; - * - * // Merge defaults and options, without modifying defaults - * var settings = extend({}, defaults, options); - * - * // -> defaults -- {"validate": false, "limit": 5, "name": "foo"} - * // -> options -- {"validate": true, "name": "bar"} - * // -> settings -- {"validate": true, "limit": 5, "name": "bar"} - */ -module.exports = (function () { - var toString = Object.prototype.toString; - var hasOwnProp = Object.prototype.hasOwnProperty; - var OBJECT_TAG = '[object Object]'; - - function isUndefined(value) { - return typeof value === 'undefined'; - } - - function isBoolean(value) { - return typeof value === 'boolean'; - } - - function isFunction(value) { - return typeof value === 'function'; - } - - function isObject(value) { - return typeof value === 'object'; - } - - function isPlainObject(value) { - var proto, ctor; - - // Detect obvious negatives. - // Use toString to catch host objects. - if (!value || toString.call(value) !== OBJECT_TAG) { - return false; - } - - proto = Object.getPrototypeOf(value); - - // Objects with no prototype (e.g., `Object.create(null)`) are plain. - if (!proto) { - return true; - } - - // Objects with prototype are plain if they were constructed by a global Object function. - ctor = hasOwnProp.call(proto, 'constructor') && proto.constructor; - return isFunction(ctor) && hasOwnProp.toString.call(ctor) === hasOwnProp.toString.call(Object); - } - - return function extend() { - var options, name, src, copy, copyIsArray, clone, - target = arguments[0] || {}, - i = 1, - length = arguments.length, - deep = false; - - // Handle a deep copy situation - if (isBoolean(target)) { - deep = target; - target = arguments[1] || {}; - // skip the boolean and the target - i = 2; - } - - // Handle case when target is a string or something (possible in deep copy) - if (!isObject(target) && !isFunction(target)) { - target = {}; - } - - for (; i < length; i += 1) { - // Only deal with non-null/undefined values - if ((options = arguments[i]) != null) { - // Extend the base object - for (name in options) { - src = target[name]; - copy = options[name]; - - // Prevent never-ending loop - if (target === copy) { - continue; - } - - // Recurse if we're merging plain objects or arrays - if (deep && copy && (isPlainObject(copy) || (copyIsArray = Array.isArray(copy)))) { - if (copyIsArray) { - copyIsArray = false; - clone = src && Array.isArray(src) ? src : []; - } else { - clone = src && isPlainObject(src) ? src : {}; - } - - // Never move original objects, clone them - target[name] = extend(deep, clone, copy); - - // Don't bring in undefined values - } else if (!isUndefined(copy)) { - target[name] = copy; - } - } - } - } - - // Return the modified object - return target; - }; -}()); diff --git a/packages/objects/extend/test.js b/packages/objects/extend/test.js deleted file mode 100644 index 0db653b4..00000000 --- a/packages/objects/extend/test.js +++ /dev/null @@ -1,92 +0,0 @@ -var extend = require('./extend'); - -describe('Object/extend', function () { - it('Merge two objects, modifying the first.', function () { - var object1 = { - apple: 0, - banana: { weight: 52, price: 100 }, - cherry: 97 - }; - - var object2 = { - banana: { price: 200 }, - durian: 100 - }; - - extend(object1, object2); - - expect(object1).toEqual({ apple: 0, banana: { price: 200 }, cherry: 97, durian: 100 }); - }); - - it('Merge two objects recursively, modifying the first.', function () { - var object1 = { - apple: 0, - banana: { weight: 52, price: 100 }, - cherry: 97 - }; - - var object2 = { - banana: { price: 200 }, - durian: 100 - }; - - extend(true, object1, object2); - - expect(object1).toEqual({ - apple: 0, - banana: { - weight: 52, - price: 200 - }, - cherry: 97, - durian: 100 - }); - }); - - it('Merge defaults and options, without modifying the defaults.', function () { - var defaults = { - validate: false, - limit: 5, - name: 'foo' - }; - - var options = { - validate: true, - name: 'bar' - }; - - var settings = extend({}, defaults, options); - - expect(defaults).toEqual({ validate: false, limit: 5, name: 'foo' }); - - expect(options).toEqual({ validate: true, name: 'bar' }); - - expect(settings).toEqual({ validate: true, limit: 5, name: 'bar' }); - }); - - it('Recursively merge array values', function () { - var o1 = { - name: 'John', - items: [ - { a: 'aaa' }, - { b: 'bbb' } - ] - }; - - var o2 = { - name: 'George', - items: [ - { c: 'ccc' } - ] - }; - - var res = extend(true, {}, o1, o2); - - expect(res.items).toHaveLength(2); - - expect(res.items).toEqual([ - { a: 'aaa', c: 'ccc' }, - { b: 'bbb' } - ]); - }); -}); diff --git a/packages/objects/schemaValidate/README.md b/packages/objects/schemaValidate/README.md deleted file mode 100644 index bae37ae7..00000000 --- a/packages/objects/schemaValidate/README.md +++ /dev/null @@ -1,62 +0,0 @@ - - -## schemaValidate(object, [schema]) ⇒ Object -Validates a plain object against a provided schema object. - -**Returns**: Object - An object holding a boolean to indicate if object is valid and an array with invalid properties if any. -**Throws**: - -- TypeError If any of the schema validators are not function. - -| Param | Type | Description | -| --- | --- | --- | -| object | Object | The object to validate. | -| [schema] | Object.<function()> | A plain object with validator functions. If `undefined` validation always passes. | - -**Example** -```js -var schema = { - name: function (value) { - // Name should be a string (required). - return typeof value === 'string'; - }, - age: function (value) { - // Age should be a number, not NaN and greater that 18 (required). - return !Number.isNaN(value) && typeof value === 'number' && value >= 18; - }, - phone: function (value) { - // Phone should be a string of specific format (required). - return /^(\+?\d{1,2}-)?\d{3}-\d{3}-\d{4}$/.test(value); - }, - // Hobbies should be an array (optional). - hobbies: function (value) { - return !value || Array.isArray(value); - }, - emails: function (value) { - // Emails should be an array of at least one item (required). - return Array.isArray(value) && value.length > 0; - } -}; - -var user_1 = { - name: 'John Doe', - age: 30, - phone: '123-456-7890', - emails: ['john_doe@gmail.com'] -}; - -var user_2 = { - name: 'George Papas', - age: 15, - phone: '123-456-7890' -}; - -schemaValidate(user_1, schema); -// -> {valid: true, invalidProperties: []} - -schemaValidate(user_2, schema); -// -> {valid: false, invalidProperties: ['age', 'emails']} - -schemaValidate(user_1); -// -> {valid: true, invalidProperties: []} -``` diff --git a/packages/objects/schemaValidate/schemaValidate.js b/packages/objects/schemaValidate/schemaValidate.js deleted file mode 100644 index c7eabebe..00000000 --- a/packages/objects/schemaValidate/schemaValidate.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; - -/** - * Validates a plain object against a provided schema object. - * - * @param {Object} object The object to validate. - * @param {Object.} [schema] A plain object with validator functions. If `undefined` validation always passes. - * @throws {TypeError} If any of the schema validators are not function. - * @return {Object} An object holding a boolean to indicate if object is valid and an array with invalid properties if any. - * @example - * - * var schema = { - * name: function (value) { - * // Name should be a string (required). - * return typeof value === 'string'; - * }, - * age: function (value) { - * // Age should be a number, not NaN and greater that 18 (required). - * return !Number.isNaN(value) && typeof value === 'number' && value >= 18; - * }, - * phone: function (value) { - * // Phone should be a string of specific format (required). - * return /^(\+?\d{1,2}-)?\d{3}-\d{3}-\d{4}$/.test(value); - * }, - * // Hobbies should be an array (optional). - * hobbies: function (value) { - * return !value || Array.isArray(value); - * }, - * emails: function (value) { - * // Emails should be an array of at least one item (required). - * return Array.isArray(value) && value.length > 0; - * } - * }; - * - * var user_1 = { - * name: 'John Doe', - * age: 30, - * phone: '123-456-7890', - * emails: ['john_doe@gmail.com'] - * }; - * - * var user_2 = { - * name: 'George Papas', - * age: 15, - * phone: '123-456-7890' - * }; - * - * schemaValidate(user_1, schema); - * // -> {valid: true, invalidProperties: []} - * - * schemaValidate(user_2, schema); - * // -> {valid: false, invalidProperties: ['age', 'emails']} - * - * schemaValidate(user_1); - * // -> {valid: true, invalidProperties: []} - */ -function schemaValidate(object, schema) { - var errorsArray = Object - .keys(schema || {}) - .map(function (property) { - var validator = schema[property]; - - if (typeof validator !== 'function') { - throw new TypeError('Schema validators must be functions'); - } - - return { - property: property, - valid: validator(object[property]) - }; - }) - .reduce(function (errors, pair) { - var validationResult = pair.valid; - var didNotValidate = validationResult === false || typeof validationResult === 'undefined'; - - if (didNotValidate) { - errors.push(pair.property); - } - - return errors; - }, []); - - return { - valid: errorsArray.length === 0, - invalidProperties: errorsArray - }; -} - -module.exports = schemaValidate; diff --git a/packages/objects/schemaValidate/test.js b/packages/objects/schemaValidate/test.js deleted file mode 100644 index 8c7580b6..00000000 --- a/packages/objects/schemaValidate/test.js +++ /dev/null @@ -1,102 +0,0 @@ -var schemaValidate = require('./schemaValidate'); - -describe('Object/schemaValidate', function () { - var schema = { - name: function (value) { - // Name should be a string (required). - return typeof value === 'string'; - }, - age: function (value) { - // Age should be a number, not NaN and greater that 18 (required). - return !Number.isNaN(value) && typeof value === 'number' && value >= 18; - }, - phone: function (value) { - // Phone should be a string of specific format (required). - return /^(\+?\d{1,2}-)?\d{3}-\d{3}-\d{4}$/.test(value); - }, - // Hobbies should be an array (optional). - hobbies: function (value) { - return !value || Array.isArray(value); - }, - emails: function (value) { - // Emails should be an array of at least one item (required). - return Array.isArray(value) && value.length > 0; - } - }; - - it('Object should be validated against provided schema', function () { - var user = { - name: 'John Doe', - age: 30, - phone: '123-456-7890', - emails: ['john_doe@gmail.com'], - hobbies: [] - }; - - expect(schemaValidate(user, schema).valid).toBe(true); - }); - - it('"age" property should be a number; thus object is invalid if string is provided', function () { - var user = { - name: 'John Doe', - age: '30', - phone: '123-456-7890', - emails: ['john_doe@gmail.com'], - hobbies: [] - }; - var res = schemaValidate(user, schema); - - expect(res.valid).toBe(false); - expect(res.invalidProperties[0]).toBe('age'); - }); - - it('"emails" property should be an array of at least one item; thus object is invalid if empty array is provided', function () { - var user = { - name: 'John Doe', - age: 30, - phone: '123-456-7890', - emails: [], - hobbies: [] - }; - var res = schemaValidate(user, schema); - - expect(res.valid).toBe(false); - expect(res.invalidProperties[0]).toBe('emails'); - }); - - it('"hobbies" property should be an optional array; thus object is valid if not provided', function () { - var user = { - name: 'John Doe', - age: 30, - phone: '123-456-7890', - emails: ['john_doe@gmail.com'] - }; - var res = schemaValidate(user, schema); - - expect(res.valid).toBe(true); - expect(res.invalidProperties).toHaveLength(0); - }); - - it('"phone" property should be astring of format "123-456-7890"; thus object is invalid if "1234567890" is provided', function () { - var user = { - name: 'John Doe', - age: 30, - phone: '1234567890', - emails: ['john_doe@gmail.com'], - hobbies: [] - }; - var res = schemaValidate(user, schema); - - expect(res.valid).toBe(false); - expect(res.invalidProperties[0]).toBe('phone'); - }); - - it('throws if schema\'s property is not function', function () { - var user = { name: 'John Doe' }; - var schema = { name: null }; - - expect(function () { - return schemaValidate(user, schema); - }).toThrow(new TypeError('Schema validators must be functions')); - }); -}); From b446aaa152c301b8a0ad37b008f9b412285daecf Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 12:54:42 +0300 Subject: [PATCH 08/17] Remove utils that native solutions exist --- README.md | 5 ---- packages/objects/forIn/README.md | 30 ------------------------ packages/objects/forIn/forIn.js | 37 ----------------------------- packages/objects/forIn/test.js | 23 ------------------ packages/objects/forOwn/README.md | 31 ------------------------ packages/objects/forOwn/forOwn.js | 39 ------------------------------- packages/objects/forOwn/test.js | 23 ------------------ 7 files changed, 188 deletions(-) delete mode 100755 packages/objects/forIn/README.md delete mode 100755 packages/objects/forIn/forIn.js delete mode 100644 packages/objects/forIn/test.js delete mode 100755 packages/objects/forOwn/README.md delete mode 100755 packages/objects/forOwn/forOwn.js delete mode 100644 packages/objects/forOwn/test.js diff --git a/README.md b/README.md index 2f08d32b..fb588f6e 100755 --- a/README.md +++ b/README.md @@ -72,15 +72,10 @@ A collection of dependency-free JavaScript utility functions. |Name|Description| |--------|-----------| -|[deepClone](https://github.com/georapbox/js-utils/tree/master/packages/objects/deepClone)|Creates a deep clone of a given value.| -|[extend](https://github.com/georapbox/js-utils/tree/master/packages/objects/extend)|Merge the contents of two or more objects together into the first object.| -|[forIn](https://github.com/georapbox/js-utils/tree/master/packages/objects/forIn)|Iterates over **own and inherited** enumerable properties of an object, executing the callback for each property. The callback is invoked with three arguments (value, key, object)| -|[forOwn](https://github.com/georapbox/js-utils/tree/master/packages/objects/forOwn)|Iterates over **own** enumerable properties of an object, executing the callback for each property. The callback is invoked with three arguments (value, key, object)| |[get](https://github.com/georapbox/js-utils/tree/master/packages/objects/get)|Gets the `value` at path of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.| |[omit](https://github.com/georapbox/js-utils/tree/master/packages/objects/omit)|Creates an object composed of the own enumerable (not inherited) property paths of object that are not omitted.| |[pick](https://github.com/georapbox/js-utils/tree/master/packages/objects/pick)|Creates an object composed of the picked object properties.| |[pickBy](https://github.com/georapbox/js-utils/tree/master/packages/objects/pickBy)|Creates an object composed of the object enumerable properties that predicate returns truthy for.| -|[schemaValidate](https://github.com/georapbox/js-utils/tree/master/packages/objects/schemaValidate)|Validates a plain object against a provided schema object.| ## Function diff --git a/packages/objects/forIn/README.md b/packages/objects/forIn/README.md deleted file mode 100755 index 97c5a06a..00000000 --- a/packages/objects/forIn/README.md +++ /dev/null @@ -1,30 +0,0 @@ - - -## forIn(obj, [callback]) ⇒ Object -Iterates over own and inherited enumerable properties of an object, executing the callback for each property. -The callback is invoked with three arguments (value, key, object) - -**Returns**: Object - The original object. - -| Param | Type | Description | -| --- | --- | --- | -| obj | Object | The object to iterate over. | -| [callback] | function | The function called per iteration. | - -**Example** -```js -function Shape() { - this.x = 0; - this.y = 0; -} - -Shape.prototype.move = function (x, y) { - this.x += x; - this.y += y; -}; - -forIn(new Shape(), function (value, key, obj) { - console.log(key); - // -> "x", "y", "move" -}); -``` diff --git a/packages/objects/forIn/forIn.js b/packages/objects/forIn/forIn.js deleted file mode 100755 index c6934057..00000000 --- a/packages/objects/forIn/forIn.js +++ /dev/null @@ -1,37 +0,0 @@ -'use strict'; - -/** - * Iterates over own and inherited enumerable properties of an object, executing the callback for each property. - * The callback is invoked with three arguments (value, key, object) - * - * @param {Object} obj The object to iterate over. - * @param {function} [callback] The function called per iteration. - * @return {Object} The original object. - * @example - * - * function Shape() { - * this.x = 0; - * this.y = 0; - * } - * - * Shape.prototype.move = function (x, y) { - * this.x += x; - * this.y += y; - * }; - * - * forIn(new Shape(), function (value, key, obj) { - * console.log(key); - * // -> "x", "y", "move" - * }); - */ -function forIn(obj, callback) { - var key; - - for (key in obj) { - typeof callback === 'function' && callback(obj[key], key, obj); - } - - return obj; -} - -module.exports = forIn; diff --git a/packages/objects/forIn/test.js b/packages/objects/forIn/test.js deleted file mode 100644 index 92a4a002..00000000 --- a/packages/objects/forIn/test.js +++ /dev/null @@ -1,23 +0,0 @@ -var forIn = require('./forIn'); - -describe('Object/forIn', function () { - it('iterates over own and inherited enumerable properties of an object', function () { - var props = []; - - function Shape() { - this.x = 0; - this.y = 0; - } - - Shape.prototype.move = function (x, y) { - this.x += x; - this.y += y; - }; - - forIn(new Shape(), function (value, key) { - props.push(key); - }); - - expect(props).toEqual(['x', 'y', 'move']); - }); -}); diff --git a/packages/objects/forOwn/README.md b/packages/objects/forOwn/README.md deleted file mode 100755 index e40a4c89..00000000 --- a/packages/objects/forOwn/README.md +++ /dev/null @@ -1,31 +0,0 @@ - - -## forOwn(obj, [callback]) ⇒ Object - -Iterates over own enumerable properties of an object, executing the callback for each property. -The callback is invoked with three arguments (value, key, object)he callback for each property. - -**Returns**: Object - The original object. - -| Param | Type | Description | -| --- | --- | --- | -| obj | Object | The object to iterate over. | -| [callback] | function | The function called per iteration. | - -**Example** -```js -function Shape() { - this.x = 0; - this.y = 0; -} - -Shape.prototype.move = function (x, y) { - this.x += x; - this.y += y; -}; - -forOwn(new Shape(), function (value, key, obj) { - console.log(key); - // -> "x", "y" -}); -``` diff --git a/packages/objects/forOwn/forOwn.js b/packages/objects/forOwn/forOwn.js deleted file mode 100755 index 4c3dda3d..00000000 --- a/packages/objects/forOwn/forOwn.js +++ /dev/null @@ -1,39 +0,0 @@ -'use strict'; - -/** - * Iterates over own enumerable properties of an object, executing the callback for each property. - * The callback is invoked with three arguments (value, key, object) - * - * @param {Object} obj The object to iterate over. - * @param {function} [callback] The function called per iteration. - * @returns {Object} The original object. - * @example - * - * function Shape() { - * this.x = 0; - * this.y = 0; - * } - * - * Shape.prototype.move = function (x, y) { - * this.x += x; - * this.y += y; - * }; - * - * forOwn(new Shape(), function (value, key, obj) { - * console.log(key); - * // -> "x", "y" - * }); - */ -function forOwn(obj, callback) { - var key; - - for (key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - typeof callback === 'function' && callback(obj[key], key, obj); - } - } - - return obj; -} - -module.exports = forOwn; diff --git a/packages/objects/forOwn/test.js b/packages/objects/forOwn/test.js deleted file mode 100644 index 461c060a..00000000 --- a/packages/objects/forOwn/test.js +++ /dev/null @@ -1,23 +0,0 @@ -var forOwn = require('./forOwn'); - -describe('Object/forOwn', function () { - it('iterates over own enumerable properties of an object', function () { - var props = []; - - function Shape() { - this.x = 0; - this.y = 0; - } - - Shape.prototype.move = function (x, y) { - this.x += x; - this.y += y; - }; - - forOwn(new Shape(), function (value, key) { - props.push(key); - }); - - expect(props).toEqual(['x', 'y']); - }); -}); From 1312e7ae8ce0dc0e3fd1373e9033d6153abf3a46 Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 12:59:38 +0300 Subject: [PATCH 09/17] Convert to ES6 --- packages/objects/get/README.md | 2 +- packages/objects/get/get.js | 10 +++++----- packages/objects/get/test.js | 10 +++++----- packages/objects/omit/README.md | 2 +- packages/objects/omit/omit.js | 10 +++++----- packages/objects/omit/test.js | 4 ++-- packages/objects/pick/README.md | 4 ++-- packages/objects/pick/pick.js | 18 +++++++++--------- packages/objects/pick/test.js | 14 +++++++------- packages/objects/pickBy/README.md | 4 ++-- packages/objects/pickBy/pickBy.js | 16 ++++++++-------- packages/objects/pickBy/test.js | 16 ++++++++-------- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/objects/get/README.md b/packages/objects/get/README.md index 3dbe2f38..4487a913 100644 --- a/packages/objects/get/README.md +++ b/packages/objects/get/README.md @@ -14,7 +14,7 @@ Gets the `value` at path of `object`. If the resolved value is `undefined`, the **Example** ```js -var object = { +const object = { a: [ { b: { diff --git a/packages/objects/get/get.js b/packages/objects/get/get.js index dadd3e38..9982319e 100644 --- a/packages/objects/get/get.js +++ b/packages/objects/get/get.js @@ -9,7 +9,7 @@ * @returns {*} Returns the resolved value. * @example * - * var object = { a: [{ b: { c: 3 } }] }; + * const object = { a: [{ b: { c: 3 } }] }; * * get(object, 'a[0]b.c'); * // -> 3 @@ -23,10 +23,10 @@ * get(object, 'a[1].b.c', 'DEFAULT'); * // -> 'DEFAULT' */ -function get(object, path, defaultValue) { - var keys = String.prototype.split.call(path, /[,[\].]+?/); +const get = (object, path, defaultValue) => { + const keys = String.prototype.split.call(path, /[,[\].]+?/); - var result = keys.reduce(function (accum, key) { + const result = keys.reduce((accum, key) => { if (key) { return accum != null ? accum[key] : void 0; } else { @@ -35,6 +35,6 @@ function get(object, path, defaultValue) { }, object); return result === void 0 || result === object ? defaultValue : result; -} +}; module.exports = get; diff --git a/packages/objects/get/test.js b/packages/objects/get/test.js index 782a7192..11d445a5 100644 --- a/packages/objects/get/test.js +++ b/packages/objects/get/test.js @@ -1,8 +1,8 @@ -var get = require('./get'); +const get = require('./get'); describe('Object/get', function () { it('Gets the value at path of object. If the resolved value is undefined, the "defaultValue" is returned in its place.', function () { - var o1 = { + const o1 = { 'a': [ { 'b': { @@ -12,20 +12,20 @@ describe('Object/get', function () { ] }; - var o2 = { + const o2 = { a: { b: null, c: 'C' } }; - var o3 = { + const o3 = { 0: { 1: 'foo' } }; - var o4 = ['a', 'b']; + const o4 = ['a', 'b']; expect(get(o1, 'a[0].b.c')).toBe(3); expect(get(o1, ['a', '0', 'b', 'c'])).toBe(3); diff --git a/packages/objects/omit/README.md b/packages/objects/omit/README.md index 2d8c7908..911b0576 100644 --- a/packages/objects/omit/README.md +++ b/packages/objects/omit/README.md @@ -13,7 +13,7 @@ Creates an object composed of the own enumerable (not inherited) property paths **Example** ```js -var obj = { +const obj = { a: 'aaa', b: 'bbb', c: 'ccc' diff --git a/packages/objects/omit/omit.js b/packages/objects/omit/omit.js index a9d3fce0..c239cb6f 100644 --- a/packages/objects/omit/omit.js +++ b/packages/objects/omit/omit.js @@ -8,7 +8,7 @@ * @returns {Object} Returns the new object. * @example * - * var obj = { + * const obj = { * a: 'aaa', * b: 'bbb', * c: 'ccc' @@ -29,17 +29,17 @@ * omit(obj, ['key_not_exists']); * // -> { a: 'aaa', b: 'bbb', c: 'ccc' } */ -function omit(obj, props) { +const omit = (obj, props) => { if (!Array.isArray(props) || props.length === 0) { props = []; } - return Object.keys(obj).reduce(function (accum, key) { + return Object.keys(obj).reduce((accum, key) => { if (props.indexOf(key) === -1) { accum[key] = obj[key]; } return accum; }, {}); -} +}; -module.exports = omit; \ No newline at end of file +module.exports = omit; diff --git a/packages/objects/omit/test.js b/packages/objects/omit/test.js index d3fecda7..b0289107 100644 --- a/packages/objects/omit/test.js +++ b/packages/objects/omit/test.js @@ -1,8 +1,8 @@ -var omit = require('./omit'); +const omit = require('./omit'); describe('Object/omit', function () { it('Creates an object composed of the own enumerable property paths of object that are not omitted', function () { - var obj1 = { + const obj1 = { a: 'aaa', b: 'bbb', c: 'ccc' diff --git a/packages/objects/pick/README.md b/packages/objects/pick/README.md index 416e58df..522226d8 100644 --- a/packages/objects/pick/README.md +++ b/packages/objects/pick/README.md @@ -19,7 +19,7 @@ Creates an object composed of the picked object properties. **Example** ```js -var object = Object.create({ +const object = Object.create({ foo: 'bar' }); @@ -37,4 +37,4 @@ pick(object, ['a', 'c', 'foo'], false); pick(object, ['d']); // -> {} -``` \ No newline at end of file +``` diff --git a/packages/objects/pick/pick.js b/packages/objects/pick/pick.js index 6f2e50ec..42514c03 100644 --- a/packages/objects/pick/pick.js +++ b/packages/objects/pick/pick.js @@ -10,7 +10,7 @@ * @returns {Object} Returns the new object. * @example * - * var object = Object.create({ + * const object = Object.create({ * foo: 'bar' * }); * @@ -29,9 +29,9 @@ * pick(object, ['d']); * // -> {} */ -function pick(object, paths, pickOwnKeys) { - var result = {}; - var type = Object.prototype.toString.call(object); +const pick = (object, paths, pickOwnKeys) => { + const result = {}; + const type = Object.prototype.toString.call(object); if ( typeof object !== 'object' @@ -57,9 +57,9 @@ function pick(object, paths, pickOwnKeys) { throw new TypeError('Expected a boolean for third argument'); } - for (var i = 0; i < paths.length; i += 1) { - var key = paths[i]; - var meetsCriteria = pickOwnKeys + for (let i = 0; i < paths.length; i += 1) { + const key = paths[i]; + const meetsCriteria = pickOwnKeys ? Object.prototype.hasOwnProperty.call(object, key) : key in object; @@ -69,6 +69,6 @@ function pick(object, paths, pickOwnKeys) { } return result; -} +}; -module.exports = pick; \ No newline at end of file +module.exports = pick; diff --git a/packages/objects/pick/test.js b/packages/objects/pick/test.js index 8f13d35b..a77364df 100644 --- a/packages/objects/pick/test.js +++ b/packages/objects/pick/test.js @@ -1,8 +1,8 @@ -var pick = require('./pick'); +const pick = require('./pick'); describe('Object/pick', function () { it('creates an object composed of the picked object properties', function () { - var o1 = Object.create({ + const o1 = Object.create({ foo: 'bar' }); @@ -26,13 +26,13 @@ describe('Object/pick', function () { O.prototype.foo = 'bar'; - var o2 = new O(1, 2, 3); + const o2 = new O(1, 2, 3); - expect(pick(o1, ['a', 'c', 'foo'])).toStrictEqual({ a: 1, c: 3 }); - expect(pick(o1, ['a', 'c', 'foo'], false)).toStrictEqual({ a: 1, c: 3, foo: 'bar' }); + expect(pick(o1, ['a', 'c', 'foo'])).toStrictEqual({a: 1, c: 3}); + expect(pick(o1, ['a', 'c', 'foo'], false)).toStrictEqual({a: 1, c: 3, foo: 'bar'}); - expect(pick(o2, ['a', 'c', 'foo'])).toStrictEqual({ a: 1, c: 3 }); - expect(pick(o2, ['a', 'c', 'foo'], false)).toStrictEqual({ a: 1, c: 3, foo: 'bar' }); + expect(pick(o2, ['a', 'c', 'foo'])).toStrictEqual({a: 1, c: 3}); + expect(pick(o2, ['a', 'c', 'foo'], false)).toStrictEqual({a: 1, c: 3, foo: 'bar'}); expect(pick(o1, ['d', 'e'])).toStrictEqual({}); expect(pick(o1, ['d', 'e'], false)).toStrictEqual({}); diff --git a/packages/objects/pickBy/README.md b/packages/objects/pickBy/README.md index ae74bdf8..d75b86d6 100644 --- a/packages/objects/pickBy/README.md +++ b/packages/objects/pickBy/README.md @@ -20,7 +20,7 @@ The predicate is invoked with two arguments: (value, key). **Example** ```js -var object = Object.create({ +const object = Object.create({ e: 5 }); @@ -67,4 +67,4 @@ pickBy(object, function (_, key) { return key === 'd'; // property "d" is not enumerable }); // -> {} -``` \ No newline at end of file +``` diff --git a/packages/objects/pickBy/pickBy.js b/packages/objects/pickBy/pickBy.js index 1d505c51..6c05c8a9 100644 --- a/packages/objects/pickBy/pickBy.js +++ b/packages/objects/pickBy/pickBy.js @@ -11,7 +11,7 @@ * @returns {Object} Returns the new object. * @example * - * var object = Object.create({ + * const object = Object.create({ * e: 5 * }); * @@ -59,9 +59,9 @@ * }); * // -> {} */ -function pickBy(object, predicate, pickOwnKeys) { - var result = {}; - var type = Object.prototype.toString.call(object); +const pickBy = (object, predicate, pickOwnKeys) => { + const result = {}; + const type = Object.prototype.toString.call(object); if ( typeof object !== 'object' @@ -87,8 +87,8 @@ function pickBy(object, predicate, pickOwnKeys) { throw new TypeError('Expected a boolean for third argument'); } - for (var key in object) { - var meetsCriteria = pickOwnKeys + for (const key in object) { + const meetsCriteria = pickOwnKeys ? Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key], key) : predicate(object[key], key); @@ -98,6 +98,6 @@ function pickBy(object, predicate, pickOwnKeys) { } return result; -} +}; -module.exports = pickBy; \ No newline at end of file +module.exports = pickBy; diff --git a/packages/objects/pickBy/test.js b/packages/objects/pickBy/test.js index 162d608e..cfc982f9 100644 --- a/packages/objects/pickBy/test.js +++ b/packages/objects/pickBy/test.js @@ -1,8 +1,8 @@ -var pickBy = require('./pickBy'); +const pickBy = require('./pickBy'); describe('Object/pickBy', function () { it('creates an object composed of the object enumerable properties that predicate returns truthy for', function () { - var o1 = Object.create({ + const o1 = Object.create({ e: 5 }); @@ -33,23 +33,23 @@ describe('Object/pickBy', function () { O.prototype.d = 4; - var o2 = new O(1, '2', 3); + const o2 = new O(1, '2', 3); expect(pickBy(o1, function (value) { return typeof value === 'number'; - })).toStrictEqual({ a: 1, c: 3 }); + })).toStrictEqual({a: 1, c: 3}); expect(pickBy(o1, function (value) { return typeof value === 'number'; - }, false)).toStrictEqual({ a: 1, c: 3, e: 5 }); + }, false)).toStrictEqual({a: 1, c: 3, e: 5}); expect(pickBy(o2, function (value) { return typeof value === 'number'; - })).toStrictEqual({ a: 1, c: 3 }); + })).toStrictEqual({a: 1, c: 3}); expect(pickBy(o2, function (value) { return typeof value === 'number'; - }, false)).toStrictEqual({ a: 1, c: 3, d: 4 }); + }, false)).toStrictEqual({a: 1, c: 3, d: 4}); expect(pickBy(o1, function (value) { return typeof value === 'function'; @@ -61,7 +61,7 @@ describe('Object/pickBy', function () { expect(pickBy(o1, function (_, key) { return key === 'a'; - }, false)).toStrictEqual({ a: 1 }); + }, false)).toStrictEqual({a: 1}); expect(pickBy(o1, function (_, key) { return key === 'd'; From 51904230b610430726bca2f916b0a5cbd40bd1fa Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 13:27:12 +0300 Subject: [PATCH 10/17] Convert to ES6 --- packages/is/isArray/isArray.js | 4 ++-- packages/is/isArray/test.js | 4 ++-- packages/is/isArrayLike/README.md | 6 +++--- packages/is/isArrayLike/isArrayLike.js | 14 +++++++------- packages/is/isArrayLike/test.js | 12 ++++++------ packages/is/isArrayLikeObject/README.md | 6 +++--- packages/is/isArrayLikeObject/isArrayLikeObject.js | 14 +++++++------- packages/is/isArrayLikeObject/test.js | 12 ++++++------ packages/is/isBoolean/isBoolean.js | 2 +- packages/is/isBoolean/test.js | 2 +- packages/is/isDate/isDate.js | 4 ++-- packages/is/isDate/test.js | 2 +- packages/is/isElement/isElement.js | 4 ++-- packages/is/isElement/test.js | 2 +- packages/is/isEmail/isEmail.js | 6 +++--- packages/is/isEmail/test.js | 2 +- packages/is/isEmpty/isEmpty.js | 6 +++--- packages/is/isEmpty/test.js | 8 ++++---- packages/is/isEven/isEven.js | 6 +++--- packages/is/isEven/test.js | 2 +- packages/is/isFalse/isFalse.js | 4 +--- packages/is/isFalse/test.js | 2 +- packages/is/isFalsy/isFalsy.js | 4 +--- packages/is/isFalsy/test.js | 4 ++-- packages/is/isFiniteNum/isFiniteNum.js | 4 ++-- packages/is/isFiniteNum/test.js | 4 ++-- packages/is/isFlatArray/isFlatArray.js | 8 +++----- packages/is/isFlatArray/test.js | 2 +- packages/is/isFunction/isFunction.js | 4 +--- packages/is/isFunction/test.js | 4 ++-- packages/is/isHexColor/isHexColor.js | 4 +--- packages/is/isHexColor/test.js | 2 +- packages/is/isHexadecimal/isHexadecimal.js | 4 +--- packages/is/isHexadecimal/test.js | 2 +- packages/is/isInteger/isInteger.js | 4 ++-- packages/is/isInteger/test.js | 4 ++-- packages/is/isIterable/isIterable.js | 4 ++-- packages/is/isIterable/test.js | 6 +++--- packages/is/isMap/isMap.js | 4 ++-- packages/is/isMap/test.js | 2 +- packages/is/isNaN/isNaN.js | 4 ++-- packages/is/isNaN/test.js | 4 ++-- packages/is/isNull/isNull.js | 4 +--- packages/is/isNull/test.js | 2 +- packages/is/isNullish/isNullish.js | 6 ++---- packages/is/isNullish/test.js | 6 +++--- packages/is/isNumber/isNumber.js | 4 ++-- packages/is/isNumber/test.js | 2 +- packages/is/isObject/isObject.js | 4 ++-- packages/is/isObject/test.js | 2 +- packages/is/isObjectLike/isObjectLike.js | 4 +--- packages/is/isObjectLike/test.js | 2 +- packages/is/isOdd/isOdd.js | 4 ++-- packages/is/isOdd/test.js | 2 +- packages/is/isPlainObject/isPlainObject.js | 6 +++--- packages/is/isPlainObject/test.js | 10 +++++----- packages/is/isPrimitive/isPrimitive.js | 4 ++-- packages/is/isPrimitive/test.js | 2 +- packages/is/isPromise/isPromise.js | 6 +++--- packages/is/isPromise/test.js | 12 ++++++------ packages/is/isRegexp/isRegexp.js | 4 +--- packages/is/isRegexp/test.js | 2 +- packages/is/isSafeInteger/isSafeInteger.js | 6 +++--- packages/is/isSafeInteger/test.js | 4 ++-- packages/is/isSet/isSet.js | 4 ++-- packages/is/isSet/test.js | 2 +- packages/is/isString/isString.js | 4 ++-- packages/is/isString/test.js | 2 +- packages/is/isSymbol/isSymbol.js | 4 ++-- packages/is/isSymbol/test.js | 2 +- packages/is/isTrue/isTrue.js | 4 +--- packages/is/isTrue/test.js | 2 +- packages/is/isTruthy/isTruthy.js | 4 +--- packages/is/isTruthy/test.js | 4 ++-- packages/is/isUndefined/README.md | 2 +- packages/is/isUndefined/isUndefined.js | 6 ++---- packages/is/isUndefined/test.js | 4 ++-- packages/is/isWeakMap/README.md | 2 +- packages/is/isWeakMap/isWeakMap.js | 6 +++--- packages/is/isWeakMap/test.js | 2 +- packages/is/isWeakSet/isWeakSet.js | 4 ++-- packages/is/isWeakSet/test.js | 2 +- 82 files changed, 167 insertions(+), 193 deletions(-) diff --git a/packages/is/isArray/isArray.js b/packages/is/isArray/isArray.js index ffb358d6..e05c7901 100644 --- a/packages/is/isArray/isArray.js +++ b/packages/is/isArray/isArray.js @@ -19,10 +19,10 @@ * isArray({ a: 'a', b: 'b' }); * // -> false */ -function isArray(value) { +const isArray = value => { return Array.isArray ? Array.isArray(value) : Object.prototype.toString.call(value) === '[object Array]'; -} +}; module.exports = isArray; diff --git a/packages/is/isArray/test.js b/packages/is/isArray/test.js index 2ebc8bed..9a676bc6 100644 --- a/packages/is/isArray/test.js +++ b/packages/is/isArray/test.js @@ -1,4 +1,4 @@ -var isArray = require('./isArray'); +const isArray = require('./isArray'); describe('is/isArray', function () { function runTests() { @@ -18,7 +18,7 @@ describe('is/isArray', function () { }); it('checks if value is array (Array.isArray is not supported)', function () { - var nativeCode = Array.isArray; + const nativeCode = Array.isArray; Array.isArray = null; runTests(); Array.isArray = nativeCode; diff --git a/packages/is/isArrayLike/README.md b/packages/is/isArrayLike/README.md index abcbcd78..e73af521 100644 --- a/packages/is/isArrayLike/README.md +++ b/packages/is/isArrayLike/README.md @@ -16,11 +16,11 @@ integer greater than or equal to 0 and less than or equal to `Number.MAX_SAFE_IN ```js function noop() {} -function dummy() { - return arguments; +function dummy(...args) { + return args; } -var args = dummy(); +const args = dummy(); isArrayLike([1, 2, 3])); // -> true diff --git a/packages/is/isArrayLike/isArrayLike.js b/packages/is/isArrayLike/isArrayLike.js index 08a1bb02..6987d505 100644 --- a/packages/is/isArrayLike/isArrayLike.js +++ b/packages/is/isArrayLike/isArrayLike.js @@ -12,11 +12,11 @@ * * function noop() {} * - * function dummy() { - * return arguments; + * function dummy(...args) { + * return args; * } * - * var args = dummy(); + * const args = dummy(); * * isArrayLike([1, 2, 3])); * // -> true @@ -45,9 +45,9 @@ * isArrayLike(args)); * // -> true */ -function isArrayLike(value) { - var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - var len = !!value && value.length; +const isArrayLike = value => { + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const len = !!value && value.length; return value != null && typeof value !== 'function' @@ -55,6 +55,6 @@ function isArrayLike(value) { && len > -1 && len % 1 === 0 && len <= MAX_SAFE_INTEGER; -} +}; module.exports = isArrayLike; diff --git a/packages/is/isArrayLike/test.js b/packages/is/isArrayLike/test.js index 73606608..fd4c5296 100644 --- a/packages/is/isArrayLike/test.js +++ b/packages/is/isArrayLike/test.js @@ -1,14 +1,14 @@ -var isArrayLike = require('./isArrayLike'); +const isArrayLike = require('./isArrayLike'); describe('is/isArrayLike', function () { function noop() {} - function dummy() { - return arguments; + function dummy(...args) { + return args; } it('check if value is array-like', function () { - var args = dummy(); + const args = dummy(); expect(isArrayLike(args)).toBe(true); @@ -18,9 +18,9 @@ describe('is/isArrayLike', function () { expect(isArrayLike(0)).toBe(false); - expect(isArrayLike({ foo: 'bar' })).toBe(false); + expect(isArrayLike({foo: 'bar'})).toBe(false); - expect(isArrayLike({ foo: 'bar', length: 10 })).toBe(true); + expect(isArrayLike({foo: 'bar', length: 10})).toBe(true); expect(isArrayLike(noop)).toBe(false); diff --git a/packages/is/isArrayLikeObject/README.md b/packages/is/isArrayLikeObject/README.md index d597efff..ba906e08 100644 --- a/packages/is/isArrayLikeObject/README.md +++ b/packages/is/isArrayLikeObject/README.md @@ -16,11 +16,11 @@ integer greater than or equal to 0 and less than or equal to `Number.MAX_SAFE_IN ```js function noop() {} -function dummy() { - return arguments; +function dummy(...args) { + return args; } -var args = dummy(); +const args = dummy(); isArrayLikeObject([1, 2, 3])); // -> true diff --git a/packages/is/isArrayLikeObject/isArrayLikeObject.js b/packages/is/isArrayLikeObject/isArrayLikeObject.js index 8756e343..1ad7f4bf 100644 --- a/packages/is/isArrayLikeObject/isArrayLikeObject.js +++ b/packages/is/isArrayLikeObject/isArrayLikeObject.js @@ -12,11 +12,11 @@ * * function noop() {} * - * function dummy() { - * return arguments; + * function dummy(...args) { + * return args; * } * - * var args = dummy(); + * const args = dummy(); * * isArrayLikeObject([1, 2, 3])); * // -> true @@ -45,9 +45,9 @@ * isArrayLikeObject(args)); * // -> true */ -function isArrayLikeObject(value) { - var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; - var len = !!value && value.length; +const isArrayLikeObject = value => { + const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; + const len = !!value && value.length; return value != null && typeof value !== 'function' @@ -56,6 +56,6 @@ function isArrayLikeObject(value) { && len > -1 && len % 1 === 0 && len <= MAX_SAFE_INTEGER; -} +}; module.exports = isArrayLikeObject; diff --git a/packages/is/isArrayLikeObject/test.js b/packages/is/isArrayLikeObject/test.js index 1477b1ba..fc625a26 100644 --- a/packages/is/isArrayLikeObject/test.js +++ b/packages/is/isArrayLikeObject/test.js @@ -1,14 +1,14 @@ -var isArrayLikeObject = require('./isArrayLikeObject'); +const isArrayLikeObject = require('./isArrayLikeObject'); describe('is/isArrayLikeObject', function () { function noop() {} - function dummy() { - return arguments; + function dummy(...args) { + return args; } it('check if value is array-like', function () { - var args = dummy(); + const args = dummy(); expect(isArrayLikeObject(args)).toBe(true); @@ -18,9 +18,9 @@ describe('is/isArrayLikeObject', function () { expect(isArrayLikeObject(0)).toBe(false); - expect(isArrayLikeObject({ foo: 'bar' })).toBe(false); + expect(isArrayLikeObject({foo: 'bar'})).toBe(false); - expect(isArrayLikeObject({ foo: 'bar', length: 10 })).toBe(true); + expect(isArrayLikeObject({foo: 'bar', length: 10})).toBe(true); expect(isArrayLikeObject(noop)).toBe(false); diff --git a/packages/is/isBoolean/isBoolean.js b/packages/is/isBoolean/isBoolean.js index 0779eb37..564f1603 100644 --- a/packages/is/isBoolean/isBoolean.js +++ b/packages/is/isBoolean/isBoolean.js @@ -19,7 +19,7 @@ * isBoolean(null); * // -> false */ -function isBoolean(value) { +const isBoolean = value => { return value === true || value === false || Object.prototype.toString.call(value) === '[object Boolean]'; diff --git a/packages/is/isBoolean/test.js b/packages/is/isBoolean/test.js index 235605da..7b435bab 100644 --- a/packages/is/isBoolean/test.js +++ b/packages/is/isBoolean/test.js @@ -1,4 +1,4 @@ -var isBoolean = require('./isBoolean'); +const isBoolean = require('./isBoolean'); describe('is/isBoolean', function () { it('checks if a value is boolean', function () { diff --git a/packages/is/isDate/isDate.js b/packages/is/isDate/isDate.js index 1d3ce053..451cdd70 100644 --- a/packages/is/isDate/isDate.js +++ b/packages/is/isDate/isDate.js @@ -13,8 +13,8 @@ * isDate(new Date().getTime()); * // -> false */ -function isDate(value) { +const isDate = value => { return Object.prototype.toString.call(value) === '[object Date]'; -} +}; module.exports = isDate; diff --git a/packages/is/isDate/test.js b/packages/is/isDate/test.js index be4751c7..69564aa8 100644 --- a/packages/is/isDate/test.js +++ b/packages/is/isDate/test.js @@ -1,4 +1,4 @@ -var isDate = require('./isDate'); +const isDate = require('./isDate'); describe('is/isDate', function () { it('checks if a value is Date object', function () { diff --git a/packages/is/isElement/isElement.js b/packages/is/isElement/isElement.js index f0a9dde6..16952150 100644 --- a/packages/is/isElement/isElement.js +++ b/packages/is/isElement/isElement.js @@ -16,8 +16,8 @@ * isElement(document.getElementsByTagName('head')[0]) * // -> true */ -function isElement(value) { +const isElement = value => { return !!value && value.nodeType === 1 && value instanceof Element === true; -} +}; module.exports = isElement; diff --git a/packages/is/isElement/test.js b/packages/is/isElement/test.js index e95baad8..92e9ca30 100644 --- a/packages/is/isElement/test.js +++ b/packages/is/isElement/test.js @@ -1,4 +1,4 @@ -var isElement = require('./isElement'); +const isElement = require('./isElement'); describe('is/isElement', function () { it('checks if a value is DOM element', function () { diff --git a/packages/is/isEmail/isEmail.js b/packages/is/isEmail/isEmail.js index f903deb2..7a4a2410 100644 --- a/packages/is/isEmail/isEmail.js +++ b/packages/is/isEmail/isEmail.js @@ -31,7 +31,7 @@ * isEmail("!#$%&'+-/=.?^`{|}~@[IPv6:0123:4567:89AB:CDEF:0123:4567:89AB:CDEF]"); * // -> false */ -function isEmail(value) { +const isEmail = value => { if (typeof value !== 'string') { throw new TypeError('Expected a string for first argument'); } @@ -41,9 +41,9 @@ function isEmail(value) { * http://stackoverflow.com/questions/46155/validate-email-address-in-javascript * @type {RegExp} */ - var emailRegex = /(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; // eslint-disable-line no-control-regex + const emailRegex = /(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/; // eslint-disable-line no-control-regex return emailRegex.test(value); -} +}; module.exports = isEmail; diff --git a/packages/is/isEmail/test.js b/packages/is/isEmail/test.js index 12f18a20..be758659 100644 --- a/packages/is/isEmail/test.js +++ b/packages/is/isEmail/test.js @@ -1,4 +1,4 @@ -var isEmail = require('./isEmail'); +const isEmail = require('./isEmail'); describe('is/isEmail', function () { it('should validate various strings as emails', function () { diff --git a/packages/is/isEmpty/isEmpty.js b/packages/is/isEmpty/isEmpty.js index 98ff3f75..007e2f22 100644 --- a/packages/is/isEmpty/isEmpty.js +++ b/packages/is/isEmpty/isEmpty.js @@ -54,8 +54,8 @@ * isEmpty(null); // -> true * isEmpty(undefined); // -> true */ -function isEmpty(value) { - var type = Object.prototype.toString.call(value); +const isEmpty = value => { + const type = Object.prototype.toString.call(value); if (value == null) { return true; @@ -74,6 +74,6 @@ function isEmpty(value) { } return Object(value) !== value || !Object.keys(value).length; -} +}; module.exports = isEmpty; diff --git a/packages/is/isEmpty/test.js b/packages/is/isEmpty/test.js index 0d6d0675..df82852c 100644 --- a/packages/is/isEmpty/test.js +++ b/packages/is/isEmpty/test.js @@ -1,4 +1,4 @@ -var isEmpty = require('./isEmpty'); +const isEmpty = require('./isEmpty'); describe('is/isEmpty', function () { it('checks if a value is an empty object, collection, map, or set.', function () { @@ -6,13 +6,13 @@ describe('is/isEmpty', function () { expect(isEmpty([1, 2, 3])).toBe(false); expect(isEmpty({})).toBe(true); - expect(isEmpty({ foo: 'bar' })).toBe(false); + expect(isEmpty({foo: 'bar'})).toBe(false); expect(isEmpty(Object.create(null))).toBe(true); expect(isEmpty(Object.create({}))).toBe(true); - expect(isEmpty(Object.create({ foo: 'bar' }))).toBe(true); + expect(isEmpty(Object.create({foo: 'bar'}))).toBe(true); expect(isEmpty(new Map())).toBe(true); - expect(isEmpty((new Map()).set('foo', 'bar'))).toBe(false); + expect(isEmpty(new Map().set('foo', 'bar'))).toBe(false); expect(isEmpty(new Set())).toBe(true); expect(isEmpty(new Set([1, 2, 3]))).toBe(false); diff --git a/packages/is/isEven/isEven.js b/packages/is/isEven/isEven.js index 259881c4..1b44ab31 100644 --- a/packages/is/isEven/isEven.js +++ b/packages/is/isEven/isEven.js @@ -28,12 +28,12 @@ * isEven(); * // -> false */ -function isEven(value) { +const isEven = value => { if (typeof value === 'object' || typeof value === 'undefined') { return false; } return value % 2 === 0; -} +}; -module.exports = isEven; \ No newline at end of file +module.exports = isEven; diff --git a/packages/is/isEven/test.js b/packages/is/isEven/test.js index 26d302b5..8347a796 100644 --- a/packages/is/isEven/test.js +++ b/packages/is/isEven/test.js @@ -1,4 +1,4 @@ -var isEven = require('./isEven'); +const isEven = require('./isEven'); describe('is/isEven', function () { it('checks if value is even', function () { diff --git a/packages/is/isFalse/isFalse.js b/packages/is/isFalse/isFalse.js index 62725dd9..b41e6996 100644 --- a/packages/is/isFalse/isFalse.js +++ b/packages/is/isFalse/isFalse.js @@ -16,8 +16,6 @@ * isFalse(); * // -> false */ -function isFalse(value) { - return value === false; -} +const isFalse = value => value === false; module.exports = isFalse; diff --git a/packages/is/isFalse/test.js b/packages/is/isFalse/test.js index 06c5cfdb..7b4cbe7c 100644 --- a/packages/is/isFalse/test.js +++ b/packages/is/isFalse/test.js @@ -1,4 +1,4 @@ -var isFalse = require('./isFalse'); +const isFalse = require('./isFalse'); describe('is/isFalse', function () { it('checks if a value is false', function () { diff --git a/packages/is/isFalsy/isFalsy.js b/packages/is/isFalsy/isFalsy.js index 8255808b..253ba040 100644 --- a/packages/is/isFalsy/isFalsy.js +++ b/packages/is/isFalsy/isFalsy.js @@ -31,8 +31,6 @@ * isFalsy(NaN); * // -> true */ -function isFalsy(value) { - return !value; -} +const isFalsy = value => !value; module.exports = isFalsy; diff --git a/packages/is/isFalsy/test.js b/packages/is/isFalsy/test.js index 4a608553..8b580367 100644 --- a/packages/is/isFalsy/test.js +++ b/packages/is/isFalsy/test.js @@ -1,4 +1,4 @@ -var isFalsy = require('./isFalsy'); +const isFalsy = require('./isFalsy'); describe('is/isFalsy', function () { it('checks if a value is falsy', function () { @@ -6,7 +6,7 @@ describe('is/isFalsy', function () { expect(isFalsy(' ')).toBe(false); - expect(isFalsy({ foo: 'bar' })).toBe(false); + expect(isFalsy({foo: 'bar'})).toBe(false); expect(isFalsy(false)).toBe(true); diff --git a/packages/is/isFiniteNum/isFiniteNum.js b/packages/is/isFiniteNum/isFiniteNum.js index 8f4f2803..3dc774b0 100644 --- a/packages/is/isFiniteNum/isFiniteNum.js +++ b/packages/is/isFiniteNum/isFiniteNum.js @@ -31,7 +31,7 @@ * isFiniteNum('0'); * // -> false */ -function isFiniteNum(value) { +const isFiniteNum = value => { if (Number.isFinite) { return Number.isFinite(value); } @@ -39,6 +39,6 @@ function isFiniteNum(value) { return value != null && typeof value === 'number' && value !== Infinity && value !== -Infinity && value === value; -} +}; module.exports = isFiniteNum; diff --git a/packages/is/isFiniteNum/test.js b/packages/is/isFiniteNum/test.js index abda9320..1ed11eb1 100644 --- a/packages/is/isFiniteNum/test.js +++ b/packages/is/isFiniteNum/test.js @@ -1,4 +1,4 @@ -var isFiniteNum = require('./isFiniteNum'); +const isFiniteNum = require('./isFiniteNum'); describe('is/isFiniteNum', function () { function runTests() { @@ -24,7 +24,7 @@ describe('is/isFiniteNum', function () { }); it('checks if a value is finite (Number.isFinite is not supported)', function () { - var nativeCode = Number.isFinite; + const nativeCode = Number.isFinite; Number.isFinite = null; runTests(); Number.isFinite = nativeCode; diff --git a/packages/is/isFlatArray/isFlatArray.js b/packages/is/isFlatArray/isFlatArray.js index b8839bf7..fcc26b7d 100644 --- a/packages/is/isFlatArray/isFlatArray.js +++ b/packages/is/isFlatArray/isFlatArray.js @@ -20,20 +20,18 @@ * isFlatArray(new Set()); * // -> false */ -function isFlatArray(value) { - var i, len; - +const isFlatArray = value => { if (!Array.isArray(value)) { return false; } - for (i = 0, len = value.length; i < len; i += 1) { + for (let i = 0; i < value.length; i += 1) { if (Array.isArray(value[i])) { return false; } } return true; -} +}; module.exports = isFlatArray; diff --git a/packages/is/isFlatArray/test.js b/packages/is/isFlatArray/test.js index 8ac55b1d..a9be0dcb 100644 --- a/packages/is/isFlatArray/test.js +++ b/packages/is/isFlatArray/test.js @@ -1,4 +1,4 @@ -var isFlatArray = require('./isFlatArray'); +const isFlatArray = require('./isFlatArray'); describe('is/isFlatArray', function () { it('checks if a value is a flat array', function () { diff --git a/packages/is/isFunction/isFunction.js b/packages/is/isFunction/isFunction.js index fea4de06..56a449d2 100644 --- a/packages/is/isFunction/isFunction.js +++ b/packages/is/isFunction/isFunction.js @@ -15,8 +15,6 @@ * isFunction('This is a test function.'); * // -> false */ -function isFunction(value) { - return typeof value === 'function'; -} +const isFunction = value => typeof value === 'function'; module.exports = isFunction; diff --git a/packages/is/isFunction/test.js b/packages/is/isFunction/test.js index 315d5203..4ffa9f3b 100644 --- a/packages/is/isFunction/test.js +++ b/packages/is/isFunction/test.js @@ -1,4 +1,4 @@ -var isFunction = require('./isFunction'); +const isFunction = require('./isFunction'); describe('is/isFunction', function () { it('checks if a value is function', function () { @@ -19,7 +19,7 @@ describe('is/isFunction', function () { expect(isFunction(genFunc)).toBe(true); expect(isFunction(true)).toBe(false); expect(isFunction(1)).toBe(false); - expect(isFunction({ foo: 'bar' })).toBe(false); + expect(isFunction({foo: 'bar'})).toBe(false); expect(isFunction([1, 2, 3])).toBe(false); expect(isFunction('foo')).toBe(false); expect(isFunction(null)).toBe(false); diff --git a/packages/is/isHexColor/isHexColor.js b/packages/is/isHexColor/isHexColor.js index 3d63597d..9426cf18 100644 --- a/packages/is/isHexColor/isHexColor.js +++ b/packages/is/isHexColor/isHexColor.js @@ -31,8 +31,6 @@ * isHexColor(); * // -> false */ -function isHexColor(value) { - return /^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(value); -} +const isHexColor = value => /^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(value); module.exports = isHexColor; diff --git a/packages/is/isHexColor/test.js b/packages/is/isHexColor/test.js index 9725158e..5ec14c48 100644 --- a/packages/is/isHexColor/test.js +++ b/packages/is/isHexColor/test.js @@ -1,4 +1,4 @@ -var isHexColor = require('./isHexColor'); +const isHexColor = require('./isHexColor'); describe('is/isHexColor', function () { it('checks if a value matches a hexadecimal color regular expression', function () { diff --git a/packages/is/isHexadecimal/isHexadecimal.js b/packages/is/isHexadecimal/isHexadecimal.js index e4618d28..ac326e4c 100644 --- a/packages/is/isHexadecimal/isHexadecimal.js +++ b/packages/is/isHexadecimal/isHexadecimal.js @@ -22,8 +22,6 @@ * isHexadecimal(6.6); * // -> false */ -function isHexadecimal(value) { - return /^[0-9a-fA-F]+$/.test(value); -} +const isHexadecimal = value => /^[0-9a-fA-F]+$/.test(value); module.exports = isHexadecimal; diff --git a/packages/is/isHexadecimal/test.js b/packages/is/isHexadecimal/test.js index 4d2e9eae..853cda23 100644 --- a/packages/is/isHexadecimal/test.js +++ b/packages/is/isHexadecimal/test.js @@ -1,4 +1,4 @@ -var isHexadecimal = require('./isHexadecimal'); +const isHexadecimal = require('./isHexadecimal'); describe('is/isHexadecimal', function () { it('checks if a value is hexadecimal', function () { diff --git a/packages/is/isInteger/isInteger.js b/packages/is/isInteger/isInteger.js index cf07b0f0..a2df343f 100644 --- a/packages/is/isInteger/isInteger.js +++ b/packages/is/isInteger/isInteger.js @@ -41,7 +41,7 @@ * isInteger(Infinity); * // -> false */ -function isInteger(value) { +const isInteger = value => { if (Number.isInteger) { return Number.isInteger(value); } @@ -49,6 +49,6 @@ function isInteger(value) { return (Object.prototype.toString.call(value) === '[object Number]' || typeof value === 'number') && value !== Infinity && value !== -Infinity && Math.floor(value) === value; -} +}; module.exports = isInteger; diff --git a/packages/is/isInteger/test.js b/packages/is/isInteger/test.js index 2db5be45..891e55e6 100644 --- a/packages/is/isInteger/test.js +++ b/packages/is/isInteger/test.js @@ -1,4 +1,4 @@ -var isInteger = require('./isInteger'); +const isInteger = require('./isInteger'); describe('is/isInteger', function () { function runTests() { @@ -28,7 +28,7 @@ describe('is/isInteger', function () { }); it('checks if a value is integer (Number.isInteger is not supported)', function () { - var nativeCode = Number.isInteger; + const nativeCode = Number.isInteger; Number.isInteger = null; runTests(); Number.isInteger = nativeCode; diff --git a/packages/is/isIterable/isIterable.js b/packages/is/isIterable/isIterable.js index 7077072b..505731e4 100644 --- a/packages/is/isIterable/isIterable.js +++ b/packages/is/isIterable/isIterable.js @@ -33,7 +33,7 @@ * isIterable(null); * // -> false */ -function isIterable(value) { +const isIterable = value => { if (typeof Symbol === 'undefined' || !Symbol.iterator) { throw new TypeError('Symbol or Symbol.iterator is not supported by your environment.'); } @@ -43,6 +43,6 @@ function isIterable(value) { } return typeof value[Symbol.iterator] === 'function'; -} +}; module.exports = isIterable; diff --git a/packages/is/isIterable/test.js b/packages/is/isIterable/test.js index 20d15281..d8e20cf5 100644 --- a/packages/is/isIterable/test.js +++ b/packages/is/isIterable/test.js @@ -1,4 +1,4 @@ -var isIterable = require('./isIterable'); +const isIterable = require('./isIterable'); describe('is/isIterable', function () { function* generatorFunc() { @@ -27,7 +27,7 @@ describe('is/isIterable', function () { }); it('should throw `TypeError` if `Symbol` is not supported', function () { - var nativeCode = window.Symbol; + const nativeCode = window.Symbol; window.Symbol = undefined; // emulate `Symbol` not being supported @@ -39,7 +39,7 @@ describe('is/isIterable', function () { }); it('should throw `TypeError` if `Symbol.iterator` is not supported', function () { - var nativeCode = window.Symbol; + const nativeCode = window.Symbol; window.Symbol = {}; // emulate `Symbol.iterator` not being supported diff --git a/packages/is/isMap/isMap.js b/packages/is/isMap/isMap.js index bcccbfc3..2530d26f 100644 --- a/packages/is/isMap/isMap.js +++ b/packages/is/isMap/isMap.js @@ -19,8 +19,8 @@ * isMap({foo: 'bar', 'hello': 'world'}); * // -> false */ -function isMap(value) { +const isMap = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object Map]'; -} +}; module.exports = isMap; diff --git a/packages/is/isMap/test.js b/packages/is/isMap/test.js index 68d31fc6..61b863e4 100644 --- a/packages/is/isMap/test.js +++ b/packages/is/isMap/test.js @@ -1,4 +1,4 @@ -var isMap = require('./isMap'); +const isMap = require('./isMap'); describe('is/isMap', function () { it('checks if a value is Map', function () { diff --git a/packages/is/isNaN/isNaN.js b/packages/is/isNaN/isNaN.js index 2346d537..0bde325a 100644 --- a/packages/is/isNaN/isNaN.js +++ b/packages/is/isNaN/isNaN.js @@ -26,13 +26,13 @@ * isNaN({}); // -> false * isNaN('blabla'); // -> false */ -function isNaN(value) { +const isNaN = value => { if (Number.isNaN) { return Number.isNaN(value); } // NaN is of type "number" and it is also the only primitive value which does not equal itself. return typeof value === 'number' && value !== value; -} +}; module.exports = isNaN; diff --git a/packages/is/isNaN/test.js b/packages/is/isNaN/test.js index a7990c19..18bd602d 100644 --- a/packages/is/isNaN/test.js +++ b/packages/is/isNaN/test.js @@ -1,4 +1,4 @@ -var isNaN = require('./isNaN'); +const isNaN = require('./isNaN'); describe('is/isNaN', function () { function runTests() { @@ -27,7 +27,7 @@ describe('is/isNaN', function () { }); it('check if value is NaN (Number.isNaN is not supported)', function () { - var nativeCode = Number.isNaN; + const nativeCode = Number.isNaN; Number.isNaN = null; runTests(); Number.isNaN = nativeCode; diff --git a/packages/is/isNull/isNull.js b/packages/is/isNull/isNull.js index 16ebcf98..d528e24a 100644 --- a/packages/is/isNull/isNull.js +++ b/packages/is/isNull/isNull.js @@ -19,8 +19,6 @@ * isNull(); * // -> false */ -function isNull(value) { - return value === null; -} +const isNull = value => value === null; module.exports = isNull; diff --git a/packages/is/isNull/test.js b/packages/is/isNull/test.js index fcb2dc12..e0d28ee8 100644 --- a/packages/is/isNull/test.js +++ b/packages/is/isNull/test.js @@ -1,4 +1,4 @@ -var isNull = require('./isNull'); +const isNull = require('./isNull'); describe('is/isNull', function () { it('checks if a valud is null', function () { diff --git a/packages/is/isNullish/isNullish.js b/packages/is/isNullish/isNullish.js index 98b2b952..94581aef 100644 --- a/packages/is/isNullish/isNullish.js +++ b/packages/is/isNullish/isNullish.js @@ -7,7 +7,7 @@ * @return {Boolean} True if the value is `null` or `undefined`; otherwise false. * @example * - * var foo; + * let foo; * * isNullish(foo); * // -> true @@ -21,8 +21,6 @@ * isNullish(); * // -> true */ -function isNullish(value) { - return value == null; -} +const isNullish = value => value == null; module.exports = isNullish; diff --git a/packages/is/isNullish/test.js b/packages/is/isNullish/test.js index b89c7bf8..0380fffb 100644 --- a/packages/is/isNullish/test.js +++ b/packages/is/isNullish/test.js @@ -1,7 +1,7 @@ -var isNullish = require('./isNullish'); +const isNullish = require('./isNullish'); describe('is/isNullish', function () { - var foo; + let foo; it('checks if a value is null or undefined', function () { expect(isNullish()).toBe(true); @@ -10,6 +10,6 @@ describe('is/isNullish', function () { expect(isNullish(null)).toBe(true); - expect(isNullish({ foo: 'bar' })).toBe(false); + expect(isNullish({foo: 'bar'})).toBe(false); }); }); diff --git a/packages/is/isNumber/isNumber.js b/packages/is/isNumber/isNumber.js index 9d971bc7..b46f1a0f 100644 --- a/packages/is/isNumber/isNumber.js +++ b/packages/is/isNumber/isNumber.js @@ -35,8 +35,8 @@ * isNumber(NaN); * // -> true */ -function isNumber(value) { +const isNumber = value => { return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]'; -} +}; module.exports = isNumber; diff --git a/packages/is/isNumber/test.js b/packages/is/isNumber/test.js index 9404fed8..a06ec6f5 100644 --- a/packages/is/isNumber/test.js +++ b/packages/is/isNumber/test.js @@ -1,4 +1,4 @@ -var isNumber = require('./isNumber'); +const isNumber = require('./isNumber'); describe('is/isNumber', function () { it('checks if a value is number', function () { diff --git a/packages/is/isObject/isObject.js b/packages/is/isObject/isObject.js index 6cb14731..4052ff8c 100644 --- a/packages/is/isObject/isObject.js +++ b/packages/is/isObject/isObject.js @@ -56,8 +56,8 @@ * isObject(Symbol('foo')); * // -> false */ -function isObject(value) { +const isObject = value => { return !!value && (typeof value === 'object' || typeof value === 'function'); -} +}; module.exports = isObject; diff --git a/packages/is/isObject/test.js b/packages/is/isObject/test.js index 36f8752f..a2e51c8e 100644 --- a/packages/is/isObject/test.js +++ b/packages/is/isObject/test.js @@ -1,4 +1,4 @@ -var isObject = require('./isObject'); +const isObject = require('./isObject'); describe('is/isObject', function () { it('checks if a value is object', function () { diff --git a/packages/is/isObjectLike/isObjectLike.js b/packages/is/isObjectLike/isObjectLike.js index 9ccd61c0..b3ea5961 100644 --- a/packages/is/isObjectLike/isObjectLike.js +++ b/packages/is/isObjectLike/isObjectLike.js @@ -55,8 +55,6 @@ * isObjectLike(Symbol('foo')); * // -> false */ -function isObjectLike(value) { - return !!value && typeof value === 'object'; -} +const isObjectLike = value => !!value && typeof value === 'object'; module.exports = isObjectLike; diff --git a/packages/is/isObjectLike/test.js b/packages/is/isObjectLike/test.js index 25f72054..4db52d40 100644 --- a/packages/is/isObjectLike/test.js +++ b/packages/is/isObjectLike/test.js @@ -1,4 +1,4 @@ -var isObjectLike = require('./isObjectLike'); +const isObjectLike = require('./isObjectLike'); describe('is/isObjectLike', function () { it('checks if a value is object-like', function () { diff --git a/packages/is/isOdd/isOdd.js b/packages/is/isOdd/isOdd.js index 86df8493..c2972cc9 100644 --- a/packages/is/isOdd/isOdd.js +++ b/packages/is/isOdd/isOdd.js @@ -28,12 +28,12 @@ * isOdd(); * // -> false */ -function isOdd(value) { +const isOdd = value => { if (typeof value === 'object' || typeof value === 'undefined') { return false; } return value % 2 === 1; -} +}; module.exports = isOdd; diff --git a/packages/is/isOdd/test.js b/packages/is/isOdd/test.js index 873c69d1..6df8ea65 100644 --- a/packages/is/isOdd/test.js +++ b/packages/is/isOdd/test.js @@ -1,4 +1,4 @@ -var isOdd = require('./isOdd'); +const isOdd = require('./isOdd'); describe('is/isOdd', function () { it('checks if a value is odd', function () { diff --git a/packages/is/isPlainObject/isPlainObject.js b/packages/is/isPlainObject/isPlainObject.js index bd42e002..42fd8f48 100644 --- a/packages/is/isPlainObject/isPlainObject.js +++ b/packages/is/isPlainObject/isPlainObject.js @@ -49,14 +49,14 @@ * isPlainObject('lorem ipsum'); * // -> false */ -function isPlainObject(value) { +const isPlainObject = value => { if (Object.prototype.toString.call(value) !== '[object Object]') { return false; } - var proto = Object.getPrototypeOf(value); + const proto = Object.getPrototypeOf(value); return proto === null || proto === Object.prototype; -} +}; module.exports = isPlainObject; diff --git a/packages/is/isPlainObject/test.js b/packages/is/isPlainObject/test.js index fea229f5..6ced040a 100644 --- a/packages/is/isPlainObject/test.js +++ b/packages/is/isPlainObject/test.js @@ -1,4 +1,4 @@ -var isPlainObject = require('./isPlainObject'); +const isPlainObject = require('./isPlainObject'); describe('is/isPlainObject', function () { function Foo() { @@ -6,13 +6,13 @@ describe('is/isPlainObject', function () { } it('checks if a valud is plain object', function () { - expect(isPlainObject({ foo: 'bar' })).toBe(true); + expect(isPlainObject({foo: 'bar'})).toBe(true); expect(isPlainObject(Object.create({}))).toBe(false); expect(isPlainObject(Object.create(null))).toBe(true); - expect(isPlainObject(Object.create({ foo: 'bar' }))).toBe(false); + expect(isPlainObject(Object.create({foo: 'bar'}))).toBe(false); expect(isPlainObject(new Foo())).toBe(false); @@ -22,7 +22,7 @@ describe('is/isPlainObject', function () { expect(isPlainObject()).toBe(false); - expect(isPlainObject(new Object({ foo: 'bar' }))).toBe(true); + expect(isPlainObject(new Object({foo: 'bar'}))).toBe(true); expect(isPlainObject(100)).toBe(false); @@ -40,7 +40,7 @@ describe('is/isPlainObject', function () { expect(isPlainObject(Symbol({}))).toBe(false); - expect(isPlainObject(Symbol(new Object({ foo: 'bar' })))).toBe(false); + expect(isPlainObject(Symbol(new Object({foo: 'bar'})))).toBe(false); expect(isPlainObject(Symbol(new Foo()))).toBe(false); }); diff --git a/packages/is/isPrimitive/isPrimitive.js b/packages/is/isPrimitive/isPrimitive.js index e200d768..977b9df0 100644 --- a/packages/is/isPrimitive/isPrimitive.js +++ b/packages/is/isPrimitive/isPrimitive.js @@ -43,12 +43,12 @@ * * isPrimitive(/s+/g); // -> false */ -function isPrimitive(value) { +const isPrimitive = value => { if (typeof value === 'object') { return value === null; } return typeof value !== 'function'; -} +}; module.exports = isPrimitive; diff --git a/packages/is/isPrimitive/test.js b/packages/is/isPrimitive/test.js index 486c29ff..57ca8e24 100644 --- a/packages/is/isPrimitive/test.js +++ b/packages/is/isPrimitive/test.js @@ -1,4 +1,4 @@ -var isPrimitive = require('./isPrimitive'); +const isPrimitive = require('./isPrimitive'); describe('is/isPrimitive', function () { it('checks if value is a primitive data type', function () { diff --git a/packages/is/isPromise/isPromise.js b/packages/is/isPromise/isPromise.js index 6bde5f63..45cad22d 100644 --- a/packages/is/isPromise/isPromise.js +++ b/packages/is/isPromise/isPromise.js @@ -21,10 +21,10 @@ * }); * // -> false */ -function isPromise(value) { +const isPromise = value => { // Checking with `Object.prototype.toString` should be enough for most cases except for the // rare case that a host object's tag is modified via `Symbol.toStringTag`, eg: - // var obj = { + // const obj = { // get [Symbol.toStringTag]() { // return 'Promise'; // } @@ -35,6 +35,6 @@ function isPromise(value) { return Object.prototype.toString.call(value) === '[object Promise]' && typeof value.then === 'function' && typeof value.catch === 'function'; -} +}; module.exports = isPromise; diff --git a/packages/is/isPromise/test.js b/packages/is/isPromise/test.js index f950e79c..8abfa7c4 100644 --- a/packages/is/isPromise/test.js +++ b/packages/is/isPromise/test.js @@ -1,12 +1,12 @@ -var isPromise = require('./isPromise'); +const isPromise = require('./isPromise'); describe('is/isPromise', function () { it('checks if a value is a Promise', function () { function noop() {} - var p1 = new Promise(noop, noop); - var p2 = Promise.resolve('Success'); - var p3 = Promise.reject('Error').catch(noop); + const p1 = new Promise(noop, noop); + const p2 = Promise.resolve('Success'); + const p3 = Promise.reject('Error').catch(noop); expect(isPromise(p1)).toBe(true); expect(isPromise(p2)).toBe(true); @@ -28,13 +28,13 @@ describe('is/isPromise', function () { return Promise.resolve('Success'); })).toBe(false); - var fp1 = { + const fp1 = { get [Symbol.toStringTag]() { return 'Promise'; } }; - var fp2 = { + const fp2 = { get [Symbol.toStringTag]() { return 'Promise'; }, diff --git a/packages/is/isRegexp/isRegexp.js b/packages/is/isRegexp/isRegexp.js index bf869be8..c531e357 100644 --- a/packages/is/isRegexp/isRegexp.js +++ b/packages/is/isRegexp/isRegexp.js @@ -13,8 +13,6 @@ * isRegexp('/^[0-9a-fA-F]+$/'); * // -> false */ -function isRegexp(value) { - return Object.prototype.toString.call(value) === '[object RegExp]'; -} +const isRegexp = value => Object.prototype.toString.call(value) === '[object RegExp]'; module.exports = isRegexp; diff --git a/packages/is/isRegexp/test.js b/packages/is/isRegexp/test.js index 065fe39f..ab997e91 100644 --- a/packages/is/isRegexp/test.js +++ b/packages/is/isRegexp/test.js @@ -1,4 +1,4 @@ -var isRegexp = require('./isRegexp'); +const isRegexp = require('./isRegexp'); describe('is/isRegexp', function () { it('checks if a value is a regular expression', function () { diff --git a/packages/is/isSafeInteger/isSafeInteger.js b/packages/is/isSafeInteger/isSafeInteger.js index c06b31ab..48e0e6a9 100644 --- a/packages/is/isSafeInteger/isSafeInteger.js +++ b/packages/is/isSafeInteger/isSafeInteger.js @@ -35,7 +35,7 @@ * isSafeInteger(3.0)); * // -> true */ -function isSafeInteger(value) { +const isSafeInteger = value => { if (Number.isSafeInteger) { return Number.isSafeInteger(value); } @@ -44,6 +44,6 @@ function isSafeInteger(value) { && Math.round(value) === value && -(Math.pow(2, 53) - 1) <= value && value <= Math.pow(2, 53) - 1; -} +}; -module.exports = isSafeInteger; \ No newline at end of file +module.exports = isSafeInteger; diff --git a/packages/is/isSafeInteger/test.js b/packages/is/isSafeInteger/test.js index 02c51cbd..260c3f32 100644 --- a/packages/is/isSafeInteger/test.js +++ b/packages/is/isSafeInteger/test.js @@ -1,4 +1,4 @@ -var isSafeInteger = require('./isSafeInteger'); +const isSafeInteger = require('./isSafeInteger'); describe('is/isSafeInteger', function () { function runTests() { @@ -26,7 +26,7 @@ describe('is/isSafeInteger', function () { }); it('check if integer number is in the safe range (Number.isSafeInteger is not supported)', function () { - var nativeCode = Number.isSafeInteger; + const nativeCode = Number.isSafeInteger; Number.isSafeInteger = null; runTests(); Number.isSafeInteger = nativeCode; diff --git a/packages/is/isSet/isSet.js b/packages/is/isSet/isSet.js index 722a458c..9c3371f9 100644 --- a/packages/is/isSet/isSet.js +++ b/packages/is/isSet/isSet.js @@ -13,8 +13,8 @@ * isSet(new WeakSet()); * // -> false */ -function isSet(value) { +const isSet = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object Set]'; -} +}; module.exports = isSet; diff --git a/packages/is/isSet/test.js b/packages/is/isSet/test.js index 5c01c986..2c088cbe 100644 --- a/packages/is/isSet/test.js +++ b/packages/is/isSet/test.js @@ -1,4 +1,4 @@ -var isSet = require('./isSet'); +const isSet = require('./isSet'); describe('is/isSet', function () { it('checks if a value is WeakMap', function () { diff --git a/packages/is/isString/isString.js b/packages/is/isString/isString.js index dd3bba69..c4cf0f0a 100644 --- a/packages/is/isString/isString.js +++ b/packages/is/isString/isString.js @@ -19,8 +19,8 @@ * isString({ a: 'a', b: 'b' }); * // -> false */ -function isString(value) { +const isString = value => { return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]'; -} +}; module.exports = isString; diff --git a/packages/is/isString/test.js b/packages/is/isString/test.js index 306380fd..7f0ac6c0 100644 --- a/packages/is/isString/test.js +++ b/packages/is/isString/test.js @@ -1,4 +1,4 @@ -var isString = require('./isString'); +const isString = require('./isString'); describe('is/isString', function () { it('checks if a value is string', function () { diff --git a/packages/is/isSymbol/isSymbol.js b/packages/is/isSymbol/isSymbol.js index 87e35d2c..91603330 100644 --- a/packages/is/isSymbol/isSymbol.js +++ b/packages/is/isSymbol/isSymbol.js @@ -22,8 +22,8 @@ * isSymbol('foo'); * // -> false */ -function isSymbol(value) { +const isSymbol = value => { return typeof value === 'symbol' || Object.prototype.toString.call(value) === '[object Symbol]'; -} +}; module.exports = isSymbol; diff --git a/packages/is/isSymbol/test.js b/packages/is/isSymbol/test.js index e727fa4a..2f84fc55 100644 --- a/packages/is/isSymbol/test.js +++ b/packages/is/isSymbol/test.js @@ -1,4 +1,4 @@ -var isSymbol = require('./isSymbol'); +const isSymbol = require('./isSymbol'); describe('is/isSymbol', function () { it('checks if a value is classified as a Symbol primitive', function () { diff --git a/packages/is/isTrue/isTrue.js b/packages/is/isTrue/isTrue.js index cb8855bf..97bc8e02 100644 --- a/packages/is/isTrue/isTrue.js +++ b/packages/is/isTrue/isTrue.js @@ -16,8 +16,6 @@ * isTrue(); * // -> false */ -function isTrue(value) { - return value === true; -} +const isTrue = value => value === true; module.exports = isTrue; diff --git a/packages/is/isTrue/test.js b/packages/is/isTrue/test.js index edda803a..91a127ef 100644 --- a/packages/is/isTrue/test.js +++ b/packages/is/isTrue/test.js @@ -1,4 +1,4 @@ -var isTrue = require('./isTrue'); +const isTrue = require('./isTrue'); describe('is/isTrue', function () { it('checks if a valud is true', function () { diff --git a/packages/is/isTruthy/isTruthy.js b/packages/is/isTruthy/isTruthy.js index 7b1ccc70..e1932c01 100644 --- a/packages/is/isTruthy/isTruthy.js +++ b/packages/is/isTruthy/isTruthy.js @@ -31,8 +31,6 @@ * isTruthy(NaN); * // -> false */ -function isTruthy(value) { - return !!value; -} +const isTruthy = value => !!value; module.exports = isTruthy; diff --git a/packages/is/isTruthy/test.js b/packages/is/isTruthy/test.js index ed020387..8986fe23 100644 --- a/packages/is/isTruthy/test.js +++ b/packages/is/isTruthy/test.js @@ -1,4 +1,4 @@ -var isTruthy = require('./isTruthy'); +const isTruthy = require('./isTruthy'); describe('is/isTruthy', function () { it('checks if a value is truthy', function () { @@ -6,7 +6,7 @@ describe('is/isTruthy', function () { expect(isTruthy(' ')).toBe(true); - expect(isTruthy({ foo: 'bar' })).toBe(true); + expect(isTruthy({foo: 'bar'})).toBe(true); expect(isTruthy(false)).toBe(false); diff --git a/packages/is/isUndefined/README.md b/packages/is/isUndefined/README.md index 2909276d..1b335ddc 100644 --- a/packages/is/isUndefined/README.md +++ b/packages/is/isUndefined/README.md @@ -11,7 +11,7 @@ Checks if a value is `undefined`. **Example** ```js -var foo; +let foo; isUndefined(foo); // -> true diff --git a/packages/is/isUndefined/isUndefined.js b/packages/is/isUndefined/isUndefined.js index a5231ea3..ed0016c6 100644 --- a/packages/is/isUndefined/isUndefined.js +++ b/packages/is/isUndefined/isUndefined.js @@ -7,7 +7,7 @@ * @return {Boolean} True if the value is `undefined`, else false. * @example * - * var foo; + * let foo; * * isUndefined(foo); * // -> true @@ -21,8 +21,6 @@ * isUndefined(); * // -> true */ -function isUndefined(value) { - return typeof value === 'undefined'; -} +const isUndefined = value => typeof value === 'undefined'; module.exports = isUndefined; diff --git a/packages/is/isUndefined/test.js b/packages/is/isUndefined/test.js index 58281215..8146d37d 100644 --- a/packages/is/isUndefined/test.js +++ b/packages/is/isUndefined/test.js @@ -1,7 +1,7 @@ -var isUndefined = require('./isUndefined'); +const isUndefined = require('./isUndefined'); describe('is/isUndefined', function () { - var foo; + let foo; it('checks if a value is undefined', function () { expect(isUndefined()).toBe(true); diff --git a/packages/is/isWeakMap/README.md b/packages/is/isWeakMap/README.md index 702ef393..78390eca 100644 --- a/packages/is/isWeakMap/README.md +++ b/packages/is/isWeakMap/README.md @@ -17,7 +17,7 @@ isWeakMap(new WeakMap()); isWeakMap(new Map()); // -> false -var obj = { +const obj = { foo: 'bar' }; diff --git a/packages/is/isWeakMap/isWeakMap.js b/packages/is/isWeakMap/isWeakMap.js index 09506185..acb20bb0 100644 --- a/packages/is/isWeakMap/isWeakMap.js +++ b/packages/is/isWeakMap/isWeakMap.js @@ -13,7 +13,7 @@ * isWeakMap(new Map()); * // -> false * - * var obj = { + * const obj = { * foo: 'bar' * }; * @@ -23,8 +23,8 @@ * isWeakMap([['foo', 'bar'], ['hello', 'world']]); * // -> false */ -function isWeakMap(value) { +const isWeakMap = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object WeakMap]'; -} +}; module.exports = isWeakMap; diff --git a/packages/is/isWeakMap/test.js b/packages/is/isWeakMap/test.js index 044781b8..5c994ed5 100644 --- a/packages/is/isWeakMap/test.js +++ b/packages/is/isWeakMap/test.js @@ -1,4 +1,4 @@ -var isWeakMap = require('./isWeakMap'); +const isWeakMap = require('./isWeakMap'); describe('is/isWeakMap', function () { it('checks if a value is WeakMap', function () { diff --git a/packages/is/isWeakSet/isWeakSet.js b/packages/is/isWeakSet/isWeakSet.js index d650c7b4..a88512b9 100644 --- a/packages/is/isWeakSet/isWeakSet.js +++ b/packages/is/isWeakSet/isWeakSet.js @@ -13,8 +13,8 @@ * isWeakSet(new Set()); * // -> false */ -function isWeakSet(value) { +const isWeakSet = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object WeakSet]'; -} +}; module.exports = isWeakSet; diff --git a/packages/is/isWeakSet/test.js b/packages/is/isWeakSet/test.js index 35a5b308..3c95c529 100644 --- a/packages/is/isWeakSet/test.js +++ b/packages/is/isWeakSet/test.js @@ -1,4 +1,4 @@ -var isWeakSet = require('./isWeakSet'); +const isWeakSet = require('./isWeakSet'); describe('is/isWeakSet', function () { it('checks if a value is WeakMap', function () { From c792f40debc3bc9769cc42d87400cc7f398e684a Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 14:39:11 +0300 Subject: [PATCH 11/17] Convert to ES6 --- README.md | 2 - packages/arrays/dropWhile/dropWhile.js | 2 +- packages/dom/preloadImages/README.md | 2 +- packages/is/isNullish/README.md | 2 +- packages/math/roundToPlaces/README.md | 2 +- packages/strings/camelCase/camelCase.js | 17 ++--- packages/strings/camelCase/test.js | 2 +- packages/strings/capitalize/capitalize.js | 10 +-- packages/strings/capitalize/test.js | 2 +- packages/strings/classnames/README.md | 2 +- packages/strings/classnames/classnames.js | 21 +++--- packages/strings/classnames/test.js | 52 ++++++------- .../collapseWhitespace/collapseWhitespace.js | 6 +- packages/strings/collapseWhitespace/test.js | 2 +- packages/strings/deburr/README.md | 5 +- packages/strings/deburr/deburr.js | 24 +++--- packages/strings/deburr/test.js | 4 +- packages/strings/escapeHTML/escapeHTML.js | 14 ++-- packages/strings/escapeHTML/test.js | 2 +- packages/strings/kebabCase/kebabCase.js | 17 ++--- packages/strings/kebabCase/test.js | 2 +- packages/strings/lines/README.md | 4 +- packages/strings/lines/lines.js | 10 +-- packages/strings/lines/test.js | 4 +- packages/strings/numberFormat/numberFormat.js | 14 ++-- packages/strings/numberFormat/test.js | 2 +- packages/strings/pascalCase/pascalCase.js | 10 +-- packages/strings/pascalCase/test.js | 2 +- packages/strings/randomString/README.md | 6 +- packages/strings/randomString/randomString.js | 29 ++++--- packages/strings/randomString/test.js | 4 +- packages/strings/removePrefix/removePrefix.js | 6 +- packages/strings/removePrefix/test.js | 2 +- packages/strings/removeSuffix/removeSuffix.js | 10 +-- packages/strings/removeSuffix/test.js | 2 +- packages/strings/snakeCase/snakeCase.js | 17 ++--- packages/strings/snakeCase/test.js | 2 +- packages/strings/squash/squash.js | 6 +- packages/strings/squash/test.js | 4 +- packages/strings/strip/README.md | 4 +- packages/strings/strip/strip.js | 19 ++--- packages/strings/strip/test.js | 4 +- packages/strings/stripHTML/README.md | 2 +- packages/strings/stripHTML/stripHTML.js | 8 +- packages/strings/stripHTML/test.js | 4 +- packages/strings/stripPunctuation/README.md | 2 +- .../stripPunctuation/stripPunctuation.js | 10 +-- packages/strings/stripPunctuation/test.js | 10 +-- .../strings/substringAfter/substringAfter.js | 6 +- packages/strings/substringAfter/test.js | 4 +- .../substringBefore/substringBefore.js | 6 +- packages/strings/substringBefore/test.js | 4 +- packages/strings/supplant/README.md | 48 ------------ packages/strings/supplant/supplant.js | 75 ------------------- packages/strings/supplant/test.js | 46 ------------ packages/strings/truncate/README.md | 2 +- packages/strings/truncate/test.js | 10 ++- packages/strings/truncate/truncate.js | 23 +++--- packages/strings/unescapeHTML/test.js | 2 +- packages/strings/unescapeHTML/unescapeHTML.js | 6 +- packages/strings/words/test.js | 2 +- packages/strings/words/words.js | 8 +- packages/strings/wrapHTML/README.md | 32 -------- packages/strings/wrapHTML/test.js | 27 ------- packages/strings/wrapHTML/wrapHTML.js | 58 -------------- 65 files changed, 218 insertions(+), 530 deletions(-) delete mode 100644 packages/strings/supplant/README.md delete mode 100644 packages/strings/supplant/supplant.js delete mode 100644 packages/strings/supplant/test.js delete mode 100644 packages/strings/wrapHTML/README.md delete mode 100644 packages/strings/wrapHTML/test.js delete mode 100644 packages/strings/wrapHTML/wrapHTML.js diff --git a/README.md b/README.md index fb588f6e..bcd45341 100755 --- a/README.md +++ b/README.md @@ -61,11 +61,9 @@ A collection of dependency-free JavaScript utility functions. |[stripPunctuation](https://github.com/georapbox/js-utils/tree/master/packages/strings/stripPunctuation)|Returns a new string with all of punctuation removed.| |[substringAfter](https://github.com/georapbox/js-utils/tree/master/packages/strings/substringAfter)|Returns a substring after a specific sequence of character(s).| |[substringBefore](https://github.com/georapbox/js-utils/tree/master/packages/strings/substringBefore)|Returns a substring before a specific sequence of character(s).| -|[supplant](https://github.com/georapbox/js-utils/tree/master/packages/strings/supplant)|supplant() does variable substitution on a string. It scans through the string looking for expressions enclosed in {{ }} braces. If an expression is found, use it as a key on the object, and if the key has a string value or number value, it is substituted for the bracket expression and it repeats.| |[truncate](https://github.com/georapbox/js-utils/tree/master/packages/strings/truncate)|Truncates a string based on character count.| |[unescapeHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/unescapeHTML)|Unescapes a HTML string.| |[words](https://github.com/georapbox/js-utils/tree/master/packages/strings/words)|Splits string into an array of its words.| -|[wrapHTML](https://github.com/georapbox/js-utils/tree/master/packages/strings/wrapHTML)|Wraps a string with a HTML tag with attributes if specified.| ## Object diff --git a/packages/arrays/dropWhile/dropWhile.js b/packages/arrays/dropWhile/dropWhile.js index 1365e307..139953a2 100644 --- a/packages/arrays/dropWhile/dropWhile.js +++ b/packages/arrays/dropWhile/dropWhile.js @@ -11,7 +11,7 @@ * @return {Array} The slice of the array. * @example * - * var books = [ + * const books = [ * {title: 'Javascript Design Patterns', read: false}, * {title: 'Programming Javascript Applications', read: false}, * {title: 'JavaScript The Good Parts', read: true}, diff --git a/packages/dom/preloadImages/README.md b/packages/dom/preloadImages/README.md index 49477e71..5ff4bff1 100644 --- a/packages/dom/preloadImages/README.md +++ b/packages/dom/preloadImages/README.md @@ -17,7 +17,7 @@ Load images to browser asynchronously so that can be cached. **Example** ```js -var images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; +const images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; function success(data) { console.log(data.currentImage.src, 'loaded'); diff --git a/packages/is/isNullish/README.md b/packages/is/isNullish/README.md index 119943e6..1fd4692f 100644 --- a/packages/is/isNullish/README.md +++ b/packages/is/isNullish/README.md @@ -11,7 +11,7 @@ Checks if value is `null` or `undefined`. **Example** ```js -var foo; +let foo; isNullish(foo); // -> true diff --git a/packages/math/roundToPlaces/README.md b/packages/math/roundToPlaces/README.md index ca4d3d5c..10f49c92 100644 --- a/packages/math/roundToPlaces/README.md +++ b/packages/math/roundToPlaces/README.md @@ -17,7 +17,7 @@ Feed with negative place values to round to powers of 10. **Example** ```js -var PI = Math.PI +const PI = Math.PI // -> 3.141592653589793 roundToPlaces(PI, 0); diff --git a/packages/strings/camelCase/camelCase.js b/packages/strings/camelCase/camelCase.js index 7a0296cf..5c941d69 100755 --- a/packages/strings/camelCase/camelCase.js +++ b/packages/strings/camelCase/camelCase.js @@ -39,22 +39,21 @@ * camelCase(' () @#$ @# @the quick brown fox jumps over the lazy dog #!#$% <> '); * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' */ -function camelCase(subjectString) { +const camelCase = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; - var words = subjectString.split(wordSeparatorRegexp); - - return words.filter(Boolean).reduce(function (accum, word, index) { - var firstChar = word.substring(0, 1); - var restChars = word.substring(1); - var tempStr = index === 0 ? firstChar.toLowerCase() + restChars : firstChar.toUpperCase() + restChars; + const wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; + const words = subjectString.split(wordSeparatorRegexp); + return words.filter(Boolean).reduce((accum, word, index) => { + const firstChar = word.substring(0, 1); + const restChars = word.substring(1); + const tempStr = index === 0 ? firstChar.toLowerCase() + restChars : firstChar.toUpperCase() + restChars; return accum + tempStr; }, ''); -} +}; module.exports = camelCase; diff --git a/packages/strings/camelCase/test.js b/packages/strings/camelCase/test.js index 0ead38ab..26dc7e54 100644 --- a/packages/strings/camelCase/test.js +++ b/packages/strings/camelCase/test.js @@ -1,4 +1,4 @@ -var camelCase = require('./camelCase'); +const camelCase = require('./camelCase'); describe('String/camel case', function () { it('should convert string to camelCase', function () { diff --git a/packages/strings/capitalize/capitalize.js b/packages/strings/capitalize/capitalize.js index 2068b10a..8c27c699 100755 --- a/packages/strings/capitalize/capitalize.js +++ b/packages/strings/capitalize/capitalize.js @@ -18,20 +18,18 @@ * capitalize('hElLo', true); * // -> 'Hello' */ -function capitalize(subjectString, lowerCaseRest) { - var firstChar, restStr; - +const capitalize = (subjectString, lowerCaseRest = false) => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } - firstChar = subjectString.substring(0, 1).toUpperCase(); + const firstChar = subjectString.substring(0, 1).toUpperCase(); - restStr = lowerCaseRest === true + const restStr = lowerCaseRest === true ? subjectString.substring(1).toLocaleLowerCase() : subjectString.substring(1); return firstChar + restStr; -} +}; module.exports = capitalize; diff --git a/packages/strings/capitalize/test.js b/packages/strings/capitalize/test.js index 786bef91..105d79d4 100644 --- a/packages/strings/capitalize/test.js +++ b/packages/strings/capitalize/test.js @@ -1,4 +1,4 @@ -var capitalize = require('./capitalize'); +const capitalize = require('./capitalize'); describe('String/capitalize', function () { it('should capitalize the first character of a string', function () { diff --git a/packages/strings/classnames/README.md b/packages/strings/classnames/README.md index cb6891fb..0bdc5f2e 100644 --- a/packages/strings/classnames/README.md +++ b/packages/strings/classnames/README.md @@ -7,7 +7,7 @@ Creates a string by conditionally joining classNames together. | Param | Type | Description | | --- | --- | --- | -| ...arguments | ...string\|...object | List of classes to be joined. Falsy arguments or arguments of unsupported type are ignored. | +| ...args | ...string\|...object | List of classes to be joined. Falsy arguments or arguments of unsupported type are ignored. | **Example** ```js diff --git a/packages/strings/classnames/classnames.js b/packages/strings/classnames/classnames.js index bef181be..06e9ff71 100644 --- a/packages/strings/classnames/classnames.js +++ b/packages/strings/classnames/classnames.js @@ -3,7 +3,7 @@ /** * Creates a string by conditionally joining classNames together. * - * @param {...string|...object} ...arguments List of classes to be joined. Falsy arguments or arguments of unsupported type are ignored. + * @param {...string|...object} ...args List of classes to be joined. Falsy arguments or arguments of unsupported type are ignored. * @returns {string} Returns the final concatenated string. * @example * @@ -25,18 +25,17 @@ * classnames('foo', 0, false, undefined, null, { bar: 1 }, NaN, { baz: 0 }); // falsy values are ignored * // -> 'foo bar' */ -function classnames(/* ...arguments */) { - var argsLength = arguments.length; - var separator = ' '; - var result = ''; - var i, key, arg; +const classnames = (...args) => { + const len = args.length; + const separator = ' '; + let result = ''; - if (!argsLength) { + if (!len) { return result; } - for (i = 0; i < argsLength; i += 1) { - arg = arguments[i]; + for (let i = 0; i < len; i += 1) { + const arg = args[i]; if (!arg) { continue; @@ -45,7 +44,7 @@ function classnames(/* ...arguments */) { if (typeof arg === 'string') { result += (result ? separator : '') + arg; } else if (typeof arg === 'object' && Object.prototype.toString.call(arg) === '[object Object]') { - for (key in arg) { + for (const key in arg) { if (Object.prototype.hasOwnProperty.call(arg, key) && arg[key]) { result += (result ? separator : '') + key; } @@ -54,6 +53,6 @@ function classnames(/* ...arguments */) { } return result; -} +}; module.exports = classnames; diff --git a/packages/strings/classnames/test.js b/packages/strings/classnames/test.js index 6fc669ac..353a67a8 100644 --- a/packages/strings/classnames/test.js +++ b/packages/strings/classnames/test.js @@ -1,4 +1,4 @@ -var classnames = require('./classnames'); +const classnames = require('./classnames'); describe('String/classnames', function () { it('returns empty string if no arguments passed', function () { @@ -15,10 +15,10 @@ describe('String/classnames', function () { }); it ('should ignore arguments of unsupported types', function () { - var res = classnames( + const res = classnames( 'foo', - { bar: true }, - [{ baz: true }], + {bar: true}, + [{baz: true}], [], 100, Symbol('foo-bar'), @@ -32,10 +32,10 @@ describe('String/classnames', function () { }); it ('combines mixed arguments (strings, objects)', function () { - var res = classnames( + const res = classnames( 'a', 'b', - { 'c': true }, - { 'd': false }, + {'c': true}, + {'d': false}, 'e', 'f' ); @@ -43,7 +43,7 @@ describe('String/classnames', function () { }); it('it joins the classes if an object is passed with multiple keys', function () { - var res = classnames({ + const res = classnames({ foo: true, bar: true }); @@ -53,23 +53,23 @@ describe('String/classnames', function () { }); it('all falsy values are ignored', function () { - var res = classnames( - { 'null': null }, - { 'undefined': void 0 }, - { 'empty-string': '' }, - { 'non-empty-string': 'foo' }, - { 'white-space': ' ' }, - { 'function': function () {} }, - { 'empty-object': {} }, - { 'non-empty-bject': { foo: 'bar' } }, - { 'empty-array': [] }, - { 'non-empty-array': ['foo', 'bar'] }, - { '1': 1 }, - { '0': 0 }, - { '-0': -0 }, - { 'NaN': NaN }, - { 'false': false }, - { 'true': true }, + const res = classnames( + {'null': null}, + {'undefined': void 0}, + {'empty-string': ''}, + {'non-empty-string': 'foo'}, + {'white-space': ' '}, + {'function': function () {}}, + {'empty-object': {}}, + {'non-empty-bject': {foo: 'bar'}}, + {'empty-array': []}, + {'non-empty-array': ['foo', 'bar']}, + {'1': 1}, + {'0': 0}, + {'-0': -0}, + {'NaN': NaN}, + {'false': false}, + {'true': true}, 'Yes, this is a long and strange string.', 0, -0, @@ -80,7 +80,7 @@ describe('String/classnames', function () { NaN ); - var expected = 'non-empty-string white-space function empty-object non-empty-bject empty-array non-empty-array 1 true Yes, this is a long and strange string.'; + const expected = 'non-empty-string white-space function empty-object non-empty-bject empty-array non-empty-array 1 true Yes, this is a long and strange string.'; expect(res).toBe(expected); }); diff --git a/packages/strings/collapseWhitespace/collapseWhitespace.js b/packages/strings/collapseWhitespace/collapseWhitespace.js index cdd4aeff..c42408ec 100644 --- a/packages/strings/collapseWhitespace/collapseWhitespace.js +++ b/packages/strings/collapseWhitespace/collapseWhitespace.js @@ -11,12 +11,12 @@ * collapseWhitespace(' Lorem \t ispum dolor sit \t amet. '); * // -> 'Lorem ispum dolor sit amet.' */ -function collapseWhitespace(subjectString) { +const collapseWhitespace = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } return subjectString.replace(/[\s\xa0]+/g, ' ').replace(/^\s+|\s+$/g, ''); -} +}; -module.exports = collapseWhitespace; \ No newline at end of file +module.exports = collapseWhitespace; diff --git a/packages/strings/collapseWhitespace/test.js b/packages/strings/collapseWhitespace/test.js index 4a218d1a..51a7f291 100644 --- a/packages/strings/collapseWhitespace/test.js +++ b/packages/strings/collapseWhitespace/test.js @@ -1,4 +1,4 @@ -var collapseWhitespace = require('./collapseWhitespace'); +const collapseWhitespace = require('./collapseWhitespace'); describe('String/collapseWhitespace', function () { it('Converts all adjacent whitespace characters to a single space.', function () { diff --git a/packages/strings/deburr/README.md b/packages/strings/deburr/README.md index c1e9ac1d..3f984fba 100644 --- a/packages/strings/deburr/README.md +++ b/packages/strings/deburr/README.md @@ -1,8 +1,7 @@ ## deburr(subjectString) ⇒ String -Deburrs a string by converting latin-1 supplementary letters to -basic latin letters and removing combining diacritical marks. +Deburrs a string by converting latin-1 supplementary letters to basic latin letters and removing combining diacritical marks. **Returns**: String - The deburred string. **Throws**: @@ -17,7 +16,7 @@ basic latin letters and removing combining diacritical marks. **Example** ```js -var str = 'Maître Corbeau, sur un arbre perché,' + +const str = 'Maître Corbeau, sur un arbre perché,' + 'Tenait en son bec un fromage.' + 'Maître Renard, par l’odeur alléché,' + 'Lui tint à peu près ce langage.'; diff --git a/packages/strings/deburr/deburr.js b/packages/strings/deburr/deburr.js index 4acbf9cc..f03831e4 100644 --- a/packages/strings/deburr/deburr.js +++ b/packages/strings/deburr/deburr.js @@ -11,7 +11,7 @@ * @return {String} The deburred string. * @example * - * var str = 'Maître Corbeau, sur un arbre perché,' + + * const str = 'Maître Corbeau, sur un arbre perché,' + * 'Tenait en son bec un fromage.' + * 'Maître Renard, par l’odeur alléché,' + * 'Lui tint à peu près ce langage.'; @@ -22,18 +22,16 @@ * deburr('déjà vu'); * // -> 'deja vu' */ -function deburr(subjectString) { - var reLatin1, deburredLetters, rsCombo, reComboMark; - +const deburr = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } // Used to match latin-1 supplementary letters (excluding mathematical operators). - reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; + const reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; // Used to map latin-1 supplementary letters to basic latin letters. - deburredLetters = { + const deburredLetters = { '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', '\xc7': 'C', '\xe7': 'c', @@ -54,15 +52,15 @@ function deburr(subjectString) { }; // Used to compose unicode capture groups. - rsCombo = ['\\u0300-\\u036f\\ufe20-\\ufe23', '\\u20d0-\\u20f0']; + const rsCombo = ['\\u0300-\\u036f\\ufe20-\\ufe23', '\\u20d0-\\u20f0']; // Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and // [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). - reComboMark = RegExp(rsCombo, 'g'); + const reComboMark = RegExp(rsCombo, 'g'); - return subjectString.replace(reLatin1, function deburrLetter(letter) { - return deburredLetters[letter]; - }).replace(reComboMark, ''); -} + return subjectString + .replace(reLatin1, letter => deburredLetters[letter]) + .replace(reComboMark, ''); +}; -module.exports = deburr; \ No newline at end of file +module.exports = deburr; diff --git a/packages/strings/deburr/test.js b/packages/strings/deburr/test.js index 71a675b5..67086947 100644 --- a/packages/strings/deburr/test.js +++ b/packages/strings/deburr/test.js @@ -1,8 +1,8 @@ -var deburr = require('./deburr'); +const deburr = require('./deburr'); describe('String/deburr', function () { it('deburrs a string by converting latin-1 supplementary letters to basic latin letters and removing combining diacritical marks', function () { - var str = 'Maître Corbeau, sur un arbre perché,' + const str = 'Maître Corbeau, sur un arbre perché,' + 'Tenait en son bec un fromage.' + 'Maître Renard, par l’odeur alléché,' + 'Lui tint à peu près ce langage.'; diff --git a/packages/strings/escapeHTML/escapeHTML.js b/packages/strings/escapeHTML/escapeHTML.js index 81c8652f..d6f206e2 100755 --- a/packages/strings/escapeHTML/escapeHTML.js +++ b/packages/strings/escapeHTML/escapeHTML.js @@ -17,14 +17,12 @@ * escapeHTML('

lorem ipsum

'); * // -> '<p data-id="1">lorem ipsum</p>' */ -function escapeHTML(subjectString) { - var entityMap; - +const escapeHTML = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } - entityMap = { + const entityMap = { '&': '&', '<': '<', '>': '>', @@ -35,9 +33,7 @@ function escapeHTML(subjectString) { '=': '=' }; - return subjectString.replace(/[&<>"'`=/]/g, function fromEntityMap(tag) { - return entityMap[tag] || tag; - }); -} + return subjectString.replace(/[&<>"'`=/]/g, tag => entityMap[tag] || tag); +}; -module.exports = escapeHTML; \ No newline at end of file +module.exports = escapeHTML; diff --git a/packages/strings/escapeHTML/test.js b/packages/strings/escapeHTML/test.js index 3f09a67c..71416351 100644 --- a/packages/strings/escapeHTML/test.js +++ b/packages/strings/escapeHTML/test.js @@ -1,4 +1,4 @@ -var escapeHTML = require('./escapeHTML'); +const escapeHTML = require('./escapeHTML'); describe('String/escapeHTML', function () { it('should escape a HTML string', function () { diff --git a/packages/strings/kebabCase/kebabCase.js b/packages/strings/kebabCase/kebabCase.js index d6201115..81e9a2db 100644 --- a/packages/strings/kebabCase/kebabCase.js +++ b/packages/strings/kebabCase/kebabCase.js @@ -42,21 +42,18 @@ * kebabCase(' () @#$ @# %the quick brown fox jumps over the lazy dog #!#$% <> '); * // -> 'the-quick-brown-fox-jumps-over-the-lazy-dog' */ -function kebabCase(subjectString) { +const kebabCase = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } - var capitalsRegexp = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g; + const capitalsRegexp = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g; // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; - var lowercase = subjectString.replace(capitalsRegexp, function (match) { - return ' ' + (match.toLowerCase() || match); // Replace all capitals with space + lower case equivalent - }); - var words = lowercase.split(wordSeparatorRegexp); // Split by spaces or any punctuation characters - var result = words.filter(Boolean).join('-'); - + const wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; + const lowercase = subjectString.replace(capitalsRegexp, match => ' ' + (match.toLowerCase() || match)); // Replace all capitals with space + lower case equivalent + const words = lowercase.split(wordSeparatorRegexp); // Split by spaces or any punctuation characters + const result = words.filter(Boolean).join('-'); return result; -} +}; module.exports = kebabCase; diff --git a/packages/strings/kebabCase/test.js b/packages/strings/kebabCase/test.js index 87bbc1e8..6ea4a76e 100644 --- a/packages/strings/kebabCase/test.js +++ b/packages/strings/kebabCase/test.js @@ -1,4 +1,4 @@ -var kebabCase = require('./kebabCase'); +const kebabCase = require('./kebabCase'); describe('String/kebabCase', function () { it('should convert string to kebab case', function () { diff --git a/packages/strings/lines/README.md b/packages/strings/lines/README.md index 3c7b8c5f..c848ca71 100644 --- a/packages/strings/lines/README.md +++ b/packages/strings/lines/README.md @@ -15,8 +15,8 @@ Creates an array with the lines of a a string. **Example** ```js -var str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; -var str2 = `You can\'t make +const str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; +const str2 = `You can\'t make an omelet without breaking a few eggs.`; diff --git a/packages/strings/lines/lines.js b/packages/strings/lines/lines.js index e29372d9..d69ac603 100644 --- a/packages/strings/lines/lines.js +++ b/packages/strings/lines/lines.js @@ -8,8 +8,8 @@ * @return {Array} An array or strings containing the lines of the string. * @example * - * var str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; - * var str2 = `You can\'t make + * const str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; + * const str2 = `You can\'t make * an omelet without * breaking a few eggs.`; * @@ -19,12 +19,12 @@ * lines(str2); * // -> ['You can't make', 'an omelet without', 'breaking a few eggs.'] */ -function lines(subjectString) { +const lines = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } return subjectString.replace(/\r\n/g, '\n').split('\n'); -} +}; -module.exports = lines; \ No newline at end of file +module.exports = lines; diff --git a/packages/strings/lines/test.js b/packages/strings/lines/test.js index d572678e..b96c9382 100644 --- a/packages/strings/lines/test.js +++ b/packages/strings/lines/test.js @@ -1,7 +1,7 @@ -var lines = require('./lines'); +const lines = require('./lines'); describe('String/lines', function () { - var str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; + const str = 'You can\'t make\nan omelet without\r\nbreaking a few eggs.'; it('should return an array with the lines from a string', function () { expect(lines(str)).toHaveLength(3); diff --git a/packages/strings/numberFormat/numberFormat.js b/packages/strings/numberFormat/numberFormat.js index 2ebaaf74..e18eb6d0 100644 --- a/packages/strings/numberFormat/numberFormat.js +++ b/packages/strings/numberFormat/numberFormat.js @@ -21,9 +21,7 @@ * numberFormat(123456789.12345, 3, ',', '.'); * // -> '123.456.789,123' */ -function numberFormat(nNumber, nDecimals, sDecimalSeparator, sThousandSeparator) { - var parts, integerPart, fractionalPart; - +const numberFormat = (nNumber, nDecimals, sDecimalSeparator, sThousandSeparator) => { if (typeof nNumber !== 'number') { throw new TypeError('Expected a number for first argument'); } @@ -35,11 +33,11 @@ function numberFormat(nNumber, nDecimals, sDecimalSeparator, sThousandSeparator) nNumber = nNumber.toFixed(~~nDecimals); sThousandSeparator = typeof sThousandSeparator === 'string' ? sThousandSeparator : ','; - parts = nNumber.split('.'); - integerPart = parts[0]; - fractionalPart = parts[1] ? (sDecimalSeparator || '.') + parts[1] : ''; + const parts = nNumber.split('.'); + const integerPart = parts[0]; + const fractionalPart = parts[1] ? (sDecimalSeparator || '.') + parts[1] : ''; return integerPart.replace(/(\d)(?=(?:\d{3})+$)/g, '$1' + sThousandSeparator) + fractionalPart; -} +}; -module.exports = numberFormat; \ No newline at end of file +module.exports = numberFormat; diff --git a/packages/strings/numberFormat/test.js b/packages/strings/numberFormat/test.js index 2423aac0..5f3fdaf6 100644 --- a/packages/strings/numberFormat/test.js +++ b/packages/strings/numberFormat/test.js @@ -1,4 +1,4 @@ -var numberFormat = require('./numberFormat'); +const numberFormat = require('./numberFormat'); describe('String/numberFormat', function () { it('formats a number based on the number of decimal points, the decimal separator and the thousands separator', function () { diff --git a/packages/strings/pascalCase/pascalCase.js b/packages/strings/pascalCase/pascalCase.js index 4f43b9e9..253b3375 100644 --- a/packages/strings/pascalCase/pascalCase.js +++ b/packages/strings/pascalCase/pascalCase.js @@ -36,22 +36,22 @@ * pascalCase(' () @#$ @# %the quick brown fox jumps over the lazy dog #!#$% <> '); * // -> 'TheQuickBrownFoxJumpsOverTheLazyDog' */ -function pascalCase(subjectString) { +const pascalCase = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; - var words = subjectString.split(wordSeparatorRegexp); + const wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; + const words = subjectString.split(wordSeparatorRegexp); - return words.reduce(function (accum, word) { + return words.reduce((accum, word) => { if (word !== '') { accum += word.substring(0, 1).toUpperCase() + word.substring(1); } return accum; }, ''); -} +}; module.exports = pascalCase; diff --git a/packages/strings/pascalCase/test.js b/packages/strings/pascalCase/test.js index f9ff4dc2..bf13d38b 100644 --- a/packages/strings/pascalCase/test.js +++ b/packages/strings/pascalCase/test.js @@ -1,4 +1,4 @@ -var pascalCase = require('./pascalCase'); +const pascalCase = require('./pascalCase'); describe('String/pascalCase', function () { it('should convert string to pascal case', function () { diff --git a/packages/strings/randomString/README.md b/packages/strings/randomString/README.md index 2e925872..9caf8d65 100644 --- a/packages/strings/randomString/README.md +++ b/packages/strings/randomString/README.md @@ -1,7 +1,7 @@ -## randomString(length, [chars]) ⇒ String -Generates a pseudo-random string of specific `length` allowing a set of characters specified by `chars`. +## randomString(len, [chars]) ⇒ String +Generates a pseudo-random string of specific `len` allowing a set of characters specified by `chars`. **Returns**: String - The random generated string. **Throws**: @@ -12,7 +12,7 @@ Generates a pseudo-random string of specific `length` allowing a set of characte | Param | Type | Default | Description | | --- | --- | --- | --- | -| length | Number | | The number of characters of the generated string. | +| len | Number | | The number of characters of the generated string. | | [chars] | String | '#aA!' | Type of characters to be allowed in the generated string. Allow numeric (`#`) characters, lower-case (`a`) characters, upper-case (`A`) characters, special (`!`) characters. | **Example** diff --git a/packages/strings/randomString/randomString.js b/packages/strings/randomString/randomString.js index 11133732..357a068f 100644 --- a/packages/strings/randomString/randomString.js +++ b/packages/strings/randomString/randomString.js @@ -1,9 +1,9 @@ 'use strict'; /** - * Generates a pseudo-random string of specific `length` allowing a set of characters specified by `chars`. + * Generates a pseudo-random string of specific `len` allowing a set of characters specified by `chars`. * - * @param {Number} length The number of characters of the generated string. + * @param {Number} len The number of characters of the generated string. * @param {String} [chars='#aA!'] Type of characters to be allowed in the generated string. * Allow numeric (`#`) characters, lower-case (`a`) characters, upper-case (`A`) characters, special (`!`) characters. * @throws {TypeError} Throws if first argument is not number. @@ -29,34 +29,31 @@ * randomString(16, 'aA'); * // -> 'YGOSgnoUIHaUvEcp' */ -function randomString(length, chars) { - var charsError = 'Expected a string for second argument, that contains one or more of the following characters: "#", "a", "A", "!"'; +const randomString = (len, chars = '#aA!') => { + const charsError = 'Expected a string for second argument, that contains one or more of the following characters: "#", "a", "A", "!"'; - if (typeof length !== 'number') { + if (typeof len !== 'number') { throw new TypeError('Expected a number for first argument'); } - if (typeof chars !== 'string' && typeof chars !== 'undefined' || chars === '') { + if (typeof chars !== 'string' || chars === '') { throw new TypeError(charsError); } - var allowedCharsSamples = chars || '#aA!'; - var mask = ''; - var result = ''; - var i = 0; - var key; + let mask = ''; + let result = ''; - var mapCharSampleToAllowedChars = { + const mapCharSampleToAllowedChars = { 'a': 'abcdefghijklmnopqrstuvwxyz', 'A': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '#': '0123456789', '!': '!#$%&()*+,\\-./:;<=>?@[]^_{|}~' }; - for (key in mapCharSampleToAllowedChars) { + for (const key in mapCharSampleToAllowedChars) { if ( Object.prototype.hasOwnProperty.call(mapCharSampleToAllowedChars, key) - && allowedCharsSamples.indexOf(key) > -1 + && chars.indexOf(key) > -1 ) { mask += mapCharSampleToAllowedChars[key]; } @@ -66,11 +63,11 @@ function randomString(length, chars) { throw new TypeError(charsError); } - for (i; i < length; i += 1) { + for (let i = 0; i < len; i += 1) { result += mask[Math.floor(Math.random() * mask.length)]; } return result; -} +}; module.exports = randomString; diff --git a/packages/strings/randomString/test.js b/packages/strings/randomString/test.js index df65ddfe..9616bd27 100644 --- a/packages/strings/randomString/test.js +++ b/packages/strings/randomString/test.js @@ -1,8 +1,8 @@ -var randomString = require('./randomString'); +const randomString = require('./randomString'); describe('String/randomString', function () { it('generates a pseudo-random string of n characters', function () { - var charsError = 'Expected a string for second argument, that contains one or more of the following characters: "#", "a", "A", "!"'; + const charsError = 'Expected a string for second argument, that contains one or more of the following characters: "#", "a", "A", "!"'; expect(randomString(16)).toHaveLength(16); diff --git a/packages/strings/removePrefix/removePrefix.js b/packages/strings/removePrefix/removePrefix.js index 4674514c..fd17bc75 100755 --- a/packages/strings/removePrefix/removePrefix.js +++ b/packages/strings/removePrefix/removePrefix.js @@ -22,12 +22,12 @@ * removePrefix('__foobar', {}); * // -> TypeError */ -function removePrefix(subjectString, prefix) { +const removePrefix = (subjectString, prefix) => { if (typeof subjectString !== 'string' || typeof prefix !== 'string' && typeof prefix !== 'undefined') { throw new TypeError('Expected all arguments to be strings'); } return subjectString.indexOf(prefix) === 0 ? subjectString.slice(prefix.length) : subjectString; -} +}; -module.exports = removePrefix; \ No newline at end of file +module.exports = removePrefix; diff --git a/packages/strings/removePrefix/test.js b/packages/strings/removePrefix/test.js index d339799f..827f6700 100644 --- a/packages/strings/removePrefix/test.js +++ b/packages/strings/removePrefix/test.js @@ -1,4 +1,4 @@ -var removePrefix = require('./removePrefix'); +const removePrefix = require('./removePrefix'); describe('String/removePrefix', function () { it('removes a specific prefix from string', function () { diff --git a/packages/strings/removeSuffix/removeSuffix.js b/packages/strings/removeSuffix/removeSuffix.js index ed7ad4e1..2961f5ff 100755 --- a/packages/strings/removeSuffix/removeSuffix.js +++ b/packages/strings/removeSuffix/removeSuffix.js @@ -22,19 +22,17 @@ * removeSuffix('foobar__', {}); * // -> TypeError */ -function removeSuffix(subjectString, suffix) { - var strLen, suffixLen; - +const removeSuffix = (subjectString, suffix) => { if (typeof subjectString !== 'string' || typeof suffix !== 'string' && typeof suffix !== 'undefined') { throw new TypeError('Expected a string for first and second argument argument'); } - strLen = subjectString.length; - suffixLen = suffix ? suffix.length : 0; + const strLen = subjectString.length; + const suffixLen = suffix ? suffix.length : 0; return subjectString.indexOf(suffix, strLen - suffixLen) !== -1 ? subjectString.slice(0, strLen - suffixLen) : subjectString; -} +}; module.exports = removeSuffix; diff --git a/packages/strings/removeSuffix/test.js b/packages/strings/removeSuffix/test.js index d08c7100..b70013e7 100644 --- a/packages/strings/removeSuffix/test.js +++ b/packages/strings/removeSuffix/test.js @@ -1,4 +1,4 @@ -var removeSuffix = require('./removeSuffix'); +const removeSuffix = require('./removeSuffix'); describe('String/removeSuffix', function () { it('removes a specific suffix from string', function () { diff --git a/packages/strings/snakeCase/snakeCase.js b/packages/strings/snakeCase/snakeCase.js index f2a0dc7d..84860e8a 100644 --- a/packages/strings/snakeCase/snakeCase.js +++ b/packages/strings/snakeCase/snakeCase.js @@ -39,21 +39,18 @@ * snakeCase(' () @#$ @# %the quick brown fox jumps over the lazy dog #!#$% <> '); * // -> 'the_quick_brown_fox_jumps_over_the_lazy_dog' */ -function snakeCase(subjectString) { +const snakeCase = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } - var capitalsRegexp = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g; + const capitalsRegexp = /[A-Z\u00C0-\u00D6\u00D9-\u00DD]/g; // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; - var lowercase = subjectString.replace(capitalsRegexp, function (match) { - return ' ' + (match.toLowerCase() || match); // Replace all capitals with space + lower case equivalent - }); - var words = lowercase.split(wordSeparatorRegexp); // Split by spaces or any punctuation characters - var result = words.filter(Boolean).join('_'); - + const wordSeparatorRegexp = /[\s\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]+/; + const lowercase = subjectString.replace(capitalsRegexp, match => ' ' + (match.toLowerCase() || match)); // Replace all capitals with space + lower case equivalent + const words = lowercase.split(wordSeparatorRegexp); // Split by spaces or any punctuation characters + const result = words.filter(Boolean).join('_'); return result; -} +}; module.exports = snakeCase; diff --git a/packages/strings/snakeCase/test.js b/packages/strings/snakeCase/test.js index c0e413b8..3c41e7d9 100644 --- a/packages/strings/snakeCase/test.js +++ b/packages/strings/snakeCase/test.js @@ -1,4 +1,4 @@ -var snakeCase = require('./snakeCase'); +const snakeCase = require('./snakeCase'); describe('String/snake case', function () { it('should convert string to snake_case', function () { diff --git a/packages/strings/squash/squash.js b/packages/strings/squash/squash.js index b538330d..245f3e87 100644 --- a/packages/strings/squash/squash.js +++ b/packages/strings/squash/squash.js @@ -19,14 +19,14 @@ * squash('\tLorem \n\vispum \tdolor \fsit \n amet ', true); * // -> 'Loremispumdolorsitamet' */ -function squash(subjectString, squashEscapeSequences) { - var regex = squashEscapeSequences ? /\s+/g : / /g; +const squash = (subjectString, squashEscapeSequences) => { + const regex = squashEscapeSequences ? /\s+/g : / /g; if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } return subjectString.replace(regex, ''); -} +}; module.exports = squash; diff --git a/packages/strings/squash/test.js b/packages/strings/squash/test.js index c58b2b55..3dab42aa 100644 --- a/packages/strings/squash/test.js +++ b/packages/strings/squash/test.js @@ -1,4 +1,4 @@ -var squash = require('./squash'); +const squash = require('./squash'); describe('String/squash', function () { it('removes all spaces from a string', function () { @@ -12,7 +12,7 @@ describe('String/squash', function () { }); it('removes all spaces from a string including escape sequences', function () { - var expected = 'Loremispumdolorsitamet'; + const expected = 'Loremispumdolorsitamet'; expect(squash('Lorem ispum dolor sit amet', true)).toBe(expected); diff --git a/packages/strings/strip/README.md b/packages/strings/strip/README.md index 7ca00f02..1cfe2e89 100755 --- a/packages/strings/strip/README.md +++ b/packages/strings/strip/README.md @@ -12,11 +12,11 @@ Creates a new string with all occurrences of [string1], [string2],... removed. | Param | Type | Description | | --- | --- | --- | | subjectString | String | The string to process. | -| [args...] | String | The substrings to remove from the original string. | +| [...args] | ...String | The substrings to remove from the original string. | **Example** ```js -var str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; +const str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; strip(str, '_'); // -> 'Loremipsumdolorsitamet. Lorem+ipsum+dolor+sit+amet. 123456789' diff --git a/packages/strings/strip/strip.js b/packages/strings/strip/strip.js index 68fc67c7..87153ff1 100755 --- a/packages/strings/strip/strip.js +++ b/packages/strings/strip/strip.js @@ -4,12 +4,12 @@ * Creates a new string with all occurrences of [string1], [string2],... removed. * * @param {String} subjectString The string to process. - * @param {String} [args...] The substrings to remove from the original string. + * @param {...String} [...args] The substrings to remove from the original string. * @throws {TypeError} If `subjectString` is not string. * @return {String} The result string. * @example * - * var str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; + * const str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; * * strip(str, '_'); * // -> 'Loremipsumdolorsitamet. Lorem+ipsum+dolor+sit+amet. 123456789' @@ -23,21 +23,16 @@ * strip(str, 'Lorem'); * // -> '_ipsum_dolor_sit_amet. +ipsum+dolor+sit+amet. 123456789' */ -function strip(subjectString /* args... */) { - var index, len; - +const strip = (subjectString, ...args) => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } - index = 1; - len = arguments.length; - - for (index; index < len; index += 1) { - subjectString = subjectString.split(arguments[index]).join(''); + for (let index = 0; index < args.length; index += 1) { + subjectString = subjectString.split(args[index]).join(''); } return subjectString; -} +}; -module.exports = strip; \ No newline at end of file +module.exports = strip; diff --git a/packages/strings/strip/test.js b/packages/strings/strip/test.js index a234d71b..3281195f 100644 --- a/packages/strings/strip/test.js +++ b/packages/strings/strip/test.js @@ -1,8 +1,8 @@ -var strip = require('./strip'); +const strip = require('./strip'); describe('String/strip', function () { it('should strip a string from all occurrences of a given substring', function () { - var str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; + const str = 'Lorem_ipsum_dolor_sit_amet. Lorem+ipsum+dolor+sit+amet. 123456789'; expect(strip(str, '_')) .toEqual('Loremipsumdolorsitamet. Lorem+ipsum+dolor+sit+amet. 123456789'); diff --git a/packages/strings/stripHTML/README.md b/packages/strings/stripHTML/README.md index 6c3b58ec..8ca8a699 100644 --- a/packages/strings/stripHTML/README.md +++ b/packages/strings/stripHTML/README.md @@ -15,7 +15,7 @@ Removes all HTML tags from a string. **Example** ```js -var str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; +const str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; stripHTML(str); // -> 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia quos dicta, doloremque veritatis.' diff --git a/packages/strings/stripHTML/stripHTML.js b/packages/strings/stripHTML/stripHTML.js index 328492fa..26d29cef 100644 --- a/packages/strings/stripHTML/stripHTML.js +++ b/packages/strings/stripHTML/stripHTML.js @@ -8,17 +8,17 @@ * @return {String} The stripped string. * @example * - * var str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; + * const str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; * * stripHTML(str); * // -> 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia quos dicta, doloremque veritatis.' */ -function stripHTML(subjectString) { +const stripHTML = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } return subjectString.replace(/<[^>]+>/g, ''); -} +}; -module.exports = stripHTML; \ No newline at end of file +module.exports = stripHTML; diff --git a/packages/strings/stripHTML/test.js b/packages/strings/stripHTML/test.js index 3a736b01..8e5d1fbd 100644 --- a/packages/strings/stripHTML/test.js +++ b/packages/strings/stripHTML/test.js @@ -1,8 +1,8 @@ -var stripHTML = require('./stripHTML'); +const stripHTML = require('./stripHTML'); describe('String/stripHTML', function () { it('should remove all HTML tags from a string', function () { - var str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; + const str = '

Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Mollitia quos dicta, doloremque veritatis.

'; expect(stripHTML(str)) .toEqual('Lorem ipsum dolor sit amet, consectetur adipisicing elit. Mollitia quos dicta, doloremque veritatis.'); diff --git a/packages/strings/stripPunctuation/README.md b/packages/strings/stripPunctuation/README.md index 99106d1a..23b6adba 100644 --- a/packages/strings/stripPunctuation/README.md +++ b/packages/strings/stripPunctuation/README.md @@ -15,7 +15,7 @@ Removes all of the punctuation from a string. **Example** ```js -var str = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; +const str = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; stripPunctuation(str); // -> You cant make an omelet without breaking a few eggs diff --git a/packages/strings/stripPunctuation/stripPunctuation.js b/packages/strings/stripPunctuation/stripPunctuation.js index 9d0446df..29531f3d 100644 --- a/packages/strings/stripPunctuation/stripPunctuation.js +++ b/packages/strings/stripPunctuation/stripPunctuation.js @@ -8,21 +8,21 @@ * @return {String} Returns the reuslt string with all punctuation stripped. * @example * - * var str = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; + * const str = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; * * stripPunctuation(str); * // -> You cant make an omelet without breaking a few eggs */ -function stripPunctuation(subjectString) { +const stripPunctuation = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var punctRegExp = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]/g; - var spaceRegExp = /\s+/g; + const punctRegExp = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]/g; + const spaceRegExp = /\s+/g; return subjectString.replace(punctRegExp, '').replace(spaceRegExp, ' '); -} +}; module.exports = stripPunctuation; diff --git a/packages/strings/stripPunctuation/test.js b/packages/strings/stripPunctuation/test.js index 213669d6..5fd1b3e4 100644 --- a/packages/strings/stripPunctuation/test.js +++ b/packages/strings/stripPunctuation/test.js @@ -1,12 +1,12 @@ -var stripPunctuation = require('./stripPunctuation'); +const stripPunctuation = require('./stripPunctuation'); describe('String/stripPunctuation', function () { it('should remove all of punctuiation from given string', function () { - var latinStr = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; - var expectedLatinStr = 'You cant make an omelet without breaking a few eggs'; + const latinStr = ';``?You can\'t [make] an *ome*let + wit&&hout \\ %break_ing/% ~ a few eg-gs.!@#-"$"+:'; + const expectedLatinStr = 'You cant make an omelet without breaking a few eggs'; - var nonLatinStr = ';``?Δεν μπορείς να [φτιάξεις] μία *ομε*λέτα + χωρ&&ίς να \\ %σπάσ_εις/% ~ μερικά αυ-γά.!@#-"$"+:'; - var expectedNonLatinStr = 'Δεν μπορείς να φτιάξεις μία ομελέτα χωρίς να σπάσεις μερικά αυγά'; + const nonLatinStr = ';``?Δεν μπορείς να [φτιάξεις] μία *ομε*λέτα + χωρ&&ίς να \\ %σπάσ_εις/% ~ μερικά αυ-γά.!@#-"$"+:'; + const expectedNonLatinStr = 'Δεν μπορείς να φτιάξεις μία ομελέτα χωρίς να σπάσεις μερικά αυγά'; expect(stripPunctuation(latinStr)).toBe(expectedLatinStr); diff --git a/packages/strings/substringAfter/substringAfter.js b/packages/strings/substringAfter/substringAfter.js index 43b09d7d..43d1a023 100644 --- a/packages/strings/substringAfter/substringAfter.js +++ b/packages/strings/substringAfter/substringAfter.js @@ -31,14 +31,14 @@ * substringAfter('🍎🍐🍊🍌🍉🍇🍓', '🍓'); * // -> '' */ -function substringAfter(subjectString, characters, last) { +const substringAfter = (subjectString, characters, last) => { if (typeof subjectString !== 'string' || typeof characters !== 'string') { throw new TypeError('Expected a string for first and second argument'); } - var index = !last ? subjectString.indexOf(characters) : subjectString.lastIndexOf(characters); + const index = !last ? subjectString.indexOf(characters) : subjectString.lastIndexOf(characters); return index !== -1 ? subjectString.substring(index + characters.length) : ''; -} +}; module.exports = substringAfter; diff --git a/packages/strings/substringAfter/test.js b/packages/strings/substringAfter/test.js index efcac2b5..9cf8a25d 100644 --- a/packages/strings/substringAfter/test.js +++ b/packages/strings/substringAfter/test.js @@ -1,8 +1,8 @@ -var substringAfter = require('./substringAfter'); +const substringAfter = require('./substringAfter'); describe('String/substringAfter', function () { it('returns a substring after a specific sequence of character(s)', function () { - var str = 'LOREM_IPSUM DOLOR_SIT AMET'; + const str = 'LOREM_IPSUM DOLOR_SIT AMET'; expect(substringAfter(str, 'SIT ')).toBe('AMET'); diff --git a/packages/strings/substringBefore/substringBefore.js b/packages/strings/substringBefore/substringBefore.js index 317919fc..74075f7c 100644 --- a/packages/strings/substringBefore/substringBefore.js +++ b/packages/strings/substringBefore/substringBefore.js @@ -31,14 +31,14 @@ * substringBefore('🍎🍐🍊🍌🍉🍇🍓', '🍎'); * // -> '' */ -function substringBefore(subjectString, characters, last) { +const substringBefore = (subjectString, characters, last) => { if (typeof subjectString !== 'string' || typeof characters !== 'string') { throw new TypeError('Expected a string for first and second argument'); } - var index = !last ? subjectString.indexOf(characters) : subjectString.lastIndexOf(characters); + const index = !last ? subjectString.indexOf(characters) : subjectString.lastIndexOf(characters); return index !== -1 ? subjectString.substring(0, index) : ''; -} +}; module.exports = substringBefore; diff --git a/packages/strings/substringBefore/test.js b/packages/strings/substringBefore/test.js index c9498848..2527bc2f 100644 --- a/packages/strings/substringBefore/test.js +++ b/packages/strings/substringBefore/test.js @@ -1,8 +1,8 @@ -var substringBefore = require('./substringBefore'); +const substringBefore = require('./substringBefore'); describe('String/substringBefore', function () { it('should return a substring before a specific sequence of character(s)', function () { - var str = 'LOREM_IPSUM DOLOR_SIT AMET'; + const str = 'LOREM_IPSUM DOLOR_SIT AMET'; expect(substringBefore(str, 'SIT')).toEqual('LOREM_IPSUM DOLOR_'); diff --git a/packages/strings/supplant/README.md b/packages/strings/supplant/README.md deleted file mode 100644 index abd112b4..00000000 --- a/packages/strings/supplant/README.md +++ /dev/null @@ -1,48 +0,0 @@ - - -## supplant(subjectString, [data]) ⇒ String -Does variable substitution on a string. -It scans through the string looking for expressions enclosed in {{ }} braces. -If an expression is found, use it as a key on the object, -and if the key has a string value or number value, it is substituted for the bracket expression and it repeats. - -**Returns**: String - The result string. -**Throws**: - -- TypeError If `subjectString` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The initial string to substitude its expressions. | -| [data] | Object | A plain object that acts as our model. If `data` omitted, returns the original string. | - -**Example** -```js -var str = '' + - '

My name is {{person.fName}} {{person.lName}} and my job is {{person.position}}.

' + - '

' + - 'My hobbies are:' + - '

    ' + - '
  • {{hobbies.0}}
  • ' + - '
  • {{hobbies.1}}
  • ' + - '
  • {{hobbies.2}}
  • ' + - '
' + - '

'; - -var data = { - person: { - fName: 'John', - lName: 'Doe', - position: 'Frontend Developer' - }, - hobbies: ['coding', 'music', 'gaming'] -}; - -supplant(str, data); -// -> My name is John Doe and my job is Frontend Developer. -// -> My hobbies are: -// -> - coding -// -> - music -// -> - gaming -``` diff --git a/packages/strings/supplant/supplant.js b/packages/strings/supplant/supplant.js deleted file mode 100644 index eb0c6066..00000000 --- a/packages/strings/supplant/supplant.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -/** - * Does variable substitution on a string. - * It scans through the string looking for expressions enclosed in {{ }} braces. - * If an expression is found, use it as a key on the object, - * and if the key has a string value or number value, it is substituted for the bracket expression and it repeats. - * - * @param {String} subjectString The initial string to substitude its expressions. - * @param {Object} [data] A plain object that acts as our model. If `data` omitted, returns the original string. - * @throws {TypeError} If `subjectString` is not string. - * @return {String} The result string. - * @example - * - * var str = '' + - * '

My name is {{person.fName}} {{person.lName}} and my job is {{person.position}}.

' + - * '

' + - * 'My hobbies are:' + - * '

    ' + - * '
  • {{hobbies.0}}
  • ' + - * '
  • {{hobbies.1}}
  • ' + - * '
  • {{hobbies.2}}
  • ' + - * '
' + - * '

'; - * - * var data = { - * person: { - * fName: 'John', - * lName: 'Doe', - * position: 'Frontend Developer' - * }, - * hobbies: ['coding', 'music', 'gaming'] - * }; - * - * supplant(str, data); - * // -> My name is John Doe and my job is Frontend Developer. - * // -> My hobbies are: - * // -> - coding - * // -> - music - * // -> - gaming - */ -function supplant(subjectString, data) { - if (typeof subjectString !== 'string') { - throw new TypeError('Expected a string for first argument'); - } - - if (data == null || typeof data !== 'object') { - return subjectString; - } - - return subjectString.replace(/{{([^{{}}]*)}}/g, function (a, b) { - var p = b.split(/\./); // Split the variable into its dot notation parts. - var c = data; // The c variable becomes our cursor that will traverse the object. - var i = 0; - var l = p.length; - - // Loop over the steps in the dot notation path. - for (i; i < l; i += 1) { - // If the key doesn't exist in the object do not process. - // Mirrors how the function worked for bad values. - if (c[p[i]] == null) { - return a; - } - - // Move the cursor up to the next step. - c = c[p[i]]; - } - - // If the data is a string or number return it, - // otherwise do not process, return the value it was, i.e. {x} - return typeof c === 'string' || typeof c === 'number' ? c : a; - }); -} - -module.exports = supplant; \ No newline at end of file diff --git a/packages/strings/supplant/test.js b/packages/strings/supplant/test.js deleted file mode 100644 index 44c7a311..00000000 --- a/packages/strings/supplant/test.js +++ /dev/null @@ -1,46 +0,0 @@ -var supplant = require('./supplant'); - -describe('String/supplant', function () { - it('should do variable substitution on a string', function () { - var originalString = '

My name is {{person.fName}} {{person.lName}} and my job is {{person.position}}.

' - + '

' - + 'My hobbies are:' - + '

    ' - + '
  • {{hobbies.0}}
  • ' - + '
  • {{hobbies.1}}
  • ' - + '
  • {{hobbies.2}}
  • ' - + '
' - + '

'; - - var expectedString = '

My name is John Doe and my job is Frontend Developer.

' - + '

' - + 'My hobbies are:' - + '

    ' - + '
  • coding
  • ' - + '
  • music
  • ' - + '
  • gaming
  • ' - + '
' - + '

'; - - var data = { - person: { - fName: 'John', - lName: 'Doe', - position: 'Frontend Developer' - }, - hobbies: ['coding', 'music', 'gaming'] - }; - - var resultString = supplant(originalString, data); - - expect(resultString).toEqual(expectedString); - - expect(supplant(originalString)).toEqual(originalString); - - expect(supplant(originalString, 'John Doe')).toEqual(originalString); - - expect(function () { - return supplant({}, data); - }).toThrow(new TypeError('Expected a string for first argument')); - }); -}); diff --git a/packages/strings/truncate/README.md b/packages/strings/truncate/README.md index 2698d331..ba35ae67 100644 --- a/packages/strings/truncate/README.md +++ b/packages/strings/truncate/README.md @@ -18,7 +18,7 @@ Truncates a string based on character count. **Example** ```js -var str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; +const str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; truncate(str, 50, '...'); // -> 'Lorem ipsum dolor sit amet, consectetur adipisicin...' diff --git a/packages/strings/truncate/test.js b/packages/strings/truncate/test.js index 8db88ec7..373b5a04 100644 --- a/packages/strings/truncate/test.js +++ b/packages/strings/truncate/test.js @@ -1,8 +1,8 @@ -var truncate = require('./truncate'); +const truncate = require('./truncate'); describe('String/truncate', function () { it('should truncate a string based on character count', function () { - var str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; + const str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; expect(truncate(str, 50, '...')).toEqual('Lorem ipsum dolor sit amet, consectetur adipisicin...'); @@ -23,11 +23,15 @@ describe('String/truncate', function () { expect(truncate(str, NaN)).toEqual(str); expect(function () { - return truncate({ item: str }, 10); + return truncate({item: str}, 10); }).toThrow(new TypeError('Expected a string for first argument')); expect(function () { return truncate(str, '10'); }).toThrow(new TypeError('Expected a number for second argument')); + + expect(function () { + return truncate(str, 10, null); + }).toThrow(new TypeError('Expected a string for third argument')); }); }); diff --git a/packages/strings/truncate/truncate.js b/packages/strings/truncate/truncate.js index 95d407ec..234163dc 100644 --- a/packages/strings/truncate/truncate.js +++ b/packages/strings/truncate/truncate.js @@ -4,15 +4,14 @@ * Truncates a string based on character count. * * @param {String} subjectString The string to truncate. - * @param {Number} [characterCount] The number of characters the truncated string contains. - * If ommitted or falsy, the initial string is returned. + * @param {Number} [characterCount] The number of characters the truncated string contains. If ommitted or falsy, the initial string is returned. * @param {String} [delimiter=""] The delimiter to add at the end of the truncated string. * @throws {TypeError} If `subjectString` is not string. * @throws {TypeError} If `characterCount` is not number. * @return {String} The truncated string. * @example * - * var str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; + * const str = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore voluptas tempora nihil commodi laborum sit eum atque iusto temporibus, odit natus odio accusantium id, labore, possimus laboriosam. Eos, ducimus, blanditiis.'; * * truncate(str, 50, '...'); * // -> 'Lorem ipsum dolor sit amet, consectetur adipisicin...' @@ -44,9 +43,7 @@ * truncate(str, '10'); * // Throws TypeError */ -function truncate(subjectString, characterCount, delimiter) { - var regex, truncated; - +const truncate = (subjectString, characterCount, delimiter = '') => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } @@ -55,6 +52,10 @@ function truncate(subjectString, characterCount, delimiter) { throw new TypeError('Expected a number for second argument'); } + if (typeof delimiter !== 'string') { + throw new TypeError('Expected a string for third argument'); + } + characterCount = Math.floor(characterCount); if ( @@ -65,13 +66,13 @@ function truncate(subjectString, characterCount, delimiter) { return subjectString; } - regex = new RegExp('^.{0,' + characterCount + '}[S]*', 'g'); - truncated = subjectString.match(regex); - delimiter = delimiter || ''; + const regex = new RegExp('^.{0,' + characterCount + '}[S]*', 'g'); + let truncated = subjectString.match(regex); + truncated = truncated[0].replace(/\s$/, ''); truncated = truncated + delimiter; return truncated; -} +}; -module.exports = truncate; \ No newline at end of file +module.exports = truncate; diff --git a/packages/strings/unescapeHTML/test.js b/packages/strings/unescapeHTML/test.js index 3624f0db..fd3e02da 100644 --- a/packages/strings/unescapeHTML/test.js +++ b/packages/strings/unescapeHTML/test.js @@ -1,4 +1,4 @@ -var unescapeHTML = require('./unescapeHTML'); +const unescapeHTML = require('./unescapeHTML'); describe('String/unescapeHTML', function () { it('should unescape a HTML string', function () { diff --git a/packages/strings/unescapeHTML/unescapeHTML.js b/packages/strings/unescapeHTML/unescapeHTML.js index 0613b2aa..25b9ef97 100644 --- a/packages/strings/unescapeHTML/unescapeHTML.js +++ b/packages/strings/unescapeHTML/unescapeHTML.js @@ -17,7 +17,7 @@ * unescapeHTML('<p data-id="1">lorem ipsum</p>'); * // -> '

lorem ipsum

' */ -function unescapeHTML(subjectString) { +const unescapeHTML = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } @@ -32,6 +32,6 @@ function unescapeHTML(subjectString) { .replace(/'/g, "'") // eslint-disable-line quotes .replace(/`/g, '`') .replace(///g, '/'); -} +}; -module.exports = unescapeHTML; \ No newline at end of file +module.exports = unescapeHTML; diff --git a/packages/strings/words/test.js b/packages/strings/words/test.js index 6c415f1c..75ee6a74 100644 --- a/packages/strings/words/test.js +++ b/packages/strings/words/test.js @@ -1,4 +1,4 @@ -var words = require('./words'); +const words = require('./words'); describe('String/words', function () { it('should count words in a subject string', function () { diff --git a/packages/strings/words/words.js b/packages/strings/words/words.js index 46c6bbd3..872da00f 100644 --- a/packages/strings/words/words.js +++ b/packages/strings/words/words.js @@ -14,16 +14,16 @@ * words('🍏 🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🍈 🍒 🍑 🥭'); * // -> ['🍏', '🍎', '🍐', '🍊', '🍋', '🍌', '🍉', '🍇', '🍓', '🍈', '🍒', '🍑', '🥭'] */ -function words(subjectString) { +const words = subjectString => { if (typeof subjectString !== 'string') { throw new TypeError('Expected a string for first argument'); } // https://stackoverflow.com/questions/4328500/how-can-i-strip-all-punctuation-from-a-string-in-javascript-using-regex/25575009#25575009 - var punctRegExp = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]/g; - var nonSpaceRegExp = /\S+/g; + const punctRegExp = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-./:;<=>?@[\]^_`{|}~]/g; + const nonSpaceRegExp = /\S+/g; return subjectString.replace(punctRegExp, '').match(nonSpaceRegExp) || []; -} +}; module.exports = words; diff --git a/packages/strings/wrapHTML/README.md b/packages/strings/wrapHTML/README.md deleted file mode 100644 index 5ece5fd9..00000000 --- a/packages/strings/wrapHTML/README.md +++ /dev/null @@ -1,32 +0,0 @@ - - -## wrapHTML(subjectString, nodeName, [nodeAttributes]) ⇒ String -Wraps a string with a HTML tag with attributes if specified. - -**Returns**: String - The wrapped string. -**Throws**: - -- TypeError If `subjectString` is not string. -- TypeError If `nodeName` is not string. - - -| Param | Type | Description | -| --- | --- | --- | -| subjectString | String | The string to wrap with the HTML tag. | -| nodeName | String | The HTML tag name that we want to wrap the string with. | -| [nodeAttributes] | Object | The desired attributes of the HTML element. | - -**Example** -```js -var str = 'Lorem ipsum dolor sit amet.'; - -var p = wrapHTML(str, 'p'); -// -> '

Lorem ipsum dolor sit amet.

' - -var div = wrapHTML(p, 'div', { - class: 'myClass', - id: 'myId', - dataType: 'myType' // Note that camelized keys are dasherized. Use string format to avoid this action. -}); -// -> '

Lorem ipsum dolor sit amet.

' -``` diff --git a/packages/strings/wrapHTML/test.js b/packages/strings/wrapHTML/test.js deleted file mode 100644 index d1ab8a63..00000000 --- a/packages/strings/wrapHTML/test.js +++ /dev/null @@ -1,27 +0,0 @@ -var wrapHTML = require('./wrapHTML'); - -describe('String/wrapHTML', function () { - it('should wrap a string with a HTML tag with attributes if specified', function () { - var str = 'Lorem ipsum dolor sit amet.'; - - var p = wrapHTML(str, 'p'); - - var div = wrapHTML(p, 'div', { - class: 'myClass', - id: 'myId', - dataType: 'myType' // Note that camelized keys are dasherized. Use string format to avoid this action. - }); - - expect(p).toEqual('

Lorem ipsum dolor sit amet.

'); - - expect(div).toEqual('

Lorem ipsum dolor sit amet.

'); - - expect(function () { - return wrapHTML(null, 'p'); - }).toThrow(new TypeError('Expected a string for first and second argument')); - - expect(function () { - return wrapHTML(str); - }).toThrow(new TypeError('Expected a string for first and second argument')); - }); -}); diff --git a/packages/strings/wrapHTML/wrapHTML.js b/packages/strings/wrapHTML/wrapHTML.js deleted file mode 100644 index 33d0720e..00000000 --- a/packages/strings/wrapHTML/wrapHTML.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -/** - * Wraps a string with a HTML tag with attributes if specified. - * - * @param {String} subjectString The string to wrap with the HTML tag. - * @param {String} nodeName The HTML tag name that we want to wrap the string with. - * @param {Object} [nodeAttributes] The desired attributes of the HTML element. - * @throws {TypeError} If `subjectString` is not string. - * @throws {TypeError} If `nodeName` is not string. - * @return {String} The wrapped string. - * @example - * - * var str = 'Lorem ipsum dolor sit amet.'; - * - * var p = wrapHTML(str, 'p'); - * // -> '

Lorem ipsum dolor sit amet.

' - * - * var div = wrapHTML(p, 'div', { - * class: 'myClass', - * id: 'myId', - * dataType: 'myType' // Note that camelized keys are dasherized. Use string format to avoid this action. - * }); - * // -> '

Lorem ipsum dolor sit amet.

' - */ -function wrapHTML(subjectString, nodeName, nodeAttributes) { - var elementName, elementAttributes, dasherizedProp, prop, wrapped; - - if (typeof subjectString !== 'string' || typeof nodeName !== 'string') { - throw new TypeError('Expected a string for first and second argument'); - } - - elementName = nodeName.replace(/[]/g, ''); - elementAttributes = ''; - wrapped = ''; - - if (typeof nodeAttributes === 'object') { - for (prop in nodeAttributes) { - if (Object.prototype.hasOwnProperty.call(nodeAttributes, prop)) { - dasherizedProp = prop - .replace(/[_\s]+/g, '-') - .replace(/([A-Z])/g, '-$1') - .replace(/-+/g, '-') - .toLowerCase(); - - elementAttributes += ' ' + dasherizedProp + '="' + nodeAttributes[prop] + '"'; - } - } - } - - wrapped = wrapped.concat( - '<', elementName, elementAttributes, '>', subjectString, '' - ); - - return wrapped; -} - -module.exports = wrapHTML; \ No newline at end of file From c7c4b3145d3350721e7be943a46a4eefccda1440 Mon Sep 17 00:00:00 2001 From: georapbox Date: Mon, 19 Sep 2022 15:04:48 +0300 Subject: [PATCH 12/17] Code styling and linting --- packages/arrays/chunk/README.md | 8 +- packages/arrays/chunk/chunk.js | 10 +- packages/arrays/diff/README.md | 4 +- packages/arrays/diff/diff.js | 4 +- packages/arrays/drop/README.md | 20 ++-- packages/arrays/drop/drop.js | 20 ++-- packages/arrays/dropRight/README.md | 20 ++-- packages/arrays/dropRight/dropRight.js | 20 ++-- packages/arrays/dropRightWhile/README.md | 2 +- .../arrays/dropRightWhile/dropRightWhile.js | 2 +- packages/arrays/dropWhile/README.md | 2 +- packages/arrays/dropWhile/dropWhile.js | 4 +- packages/arrays/groupBy/README.md | 4 +- packages/arrays/groupBy/groupBy.js | 4 +- packages/arrays/groupBy/test.js | 22 ++--- packages/arrays/insert/README.md | 16 ++-- packages/arrays/insert/insert.js | 16 ++-- packages/arrays/insert/test.js | 2 +- packages/arrays/intersect/README.md | 4 +- packages/arrays/intersect/intersect.js | 9 +- packages/arrays/move/README.md | 8 +- packages/arrays/move/move.js | 8 +- packages/arrays/partition/README.md | 4 +- packages/arrays/partition/partition.js | 4 +- packages/arrays/pluck/README.md | 4 +- packages/arrays/pluck/pluck.js | 4 +- packages/arrays/pluck/test.js | 8 +- packages/arrays/remove/README.md | 14 +-- packages/arrays/remove/remove.js | 16 ++-- packages/arrays/remove/test.js | 2 +- packages/arrays/shuffle/README.md | 2 +- packages/arrays/shuffle/shuffle.js | 2 +- packages/arrays/shuffle/test.js | 2 +- packages/arrays/sort/README.md | 12 +-- packages/arrays/sort/sort.js | 14 +-- packages/arrays/sortBy/README.md | 8 +- packages/arrays/sortBy/sortBy.js | 8 +- packages/arrays/sortBy/test.js | 72 +++++++------- packages/arrays/tail/README.md | 6 +- packages/arrays/tail/tail.js | 6 +- packages/arrays/take/README.md | 18 ++-- packages/arrays/take/take.js | 18 ++-- packages/arrays/takeRight/README.md | 18 ++-- packages/arrays/takeRight/takeRight.js | 18 ++-- packages/arrays/takeRightWhile/README.md | 2 +- .../arrays/takeRightWhile/takeRightWhile.js | 2 +- packages/arrays/takeRightWhile/test.js | 12 +-- packages/arrays/takeWhile/README.md | 2 +- packages/arrays/takeWhile/takeWhile.js | 2 +- packages/arrays/takeWhile/test.js | 12 +-- packages/arrays/uniq/README.md | 2 +- packages/arrays/uniq/uniq.js | 2 +- packages/arrays/uniqBy/README.md | 4 +- packages/arrays/uniqBy/test.js | 44 ++++----- packages/arrays/uniqBy/uniqBy.js | 4 +- packages/arrays/zip/README.md | 10 +- packages/arrays/zip/zip.js | 12 +-- .../canvas/convertImageToBase64/README.md | 2 +- .../convertImageToBase64.js | 2 +- packages/dom/cookie/README.md | 10 +- packages/dom/cookie/cookie.js | 8 +- packages/dom/preloadImages/preloadImages.js | 2 +- packages/dom/whichAnimationEnd/README.md | 2 +- .../whichAnimationEnd/whichAnimationEnd.js | 4 +- packages/dom/whichTransitionEnd/README.md | 2 +- .../whichTransitionEnd/whichTransitionEnd.js | 4 +- packages/function/after/after.js | 2 +- packages/function/ary/README.md | 2 +- packages/function/ary/ary.js | 2 +- packages/function/ary/test.js | 2 +- packages/function/before/before.js | 2 +- packages/function/once/once.js | 2 +- packages/function/throttle/throttle.js | 4 +- packages/function/unary/README.md | 2 +- packages/function/unary/test.js | 2 +- packages/function/unary/unary.js | 2 +- packages/is/isArray/README.md | 8 +- packages/is/isArray/isArray.js | 10 +- packages/is/isArray/test.js | 2 +- packages/is/isArrayLike/README.md | 18 ++-- packages/is/isArrayLike/isArrayLike.js | 20 ++-- packages/is/isArrayLikeObject/README.md | 18 ++-- .../is/isArrayLikeObject/isArrayLikeObject.js | 20 ++-- packages/is/isBoolean/README.md | 8 +- packages/is/isBoolean/isBoolean.js | 12 +-- packages/is/isDate/README.md | 4 +- packages/is/isDate/isDate.js | 6 +- packages/is/isElement/README.md | 6 +- packages/is/isElement/isElement.js | 8 +- packages/is/isEmail/README.md | 16 ++-- packages/is/isEmail/isEmail.js | 18 ++-- packages/is/isEmpty/README.md | 94 +++++++++---------- packages/is/isEmpty/isEmpty.js | 74 +++++++-------- packages/is/isEven/README.md | 14 +-- packages/is/isEven/isEven.js | 16 ++-- packages/is/isFalse/README.md | 6 +- packages/is/isFalse/isFalse.js | 8 +- packages/is/isFalsy/README.md | 16 ++-- packages/is/isFalsy/isFalsy.js | 16 ++-- packages/is/isFiniteNum/README.md | 16 ++-- packages/is/isFiniteNum/isFiniteNum.js | 20 ++-- packages/is/isFlatArray/README.md | 8 +- packages/is/isFlatArray/isFlatArray.js | 8 +- packages/is/isFunction/README.md | 4 +- packages/is/isFunction/isFunction.js | 6 +- packages/is/isHexColor/README.md | 16 ++-- packages/is/isHexColor/isHexColor.js | 18 ++-- packages/is/isHexadecimal/README.md | 10 +- packages/is/isHexadecimal/isHexadecimal.js | 12 +-- packages/is/isInteger/README.md | 22 ++--- packages/is/isInteger/isInteger.js | 24 ++--- packages/is/isIterable/README.md | 14 +-- packages/is/isIterable/isIterable.js | 14 +-- packages/is/isMap/README.md | 8 +- packages/is/isMap/isMap.js | 10 +- packages/is/isNaN/README.md | 28 +++--- packages/is/isNaN/isNaN.js | 30 +++--- packages/is/isNull/README.md | 8 +- packages/is/isNull/isNull.js | 10 +- packages/is/isNullish/README.md | 8 +- packages/is/isNullish/isNullish.js | 10 +- packages/is/isNumber/README.md | 18 ++-- packages/is/isNumber/isNumber.js | 20 ++-- packages/is/isObject/README.md | 32 +++---- packages/is/isObject/isObject.js | 34 +++---- packages/is/isObjectLike/README.md | 32 +++---- packages/is/isObjectLike/isObjectLike.js | 32 +++---- packages/is/isOdd/README.md | 14 +-- packages/is/isOdd/isOdd.js | 16 ++-- packages/is/isPlainObject/README.md | 24 ++--- packages/is/isPlainObject/isPlainObject.js | 26 ++--- packages/is/isPrimitive/README.md | 36 +++---- packages/is/isPrimitive/isPrimitive.js | 36 +++---- packages/is/isPromise/README.md | 8 +- packages/is/isPromise/isPromise.js | 8 +- packages/is/isRegexp/README.md | 4 +- packages/is/isRegexp/isRegexp.js | 6 +- packages/is/isSafeInteger/README.md | 18 ++-- packages/is/isSafeInteger/isSafeInteger.js | 20 ++-- packages/is/isSet/README.md | 4 +- packages/is/isSet/isSet.js | 6 +- packages/is/isString/README.md | 8 +- packages/is/isString/isString.js | 10 +- packages/is/isSymbol/README.md | 10 +- packages/is/isSymbol/isSymbol.js | 12 +-- packages/is/isTrue/README.md | 6 +- packages/is/isTrue/isTrue.js | 8 +- packages/is/isTruthy/README.md | 16 ++-- packages/is/isTruthy/isTruthy.js | 18 ++-- packages/is/isUndefined/README.md | 8 +- packages/is/isUndefined/isUndefined.js | 10 +- packages/is/isWeakMap/README.md | 8 +- packages/is/isWeakMap/isWeakMap.js | 10 +- packages/is/isWeakSet/README.md | 4 +- packages/is/isWeakSet/isWeakSet.js | 6 +- packages/math/average/README.md | 28 +++--- packages/math/average/average.js | 28 +++--- packages/math/clamp/README.md | 12 +-- packages/math/clamp/clamp.js | 12 +-- packages/math/degreesToRadians/README.md | 10 +- .../math/degreesToRadians/degreesToRadians.js | 12 +-- packages/math/inRange/README.md | 10 +- packages/math/inRange/inRange.js | 10 +- packages/math/lerp/README.md | 10 +- packages/math/lerp/lerp.js | 10 +- packages/math/max/README.md | 16 ++-- packages/math/max/max.js | 16 ++-- packages/math/min/README.md | 18 ++-- packages/math/min/min.js | 18 ++-- packages/math/normalize/README.md | 12 +-- packages/math/normalize/normalize.js | 12 +-- packages/math/radiansToDegrees/README.md | 10 +- .../math/radiansToDegrees/radiansToDegrees.js | 10 +- packages/math/randomDist/README.md | 2 +- packages/math/randomDist/randomDist.js | 2 +- packages/math/randomInt/README.md | 2 +- packages/math/randomInt/randomInt.js | 2 +- packages/math/randomRange/README.md | 2 +- packages/math/randomRange/randomRange.js | 2 +- packages/math/roundToNearest/README.md | 10 +- .../math/roundToNearest/roundToNearest.js | 12 +-- packages/math/roundToPlaces/README.md | 20 ++-- packages/math/roundToPlaces/roundToPlaces.js | 20 ++-- packages/objects/get/README.md | 8 +- packages/objects/get/get.js | 8 +- packages/objects/omit/README.md | 10 +- packages/objects/omit/omit.js | 10 +- packages/objects/pick/README.md | 6 +- packages/objects/pick/pick.js | 6 +- packages/objects/pickBy/README.md | 10 +- packages/objects/pickBy/pickBy.js | 10 +- packages/strings/camelCase/README.md | 20 ++-- packages/strings/camelCase/camelCase.js | 22 ++--- packages/strings/capitalize/README.md | 4 +- packages/strings/capitalize/capitalize.js | 6 +- packages/strings/classnames/README.md | 12 +-- packages/strings/classnames/classnames.js | 12 +-- packages/strings/collapseWhitespace/README.md | 2 +- .../collapseWhitespace/collapseWhitespace.js | 4 +- packages/strings/deburr/README.md | 4 +- packages/strings/deburr/deburr.js | 6 +- packages/strings/escapeHTML/README.md | 6 +- packages/strings/escapeHTML/escapeHTML.js | 8 +- packages/strings/kebabCase/README.md | 22 ++--- packages/strings/kebabCase/kebabCase.js | 24 ++--- packages/strings/lines/README.md | 4 +- packages/strings/lines/lines.js | 6 +- packages/strings/numberFormat/README.md | 6 +- packages/strings/numberFormat/numberFormat.js | 10 +- packages/strings/pascalCase/README.md | 18 ++-- packages/strings/pascalCase/pascalCase.js | 20 ++-- packages/strings/randomString/README.md | 12 +-- packages/strings/randomString/randomString.js | 12 +-- packages/strings/removePrefix/README.md | 8 +- packages/strings/removePrefix/removePrefix.js | 10 +- packages/strings/removeSuffix/README.md | 8 +- packages/strings/removeSuffix/removeSuffix.js | 10 +- packages/strings/snakeCase/README.md | 20 ++-- packages/strings/snakeCase/snakeCase.js | 22 ++--- packages/strings/squash/README.md | 8 +- packages/strings/squash/squash.js | 8 +- packages/strings/strip/README.md | 8 +- packages/strings/strip/strip.js | 10 +- packages/strings/stripHTML/README.md | 2 +- packages/strings/stripHTML/stripHTML.js | 4 +- packages/strings/stripPunctuation/README.md | 2 +- .../stripPunctuation/stripPunctuation.js | 4 +- packages/strings/substringAfter/README.md | 12 +-- .../strings/substringAfter/substringAfter.js | 14 +-- packages/strings/substringBefore/README.md | 12 +-- .../substringBefore/substringBefore.js | 14 +-- packages/strings/truncate/README.md | 16 ++-- packages/strings/truncate/truncate.js | 18 ++-- packages/strings/unescapeHTML/README.md | 6 +- packages/strings/unescapeHTML/unescapeHTML.js | 8 +- packages/strings/words/README.md | 4 +- packages/strings/words/words.js | 6 +- 237 files changed, 1377 insertions(+), 1380 deletions(-) diff --git a/packages/arrays/chunk/README.md b/packages/arrays/chunk/README.md index 6f2dedfd..6f4ee876 100644 --- a/packages/arrays/chunk/README.md +++ b/packages/arrays/chunk/README.md @@ -19,14 +19,14 @@ If array can’t be split evenly, the final chunk will be the remaining elements **Example** ```js chunk([1, 2, 3, 4], 2); -// -> [[1, 2], [3, 4]] +// => [[1, 2], [3, 4]] chunk([1, 2, 3, 4, 5], 2); -// -> [[1, 2], [3, 4], [5]] +// => [[1, 2], [3, 4], [5]] chunk([1, 2, 3, 4], 3); -// -> [[1, 2, 3], [4]] +// => [[1, 2, 3], [4]] chunk([1, 2, 3, 4], 2.7); -// -> [[1, 2], [3, 4]] +// => [[1, 2], [3, 4]] ``` diff --git a/packages/arrays/chunk/chunk.js b/packages/arrays/chunk/chunk.js index 61a00cd7..5330f316 100644 --- a/packages/arrays/chunk/chunk.js +++ b/packages/arrays/chunk/chunk.js @@ -9,20 +9,20 @@ * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `size` is not number. * @throws {RangeError} If `size` is not a positive number, or zero, or `NaN`, or greater than `Number.MAX_SAFE_INTEGER`. - * @return {Array} The new array containing chunks. If `size` is lower than 1, an empty array is returned. + * @returns {Array} The new array containing chunks. If `size` is lower than 1, an empty array is returned. * @example * * chunk([1, 2, 3, 4], 2); - * // -> [[1, 2], [3, 4]] + * // => [[1, 2], [3, 4]] * * chunk([1, 2, 3, 4, 5], 2); - * // -> [[1, 2], [3, 4], [5]] + * // => [[1, 2], [3, 4], [5]] * * chunk([1, 2, 3, 4], 3); - * // -> [[1, 2, 3], [4]] + * // => [[1, 2, 3], [4]] * * chunk([1, 2, 3, 4], 2.7); - * // -> [[1, 2], [3, 4]] + * // => [[1, 2], [3, 4]] */ const chunk = (array, size) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/diff/README.md b/packages/arrays/diff/README.md index 894876ff..f08a4ff7 100644 --- a/packages/arrays/diff/README.md +++ b/packages/arrays/diff/README.md @@ -25,8 +25,8 @@ const a = [1, 2, 3, 4, 5, obj]; const b = [5, 2, 10, obj]; diff(a, b); -// -> [1, 3, 4] +// => [1, 3, 4] diff(a, []); -// -> [1, 2, 3, 4, 5, obj] +// => [1, 2, 3, 4, 5, obj] ``` diff --git a/packages/arrays/diff/diff.js b/packages/arrays/diff/diff.js index 5522778a..d6122636 100644 --- a/packages/arrays/diff/diff.js +++ b/packages/arrays/diff/diff.js @@ -18,10 +18,10 @@ * const b = [5, 2, 10, obj]; * * diff(a, b); - * // -> [1, 3, 4] + * // => [1, 3, 4] * * diff(a, []); - * // -> [1, 2, 3, 4, 5, obj] + * // => [1, 2, 3, 4, 5, obj] */ const diff = (arrayA, arrayB) => { if (!Array.isArray(arrayA) || !Array.isArray(arrayB)) { diff --git a/packages/arrays/drop/README.md b/packages/arrays/drop/README.md index 5a98dead..002f51cb 100644 --- a/packages/arrays/drop/README.md +++ b/packages/arrays/drop/README.md @@ -18,32 +18,32 @@ Creates a slice of `array` with `n` elements dropped from the beginning. **Example** ```js drop([1, 2, 3, 4, 5]); -// -> [2, 3, 4, 5] +// => [2, 3, 4, 5] drop([1, 2, 3, 4, 5], null); -// -> [2, 3, 4, 5] +// => [2, 3, 4, 5] drop([1, 2, 3, 4, 5], NaN); -// -> [2, 3, 4, 5] +// => [2, 3, 4, 5] drop([1, 2, 3, 4, 5], 3); -// -> [4, 5] +// => [4, 5] drop([1, 2, 3, 4, 5], 0); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] drop([1, 2, 3, 4, 5], -2); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] drop([1, 2, 3, 4, 5], 10); -// -> [] +// => [] drop([1, 2, 3, 4, 5], Number.MAX_VALUE); -// -> [] +// => [] drop([1, 2, 3, 4, 5], '2'); -// -> Throws TypeError +// => Throws TypeError drop({}, 2); -// -> Throws TypeError +// => Throws TypeError ``` diff --git a/packages/arrays/drop/drop.js b/packages/arrays/drop/drop.js index 77c9c237..209df0a0 100644 --- a/packages/arrays/drop/drop.js +++ b/packages/arrays/drop/drop.js @@ -11,34 +11,34 @@ * @example * * drop([1, 2, 3, 4, 5]); - * // -> [2, 3, 4, 5] + * // => [2, 3, 4, 5] * * drop([1, 2, 3, 4, 5], null); - * // -> [2, 3, 4, 5] + * // => [2, 3, 4, 5] * * drop([1, 2, 3, 4, 5], NaN); - * // -> [2, 3, 4, 5] + * // => [2, 3, 4, 5] * * drop([1, 2, 3, 4, 5], 3); - * // -> [4, 5] + * // => [4, 5] * * drop([1, 2, 3, 4, 5], 0); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * drop([1, 2, 3, 4, 5], -2); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * drop([1, 2, 3, 4, 5], 10); - * // -> [] + * // => [] * * drop([1, 2, 3, 4, 5], Number.MAX_VALUE); - * // -> [] + * // => [] * * drop([1, 2, 3, 4, 5], '2'); - * // -> Throws TypeError + * // => Throws TypeError * * drop({}, 2); - * // -> Throws TypeError + * // => Throws TypeError */ const drop = (array, n) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/dropRight/README.md b/packages/arrays/dropRight/README.md index f830e667..b62f9e95 100644 --- a/packages/arrays/dropRight/README.md +++ b/packages/arrays/dropRight/README.md @@ -18,32 +18,32 @@ Creates a slice of `array` with `n` elements dropped from the end. **Example** ```js dropRight([1, 2, 3, 4, 5]); -// -> [1, 2, 3, 4] +// => [1, 2, 3, 4] dropRight([1, 2, 3, 4, 5], null); -// -> [1, 2, 3, 4] +// => [1, 2, 3, 4] dropRight([1, 2, 3, 4, 5], NaN); -// -> [1, 2, 3, 4] +// => [1, 2, 3, 4] dropRight([1, 2, 3, 4, 5], 3); -// -> [1, 2] +// => [1, 2] dropRight([1, 2, 3, 4, 5], 0); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] dropRight([1, 2, 3, 4, 5], -2); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] dropRight([1, 2, 3, 4, 5], 10); -// -> [] +// => [] dropRight([1, 2, 3, 4, 5], Number.MAX_VALUE); -// -> [] +// => [] dropRight([1, 2, 3, 4, 5], '2'); -// -> Throws TypeError +// => Throws TypeError dropRight({}, 2); -// -> Throws TypeError +// => Throws TypeError ``` diff --git a/packages/arrays/dropRight/dropRight.js b/packages/arrays/dropRight/dropRight.js index 00481abe..1dbfc774 100644 --- a/packages/arrays/dropRight/dropRight.js +++ b/packages/arrays/dropRight/dropRight.js @@ -11,34 +11,34 @@ * @example * * dropRight([1, 2, 3, 4, 5]); - * // -> [1, 2, 3, 4] + * // => [1, 2, 3, 4] * * dropRight([1, 2, 3, 4, 5], null); - * // -> [1, 2, 3, 4] + * // => [1, 2, 3, 4] * * dropRight([1, 2, 3, 4, 5], NaN); - * // -> [1, 2, 3, 4] + * // => [1, 2, 3, 4] * * dropRight([1, 2, 3, 4, 5], 3); - * // -> [1, 2] + * // => [1, 2] * * dropRight([1, 2, 3, 4, 5], 0); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * dropRight([1, 2, 3, 4, 5], -2); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * dropRight([1, 2, 3, 4, 5], 10); - * // -> [] + * // => [] * * dropRight([1, 2, 3, 4, 5], Number.MAX_VALUE); - * // -> [] + * // => [] * * dropRight([1, 2, 3, 4, 5], '2'); - * // -> Throws TypeError + * // => Throws TypeError * * dropRight({}, 2); - * // -> Throws TypeError + * // => Throws TypeError */ const dropRight = (array, n) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/dropRightWhile/README.md b/packages/arrays/dropRightWhile/README.md index 37b5bc64..b5cdec13 100644 --- a/packages/arrays/dropRightWhile/README.md +++ b/packages/arrays/dropRightWhile/README.md @@ -28,5 +28,5 @@ const books = [ dropRightWhile(books, function (book, index, books) { return !book.read; }); -// -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}] +// => [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}] ``` diff --git a/packages/arrays/dropRightWhile/dropRightWhile.js b/packages/arrays/dropRightWhile/dropRightWhile.js index 3042d4e3..530e59fa 100644 --- a/packages/arrays/dropRightWhile/dropRightWhile.js +++ b/packages/arrays/dropRightWhile/dropRightWhile.js @@ -21,7 +21,7 @@ * dropRightWhile(books, function (book, index, books) { * return !book.read; * }); - * // -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}] + * // => [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: true}] * */ const dropRightWhile = (array, predicate) => { diff --git a/packages/arrays/dropWhile/README.md b/packages/arrays/dropWhile/README.md index e9414800..7892291f 100644 --- a/packages/arrays/dropWhile/README.md +++ b/packages/arrays/dropWhile/README.md @@ -28,5 +28,5 @@ const books = [ dropWhile(books, function (book, index, books) { return !book.read; }); -// -> [{title: 'JavaScript The Good Parts', read: true}, {title: 'Eloquent Javascript', read: false}] +// => [{title: 'JavaScript The Good Parts', read: true}, {title: 'Eloquent Javascript', read: false}] ``` diff --git a/packages/arrays/dropWhile/dropWhile.js b/packages/arrays/dropWhile/dropWhile.js index 139953a2..8349285c 100644 --- a/packages/arrays/dropWhile/dropWhile.js +++ b/packages/arrays/dropWhile/dropWhile.js @@ -8,7 +8,7 @@ * @param {function} predicate The function invoked per iteration. * @throws {TypeError} If `array` is not array. * @throws {TypeError} If `predicate` is not function but not if is `undefined`. - * @return {Array} The slice of the array. + * @returns {Array} The slice of the array. * @example * * const books = [ @@ -21,7 +21,7 @@ * dropWhile(books, function (book, index, books) { * return !book.read; * }); - * // -> [{title: 'JavaScript The Good Parts', read: true}, {title: 'Eloquent Javascript', read: false}] + * // => [{title: 'JavaScript The Good Parts', read: true}, {title: 'Eloquent Javascript', read: false}] */ const dropWhile = (array, predicate) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/groupBy/README.md b/packages/arrays/groupBy/README.md index 7b1d6e10..6d4000d0 100644 --- a/packages/arrays/groupBy/README.md +++ b/packages/arrays/groupBy/README.md @@ -19,7 +19,7 @@ The order of grouped values is determined by the order they occur in the `array` groupBy(['one', 'two', 'three', 'four', 'five'], function (item) { return item.length; }); -// -> { '3': ['one', 'two'], '4': ['four', 'five'], '5': ['three'] } +// => { '3': ['one', 'two'], '4': ['four', 'five'], '5': ['three'] } groupBy([ { name: 'John' }, @@ -30,5 +30,5 @@ groupBy([ { name: 'Alex' }, { name: 'George' } ], 'name'); -// -> { 'John': [{'name': 'John'}, {'name': 'John'}], 'George': [{'name': 'George'}, {'name': 'George'}], 'Helen': [{'name': 'Helen'}, {'name': 'Helen'}], 'Alex': [{'name': 'Alex'}] } +// => { 'John': [{'name': 'John'}, {'name': 'John'}], 'George': [{'name': 'George'}, {'name': 'George'}], 'Helen': [{'name': 'Helen'}, {'name': 'Helen'}], 'Alex': [{'name': 'Alex'}] } ``` diff --git a/packages/arrays/groupBy/groupBy.js b/packages/arrays/groupBy/groupBy.js index fd4bbfd7..526fedaa 100644 --- a/packages/arrays/groupBy/groupBy.js +++ b/packages/arrays/groupBy/groupBy.js @@ -13,7 +13,7 @@ * groupBy(['one', 'two', 'three', 'four', 'five'], function (item) { * return item.length; * }); - * // -> { '3': ['one', 'two'], '4': ['four', 'five'], '5': ['three'] } + * // => { '3': ['one', 'two'], '4': ['four', 'five'], '5': ['three'] } * * groupBy([ * { name: 'John' }, @@ -24,7 +24,7 @@ * { name: 'Alex' }, * { name: 'George' } * ], 'name'); - * // -> { 'John': [{'name': 'John'}, {'name': 'John'}], 'George': [{'name': 'George'}, {'name': 'George'}], 'Helen': [{'name': 'Helen'}, {'name': 'Helen'}], 'Alex': [{'name': 'Alex'}] } + * // => { 'John': [{'name': 'John'}, {'name': 'John'}], 'George': [{'name': 'George'}, {'name': 'George'}], 'Helen': [{'name': 'Helen'}, {'name': 'Helen'}], 'Alex': [{'name': 'Alex'}] } */ const groupBy = (array, iteratee) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/groupBy/test.js b/packages/arrays/groupBy/test.js index 68104003..df6dd836 100644 --- a/packages/arrays/groupBy/test.js +++ b/packages/arrays/groupBy/test.js @@ -5,13 +5,13 @@ describe('Array/groupBy', function () { const arr1 = ['one', 'two', 'three', 'four', 'five']; const arr2 = [ - { name: 'John' }, - { name: 'George' }, - { name: 'Helen' }, - { name: 'John' }, - { name: 'Helen' }, - { name: 'Alex' }, - { name: 'George' } + {name: 'John'}, + {name: 'George'}, + {name: 'Helen'}, + {name: 'John'}, + {name: 'Helen'}, + {name: 'Alex'}, + {name: 'George'} ]; const arr3 = [9.5, 6.3, 4.9, 6.8, 9.0, 9.3]; @@ -23,10 +23,10 @@ describe('Array/groupBy', function () { }; const exp2 = { - John: [{ name: 'John' }, { name: 'John' }], - George: [{ name: 'George' }, { name: 'George' }], - Helen: [{ name: 'Helen' }, { name: 'Helen' }], - Alex: [{ name: 'Alex' }] + John: [{name: 'John'}, {name: 'John'}], + George: [{name: 'George'}, {name: 'George'}], + Helen: [{name: 'Helen'}, {name: 'Helen'}], + Alex: [{name: 'Alex'}] }; const exp3 = { diff --git a/packages/arrays/insert/README.md b/packages/arrays/insert/README.md index aff21a99..b0768a54 100644 --- a/packages/arrays/insert/README.md +++ b/packages/arrays/insert/README.md @@ -21,26 +21,26 @@ Inserts one or more elements to array at a specific index. const arr = [1, 2, 3]; insert(arr, 0, 'a'); -// -> ['a', 1, 2, 3] +// => ['a', 1, 2, 3] insert(arr, 2, 'a'); -// -> [1, 2, 'a', 3] +// => [1, 2, 'a', 3] insert(arr, -1, 'a'); -// -> [1, 2, 'a', 3] +// => [1, 2, 'a', 3] insert(arr, 0.9, 'a'); -// -> ['a', 1, 2, 3]; +// => ['a', 1, 2, 3]; insert(arr, arr.length + 1, 'a'); -// -> [1, 2, 3, 'a'] +// => [1, 2, 3, 'a'] insert(arr, 1, 'a', 'b', 'c'); -// -> [1, 'a', 'b', 'c', 2, 3] +// => [1, 'a', 'b', 'c', 2, 3] insert(arr, 2, undefined); -// -> [1, 2, undefined, 3] +// => [1, 2, undefined, 3] insert(arr, 2); -// -> [1, 2, 3] +// => [1, 2, 3] ``` diff --git a/packages/arrays/insert/insert.js b/packages/arrays/insert/insert.js index c2c07704..48a648b8 100644 --- a/packages/arrays/insert/insert.js +++ b/packages/arrays/insert/insert.js @@ -17,28 +17,28 @@ * const arr = [1, 2, 3]; * * insert(arr, 0, 'a'); - * // -> ['a', 1, 2, 3] + * // => ['a', 1, 2, 3] * * insert(arr, 2, 'a'); - * // -> [1, 2, 'a', 3] + * // => [1, 2, 'a', 3] * * insert(arr, -1, 'a'); - * // -> [1, 2, 'a', 3] + * // => [1, 2, 'a', 3] * * insert(arr, 0.9, 'a'); - * // -> ['a', 1, 2, 3]; + * // => ['a', 1, 2, 3]; * * insert(arr, arr.length + 1, 'a'); - * // -> [1, 2, 3, 'a'] + * // => [1, 2, 3, 'a'] * * insert(arr, 1, 'a', 'b', 'c'); - * // -> [1, 'a', 'b', 'c', 2, 3] + * // => [1, 'a', 'b', 'c', 2, 3] * * insert(arr, 2, undefined); - * // -> [1, 2, undefined, 3] + * // => [1, 2, undefined, 3] * * insert(arr, 2); - * // -> [1, 2, 3] + * // => [1, 2, 3] */ const insert = (array, start, ...elements) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/insert/test.js b/packages/arrays/insert/test.js index 3b4ca2bc..5410ca5f 100644 --- a/packages/arrays/insert/test.js +++ b/packages/arrays/insert/test.js @@ -27,7 +27,7 @@ describe('Array/insert', function () { expect(insert(arr, 2, undefined)).toEqual([1, 2, undefined, 3]); expect(function () { - return insert({ foo: 'bar' }, 0, ['a', 'b']); + return insert({foo: 'bar'}, 0, ['a', 'b']); }).toThrow(new TypeError('Expected an array for first argument')); expect(function () { diff --git a/packages/arrays/intersect/README.md b/packages/arrays/intersect/README.md index 4cd4182d..3db37157 100644 --- a/packages/arrays/intersect/README.md +++ b/packages/arrays/intersect/README.md @@ -20,8 +20,8 @@ const arrB = [2, 7, 'foo', NaN, 3]; const arrC = [1, 2, 3, NaN]; intersect(arrA, arrB); -// -> [NaN, 3, 'foo'] +// => [NaN, 3, 'foo'] intersect(arrA, arrB, arrC); -// -> [NaN, 3] +// => [NaN, 3] ``` diff --git a/packages/arrays/intersect/intersect.js b/packages/arrays/intersect/intersect.js index 3418ae65..ace6afe2 100644 --- a/packages/arrays/intersect/intersect.js +++ b/packages/arrays/intersect/intersect.js @@ -14,10 +14,10 @@ * const arrC = [1, 2, 3, NaN]; * * intersect(arrA, arrB); - * // -> [NaN, 3, 'foo'] + * // => [NaN, 3, 'foo'] * * intersect(arrA, arrB, arrC); - * // -> [NaN, 3] + * // => [NaN, 3] */ const intersect = (...arrays) => { let len = arrays.length; @@ -38,10 +38,7 @@ const intersect = (...arrays) => { while (index < currentArray.length) { const currentElement = currentArray[index]; - if ( - element === currentElement - || (element !== element && currentElement !== currentElement) // Check for NaN values - ) { + if (element === currentElement || Number.isNaN(element) && Number.isNaN(currentElement)) { return true; } diff --git a/packages/arrays/move/README.md b/packages/arrays/move/README.md index af37082c..5e8e033a 100644 --- a/packages/arrays/move/README.md +++ b/packages/arrays/move/README.md @@ -21,14 +21,14 @@ Move an array element to a different position. const array = ['A', 'B', 'C', 'D', 'E']; move(array, 0, 1); -// -> ['B', 'A', 'C', 'D', 'E'] +// => ['B', 'A', 'C', 'D', 'E'] move(array, 0, array.length - 1); -// -> ['B', 'C', 'D', 'E', 'A'] +// => ['B', 'C', 'D', 'E', 'A'] move(array, -1, 3); -// -> ['A', 'B', 'C', 'E', 'D'] +// => ['A', 'B', 'C', 'E', 'D'] move(array, -1, -3); -// -> ['A', 'B', 'E', 'C', 'D'] +// => ['A', 'B', 'E', 'C', 'D'] ``` diff --git a/packages/arrays/move/move.js b/packages/arrays/move/move.js index fd8874a2..d05843ff 100644 --- a/packages/arrays/move/move.js +++ b/packages/arrays/move/move.js @@ -14,16 +14,16 @@ * const array = ['A', 'B', 'C', 'D', 'E']; * * move(array, 0, 1); - * // -> ['B', 'A', 'C', 'D', 'E'] + * // => ['B', 'A', 'C', 'D', 'E'] * * move(array, 0, array.length - 1); - * // -> ['B', 'C', 'D', 'E', 'A'] + * // => ['B', 'C', 'D', 'E', 'A'] * * move(array, -1, 3); - * // -> ['A', 'B', 'C', 'E', 'D'] + * // => ['A', 'B', 'C', 'E', 'D'] * * move(array, -1, -3); - * // -> ['A', 'B', 'E', 'C', 'D'] + * // => ['A', 'B', 'E', 'C', 'D'] */ const move = (array, fromIndex, toIndex) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/partition/README.md b/packages/arrays/partition/README.md index a8d1e19a..d7c73266 100644 --- a/packages/arrays/partition/README.md +++ b/packages/arrays/partition/README.md @@ -31,10 +31,10 @@ const users = [{ }]; partition(users, user => user.isAdmin); -// -> [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] +// => [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] const numbers = [1, 3, 5, -4, 6, -2]; partition(numbers, num => num > 0); -// -> [[1, 3, 5, 6], [-4, -2]] +// => [[1, 3, 5, 6], [-4, -2]] ``` diff --git a/packages/arrays/partition/partition.js b/packages/arrays/partition/partition.js index 4fb15b13..c91fe916 100644 --- a/packages/arrays/partition/partition.js +++ b/packages/arrays/partition/partition.js @@ -24,12 +24,12 @@ * }]; * * partition(users, user => user.isAdmin); - * // -> [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] + * // => [[{ name: 'John', isAdmin: true }, { name: 'Alice', isAdmin: true }], [{ name: 'George', isAdmin: false }]] * * const numbers = [1, 3, 5, -4, 6, -2]; * * partition(numbers, num => num > 0); - * // -> [[1, 3, 5, 6], [-4, -2]] + * // => [[1, 3, 5, 6], [-4, -2]] */ const partition = (array, predicate = x => x) => { const part1 = []; diff --git a/packages/arrays/pluck/README.md b/packages/arrays/pluck/README.md index 0fd73a2f..b7faaacd 100755 --- a/packages/arrays/pluck/README.md +++ b/packages/arrays/pluck/README.md @@ -24,8 +24,8 @@ const books = [ ]; pluck(books, 'title'); -// -> ["Around the World in Eighty Days", "The Mist", "Journey to the Center of the Earth", "The Monster in the Closet"] +// => ["Around the World in Eighty Days", "The Mist", "Journey to the Center of the Earth", "The Monster in the Closet"] pluck(books, 'author'); -// -> ["Jules Verne", "Stephen King", "Jules Verne", "Stephen King"] +// => ["Jules Verne", "Stephen King", "Jules Verne", "Stephen King"] ``` diff --git a/packages/arrays/pluck/pluck.js b/packages/arrays/pluck/pluck.js index 96852e57..6edff54f 100755 --- a/packages/arrays/pluck/pluck.js +++ b/packages/arrays/pluck/pluck.js @@ -17,10 +17,10 @@ * ]; * * pluck(books, 'title'); - * // -> ["Around the World in Eighty Days", "The Mist", "Journey to the Center of the Earth", "The Monster in the Closet"] + * // => ["Around the World in Eighty Days", "The Mist", "Journey to the Center of the Earth", "The Monster in the Closet"] * * pluck(books, 'author'); - * // -> ["Jules Verne", "Stephen King", "Jules Verne", "Stephen King"] + * // => ["Jules Verne", "Stephen King", "Jules Verne", "Stephen King"] */ const pluck = (array, key) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/pluck/test.js b/packages/arrays/pluck/test.js index 47aba1cf..c37f08c5 100644 --- a/packages/arrays/pluck/test.js +++ b/packages/arrays/pluck/test.js @@ -2,10 +2,10 @@ const pluck = require('./pluck'); describe('Array/pluck', function () { const books = [ - { title: 'Around the World in Eighty Days', author: 'Jules Verne' }, - { title: 'The Mist', author: 'Stephen King' }, - { title: 'Journey to the Center of the Earth', author: 'Jules Verne' }, - { title: 'The Monster in the Closet', author: 'Stephen King' } + {title: 'Around the World in Eighty Days', author: 'Jules Verne'}, + {title: 'The Mist', author: 'Stephen King'}, + {title: 'Journey to the Center of the Earth', author: 'Jules Verne'}, + {title: 'The Monster in the Closet', author: 'Stephen King'} ]; it('plucks the array', function () { diff --git a/packages/arrays/remove/README.md b/packages/arrays/remove/README.md index f9269366..b8f1bb0b 100644 --- a/packages/arrays/remove/README.md +++ b/packages/arrays/remove/README.md @@ -19,23 +19,23 @@ Removes one or more elements from an array at the specified index(es). const arr = [1, 2, 3, 4, 5]; remove(arr, 0); -// -> [2, 3, 4, 5] +// => [2, 3, 4, 5] remove(arr, 0, 1); -// -> [3, 4, 5] +// => [3, 4, 5] remove(arr, 0, 4); -// -> [2, 3, 4] +// => [2, 3, 4] remove(arr); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] remove(arr, arr.length); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] remove(arr, arr.length - 1); -// -> [1, 2, 3, 4] +// => [1, 2, 3, 4] remove(arr, NaN); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] ``` diff --git a/packages/arrays/remove/remove.js b/packages/arrays/remove/remove.js index 784e73da..1a401a72 100644 --- a/packages/arrays/remove/remove.js +++ b/packages/arrays/remove/remove.js @@ -12,25 +12,25 @@ * const arr = [1, 2, 3, 4, 5]; * * remove(arr, 0); - * // -> [2, 3, 4, 5] + * // => [2, 3, 4, 5] * * remove(arr, 0, 1); - * // -> [3, 4, 5] + * // => [3, 4, 5] * * remove(arr, 0, 4); - * // -> [2, 3, 4] + * // => [2, 3, 4] * * remove(arr); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * remove(arr, arr.length); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * remove(arr, arr.length - 1); - * // -> [1, 2, 3, 4] + * // => [1, 2, 3, 4] * * remove(arr, NaN); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] */ const remove = (array, ...indexes) => { if (!Array.isArray(array)) { @@ -38,7 +38,7 @@ const remove = (array, ...indexes) => { } return array.filter((_, index) => { - return typeof index === 'number' && index === index // check if number and not NaN + return typeof index === 'number' && !Number.isNaN(index) ? indexes.indexOf(index) === -1 : false; }); diff --git a/packages/arrays/remove/test.js b/packages/arrays/remove/test.js index 396ec2c1..08fed8ba 100644 --- a/packages/arrays/remove/test.js +++ b/packages/arrays/remove/test.js @@ -33,7 +33,7 @@ describe('Array/remove', function () { expect(remove(arr, '0', '1')).toEqual([1, 2, 3, 4, 5]); expect(function () { - return remove({ foo: 'bar' }, [0]); + return remove({foo: 'bar'}, [0]); }).toThrow(new TypeError('Expected an array for first argument')); }); }); diff --git a/packages/arrays/shuffle/README.md b/packages/arrays/shuffle/README.md index 90c78ece..cfdc1de3 100644 --- a/packages/arrays/shuffle/README.md +++ b/packages/arrays/shuffle/README.md @@ -17,5 +17,5 @@ using the Fisher-Yates (aka Knuth) Shuffle algorithm. **Example** ```js shuffle(arr); -// -> ['b', 'f', 'h', 'e', 'd', 'c', 'g', 'a'] +// => ['b', 'f', 'h', 'e', 'd', 'c', 'g', 'a'] ``` diff --git a/packages/arrays/shuffle/shuffle.js b/packages/arrays/shuffle/shuffle.js index b061fab7..bd22ae10 100644 --- a/packages/arrays/shuffle/shuffle.js +++ b/packages/arrays/shuffle/shuffle.js @@ -10,7 +10,7 @@ * @example * * shuffle(arr); - * // -> ['b', 'f', 'h', 'e', 'd', 'c', 'g', 'a'] + * // => ['b', 'f', 'h', 'e', 'd', 'c', 'g', 'a'] */ const shuffle = array => { if (!Array.isArray(array)) { diff --git a/packages/arrays/shuffle/test.js b/packages/arrays/shuffle/test.js index 87d2aec3..8a80fb42 100644 --- a/packages/arrays/shuffle/test.js +++ b/packages/arrays/shuffle/test.js @@ -9,7 +9,7 @@ describe('Array/shuffle', function () { expect(shuffle(arr)).not.toEqual(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']); expect(function () { - return shuffle({ a: 'a', b: 'b', c: 'c' }); + return shuffle({a: 'a', b: 'b', c: 'c'}); }).toThrow(new TypeError('Expected an array for first argument')); }); }); diff --git a/packages/arrays/sort/README.md b/packages/arrays/sort/README.md index 650f55c4..edc7ad7e 100644 --- a/packages/arrays/sort/README.md +++ b/packages/arrays/sort/README.md @@ -18,20 +18,20 @@ If array values are of different type, the result is not guaranteed to be correc **Example** ```js sort(['Delta', 'Omega', 'alpha', 'CHARLIE', 'lorem', 'bravo']); -// -> ['alpha', 'bravo', 'CHARLIE', 'Delta', 'lorem', 'Omega'] +// => ['alpha', 'bravo', 'CHARLIE', 'Delta', 'lorem', 'Omega'] sort(['Delta', 'Omega', 'alpha', 'CHARLIE', 'lorem', 'bravo'], false); -// -> ['Omega', 'lorem', 'Delta', 'CHARLIE', 'bravo', 'alpha'] +// => ['Omega', 'lorem', 'Delta', 'CHARLIE', 'bravo', 'alpha'] sort([4, 6, 2, 9, 100, 321, -2, 99], true); -// -> [-2, 2, 4, 6, 9, 99, 100, 321] +// => [-2, 2, 4, 6, 9, 99, 100, 321] sort([4, 6, 2, 9, 100, 321, -2, 99], false); -// -> [321, 100, 99, 9, 6, 4, 2, -2] +// => [321, 100, 99, 9, 6, 4, 2, -2] sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], true); -// -> [-10, -2, 2, 4, 6, 9, 99, 100, 321] +// => [-10, -2, 2, 4, 6, 9, 99, 100, 321] sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], false); -// -> [321, 100, 99, 9, 6, 4, 2, -2, -10] +// => [321, 100, 99, 9, 6, 4, 2, -2, -10] ``` diff --git a/packages/arrays/sort/sort.js b/packages/arrays/sort/sort.js index 934c18c6..f7501ee7 100644 --- a/packages/arrays/sort/sort.js +++ b/packages/arrays/sort/sort.js @@ -12,29 +12,29 @@ * @example * * sort(['Delta', 'Omega', 'alpha', 'CHARLIE', 'lorem', 'bravo']); - * // -> ['alpha', 'bravo', 'CHARLIE', 'Delta', 'lorem', 'Omega'] + * // => ['alpha', 'bravo', 'CHARLIE', 'Delta', 'lorem', 'Omega'] * * sort(['Delta', 'Omega', 'alpha', 'CHARLIE', 'lorem', 'bravo'], false); - * // -> ['Omega', 'lorem', 'Delta', 'CHARLIE', 'bravo', 'alpha'] + * // => ['Omega', 'lorem', 'Delta', 'CHARLIE', 'bravo', 'alpha'] * * sort([4, 6, 2, 9, 100, 321, -2, 99], true); - * // -> [-2, 2, 4, 6, 9, 99, 100, 321] + * // => [-2, 2, 4, 6, 9, 99, 100, 321] * * sort([4, 6, 2, 9, 100, 321, -2, 99], false); - * // -> [321, 100, 99, 9, 6, 4, 2, -2] + * // => [321, 100, 99, 9, 6, 4, 2, -2] * * sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], true); - * // -> [-10, -2, 2, 4, 6, 9, 99, 100, 321] + * // => [-10, -2, 2, 4, 6, 9, 99, 100, 321] * * sort([4, 6, undefined, 2, 9, -10, 100, 321, -2, null, 99], false); - * // -> [321, 100, 99, 9, 6, 4, 2, -2, -10] + * // => [321, 100, 99, 9, 6, 4, 2, -2, -10] */ const sort = (array, ascending = true) => { if (!Array.isArray(array)) { throw new TypeError('Expected an array for first argument'); } - return array.filter(el => el != null && el === el) // Remove any `null`, `undefined` or `NaN` values. + return array.filter(el => el != null && !Number.isNaN(el)) // Remove any `null`, `undefined` or `NaN` values. .map(el => typeof el === 'string' ? el.toLowerCase() : el) .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0) * [-1, 1][+!!ascending]); }; diff --git a/packages/arrays/sortBy/README.md b/packages/arrays/sortBy/README.md index 432225ac..1fafc8ae 100644 --- a/packages/arrays/sortBy/README.md +++ b/packages/arrays/sortBy/README.md @@ -25,16 +25,16 @@ const homes = [ ]; sortBy(homes, 'h_id'); -// -> "[{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":8,"city":"Dallas","price":"162500"}]" +// => "[{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":8,"city":"Dallas","price":"162500"}]" sortBy(homes, 'h_id', false); -// -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" +// => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" sortBy(homes, 'price', true); -// -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" +// => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" sortBy(homes, 'price', true, function (field) { return parseInt(field); }); -// -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"}]" +// => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"}]" ``` diff --git a/packages/arrays/sortBy/sortBy.js b/packages/arrays/sortBy/sortBy.js index 0a7b5579..46b7c0d8 100755 --- a/packages/arrays/sortBy/sortBy.js +++ b/packages/arrays/sortBy/sortBy.js @@ -18,18 +18,18 @@ * ]; * * sortBy(homes, 'h_id'); - * // -> "[{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":8,"city":"Dallas","price":"162500"}]" + * // => "[{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":8,"city":"Dallas","price":"162500"}]" * * sortBy(homes, 'h_id', false); - * // -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" + * // => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" * * sortBy(homes, 'price', true); - * // -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" + * // => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":5,"city":"new York","price":"162500.1"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"}]" * * sortBy(homes, 'price', true, function (field) { * return parseInt(field); * }); - * // -> "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"}]" + * // => "[{"h_id":8,"city":"Dallas","price":"162500"},{"h_id":4,"city":"Bevery Hills","price":"162500.5"},{"h_id":5,"city":"new York","price":"162500.1"}]" */ const sortBy = (array, field, ascending = true, primer) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/sortBy/test.js b/packages/arrays/sortBy/test.js index f54b9611..a4722145 100644 --- a/packages/arrays/sortBy/test.js +++ b/packages/arrays/sortBy/test.js @@ -2,69 +2,69 @@ const sortBy = require('./sortBy'); describe('Array/sortBy', function () { const people = [ - { name: 'Elena', age: '2' }, - { name: 'George', age: '33' }, - { name: 'Vasiliki', age: '32' }, - { name: 'Vaggelis', age: '30' } + {name: 'Elena', age: '2'}, + {name: 'George', age: '33'}, + {name: 'Vasiliki', age: '32'}, + {name: 'Vaggelis', age: '30'} ]; it('sorts an array of objects by property', function () { expect(sortBy(people, 'name')).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'George', age: '33' }, - { name: 'Vaggelis', age: '30' }, - { name: 'Vasiliki', age: '32' } + {name: 'Elena', age: '2'}, + {name: 'George', age: '33'}, + {name: 'Vaggelis', age: '30'}, + {name: 'Vasiliki', age: '32'} ]); expect(sortBy(people, 'name', false)).toEqual([ - { name: 'Vasiliki', age: '32' }, - { name: 'Vaggelis', age: '30' }, - { name: 'George', age: '33' }, - { name: 'Elena', age: '2' } + {name: 'Vasiliki', age: '32'}, + {name: 'Vaggelis', age: '30'}, + {name: 'George', age: '33'}, + {name: 'Elena', age: '2'} ]); expect(sortBy(people, 'name', null)).toEqual([ - { name: 'Vasiliki', age: '32' }, - { name: 'Vaggelis', age: '30' }, - { name: 'George', age: '33' }, - { name: 'Elena', age: '2' } + {name: 'Vasiliki', age: '32'}, + {name: 'Vaggelis', age: '30'}, + {name: 'George', age: '33'}, + {name: 'Elena', age: '2'} ]); expect(sortBy(people, 'age', true, function (age) { return age * 2; })).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'Vaggelis', age: '30' }, - { name: 'Vasiliki', age: '32' }, - { name: 'George', age: '33' } + {name: 'Elena', age: '2'}, + {name: 'Vaggelis', age: '30'}, + {name: 'Vasiliki', age: '32'}, + {name: 'George', age: '33'} ]); expect(sortBy(people, 'age', true, {})).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'Vaggelis', age: '30' }, - { name: 'Vasiliki', age: '32' }, - { name: 'George', age: '33' } + {name: 'Elena', age: '2'}, + {name: 'Vaggelis', age: '30'}, + {name: 'Vasiliki', age: '32'}, + {name: 'George', age: '33'} ]); expect(sortBy([...people, undefined, null, NaN, 'foo', 100, [1, 2, 3], () => void 0, new Set(), new Map(), Symbol('foo'), new Date()], 'age')).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'Vaggelis', age: '30' }, - { name: 'Vasiliki', age: '32' }, - { name: 'George', age: '33' }, + {name: 'Elena', age: '2'}, + {name: 'Vaggelis', age: '30'}, + {name: 'Vasiliki', age: '32'}, + {name: 'George', age: '33'}, ]); expect(sortBy(people, 'nonExistentProperty')).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'George', age: '33' }, - { name: 'Vasiliki', age: '32' }, - { name: 'Vaggelis', age: '30' } + {name: 'Elena', age: '2'}, + {name: 'George', age: '33'}, + {name: 'Vasiliki', age: '32'}, + {name: 'Vaggelis', age: '30'} ]); expect(sortBy(people, 'nonExistentProperty', false)).toEqual([ - { name: 'Elena', age: '2' }, - { name: 'George', age: '33' }, - { name: 'Vasiliki', age: '32' }, - { name: 'Vaggelis', age: '30' } + {name: 'Elena', age: '2'}, + {name: 'George', age: '33'}, + {name: 'Vasiliki', age: '32'}, + {name: 'Vaggelis', age: '30'} ]); expect(function () { diff --git a/packages/arrays/tail/README.md b/packages/arrays/tail/README.md index e0bc0b27..90a24110 100644 --- a/packages/arrays/tail/README.md +++ b/packages/arrays/tail/README.md @@ -16,11 +16,11 @@ Gets all but the first element of array. **Example** ```js tail([1, 2, 3,]); -// -> [2, 3] +// => [2, 3] tail([1]); -// -> [] +// => [] tail([]); -// -> [] +// => [] ``` diff --git a/packages/arrays/tail/tail.js b/packages/arrays/tail/tail.js index 4f9ecbba..36971635 100644 --- a/packages/arrays/tail/tail.js +++ b/packages/arrays/tail/tail.js @@ -9,13 +9,13 @@ * @example * * tail([1, 2, 3,]); - * // -> [2, 3] + * // => [2, 3] * * tail([1]); - * // -> [] + * // => [] * * tail([]); - * // -> [] + * // => [] */ const tail = array => { if (!Array.isArray(array)) { diff --git a/packages/arrays/take/README.md b/packages/arrays/take/README.md index 3cec06df..53417824 100644 --- a/packages/arrays/take/README.md +++ b/packages/arrays/take/README.md @@ -18,29 +18,29 @@ Creates a slice of `array` with `n` items taken from the beginning. **Example** ```js take([1, 2, 3, 4, 5]); -// -> [1] +// => [1] take([1, 2, 3, 4, 5], NaN); -// -> [1] +// => [1] take([1, 2, 3, 4, 5], 3); -// -> [1, 2, 3] +// => [1, 2, 3] take([1, 2, 3, 4, 5], 0); -// -> [] +// => [] take([1, 2, 3, 4, 5], -2); -// -> [] +// => [] take([1, 2, 3, 4, 5], 10); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] take([1, 2, 3, 4, 5], Number.MAX_VALUE); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] take([1, 2, 3, 4, 5], '2'); -// -> Throws TypeError +// => Throws TypeError take({}, 2); -// -> Throws TypeError +// => Throws TypeError ``` diff --git a/packages/arrays/take/take.js b/packages/arrays/take/take.js index 02184ac9..f4d639f4 100644 --- a/packages/arrays/take/take.js +++ b/packages/arrays/take/take.js @@ -11,31 +11,31 @@ * @example * * take([1, 2, 3, 4, 5]); - * // -> [1] + * // => [1] * * take([1, 2, 3, 4, 5], NaN); - * // -> [1] + * // => [1] * * take([1, 2, 3, 4, 5], 3); - * // -> [1, 2, 3] + * // => [1, 2, 3] * * take([1, 2, 3, 4, 5], 0); - * // -> [] + * // => [] * * take([1, 2, 3, 4, 5], -2); - * // -> [] + * // => [] * * take([1, 2, 3, 4, 5], 10); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * take([1, 2, 3, 4, 5], Number.MAX_VALUE); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * take([1, 2, 3, 4, 5], '2'); - * // -> Throws TypeError + * // => Throws TypeError * * take({}, 2); - * // -> Throws TypeError + * // => Throws TypeError */ const take = (array, n = 1) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/takeRight/README.md b/packages/arrays/takeRight/README.md index c420f6d6..e98060d9 100644 --- a/packages/arrays/takeRight/README.md +++ b/packages/arrays/takeRight/README.md @@ -18,29 +18,29 @@ Creates a slice of `array` with `n` items taken from the end. **Example** ```js takeRight([1, 2, 3, 4, 5]); -// -> [5] +// => [5] takeRight([1, 2, 3, 4, 5], NaN); -// -> [5] +// => [5] takeRight([1, 2, 3, 4, 5], 3); -// -> [3, 4, 5] +// => [3, 4, 5] takeRight([1, 2, 3, 4, 5], 0); -// -> [] +// => [] takeRight([1, 2, 3, 4, 5], -2); -// -> [] +// => [] takeRight([1, 2, 3, 4, 5], 10); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] takeRight([1, 2, 3, 4, 5], Number.MAX_VALUE); -// -> [1, 2, 3, 4, 5] +// => [1, 2, 3, 4, 5] takeRight([1, 2, 3, 4, 5], '2'); -// -> Throws TypeError +// => Throws TypeError takeRight({}, 2); -// -> Throws TypeError +// => Throws TypeError ``` diff --git a/packages/arrays/takeRight/takeRight.js b/packages/arrays/takeRight/takeRight.js index 6c617aa6..bbb5526c 100644 --- a/packages/arrays/takeRight/takeRight.js +++ b/packages/arrays/takeRight/takeRight.js @@ -11,31 +11,31 @@ * @example * * takeRight([1, 2, 3, 4, 5]); - * // -> [5] + * // => [5] * * takeRight([1, 2, 3, 4, 5], NaN); - * // -> [5] + * // => [5] * * takeRight([1, 2, 3, 4, 5], 3); - * // -> [3, 4, 5] + * // => [3, 4, 5] * * takeRight([1, 2, 3, 4, 5], 0); - * // -> [] + * // => [] * * takeRight([1, 2, 3, 4, 5], -2); - * // -> [] + * // => [] * * takeRight([1, 2, 3, 4, 5], 10); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * takeRight([1, 2, 3, 4, 5], Number.MAX_VALUE); - * // -> [1, 2, 3, 4, 5] + * // => [1, 2, 3, 4, 5] * * takeRight([1, 2, 3, 4, 5], '2'); - * // -> Throws TypeError + * // => Throws TypeError * * takeRight({}, 2); - * // -> Throws TypeError + * // => Throws TypeError */ const takeRight = (array, n = 1) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/takeRightWhile/README.md b/packages/arrays/takeRightWhile/README.md index 7bba0034..e287eec1 100644 --- a/packages/arrays/takeRightWhile/README.md +++ b/packages/arrays/takeRightWhile/README.md @@ -28,5 +28,5 @@ const books = [ takeRightWhile(books, function (book, index, books) { return !book.read; }); -// -> [{title: 'JavaScript The Good Parts', read: false}, {title: 'Eloquent Javascript', read: false}] +// => [{title: 'JavaScript The Good Parts', read: false}, {title: 'Eloquent Javascript', read: false}] ``` diff --git a/packages/arrays/takeRightWhile/takeRightWhile.js b/packages/arrays/takeRightWhile/takeRightWhile.js index 3ab8e882..cbfc643e 100644 --- a/packages/arrays/takeRightWhile/takeRightWhile.js +++ b/packages/arrays/takeRightWhile/takeRightWhile.js @@ -21,7 +21,7 @@ * takeRightWhile(books, function (book, index, books) { * return !book.read; * }); - * // -> [{title: 'JavaScript The Good Parts', read: false}, {title: 'Eloquent Javascript', read: false}] + * // => [{title: 'JavaScript The Good Parts', read: false}, {title: 'Eloquent Javascript', read: false}] */ const takeRightWhile = (array, predicate) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/takeRightWhile/test.js b/packages/arrays/takeRightWhile/test.js index 7b337d20..02c6b640 100644 --- a/packages/arrays/takeRightWhile/test.js +++ b/packages/arrays/takeRightWhile/test.js @@ -3,10 +3,10 @@ const takeRightWhile = require('./takeRightWhile'); describe('Array/takeRightWhile', function () { it('creates a slice of array with n items taken from the end', function () { const books = [ - { title: 'Javascript Design Patterns', read: false }, - { title: 'Programming Javascript Applications', read: true }, - { title: 'JavaScript The Good Parts', read: false }, - { title: 'Eloquent Javascript', read: false } + {title: 'Javascript Design Patterns', read: false}, + {title: 'Programming Javascript Applications', read: true}, + {title: 'JavaScript The Good Parts', read: false}, + {title: 'Eloquent Javascript', read: false} ]; const unread = takeRightWhile(books, function (book) { @@ -18,8 +18,8 @@ describe('Array/takeRightWhile', function () { }); expect(unread).toEqual([ - { title: 'JavaScript The Good Parts', read: false }, - { title: 'Eloquent Javascript', read: false } + {title: 'JavaScript The Good Parts', read: false}, + {title: 'Eloquent Javascript', read: false} ]); expect(read).toEqual([]); diff --git a/packages/arrays/takeWhile/README.md b/packages/arrays/takeWhile/README.md index a93821c2..677f6d4a 100644 --- a/packages/arrays/takeWhile/README.md +++ b/packages/arrays/takeWhile/README.md @@ -28,5 +28,5 @@ const books = [ takeWhile(books, function (book, index, books) { return !book.read; }); -// -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}] +// => [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}] ``` diff --git a/packages/arrays/takeWhile/takeWhile.js b/packages/arrays/takeWhile/takeWhile.js index da7f49bf..5ce2e51e 100644 --- a/packages/arrays/takeWhile/takeWhile.js +++ b/packages/arrays/takeWhile/takeWhile.js @@ -21,7 +21,7 @@ * takeWhile(books, function (book, index, books) { * return !book.read; * }); - * // -> [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}] + * // => [{title: 'Javascript Design Patterns', read: false}, {title: 'Programming Javascript Applications', read: false}] */ const takeWhile = (array, predicate) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/takeWhile/test.js b/packages/arrays/takeWhile/test.js index 13510a89..e474ab5b 100644 --- a/packages/arrays/takeWhile/test.js +++ b/packages/arrays/takeWhile/test.js @@ -3,10 +3,10 @@ const takeWhile = require('./takeWhile'); describe('Array/takeWhile', function () { it('creates a slice of array with elements taken from the beginning, until predicate returns falsy', function () { const books = [ - { title: 'Javascript Design Patterns', read: false }, - { title: 'Programming Javascript Applications', read: false }, - { title: 'JavaScript The Good Parts', read: true }, - { title: 'Eloquent Javascript', read: false } + {title: 'Javascript Design Patterns', read: false}, + {title: 'Programming Javascript Applications', read: false}, + {title: 'JavaScript The Good Parts', read: true}, + {title: 'Eloquent Javascript', read: false} ]; const firstUnread = takeWhile(books, function (book) { @@ -18,8 +18,8 @@ describe('Array/takeWhile', function () { }); expect(firstUnread).toEqual([ - { title: 'Javascript Design Patterns', read: false }, - { title: 'Programming Javascript Applications', read: false } + {title: 'Javascript Design Patterns', read: false}, + {title: 'Programming Javascript Applications', read: false} ]); expect(firstRead).toEqual([]); diff --git a/packages/arrays/uniq/README.md b/packages/arrays/uniq/README.md index a4375620..909a6157 100755 --- a/packages/arrays/uniq/README.md +++ b/packages/arrays/uniq/README.md @@ -20,5 +20,5 @@ const arr = ['foo', 'bar']; const values = ['a', 'a', 'b', '2', 2, obj, obj, arr, arr, true, true, false, false, NaN, NaN]; uniq(values); -// -> ['a', 'b', '2', 2, obj, arr, true, false, NaN] +// => ['a', 'b', '2', 2, obj, arr, true, false, NaN] ``` diff --git a/packages/arrays/uniq/uniq.js b/packages/arrays/uniq/uniq.js index 8545dcb0..450c0070 100755 --- a/packages/arrays/uniq/uniq.js +++ b/packages/arrays/uniq/uniq.js @@ -14,7 +14,7 @@ * const values = ['a', 'a', 'b', '2', 2, obj, obj, arr, arr, true, true, false, false, NaN, NaN]; * * uniq(values); - * // -> ['a', 'b', '2', 2, obj, arr, true, false, NaN] + * // => ['a', 'b', '2', 2, obj, arr, true, false, NaN] */ const uniq = array => { if (!Array.isArray(array)) { diff --git a/packages/arrays/uniqBy/README.md b/packages/arrays/uniqBy/README.md index 85b88241..e79c7cad 100644 --- a/packages/arrays/uniqBy/README.md +++ b/packages/arrays/uniqBy/README.md @@ -30,10 +30,10 @@ const arr2 = [ ]; uniqBy(arr1, 'id'); -// -> [{ id: 1, name: 'John' }, { id: 2, name: 'George' }] +// => [{ id: 1, name: 'John' }, { id: 2, name: 'George' }] uniqBy(arr2, function (o) { return Math.floor(o.v); }); -// -> [{ v: 1.6 }, { v: 2.1 }] +// => [{ v: 1.6 }, { v: 2.1 }] ``` diff --git a/packages/arrays/uniqBy/test.js b/packages/arrays/uniqBy/test.js index 1749d670..d2db760e 100644 --- a/packages/arrays/uniqBy/test.js +++ b/packages/arrays/uniqBy/test.js @@ -3,51 +3,51 @@ const uniqBy = require('./uniqBy'); describe('Array/uniqBy', function () { it('Creates an object composed of keys generated from the results of running each element of array through iteratee', function () { const arr1 = [ - { id: 1, name: 'John' }, - { id: 2, name: 'George' }, - { id: 1, name: 'Helen' }, - { id: 3, name: 'Helen' } + {id: 1, name: 'John'}, + {id: 2, name: 'George'}, + {id: 1, name: 'Helen'}, + {id: 3, name: 'Helen'} ]; const arr2 = [ - { v: 1.6 }, - { v: 2.1 }, - { v: 1.1 } + {v: 1.6}, + {v: 2.1}, + {v: 1.1} ]; const arr3 = [ - { x: '0', y: '1', z: '2' }, - { x: '1', y: '0', z: '2' }, - { x: '0', y: '1', z: '2' }, - { x: '2', y: '1', z: '0' } + {x: '0', y: '1', z: '2'}, + {x: '1', y: '0', z: '2'}, + {x: '0', y: '1', z: '2'}, + {x: '2', y: '1', z: '0'} ]; expect(uniqBy(arr1, 'id')).toEqual([ - { id: 1, name: 'John' }, - { id: 2, name: 'George' }, - { id: 3, name: 'Helen' } + {id: 1, name: 'John'}, + {id: 2, name: 'George'}, + {id: 3, name: 'Helen'} ]); expect(uniqBy(arr1, 'name')).toEqual([ - { id: 1, name: 'John' }, + {id: 1, name: 'John'}, - { id: 2, name: 'George' }, - { id: 1, name: 'Helen' } + {id: 2, name: 'George'}, + {id: 1, name: 'Helen'} ]); expect(uniqBy(arr2, function (o) { return Math.floor(o.v); })).toEqual([ - { v: 1.6 }, - { v: 2.1 } + {v: 1.6}, + {v: 2.1} ]); expect(uniqBy(arr3, function (o) { return o.x + o.y + o.z; })).toEqual([ - { x: '0', y: '1', z: '2' }, - { x: '1', y: '0', z: '2' }, - { x: '2', y: '1', z: '0' } + {x: '0', y: '1', z: '2'}, + {x: '1', y: '0', z: '2'}, + {x: '2', y: '1', z: '0'} ]); expect(function () { diff --git a/packages/arrays/uniqBy/uniqBy.js b/packages/arrays/uniqBy/uniqBy.js index f843629b..432c2e70 100644 --- a/packages/arrays/uniqBy/uniqBy.js +++ b/packages/arrays/uniqBy/uniqBy.js @@ -23,12 +23,12 @@ * ]; * * uniqBy(arr1, 'id'); - * // -> [{ id: 1, name: 'John' }, { id: 2, name: 'George' }] + * // => [{ id: 1, name: 'John' }, { id: 2, name: 'George' }] * * uniqBy(arr2, function (o) { * return Math.floor(o.v); * }); - * // -> [{ v: 1.6 }, { v: 2.1 }] + * // => [{ v: 1.6 }, { v: 2.1 }] */ const uniqBy = (array, iteratee) => { if (!Array.isArray(array)) { diff --git a/packages/arrays/zip/README.md b/packages/arrays/zip/README.md index 878a9b3b..18bc7b2f 100644 --- a/packages/arrays/zip/README.md +++ b/packages/arrays/zip/README.md @@ -16,17 +16,17 @@ the second of which contains the second elements of the given arrays, and so on. **Example** ```js zip([1, 2, 3], [11, 22, 33], [111, 222, 333]); -// -> [ [1, 11, 111], [2, 22, 222], [3, 33, 333] ] +// => [ [1, 11, 111], [2, 22, 222], [3, 33, 333] ] zip([1, 2, 3], [11, 22, 33], [111, 222]); -// -> [ [1, 11, 111], [2, 22, 222], [3, 33, undefined] ] +// => [ [1, 11, 111], [2, 22, 222], [3, 33, undefined] ] zip([1, 2, 3], [11, 22, 33], [111, 222]); -// -> [ [1, 11, 111], [2, 22, undefined], [3, undefined, undefined] ] +// => [ [1, 11, 111], [2, 22, undefined], [3, undefined, undefined] ] zip([], []); -// -> [] +// => [] zip(); -// -> [] +// => [] ``` diff --git a/packages/arrays/zip/zip.js b/packages/arrays/zip/zip.js index cf0f49d8..e33141f1 100644 --- a/packages/arrays/zip/zip.js +++ b/packages/arrays/zip/zip.js @@ -6,23 +6,23 @@ * * @param {...Array} arrays The arrays to process. * @throws {TypeError} If any of the arguments is not array. - * @return {Array} Returns the new array of grouped elements. + * @returns {Array} Returns the new array of grouped elements. * @example * * zip([1, 2, 3], [11, 22, 33], [111, 222, 333]); - * // -> [ [1, 11, 111], [2, 22, 222], [3, 33, 333] ] + * // => [ [1, 11, 111], [2, 22, 222], [3, 33, 333] ] * * zip([1, 2, 3], [11, 22, 33], [111, 222]); - * // -> [ [1, 11, 111], [2, 22, 222], [3, 33, undefined] ] + * // => [ [1, 11, 111], [2, 22, 222], [3, 33, undefined] ] * * zip([1, 2, 3], [11, 22, 33], [111, 222]); - * // -> [ [1, 11, 111], [2, 22, undefined], [3, undefined, undefined] ] + * // => [ [1, 11, 111], [2, 22, undefined], [3, undefined, undefined] ] * * zip([], []); - * // -> [] + * // => [] * * zip(); - * // -> [] + * // => [] */ const zip = (...arrays) => { let len = arrays.length; diff --git a/packages/canvas/convertImageToBase64/README.md b/packages/canvas/convertImageToBase64/README.md index 9190160f..4f64cba6 100644 --- a/packages/canvas/convertImageToBase64/README.md +++ b/packages/canvas/convertImageToBase64/README.md @@ -14,5 +14,5 @@ Converts an image's content to Data URI scheme. convertImageToBase64('images/index.png').then(function (string64) { return string64; }); -// -> data:image/png;base64,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 +// => data:image/png;base64,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 ``` diff --git a/packages/canvas/convertImageToBase64/convertImageToBase64.js b/packages/canvas/convertImageToBase64/convertImageToBase64.js index 8bd6be31..d0d15971 100644 --- a/packages/canvas/convertImageToBase64/convertImageToBase64.js +++ b/packages/canvas/convertImageToBase64/convertImageToBase64.js @@ -10,7 +10,7 @@ * convertImageToBase64('images/index.png').then(function (string64) { * return string64; * }); - * // -> data:image/png;base64,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 + * // => data:image/png;base64,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 */ const convertImageToBase64 = url => { const canvas = document.createElement('canvas'); diff --git a/packages/dom/cookie/README.md b/packages/dom/cookie/README.md index 6e3af8bf..ef68fa1a 100644 --- a/packages/dom/cookie/README.md +++ b/packages/dom/cookie/README.md @@ -40,7 +40,7 @@ cookie.set('foo', 'bar', { secure: true, samesite: 'strict' }); -// -> undefined +// => undefined ``` @@ -61,10 +61,10 @@ Get a cookie by its name. **Example** ```js cookie.get('foo'); -// -> 'bar' +// => 'bar' cookie.get('cookie-that-does-not-exist'); -// -> '' +// => '' ``` @@ -84,5 +84,5 @@ Deletes a cookie by its name. **Example** ```js cookie.remove('foo'); -// -> undefined -``` \ No newline at end of file +// => undefined +``` diff --git a/packages/dom/cookie/cookie.js b/packages/dom/cookie/cookie.js index 1dca41be..ab6b4e01 100644 --- a/packages/dom/cookie/cookie.js +++ b/packages/dom/cookie/cookie.js @@ -27,7 +27,7 @@ module.exports = (function () { * secure: true, * samesite: 'strict' * }); - * // -> undefined + * // => undefined */ function setCookie(name, value, options = {}) { if (typeof name !== 'string' || typeof value !== 'string') { @@ -63,10 +63,10 @@ module.exports = (function () { * @example * * cookie.get('foo'); - * // -> 'bar' + * // => 'bar' * * cookie.get('cookie-that-does-not-exist'); - * // -> '' + * // => '' */ function getCookie(name) { if (typeof name !== 'string') { @@ -90,7 +90,7 @@ module.exports = (function () { * @example * * cookie.remove('foo'); - * // -> undefined + * // => undefined */ function removeCookie(name) { if (typeof name !== 'string') { diff --git a/packages/dom/preloadImages/preloadImages.js b/packages/dom/preloadImages/preloadImages.js index 552f147b..89cafa39 100644 --- a/packages/dom/preloadImages/preloadImages.js +++ b/packages/dom/preloadImages/preloadImages.js @@ -8,7 +8,7 @@ * @param {function} [errorCallback] A function to be executed after an image is not loaded. * @param {function} [alwaysCallback] A function to be always executed regardless an image is loaded or failed to load. * @throws {TypeError} If `images` is not array. - * @return {undefined} + * @returns {undefined} * @example * * const images = ['image-1.jpg', 'image-2.jpg', 'image-3.jpg']; diff --git a/packages/dom/whichAnimationEnd/README.md b/packages/dom/whichAnimationEnd/README.md index 10595c7f..fb7149b9 100644 --- a/packages/dom/whichAnimationEnd/README.md +++ b/packages/dom/whichAnimationEnd/README.md @@ -7,7 +7,7 @@ Detects the supported property name for the `animationend` event. **Example** ```js const animEnd = whichAnimationEnd(); -// -> eg 'animationend' +// => eg 'animationend' element.addEventListener(animEnd, function () { // Do soething... diff --git a/packages/dom/whichAnimationEnd/whichAnimationEnd.js b/packages/dom/whichAnimationEnd/whichAnimationEnd.js index ed91de16..de41d7b7 100644 --- a/packages/dom/whichAnimationEnd/whichAnimationEnd.js +++ b/packages/dom/whichAnimationEnd/whichAnimationEnd.js @@ -3,11 +3,11 @@ /** * Detects the supported property name for the `animationend` event. * - * @return {String} The supported property name or `undefined` if not supported. + * @returns {String} The supported property name or `undefined` if not supported. * @example * * const animEnd = whichAnimationEnd(); - * // -> eg 'animationend' + * // => eg 'animationend' * * element.addEventListener(animEnd, function () { * // Do soething... diff --git a/packages/dom/whichTransitionEnd/README.md b/packages/dom/whichTransitionEnd/README.md index 538fdb4e..8c14b93e 100644 --- a/packages/dom/whichTransitionEnd/README.md +++ b/packages/dom/whichTransitionEnd/README.md @@ -7,7 +7,7 @@ Detects the supported property name for the `transitionend` event. **Example** ```js const transEnd = whichTransitionEnd(); -// -> eg 'transitionend' +// => eg 'transitionend' element.addEventListener(transEnd, function () { // Do soething... diff --git a/packages/dom/whichTransitionEnd/whichTransitionEnd.js b/packages/dom/whichTransitionEnd/whichTransitionEnd.js index c68d78ee..fb5f6223 100644 --- a/packages/dom/whichTransitionEnd/whichTransitionEnd.js +++ b/packages/dom/whichTransitionEnd/whichTransitionEnd.js @@ -3,11 +3,11 @@ /** * Detects the supported property name for the `transitionend` event. * - * @return {String} The supported property name or `undefined` if not supported. + * @returns {String} The supported property name or `undefined` if not supported. * @example * * const transEnd = whichTransitionEnd(); - * // -> eg 'transitionend' + * // => eg 'transitionend' * * element.addEventListener(transEnd, function () { * // Do soething... diff --git a/packages/function/after/after.js b/packages/function/after/after.js index accc48d7..e99f4d54 100644 --- a/packages/function/after/after.js +++ b/packages/function/after/after.js @@ -11,7 +11,7 @@ * @param {function} fn The function to restrict. * @throws {TypeError} If `n` is not number. * @throws {TypeError} If `fn` is not function. - * @return {function} The new restricted function. + * @returns {function} The new restricted function. * @example * * const doSomething = after(4, () => console.log('Do something...'); diff --git a/packages/function/ary/README.md b/packages/function/ary/README.md index 938f5ffe..a17e02d6 100644 --- a/packages/function/ary/README.md +++ b/packages/function/ary/README.md @@ -21,5 +21,5 @@ const array = ['1', '2', '3']; const toInteger = ary(parseInt, 1); -array.map(toInteger); // -> [1, 2, 3] +array.map(toInteger); // => [1, 2, 3] ``` diff --git a/packages/function/ary/ary.js b/packages/function/ary/ary.js index 9270847c..73d832c8 100644 --- a/packages/function/ary/ary.js +++ b/packages/function/ary/ary.js @@ -14,7 +14,7 @@ * * const toInteger = ary(parseInt, 1); * - * array.map(toInteger); // -> [1, 2, 3] + * array.map(toInteger); // => [1, 2, 3] */ const ary = (fn, n) => { if (typeof fn !== 'function') { diff --git a/packages/function/ary/test.js b/packages/function/ary/test.js index 20cb2229..753f577a 100644 --- a/packages/function/ary/test.js +++ b/packages/function/ary/test.js @@ -1,7 +1,7 @@ const ary = require('./ary.js'); describe('Function/ary', function () { - const fn = (a, b) => ([a, b]); + const fn = (a, b) => [a, b]; it('should create a function that accepts up to 1 argument, ignoring any additional arguments', function () { expect(ary(fn, 1)()).toStrictEqual([void 0, void 0]); diff --git a/packages/function/before/before.js b/packages/function/before/before.js index 620d7673..817ebb0e 100644 --- a/packages/function/before/before.js +++ b/packages/function/before/before.js @@ -11,7 +11,7 @@ * @param {function} func The function to restrict. * @throws {TypeError} If `n` is not number. * @throws {TypeError} If `fn` is not function. - * @return {function} Returns the new restricted function. + * @returns {function} Returns the new restricted function. * @example * * const doSomething = before(6, () => console.log('Do something...')); diff --git a/packages/function/once/once.js b/packages/function/once/once.js index 7d0315ea..f8eb7116 100644 --- a/packages/function/once/once.js +++ b/packages/function/once/once.js @@ -5,7 +5,7 @@ * * @param {function} fn The function to restrict. * @throws {TypeError} If `fn` is not function. - * @return {function} Returns the new restricted function. + * @returns {function} Returns the new restricted function. * @example * * let num = 0; diff --git a/packages/function/throttle/throttle.js b/packages/function/throttle/throttle.js index 450d1226..d33b8e2f 100644 --- a/packages/function/throttle/throttle.js +++ b/packages/function/throttle/throttle.js @@ -31,11 +31,11 @@ const throttle = (fn, wait = 0) => { clearTimeout(timerId); timerId = setTimeout(() => { - if ((Date.now() - lastRan) >= wait) { + if (Date.now() - lastRan >= wait) { fn(...args); lastRan = Date.now(); } - }, (wait - (Date.now() - lastRan)) || 0); + }, wait - (Date.now() - lastRan) || 0); } }; }; diff --git a/packages/function/unary/README.md b/packages/function/unary/README.md index f79daafb..d1584c06 100644 --- a/packages/function/unary/README.md +++ b/packages/function/unary/README.md @@ -19,5 +19,5 @@ const array = ['1', '2', '3']; const toInteger = unary(parseInt); -array.map(toInteger); // -> [1, 2, 3] +array.map(toInteger); // => [1, 2, 3] ``` diff --git a/packages/function/unary/test.js b/packages/function/unary/test.js index c9388ee5..d7b70044 100644 --- a/packages/function/unary/test.js +++ b/packages/function/unary/test.js @@ -1,7 +1,7 @@ const unary = require('./unary.js'); describe('Function/unary', function () { - const fn = (a, b) => ([a, b]); + const fn = (a, b) => [a, b]; it('should create a function that accepts up to 1 argument, ignoring any additional arguments', function () { expect(unary(fn)()).toStrictEqual([void 0, void 0]); diff --git a/packages/function/unary/unary.js b/packages/function/unary/unary.js index be0e816f..8d687f9d 100644 --- a/packages/function/unary/unary.js +++ b/packages/function/unary/unary.js @@ -12,7 +12,7 @@ * * const toInteger = unary(parseInt); * - * array.map(toInteger); // -> [1, 2, 3] + * array.map(toInteger); // => [1, 2, 3] */ const unary = fn => { if (typeof fn !== 'function') { diff --git a/packages/is/isArray/README.md b/packages/is/isArray/README.md index f8d390bc..e9f37896 100644 --- a/packages/is/isArray/README.md +++ b/packages/is/isArray/README.md @@ -12,14 +12,14 @@ Checks if a value is array. **Example** ```js isArray(['a', 'b', 'c', 'd']); -// -> true +// => true isArray(100); -// -> false +// => false isArray('Lorem ipsum dolor sit amet'); -// -> false +// => false isArray({ a: 'a', b: 'b' }); -// -> false +// => false ``` diff --git a/packages/is/isArray/isArray.js b/packages/is/isArray/isArray.js index e05c7901..29c5f85e 100644 --- a/packages/is/isArray/isArray.js +++ b/packages/is/isArray/isArray.js @@ -4,20 +4,20 @@ * Checks if a value is array. * * @param {*} value The value to check if is array. - * @return {Boolean} True if array, else false. + * @returns {Boolean} True if array, else false. * @example * * isArray(['a', 'b', 'c', 'd']); - * // -> true + * // => true * * isArray(100); - * // -> false + * // => false * * isArray('Lorem ipsum dolor sit amet'); - * // -> false + * // => false * * isArray({ a: 'a', b: 'b' }); - * // -> false + * // => false */ const isArray = value => { return Array.isArray diff --git a/packages/is/isArray/test.js b/packages/is/isArray/test.js index 9a676bc6..db4af9cc 100644 --- a/packages/is/isArray/test.js +++ b/packages/is/isArray/test.js @@ -4,7 +4,7 @@ describe('is/isArray', function () { function runTests() { expect(isArray(['a', 'b', 'c', 'd'])).toBe(true); - expect(isArray({ a: 'a', b: 'b' })).toBe(false); + expect(isArray({a: 'a', b: 'b'})).toBe(false); expect(isArray('abcdefg')).toBe(false); diff --git a/packages/is/isArrayLike/README.md b/packages/is/isArrayLike/README.md index e73af521..e52ee29a 100644 --- a/packages/is/isArrayLike/README.md +++ b/packages/is/isArrayLike/README.md @@ -23,29 +23,29 @@ function dummy(...args) { const args = dummy(); isArrayLike([1, 2, 3])); -// -> true +// => true isArrayLike('abc')); -// -> true +// => true isArrayLike(0)); -// -> false +// => false isArrayLike({foo: 'bar'})); -// -> false +// => false isArrayLike(noop)); -// -> false +// => false isArrayLike(null)); -// -> false +// => false isArrayLike()); -// -> false +// => false isArrayLike(document.body.children); -// -> true +// => true isArrayLike(args)); -// -> true +// => true ``` diff --git a/packages/is/isArrayLike/isArrayLike.js b/packages/is/isArrayLike/isArrayLike.js index 6987d505..b771b0b1 100644 --- a/packages/is/isArrayLike/isArrayLike.js +++ b/packages/is/isArrayLike/isArrayLike.js @@ -7,7 +7,7 @@ * integer greater than or equal to 0 and less than or equal to `Number.MAX_SAFE_INTEGER`. * * @param {*} value The value to check. - * @return {Boolean} True if value is array-like, else false. + * @returns {Boolean} True if value is array-like, else false. * @example * * function noop() {} @@ -19,31 +19,31 @@ * const args = dummy(); * * isArrayLike([1, 2, 3])); - * // -> true + * // => true * * isArrayLike('abc')); - * // -> true + * // => true * * isArrayLike(0)); - * // -> false + * // => false * * isArrayLike({foo: 'bar'})); - * // -> false + * // => false * * isArrayLike(noop)); - * // -> false + * // => false * * isArrayLike(null)); - * // -> false + * // => false * * isArrayLike()); - * // -> false + * // => false * * isArrayLike(document.body.children); - * // -> true + * // => true * * isArrayLike(args)); - * // -> true + * // => true */ const isArrayLike = value => { const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; diff --git a/packages/is/isArrayLikeObject/README.md b/packages/is/isArrayLikeObject/README.md index ba906e08..293ec6d0 100644 --- a/packages/is/isArrayLikeObject/README.md +++ b/packages/is/isArrayLikeObject/README.md @@ -23,29 +23,29 @@ function dummy(...args) { const args = dummy(); isArrayLikeObject([1, 2, 3])); -// -> true +// => true isArrayLikeObject('abc')); -// -> false +// => false isArrayLikeObject(0)); -// -> false +// => false isArrayLikeObject({foo: 'bar'})); -// -> false +// => false isArrayLikeObject(noop)); -// -> false +// => false isArrayLikeObject(null)); -// -> false +// => false isArrayLikeObject()); -// -> false +// => false isArrayLikeObject(document.body.children); -// -> true +// => true isArrayLikeObject(args)); -// -> true +// => true ``` diff --git a/packages/is/isArrayLikeObject/isArrayLikeObject.js b/packages/is/isArrayLikeObject/isArrayLikeObject.js index 1ad7f4bf..2c747084 100644 --- a/packages/is/isArrayLikeObject/isArrayLikeObject.js +++ b/packages/is/isArrayLikeObject/isArrayLikeObject.js @@ -7,7 +7,7 @@ * integer greater than or equal to 0 and less than or equal to `Number.MAX_SAFE_INTEGER`. * * @param {*} value The value to check. - * @return {Boolean} True if value is array-like and object, else false. + * @returns {Boolean} True if value is array-like and object, else false. * @example * * function noop() {} @@ -19,31 +19,31 @@ * const args = dummy(); * * isArrayLikeObject([1, 2, 3])); - * // -> true + * // => true * * isArrayLikeObject('abc')); - * // -> false + * // => false * * isArrayLikeObject(0)); - * // -> false + * // => false * * isArrayLikeObject({foo: 'bar'})); - * // -> false + * // => false * * isArrayLikeObject(noop)); - * // -> false + * // => false * * isArrayLikeObject(null)); - * // -> false + * // => false * * isArrayLikeObject()); - * // -> false + * // => false * * isArrayLikeObject(document.body.children); - * // -> true + * // => true * * isArrayLikeObject(args)); - * // -> true + * // => true */ const isArrayLikeObject = value => { const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; diff --git a/packages/is/isBoolean/README.md b/packages/is/isBoolean/README.md index d95a6d17..69ad9830 100644 --- a/packages/is/isBoolean/README.md +++ b/packages/is/isBoolean/README.md @@ -12,14 +12,14 @@ Checks if a value is boolean. **Example** ```js isBoolean(true); -// -> true +// => true isBoolean(false); -// -> true +// => true isBoolean({a: 'a'}); -// -> false +// => false isBoolean(null); -// -> false +// => false ``` diff --git a/packages/is/isBoolean/isBoolean.js b/packages/is/isBoolean/isBoolean.js index 564f1603..621cd7f0 100644 --- a/packages/is/isBoolean/isBoolean.js +++ b/packages/is/isBoolean/isBoolean.js @@ -4,25 +4,25 @@ * Checks if a value is boolean. * * @param {*} value The value to check. - * @return {Boolean} True if the 'value' is a boolean value, else false. + * @returns {Boolean} True if the 'value' is a boolean value, else false. * @example * * isBoolean(true); - * // -> true + * // => true * * isBoolean(false); - * // -> true + * // => true * * isBoolean({a: 'a'}); - * // -> false + * // => false * * isBoolean(null); - * // -> false + * // => false */ const isBoolean = value => { return value === true || value === false || Object.prototype.toString.call(value) === '[object Boolean]'; -} +}; module.exports = isBoolean; diff --git a/packages/is/isDate/README.md b/packages/is/isDate/README.md index 3c3b2ebc..d194ed8b 100644 --- a/packages/is/isDate/README.md +++ b/packages/is/isDate/README.md @@ -12,8 +12,8 @@ Checks if a value is a date object. **Example** ```js isDate(new Date()); -// -> true +// => true isDate(new Date().getTime()); -// -> false +// => false ``` diff --git a/packages/is/isDate/isDate.js b/packages/is/isDate/isDate.js index 451cdd70..56cf47c8 100644 --- a/packages/is/isDate/isDate.js +++ b/packages/is/isDate/isDate.js @@ -4,14 +4,14 @@ * Checks if a value is a date object. * * @param {*} value The value to check. - * @return {Boolean} True if 'value' is a date, else returns false. + * @returns {Boolean} True if 'value' is a date, else returns false. * @example * * isDate(new Date()); - * // -> true + * // => true * * isDate(new Date().getTime()); - * // -> false + * // => false */ const isDate = value => { return Object.prototype.toString.call(value) === '[object Date]'; diff --git a/packages/is/isElement/README.md b/packages/is/isElement/README.md index 047edbea..6229847e 100644 --- a/packages/is/isElement/README.md +++ b/packages/is/isElement/README.md @@ -12,11 +12,11 @@ Checks if a value is a DOM element. **Example** ```js isElement('Lorem ipusm dolr sit amet.'); -// -> false +// => false isElement(document.body); -// -> true +// => true isElement(document.getElementsByTagName('head')[0]) -// -> true +// => true ``` diff --git a/packages/is/isElement/isElement.js b/packages/is/isElement/isElement.js index 16952150..fb1589b8 100644 --- a/packages/is/isElement/isElement.js +++ b/packages/is/isElement/isElement.js @@ -4,17 +4,17 @@ * Checks if a value is a DOM element. * * @param {*} value The value to check. - * @return {Boolean} True if 'value' is a DOM element, else false. + * @returns {Boolean} True if 'value' is a DOM element, else false. * @example * * isElement('Lorem ipusm dolr sit amet.'); - * // -> false + * // => false * * isElement(document.body); - * // -> true + * // => true * * isElement(document.getElementsByTagName('head')[0]) - * // -> true + * // => true */ const isElement = value => { return !!value && value.nodeType === 1 && value instanceof Element === true; diff --git a/packages/is/isEmail/README.md b/packages/is/isEmail/README.md index dfdb0f0c..640f884c 100644 --- a/packages/is/isEmail/README.md +++ b/packages/is/isEmail/README.md @@ -12,26 +12,26 @@ Validates a string as email address. **Example** ```js isEmail('me@example.com'; -// -> true +// => true isEmail('a.nonymous@example.com'; -// -> true +// => true isEmail('name+tag@example.com'; -// -> true +// => true isEmail('name\@tag@example.com'); -// -> true +// => true isEmail('name@tag@example.com'); -// -> true +// => true isEmail('spaces are allowed@example.com'); -// -> true +// => true isEmail("!#$%&'+-/=.?^`{|}~@[1.0.0.127]"); -// -> true +// => true isEmail("!#$%&'+-/=.?^`{|}~@[IPv6:0123:4567:89AB:CDEF:0123:4567:89AB:CDEF]"); -// -> false +// => false ``` diff --git a/packages/is/isEmail/isEmail.js b/packages/is/isEmail/isEmail.js index 7a4a2410..81ce504d 100644 --- a/packages/is/isEmail/isEmail.js +++ b/packages/is/isEmail/isEmail.js @@ -4,32 +4,32 @@ * Validates a string as email address. * * @param {String} value The string to validate. - * @return {Boolean} True if valid email, else false. + * @returns {Boolean} True if valid email, else false. * @example * * isEmail('me@example.com'; - * // -> true + * // => true * * isEmail('a.nonymous@example.com'; - * // -> true + * // => true * * isEmail('name+tag@example.com'; - * // -> true + * // => true * * isEmail('name\@tag@example.com'); - * // -> true + * // => true * * isEmail('name@tag@example.com'); - * // -> true + * // => true * * isEmail('spaces are allowed@example.com'); - * // -> true + * // => true * * isEmail("!#$%&'+-/=.?^`{|}~@[1.0.0.127]"); - * // -> true + * // => true * * isEmail("!#$%&'+-/=.?^`{|}~@[IPv6:0123:4567:89AB:CDEF:0123:4567:89AB:CDEF]"); - * // -> false + * // => false */ const isEmail = value => { if (typeof value !== 'string') { diff --git a/packages/is/isEmpty/README.md b/packages/is/isEmpty/README.md index 6db84f0a..7b0873d9 100644 --- a/packages/is/isEmpty/README.md +++ b/packages/is/isEmpty/README.md @@ -13,51 +13,51 @@ Any other primitive types (`number`, `null`, `undefined`, `boolean` `symbol`, `f **Example** ```js -isEmpty([]); // -> true -isEmpty([1, 2, 3]); // -> false - -isEmpty({}); // -> true -isEmpty({foo: 'bar'}); // -> false -isEmpty(Object.create(null)); // -> true -isEmpty(Object.create({})); // -> true -isEmpty(Object.create({foo: 'bar'})); // -> true - -isEmpty(new Map()); // -> true -isEmpty((new Map()).set('foo', 'bar')); // -> false - -isEmpty(new Set()); // -> true -isEmpty(new Set([1, 2, 3])); // -> false - -isEmpty(Symbol()); // -> true -isEmpty(Symbol('foo')); // -> true - -isEmpty(''); // -> true -isEmpty(String('')); // -> true -isEmpty(new String('')); // -> true -isEmpty('foo'); // -> false -isEmpty(String('foo')); // -> false -isEmpty(new String('foo')); // -> false - -isEmpty(0); // -> true -isEmpty(Number(0)); // -> true -isEmpty(new Number(0)); // -> true -isEmpty(1); // -> true -isEmpty(Number(1)); // -> true -isEmpty(new Number(1)); // -> true - -isEmpty(true); // -> true -isEmpty(Boolean(true)); // -> true -isEmpty(new Boolean(true)); // -> true -isEmpty(false); // -> true -isEmpty(Boolean(false)); // -> true -isEmpty(new Boolean(false)); // -> true - -isEmpty(function noop() {}); // -> true -isEmpty(class MyClass {}); // -> true - -isEmpty(/s+/g); // -> true -isEmpty(new RegExp('s+', 'g')); // -> true - -isEmpty(null); // -> true -isEmpty(undefined); // -> true +isEmpty([]); // => true +isEmpty([1, 2, 3]); // => false + +isEmpty({}); // => true +isEmpty({foo: 'bar'}); // => false +isEmpty(Object.create(null)); // => true +isEmpty(Object.create({})); // => true +isEmpty(Object.create({foo: 'bar'})); // => true + +isEmpty(new Map()); // => true +isEmpty((new Map()).set('foo', 'bar')); // => false + +isEmpty(new Set()); // => true +isEmpty(new Set([1, 2, 3])); // => false + +isEmpty(Symbol()); // => true +isEmpty(Symbol('foo')); // => true + +isEmpty(''); // => true +isEmpty(String('')); // => true +isEmpty(new String('')); // => true +isEmpty('foo'); // => false +isEmpty(String('foo')); // => false +isEmpty(new String('foo')); // => false + +isEmpty(0); // => true +isEmpty(Number(0)); // => true +isEmpty(new Number(0)); // => true +isEmpty(1); // => true +isEmpty(Number(1)); // => true +isEmpty(new Number(1)); // => true + +isEmpty(true); // => true +isEmpty(Boolean(true)); // => true +isEmpty(new Boolean(true)); // => true +isEmpty(false); // => true +isEmpty(Boolean(false)); // => true +isEmpty(new Boolean(false)); // => true + +isEmpty(function noop() {}); // => true +isEmpty(class MyClass {}); // => true + +isEmpty(/s+/g); // => true +isEmpty(new RegExp('s+', 'g')); // => true + +isEmpty(null); // => true +isEmpty(undefined); // => true ``` diff --git a/packages/is/isEmpty/isEmpty.js b/packages/is/isEmpty/isEmpty.js index 007e2f22..724c1c1b 100644 --- a/packages/is/isEmpty/isEmpty.js +++ b/packages/is/isEmpty/isEmpty.js @@ -6,53 +6,53 @@ * @returns {Boolean} Returns `true` if value is empty, otherwise `false`. * @example * - * isEmpty([]); // -> true - * isEmpty([1, 2, 3]); // -> false + * isEmpty([]); // => true + * isEmpty([1, 2, 3]); // => false * - * isEmpty({}); // -> true - * isEmpty({foo: 'bar'}); // -> false - * isEmpty(Object.create(null)); // -> true - * isEmpty(Object.create({})); // -> true - * isEmpty(Object.create({foo: 'bar'})); // -> true + * isEmpty({}); // => true + * isEmpty({foo: 'bar'}); // => false + * isEmpty(Object.create(null)); // => true + * isEmpty(Object.create({})); // => true + * isEmpty(Object.create({foo: 'bar'})); // => true * - * isEmpty(new Map()); // -> true - * isEmpty((new Map()).set('foo', 'bar')); // -> false + * isEmpty(new Map()); // => true + * isEmpty((new Map()).set('foo', 'bar')); // => false * - * isEmpty(new Set()); // -> true - * isEmpty(new Set([1, 2, 3])); // -> false + * isEmpty(new Set()); // => true + * isEmpty(new Set([1, 2, 3])); // => false * - * isEmpty(Symbol()); // -> true - * isEmpty(Symbol('foo')); // -> true + * isEmpty(Symbol()); // => true + * isEmpty(Symbol('foo')); // => true * - * isEmpty(''); // -> true - * isEmpty(String('')); // -> true - * isEmpty(new String('')); // -> true - * isEmpty('foo'); // -> false - * isEmpty(String('foo')); // -> false - * isEmpty(new String('foo')); // -> false + * isEmpty(''); // => true + * isEmpty(String('')); // => true + * isEmpty(new String('')); // => true + * isEmpty('foo'); // => false + * isEmpty(String('foo')); // => false + * isEmpty(new String('foo')); // => false * - * isEmpty(0); // -> true - * isEmpty(Number(0)); // -> true - * isEmpty(new Number(0)); // -> true - * isEmpty(1); // -> true - * isEmpty(Number(1)); // -> true - * isEmpty(new Number(1)); // -> true + * isEmpty(0); // => true + * isEmpty(Number(0)); // => true + * isEmpty(new Number(0)); // => true + * isEmpty(1); // => true + * isEmpty(Number(1)); // => true + * isEmpty(new Number(1)); // => true * - * isEmpty(true); // -> true - * isEmpty(Boolean(true)); // -> true - * isEmpty(new Boolean(true)); // -> true - * isEmpty(false); // -> true - * isEmpty(Boolean(false)); // -> true - * isEmpty(new Boolean(false)); // -> true + * isEmpty(true); // => true + * isEmpty(Boolean(true)); // => true + * isEmpty(new Boolean(true)); // => true + * isEmpty(false); // => true + * isEmpty(Boolean(false)); // => true + * isEmpty(new Boolean(false)); // => true * - * isEmpty(function noop() {}); // -> true - * isEmpty(class MyClass {}); // -> true + * isEmpty(function noop() {}); // => true + * isEmpty(class MyClass {}); // => true * - * isEmpty(/s+/g); // -> true - * isEmpty(new RegExp('s+', 'g')); // -> true + * isEmpty(/s+/g); // => true + * isEmpty(new RegExp('s+', 'g')); // => true * - * isEmpty(null); // -> true - * isEmpty(undefined); // -> true + * isEmpty(null); // => true + * isEmpty(undefined); // => true */ const isEmpty = value => { const type = Object.prototype.toString.call(value); diff --git a/packages/is/isEven/README.md b/packages/is/isEven/README.md index 2a09cc0f..eb4124f0 100644 --- a/packages/is/isEven/README.md +++ b/packages/is/isEven/README.md @@ -12,23 +12,23 @@ Checks if a value is even. **Example** ```js isEven(0); -// -> true +// => true isEven(2); -// -> true +// => true isEven(3); -// -> false +// => false isEven(5); -// -> false +// => false isEven('2'); -// -> true +// => true isEven(null); -// -> false +// => false isEven(); -// -> false +// => false ``` diff --git a/packages/is/isEven/isEven.js b/packages/is/isEven/isEven.js index 1b44ab31..3e2d9e06 100644 --- a/packages/is/isEven/isEven.js +++ b/packages/is/isEven/isEven.js @@ -4,29 +4,29 @@ * Checks if a value is even. * * @param {Number} value The value to check. - * @return {Boolean} True if number is even, else false. + * @returns {Boolean} True if number is even, else false. * @example * * isEven(0); - * // -> true + * // => true * * isEven(2); - * // -> true + * // => true * * isEven(3); - * // -> false + * // => false * * isEven(5); - * // -> false + * // => false * * isEven('2'); - * // -> true + * // => true * * isEven(null); - * // -> false + * // => false * * isEven(); - * // -> false + * // => false */ const isEven = value => { if (typeof value === 'object' || typeof value === 'undefined') { diff --git a/packages/is/isFalse/README.md b/packages/is/isFalse/README.md index d6107805..6b146eed 100644 --- a/packages/is/isFalse/README.md +++ b/packages/is/isFalse/README.md @@ -12,11 +12,11 @@ Checks if a value is `false` (strict equality). **Example** ```js isFalse(false); -// -> true +// => true isFalse(true); -// -> false +// => false isFalse(); -// -> false +// => false ``` diff --git a/packages/is/isFalse/isFalse.js b/packages/is/isFalse/isFalse.js index b41e6996..79d62431 100644 --- a/packages/is/isFalse/isFalse.js +++ b/packages/is/isFalse/isFalse.js @@ -4,17 +4,17 @@ * Checks if a value is `false` (strict equality). * * @param {*} value The value to check. - * @return {Boolean} True if the 'value' is false, else false. + * @returns {Boolean} True if the 'value' is false, else false. * @example * * isFalse(false); - * // -> true + * // => true * * isFalse(true); - * // -> false + * // => false * * isFalse(); - * // -> false + * // => false */ const isFalse = value => value === false; diff --git a/packages/is/isFalsy/README.md b/packages/is/isFalsy/README.md index 14da45aa..a2f488c5 100644 --- a/packages/is/isFalsy/README.md +++ b/packages/is/isFalsy/README.md @@ -12,26 +12,26 @@ Checks if a value is a falsy one. **Example** ```js isFalsy(true); -// -> false +// => false isFalsy(' '); -// -> false +// => false isFalsy(1); -// -> false +// => false isFalsy(false); -// -> true +// => true isFalsy(''); -// -> true +// => true isFalsy(); -// -> true +// => true isFalsy(0); -// -> true +// => true isFalsy(NaN); -// -> true +// => true ``` diff --git a/packages/is/isFalsy/isFalsy.js b/packages/is/isFalsy/isFalsy.js index 253ba040..a3f976b1 100644 --- a/packages/is/isFalsy/isFalsy.js +++ b/packages/is/isFalsy/isFalsy.js @@ -8,28 +8,28 @@ * @example * * isFalsy(true); - * // -> false + * // => false * * isFalsy(' '); - * // -> false + * // => false * * isFalsy(1); - * // -> false + * // => false * * isFalsy(false); - * // -> true + * // => true * * isFalsy(''); - * // -> true + * // => true * * isFalsy(); - * // -> true + * // => true * * isFalsy(0); - * // -> true + * // => true * * isFalsy(NaN); - * // -> true + * // => true */ const isFalsy = value => !value; diff --git a/packages/is/isFiniteNum/README.md b/packages/is/isFiniteNum/README.md index a4ef5b89..d786da26 100644 --- a/packages/is/isFiniteNum/README.md +++ b/packages/is/isFiniteNum/README.md @@ -12,26 +12,26 @@ Checks if 'value' is a finite number. **Example** ```js isFiniteNum(Infinity); -// -> false +// => false isFiniteNum(NaN); -// -> false +// => false isFiniteNum(-Infinity); -// -> false +// => false isFiniteNum(0); -// -> true +// => true isFiniteNum(2e64); -// -> true +// => true isFiniteNum(null); -// -> false +// => false isFiniteNum(undefined); -// -> false +// => false isFiniteNum('0'); -// -> false +// => false ``` diff --git a/packages/is/isFiniteNum/isFiniteNum.js b/packages/is/isFiniteNum/isFiniteNum.js index 3dc774b0..d62e44e4 100644 --- a/packages/is/isFiniteNum/isFiniteNum.js +++ b/packages/is/isFiniteNum/isFiniteNum.js @@ -4,32 +4,32 @@ * Checks if a value is a finite number. * * @param {*} value The value to check. - * @return {Boolean} True if value is a finite number, else false. + * @returns {Boolean} True if value is a finite number, else false. * @example * * isFiniteNum(Infinity); - * // -> false + * // => false * * isFiniteNum(NaN); - * // -> false + * // => false * * isFiniteNum(-Infinity); - * // -> false + * // => false * * isFiniteNum(0); - * // -> true + * // => true * * isFiniteNum(2e64); - * // -> true + * // => true * * isFiniteNum(null); - * // -> false + * // => false * * isFiniteNum(undefined); - * // -> false + * // => false * * isFiniteNum('0'); - * // -> false + * // => false */ const isFiniteNum = value => { if (Number.isFinite) { @@ -38,7 +38,7 @@ const isFiniteNum = value => { return value != null && typeof value === 'number' && value !== Infinity && value !== -Infinity - && value === value; + && !Number.isNaN(value); }; module.exports = isFiniteNum; diff --git a/packages/is/isFlatArray/README.md b/packages/is/isFlatArray/README.md index 8c1cabf9..1b5414dc 100644 --- a/packages/is/isFlatArray/README.md +++ b/packages/is/isFlatArray/README.md @@ -12,14 +12,14 @@ Checks if a value is a flat array. If the value is not array, will return `false **Example** ```js isFlatArray([1, 2, 3, 4, 5, 6, 7, 8, 9]); -// -> true +// => true isFlatArray([1, 2, [3], [4, 5], 6, 7, [8], 9]); -// -> false +// => false isFlatArray([]); -// -> true +// => true isFlatArray(new Set()); -// -> false +// => false ``` diff --git a/packages/is/isFlatArray/isFlatArray.js b/packages/is/isFlatArray/isFlatArray.js index fcc26b7d..f056a873 100644 --- a/packages/is/isFlatArray/isFlatArray.js +++ b/packages/is/isFlatArray/isFlatArray.js @@ -9,16 +9,16 @@ * @example * * isFlatArray([1, 2, 3, 4, 5, 6, 7, 8, 9]); - * // -> true + * // => true * * isFlatArray([1, 2, [3], [4, 5], 6, 7, [8], 9]); - * // -> false + * // => false * * isFlatArray([]); - * // -> true + * // => true * * isFlatArray(new Set()); - * // -> false + * // => false */ const isFlatArray = value => { if (!Array.isArray(value)) { diff --git a/packages/is/isFunction/README.md b/packages/is/isFunction/README.md index f33e7414..d353c385 100644 --- a/packages/is/isFunction/README.md +++ b/packages/is/isFunction/README.md @@ -14,8 +14,8 @@ Checks if a value is a function. isFunction(function test() { return 'This is test function.'; }); -// -> true +// => true isFunction('This is a test function.'); -// -> false +// => false ``` diff --git a/packages/is/isFunction/isFunction.js b/packages/is/isFunction/isFunction.js index 56a449d2..75b67578 100644 --- a/packages/is/isFunction/isFunction.js +++ b/packages/is/isFunction/isFunction.js @@ -4,16 +4,16 @@ * Checks if a value is a function. * * @param {*} value The value to check. - * @return {Boolean} True if value is a function, else returns false. + * @returns {Boolean} True if value is a function, else returns false. * @example * * isFunction(function test() { * return 'This is test function.'; * }); - * // -> true + * // => true * * isFunction('This is a test function.'); - * // -> false + * // => false */ const isFunction = value => typeof value === 'function'; diff --git a/packages/is/isHexColor/README.md b/packages/is/isHexColor/README.md index 79e80247..cab26bd3 100644 --- a/packages/is/isHexColor/README.md +++ b/packages/is/isHexColor/README.md @@ -12,26 +12,26 @@ Checks if a value matches a hexadecimal color regular expression. **Example** ```js isHexColor('#f5f5f5'); -// -> true +// => true isHexColor('#9c0'); -// -> true +// => true isHexColor('333'); -// -> true +// => true isHexColor(333); -// -> true +// => true isHexColor(6.6); -// -> false +// => false isHexColor('foo'); -// -> false +// => false isHexColor(null); -// -> false +// => false isHexColor(); -// -> false +// => false ``` diff --git a/packages/is/isHexColor/isHexColor.js b/packages/is/isHexColor/isHexColor.js index 9426cf18..06d02506 100644 --- a/packages/is/isHexColor/isHexColor.js +++ b/packages/is/isHexColor/isHexColor.js @@ -4,32 +4,32 @@ * Checks if a value matches a hexadecimal color regular expression. * * @param {*} value The value to check. - * @return {Boolean} True if value is a hexadecimal color regexp, else false. + * @returns {Boolean} True if value is a hexadecimal color regexp, else false. * @example * * isHexColor('#f5f5f5'); - * // -> true + * // => true * * isHexColor('#9c0'); - * // -> true + * // => true * * isHexColor('333'); - * // -> true + * // => true * * isHexColor(333); - * // -> true + * // => true * * isHexColor(6.6); - * // -> false + * // => false * * isHexColor('foo'); - * // -> false + * // => false * * isHexColor(null); - * // -> false + * // => false * * isHexColor(); - * // -> false + * // => false */ const isHexColor = value => /^#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/.test(value); diff --git a/packages/is/isHexadecimal/README.md b/packages/is/isHexadecimal/README.md index fb7452c1..734c4687 100644 --- a/packages/is/isHexadecimal/README.md +++ b/packages/is/isHexadecimal/README.md @@ -12,17 +12,17 @@ Checks if a value matches a hexadecimal regular expression. **Example** ```js isHexadecimal('f5f5f5'); -// -> true +// => true isHexadecimal('9c0'); -// -> true +// => true isHexadecimal(333); -// -> true +// => true isHexadecimal('foo'); -// -> false +// => false isHexadecimal(6.6); -// -> false +// => false ``` diff --git a/packages/is/isHexadecimal/isHexadecimal.js b/packages/is/isHexadecimal/isHexadecimal.js index ac326e4c..64dc9648 100644 --- a/packages/is/isHexadecimal/isHexadecimal.js +++ b/packages/is/isHexadecimal/isHexadecimal.js @@ -4,23 +4,23 @@ * Checks if a value matches a hexadecimal regular expression. * * @param {*} value The value to check. - * @return {Boolean} True if value is a hexadecimal, else false. + * @returns {Boolean} True if value is a hexadecimal, else false. * @example * * isHexadecimal('f5f5f5'); - * // -> true + * // => true * * isHexadecimal('9c0'); - * // -> true + * // => true * * isHexadecimal(333); - * // -> true + * // => true * * isHexadecimal('foo'); - * // -> false + * // => false * * isHexadecimal(6.6); - * // -> false + * // => false */ const isHexadecimal = value => /^[0-9a-fA-F]+$/.test(value); diff --git a/packages/is/isInteger/README.md b/packages/is/isInteger/README.md index f2af4dce..3d419f29 100644 --- a/packages/is/isInteger/README.md +++ b/packages/is/isInteger/README.md @@ -13,35 +13,35 @@ If the value is NaN or infinite, return false. **Example** ```js isInteger(1); -// -> true +// => true isInteger(9007199254740992); -// -> true +// => true isInteger(-9007199254740992); -// -> true +// => true isInteger(-100000); -// -> true +// => true isInteger(0); -// -> true +// => true isInteger(0.1); -// -> false +// => false isInteger(Math.PI); -// -> false +// => false isInteger(NaN); -// -> false +// => false isInteger('10'); -// -> false +// => false isInteger(Number.MAX_VALUE); -// -> false +// => false isInteger(Infinity); -// -> false +// => false ``` diff --git a/packages/is/isInteger/isInteger.js b/packages/is/isInteger/isInteger.js index a2df343f..96981a4a 100644 --- a/packages/is/isInteger/isInteger.js +++ b/packages/is/isInteger/isInteger.js @@ -5,41 +5,41 @@ * If the value is NaN or infinite, return false. * * @param {*} value The value to check. - * @return {Boolean} True if value is integer, else false. + * @returns {Boolean} True if value is integer, else false. * @example * * isInteger(1); - * // -> true + * // => true * * isInteger(9007199254740992); - * // -> true + * // => true * * isInteger(-9007199254740992); - * // -> true + * // => true * * isInteger(-100000); - * // -> true + * // => true * * isInteger(0); - * // -> true + * // => true * * isInteger(0.1); - * // -> false + * // => false * * isInteger(Math.PI); - * // -> false + * // => false * * isInteger(NaN); - * // -> false + * // => false * * isInteger('10'); - * // -> false + * // => false * * isInteger(Number.MAX_VALUE); - * // -> false + * // => false * * isInteger(Infinity); - * // -> false + * // => false */ const isInteger = value => { if (Number.isInteger) { diff --git a/packages/is/isIterable/README.md b/packages/is/isIterable/README.md index ddf6beae..c1bc766d 100644 --- a/packages/is/isIterable/README.md +++ b/packages/is/isIterable/README.md @@ -19,23 +19,23 @@ function* generatorFunc() { } isIterable([]); -// -> true +// => true isIterable(new Map()); -// -> true +// => true isIterable(''); -// -> true +// => true isIterable(generatorFunc()); -// -> true +// => true isIterable({}); -// -> false +// => false isIterable(0); -// -> false +// => false isIterable(null); -// -> false +// => false ``` diff --git a/packages/is/isIterable/isIterable.js b/packages/is/isIterable/isIterable.js index 505731e4..572ca9ba 100644 --- a/packages/is/isIterable/isIterable.js +++ b/packages/is/isIterable/isIterable.js @@ -13,25 +13,25 @@ * } * * isIterable([]); - * // -> true + * // => true * * isIterable(new Map()); - * // -> true + * // => true * * isIterable(''); - * // -> true + * // => true * * isIterable(generatorFunc()); - * // -> true + * // => true * * isIterable({}); - * // -> false + * // => false * * isIterable(0); - * // -> false + * // => false * * isIterable(null); - * // -> false + * // => false */ const isIterable = value => { if (typeof Symbol === 'undefined' || !Symbol.iterator) { diff --git a/packages/is/isMap/README.md b/packages/is/isMap/README.md index bfcdd1ab..57281b30 100644 --- a/packages/is/isMap/README.md +++ b/packages/is/isMap/README.md @@ -12,14 +12,14 @@ Checks if value is classified as a Map object. **Example** ```js isMap(new Map()); -// -> true +// => true isMap(new WeakMap()); -// -> false +// => false isMap(new Map([['foo', 'bar'], ['hello', 'world']])); -// -> true +// => true isMap({foo: 'bar', 'hello': 'world'}); -// -> false +// => false ``` diff --git a/packages/is/isMap/isMap.js b/packages/is/isMap/isMap.js index 2530d26f..6cc9a647 100644 --- a/packages/is/isMap/isMap.js +++ b/packages/is/isMap/isMap.js @@ -4,20 +4,20 @@ * Checks if a value is classified as a Map object. * * @param {*} value The value to check. - * @return {Boolean} True if value is classified as a Map object, else false. + * @returns {Boolean} True if value is classified as a Map object, else false. * @example * * isMap(new Map()); - * // -> true + * // => true * * isMap(new WeakMap()); - * // -> false + * // => false * * isMap(new Map([['foo', 'bar'], ['hello', 'world']])); - * // -> true + * // => true * * isMap({foo: 'bar', 'hello': 'world'}); - * // -> false + * // => false */ const isMap = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object Map]'; diff --git a/packages/is/isNaN/README.md b/packages/is/isNaN/README.md index daacefc7..9e26b827 100644 --- a/packages/is/isNaN/README.md +++ b/packages/is/isNaN/README.md @@ -12,21 +12,21 @@ It is an implementation similar to native `Number.isNaN()` which is a more robus **Example** ```js -isNaN(NaN); // -> true -isNaN(Number.NaN); // -> true -isNaN(0 / 0); // -> true +isNaN(NaN); // => true +isNaN(Number.NaN); // => true +isNaN(0 / 0); // => true -isNaN(true); // -> true -isNaN(null); // -> true -isNaN(37); // -> true -isNaN('37'); // -> true -isNaN('37.37'); // -> true -isNaN(''); // -> true -isNaN(' '); // -> true +isNaN(true); // => true +isNaN(null); // => true +isNaN(37); // => true +isNaN('37'); // => true +isNaN('37.37'); // => true +isNaN(''); // => true +isNaN(' '); // => true // e.g. these would have been true with global isNaN() -isNaN('NaN'); // -> false -isNaN(undefined); // -> false -isNaN({}); // -> false -isNaN('blabla'); // -> false +isNaN('NaN'); // => false +isNaN(undefined); // => false +isNaN({}); // => false +isNaN('blabla'); // => false ``` diff --git a/packages/is/isNaN/isNaN.js b/packages/is/isNaN/isNaN.js index 0bde325a..29acb978 100644 --- a/packages/is/isNaN/isNaN.js +++ b/packages/is/isNaN/isNaN.js @@ -5,26 +5,26 @@ * It is an implementation similar to native `Number.isNaN()` which is a more robust version of the original, global `isNaN()`. * * @param {*} value The value to be tested for `NaN`. - * @return {Boolean} Returns `true` if the given value is `NaN` and its type is `Number`; otherwise, `false`. + * @returns {Boolean} Returns `true` if the given value is `NaN` and its type is `Number`; otherwise, `false`. * @example * - * isNaN(NaN); // -> true - * isNaN(Number.NaN); // -> true - * isNaN(0 / 0); // -> true + * isNaN(NaN); // => true + * isNaN(Number.NaN); // => true + * isNaN(0 / 0); // => true * - * isNaN(true); // -> true - * isNaN(null); // -> true - * isNaN(37); // -> true - * isNaN('37'); // -> true - * isNaN('37.37'); // -> true - * isNaN(''); // -> true - * isNaN(' '); // -> true + * isNaN(true); // => true + * isNaN(null); // => true + * isNaN(37); // => true + * isNaN('37'); // => true + * isNaN('37.37'); // => true + * isNaN(''); // => true + * isNaN(' '); // => true * * // e.g. these would have been true with global isNaN() - * isNaN('NaN'); // -> false - * isNaN(undefined); // -> false - * isNaN({}); // -> false - * isNaN('blabla'); // -> false + * isNaN('NaN'); // => false + * isNaN(undefined); // => false + * isNaN({}); // => false + * isNaN('blabla'); // => false */ const isNaN = value => { if (Number.isNaN) { diff --git a/packages/is/isNull/README.md b/packages/is/isNull/README.md index 667308f6..13e9a070 100644 --- a/packages/is/isNull/README.md +++ b/packages/is/isNull/README.md @@ -12,14 +12,14 @@ Checks if a value is `null`. **Example** ```js isNull(null); -// -> true +// => true isNull(true); -// -> false +// => false isNull({a: 'a'}); -// -> false +// => false isNull(); -// -> false +// => false ``` diff --git a/packages/is/isNull/isNull.js b/packages/is/isNull/isNull.js index d528e24a..9370d085 100644 --- a/packages/is/isNull/isNull.js +++ b/packages/is/isNull/isNull.js @@ -4,20 +4,20 @@ * Checks if a value is `null`. * * @param {*} value The value to check. - * @return {Boolean} True if the 'value' is null, else false. + * @returns {Boolean} True if the 'value' is null, else false. * @example * * isNull(null); - * // -> true + * // => true * * isNull(true); - * // -> false + * // => false * * isNull({a: 'a'}); - * // -> false + * // => false * * isNull(); - * // -> false + * // => false */ const isNull = value => value === null; diff --git a/packages/is/isNullish/README.md b/packages/is/isNullish/README.md index 1fd4692f..85a3f8cc 100644 --- a/packages/is/isNullish/README.md +++ b/packages/is/isNullish/README.md @@ -14,14 +14,14 @@ Checks if value is `null` or `undefined`. let foo; isNullish(foo); -// -> true +// => true isNullish(null); -// -> true +// => true isNullish({foo: 'bar'}); -// -> false +// => false isNullish(); -// -> true +// => true ``` diff --git a/packages/is/isNullish/isNullish.js b/packages/is/isNullish/isNullish.js index 94581aef..0850a165 100644 --- a/packages/is/isNullish/isNullish.js +++ b/packages/is/isNullish/isNullish.js @@ -4,22 +4,22 @@ * Checks if a value is `null` or `undefined`. * * @param {*} value The value to check. - * @return {Boolean} True if the value is `null` or `undefined`; otherwise false. + * @returns {Boolean} True if the value is `null` or `undefined`; otherwise false. * @example * * let foo; * * isNullish(foo); - * // -> true + * // => true * * isNullish(null); - * // -> true + * // => true * * isNullish({foo: 'bar'}); - * // -> false + * // => false * * isNullish(); - * // -> true + * // => true */ const isNullish = value => value == null; diff --git a/packages/is/isNumber/README.md b/packages/is/isNumber/README.md index 1edd6273..fb06bc57 100644 --- a/packages/is/isNumber/README.md +++ b/packages/is/isNumber/README.md @@ -13,29 +13,29 @@ Checks if a value is a number. **Example** ```js isNumber(10); -// -> true +// => true isNumber('10'); -// -> false +// => false isNumber(new Date()); -// -> false +// => false isNumber(new Date().getTime()); -// -> true +// => true isNumber(true);; -// -> false +// => false isNumber(null);; -// -> false +// => false isNumber(undefined);; -// -> false +// => false isNumber(''); -// -> false +// => false isNumber(NaN); -// -> true +// => true ``` diff --git a/packages/is/isNumber/isNumber.js b/packages/is/isNumber/isNumber.js index b46f1a0f..9790bc13 100644 --- a/packages/is/isNumber/isNumber.js +++ b/packages/is/isNumber/isNumber.js @@ -5,35 +5,35 @@ * * @NOTE: `NaN` is considered to be a number, as so will return true. * @param {*} value The value to check. - * @return {Boolean} True if value is a number, else false. + * @returns {Boolean} True if value is a number, else false. * @example * * isNumber(10); - * // -> true + * // => true * * isNumber('10'); - * // -> false + * // => false * * isNumber(new Date()); - * // -> false + * // => false * * isNumber(new Date().getTime()); - * // -> true + * // => true * * isNumber(true);; - * // -> false + * // => false * * isNumber(null);; - * // -> false + * // => false * * isNumber(undefined);; - * // -> false + * // => false * * isNumber(''); - * // -> false + * // => false * * isNumber(NaN); - * // -> true + * // => true */ const isNumber = value => { return typeof value === 'number' || Object.prototype.toString.call(value) === '[object Number]'; diff --git a/packages/is/isObject/README.md b/packages/is/isObject/README.md index e1f1a920..5ae7a179 100644 --- a/packages/is/isObject/README.md +++ b/packages/is/isObject/README.md @@ -12,50 +12,50 @@ Checks if a value is the [language type](https://262.ecma-international.org/#sec **Example** ```js isObject({}); -// -> true +// => true isObject(Object.create({})); -// -> true +// => true isObject(Object.create(null)); -// -> true +// => true isObject(function test() {}); -// -> true +// => true isObject([1, 2, 3]); -// -> true +// => true isObject(new Number(0)); -// -> true +// => true isObject(new String('Hello world')); -// -> true +// => true isObject(new RegExp('s+'))); -// -> true +// => true isObject(/s+/); -// -> true +// => true isObject(new Map()); -// -> true +// => true isObject(new Set()); -// -> true +// => true isObject(1); -// -> false +// => false isObject('Hello world'); -// -> false +// => false isObject(null); -// -> false +// => false isObject(Boolean(1)); -// -> false +// => false isObject(Symbol('foo')); -// -> false +// => false ``` diff --git a/packages/is/isObject/isObject.js b/packages/is/isObject/isObject.js index 4052ff8c..28e78380 100644 --- a/packages/is/isObject/isObject.js +++ b/packages/is/isObject/isObject.js @@ -5,56 +5,56 @@ * (e.g. arrays, functions, objects, regexes, `new Number(0)`, `new String('')`) * * @param {*} value The value to check. - * @return {Boolean} Returns `true` if `value` is an object, else `false`. + * @returns {Boolean} Returns `true` if `value` is an object, else `false`. * @example * * isObject({}); - * // -> true + * // => true * * isObject(Object.create({})); - * // -> true + * // => true * * isObject(Object.create(null)); - * // -> true + * // => true * * isObject(function test() {}); - * // -> true + * // => true * * isObject([1, 2, 3]); - * // -> true + * // => true * * isObject(new Number(0)); - * // -> true + * // => true * * isObject(new String('Hello world')); - * // -> true + * // => true * * isObject(new RegExp('s+'))); - * // -> true + * // => true * * isObject(/s+/); - * // -> true + * // => true * * isObject(new Map()); - * // -> true + * // => true * * isObject(new Set()); - * // -> true + * // => true * * isObject(0); - * // -> false + * // => false * * isObject('Hello world'); - * // -> false + * // => false * * isObject(null); - * // -> false + * // => false * * isObject(Boolean(1)); - * // -> false + * // => false * * isObject(Symbol('foo')); - * // -> false + * // => false */ const isObject = value => { return !!value && (typeof value === 'object' || typeof value === 'function'); diff --git a/packages/is/isObjectLike/README.md b/packages/is/isObjectLike/README.md index 61343782..0471363f 100644 --- a/packages/is/isObjectLike/README.md +++ b/packages/is/isObjectLike/README.md @@ -12,50 +12,50 @@ Checks if a value is object-like. A value is object-like if it's not `null` and **Example** ```js isObjectLike({}); -// -> true +// => true isObjectLike(Object.create({})); -// -> true +// => true isObjectLike(Object.create(null)); -// -> true +// => true isObjectLike([1, 2, 3]); -// -> true +// => true isObjectLike(new Number(0)); -// -> true +// => true isObjectLike(new String('Hello world')); -// -> true +// => true isObjectLike(new RegExp('s+'))); -// -> true +// => true isObjectLike(/s+/); -// -> true +// => true isObjectLike(new Map()); -// -> true +// => true isObjectLike(new Set()); -// -> true +// => true isObjectLike(0); -// -> false +// => false isObjectLike('Hello world'); -// -> false +// => false isObjectLike(function noop() {}); -// -> false +// => false isObjectLike(null); -// -> false +// => false isObjectLike(Boolean(1)); -// -> false +// => false isObjectLike(Symbol('foo')); -// -> false +// => false ``` diff --git a/packages/is/isObjectLike/isObjectLike.js b/packages/is/isObjectLike/isObjectLike.js index b3ea5961..8cc8b6fb 100644 --- a/packages/is/isObjectLike/isObjectLike.js +++ b/packages/is/isObjectLike/isObjectLike.js @@ -8,52 +8,52 @@ * @example * * isObjectLike({}); - * // -> true + * // => true * * isObjectLike(Object.create({})); - * // -> true + * // => true * * isObjectLike(Object.create(null)); - * // -> true + * // => true * * isObjectLike([1, 2, 3]); - * // -> true + * // => true * * isObjectLike(new Number(0)); - * // -> true + * // => true * * isObjectLike(new String('Hello world')); - * // -> true + * // => true * * isObjectLike(new RegExp('s+'))); - * // -> true + * // => true * * isObjectLike(/s+/); - * // -> true + * // => true * * isObjectLike(new Map()); - * // -> true + * // => true * * isObjectLike(new Set()); - * // -> true + * // => true * * isObjectLike(0); - * // -> false + * // => false * * isObjectLike('Hello world'); - * // -> false + * // => false * * isObjectLike(function noop() {}); - * // -> false + * // => false * * isObjectLike(null); - * // -> false + * // => false * * isObject(Boolean(1)); - * // -> false + * // => false * * isObjectLike(Symbol('foo')); - * // -> false + * // => false */ const isObjectLike = value => !!value && typeof value === 'object'; diff --git a/packages/is/isOdd/README.md b/packages/is/isOdd/README.md index 6fe0026d..9543e0aa 100644 --- a/packages/is/isOdd/README.md +++ b/packages/is/isOdd/README.md @@ -12,23 +12,23 @@ Checks if a value is odd. **Example** ```js isOdd(0); -// -> false +// => false isOdd(2); -// -> false +// => false isOdd(3); -// -> true +// => true isOdd(5); -// -> true +// => true isOdd('5'); -// -> true +// => true isOdd(null); -// -> false +// => false isOdd(); -// -> false +// => false ``` diff --git a/packages/is/isOdd/isOdd.js b/packages/is/isOdd/isOdd.js index c2972cc9..313c8d0b 100644 --- a/packages/is/isOdd/isOdd.js +++ b/packages/is/isOdd/isOdd.js @@ -4,29 +4,29 @@ * Checks if a value is odd. * * @param {Number} value The value to check. - * @return {Boolean} True if value is odd, else false. + * @returns {Boolean} True if value is odd, else false. * @example * * isOdd(0); - * // -> false + * // => false * *isOdd(2); - * // -> false + * // => false * * isOdd(3); - * // -> true + * // => true * * isOdd(5); - * // -> true + * // => true * * isOdd('5'); - * // -> true + * // => true * * isOdd(null); - * // -> false + * // => false * * isOdd(); - * // -> false + * // => false */ const isOdd = value => { if (typeof value === 'object' || typeof value === 'undefined') { diff --git a/packages/is/isPlainObject/README.md b/packages/is/isPlainObject/README.md index 6c91f887..13200f17 100644 --- a/packages/is/isPlainObject/README.md +++ b/packages/is/isPlainObject/README.md @@ -19,38 +19,38 @@ function Foo() { } isPlainObject({}); -// -> true +// => true isPlainObject({foo: 'bar'}); -// -> true +// => true isPlainObject(new Object({foo: 'bar'})); -// -> true +// => true isPlainObject(new Foo()); -// -> false +// => false isPlainObject(Object.create(null)); -// -> true +// => true isPlainObject(Object.create({})); -// -> false +// => false isPlainObject(Object.create({foo: 'bar'})); -// -> false +// => false isPlainObject([1, 2, 3]); -// -> false +// => false isPlainObject(null); -// -> false +// => false isPlainObject(); -// -> false +// => false isPlainObject(100); -// -> false +// => false isPlainObject('lorem ipsum'); -// -> false +// => false ``` diff --git a/packages/is/isPlainObject/isPlainObject.js b/packages/is/isPlainObject/isPlainObject.js index 42fd8f48..1a806a13 100644 --- a/packages/is/isPlainObject/isPlainObject.js +++ b/packages/is/isPlainObject/isPlainObject.js @@ -6,7 +6,7 @@ * * @NOTE Use with caution as host objects (or objects used by browser host environments to complete the execution environment of ECMAScript) have a number of inconsistencies which are difficult to robustly feature detect cross-platform. * @param {*} value The value to check. - * @return {Boolean} True if value is a plain object, else false. + * @returns {Boolean} True if value is a plain object, else false. * @example * * function Foo() { @@ -14,40 +14,40 @@ * } * * isPlainObject({}); - * // -> true + * // => true * * isPlainObject({foo: 'bar'}); - * // -> true + * // => true * * isPlainObject(new Object({foo: 'bar'})); - * // -> true + * // => true * * isPlainObject(new Foo()); - * // -> false + * // => false * * isPlainObject(Object.create(null)); - * // -> true + * // => true * * isPlainObject(Object.create({})); - * // -> false + * // => false * * isPlainObject(Object.create({foo: 'bar'})); - * // -> false + * // => false * * isPlainObject([1, 2, 3]); - * // -> false + * // => false * * isPlainObject(null); - * // -> false + * // => false * * isPlainObject(); - * // -> false + * // => false * * isPlainObject(100); - * // -> false + * // => false * * isPlainObject('lorem ipsum'); - * // -> false + * // => false */ const isPlainObject = value => { if (Object.prototype.toString.call(value) !== '[object Object]') { diff --git a/packages/is/isPrimitive/README.md b/packages/is/isPrimitive/README.md index a78b2ddd..270cc8da 100644 --- a/packages/is/isPrimitive/README.md +++ b/packages/is/isPrimitive/README.md @@ -11,39 +11,39 @@ Checks if value is a primitive data type. **Example** ```js -isPrimitive(null); // -> true +isPrimitive(null); // => true -isPrimitive(undefined); // -> true +isPrimitive(undefined); // => true -isPrimitive(123); // -> true +isPrimitive(123); // => true -isPrimitive(Infinity); // -> true +isPrimitive(Infinity); // => true -isPrimitive(NaN); // -> true +isPrimitive(NaN); // => true -isPrimitive('foo'); // -> true +isPrimitive('foo'); // => true -isPrimitive(true); // -> true +isPrimitive(true); // => true -isPrimitive(false); // -> true +isPrimitive(false); // => true -isPrimitive(Symbol('foo')); // -> true +isPrimitive(Symbol('foo')); // => true -isPrimitive({}); // -> false +isPrimitive({}); // => false -isPrimitive([]); // -> false +isPrimitive([]); // => false -isPrimitive(function () {}); // -> false +isPrimitive(function () {}); // => false -isPrimitive(new Map()); // -> false +isPrimitive(new Map()); // => false -isPrimitive(new WeakMap()); // -> false +isPrimitive(new WeakMap()); // => false -isPrimitive(new Set()); // -> false +isPrimitive(new Set()); // => false -isPrimitive(new WeakSet()); // -> false +isPrimitive(new WeakSet()); // => false -isPrimitive(new Date()); // -> false +isPrimitive(new Date()); // => false -isPrimitive(/s+/g); // -> false +isPrimitive(/s+/g); // => false ``` diff --git a/packages/is/isPrimitive/isPrimitive.js b/packages/is/isPrimitive/isPrimitive.js index 977b9df0..e9cdd44e 100644 --- a/packages/is/isPrimitive/isPrimitive.js +++ b/packages/is/isPrimitive/isPrimitive.js @@ -7,41 +7,41 @@ * @returns {Boolean} Returns `true` if value is primitive, otherwise `false`. * @example * - * isPrimitive(null); // -> true + * isPrimitive(null); // => true * - * isPrimitive(undefined); // -> true + * isPrimitive(undefined); // => true * - * isPrimitive(123); // -> true + * isPrimitive(123); // => true * - * isPrimitive(Infinity); // -> true + * isPrimitive(Infinity); // => true * - * isPrimitive(NaN); // -> true + * isPrimitive(NaN); // => true * - * isPrimitive('foo'); // -> true + * isPrimitive('foo'); // => true * - * isPrimitive(true); // -> true + * isPrimitive(true); // => true * - * isPrimitive(false); // -> true + * isPrimitive(false); // => true * - * isPrimitive(Symbol('foo')); // -> true + * isPrimitive(Symbol('foo')); // => true * - * isPrimitive({}); // -> false + * isPrimitive({}); // => false * - * isPrimitive([]); // -> false + * isPrimitive([]); // => false * - * isPrimitive(function () {}); // -> false + * isPrimitive(function () {}); // => false * - * isPrimitive(new Map()); // -> false + * isPrimitive(new Map()); // => false * - * isPrimitive(new WeakMap()); // -> false + * isPrimitive(new WeakMap()); // => false * - * isPrimitive(new Set()); // -> false + * isPrimitive(new Set()); // => false * - * isPrimitive(new WeakSet()); // -> false + * isPrimitive(new WeakSet()); // => false * - * isPrimitive(new Date()); // -> false + * isPrimitive(new Date()); // => false * - * isPrimitive(/s+/g); // -> false + * isPrimitive(/s+/g); // => false */ const isPrimitive = value => { if (typeof value === 'object') { diff --git a/packages/is/isPromise/README.md b/packages/is/isPromise/README.md index 32680e5f..df4dfcf1 100644 --- a/packages/is/isPromise/README.md +++ b/packages/is/isPromise/README.md @@ -12,16 +12,16 @@ Check if a value is a native ES2015 Promise. **Example** ```js isPromise(new Promise(resolve, reject)); -// -> true +// => true isPromise(Promise.resolve('Success')); -// -> true +// => true isPromise(Promise.reject('Error')); -// -> true +// => true isPromise(function () { return Promise.resolve('Success'); }); -// -> false +// => false ``` diff --git a/packages/is/isPromise/isPromise.js b/packages/is/isPromise/isPromise.js index 45cad22d..601e0b6a 100644 --- a/packages/is/isPromise/isPromise.js +++ b/packages/is/isPromise/isPromise.js @@ -8,18 +8,18 @@ * @example * * isPromise(new Promise(resolve, reject)); - * // -> true + * // => true * * isPromise(Promise.resolve('Success')); - * // -> true + * // => true * * isPromise(Promise.reject('Error')); - * // -> true + * // => true * * isPromise(function () { * return Promise.resolve('Success'); * }); - * // -> false + * // => false */ const isPromise = value => { // Checking with `Object.prototype.toString` should be enough for most cases except for the diff --git a/packages/is/isRegexp/README.md b/packages/is/isRegexp/README.md index 325b4f19..0e9e5d2b 100644 --- a/packages/is/isRegexp/README.md +++ b/packages/is/isRegexp/README.md @@ -12,8 +12,8 @@ Checks if a value is a regular expression. **Example** ```js isRegexp(/^[0-9a-fA-F]+$/); -// -> true +// => true isRegexp('/^[0-9a-fA-F]+$/'); -// -> false +// => false ``` diff --git a/packages/is/isRegexp/isRegexp.js b/packages/is/isRegexp/isRegexp.js index c531e357..3230c54f 100644 --- a/packages/is/isRegexp/isRegexp.js +++ b/packages/is/isRegexp/isRegexp.js @@ -4,14 +4,14 @@ * Checks if a value is a regular expression. * * @param {*} value The value to check. - * @return {Boolean} True if the value is a regular expression, else false. + * @returns {Boolean} True if the value is a regular expression, else false. * @example * * isRegexp(/^[0-9a-fA-F]+$/); - * // -> true + * // => true * * isRegexp('/^[0-9a-fA-F]+$/'); - * // -> false + * // => false */ const isRegexp = value => Object.prototype.toString.call(value) === '[object RegExp]'; diff --git a/packages/is/isSafeInteger/README.md b/packages/is/isSafeInteger/README.md index 2f539388..e85a0e1f 100644 --- a/packages/is/isSafeInteger/README.md +++ b/packages/is/isSafeInteger/README.md @@ -13,29 +13,29 @@ Checks if an integer number is in the safe range, i.e., it is correctly represen **Example** ```js isSafeInteger(3)); -// -> true +// => true isSafeInteger(Math.pow(2, 53))); -// -> false +// => false isSafeInteger(-Math.pow(2, 53))). -// -> false +// => false isSafeInteger(Math.pow(2, 53) - 1)); -// -> true +// => true isSafeInteger(NaN)); -// -> false +// => false isSafeInteger(Infinity)); -// -> false +// => false isSafeInteger('3')); -// -> false +// => false isSafeInteger(3.1)); -// -> false +// => false isSafeInteger(3.0)); -// -> true +// => true ``` diff --git a/packages/is/isSafeInteger/isSafeInteger.js b/packages/is/isSafeInteger/isSafeInteger.js index 48e0e6a9..9735d784 100644 --- a/packages/is/isSafeInteger/isSafeInteger.js +++ b/packages/is/isSafeInteger/isSafeInteger.js @@ -5,35 +5,35 @@ * (where all numbers, including integer numbers, are technically floating point number). * * @param {*} value The value to check. - * @return {Boolean} True if safe integer, else false. + * @returns {Boolean} True if safe integer, else false. * @example * * isSafeInteger(3)); - * // -> true + * // => true * * isSafeInteger(Math.pow(2, 53))); - * // -> false + * // => false * * isSafeInteger(-Math.pow(2, 53))). - * // -> false + * // => false * * isSafeInteger(Math.pow(2, 53) - 1)); - * // -> true + * // => true * * isSafeInteger(NaN)); - * // -> false + * // => false * * isSafeInteger(Infinity)); - * // -> false + * // => false * * isSafeInteger('3')); - * // -> false + * // => false * * isSafeInteger(3.1)); - * // -> false + * // => false * * isSafeInteger(3.0)); - * // -> true + * // => true */ const isSafeInteger = value => { if (Number.isSafeInteger) { diff --git a/packages/is/isSet/README.md b/packages/is/isSet/README.md index f4a57d3b..7b2c1008 100644 --- a/packages/is/isSet/README.md +++ b/packages/is/isSet/README.md @@ -12,8 +12,8 @@ Checks if a value is classified as a Set object. **Example** ```js isSet(new Set()); -// -> true +// => true isSet(new WeakSet()); -// -> false +// => false ``` diff --git a/packages/is/isSet/isSet.js b/packages/is/isSet/isSet.js index 9c3371f9..ab5287f8 100644 --- a/packages/is/isSet/isSet.js +++ b/packages/is/isSet/isSet.js @@ -4,14 +4,14 @@ * Checks if a value is classified as a Set object. * * @param {*} value The value to check. - * @return {Boolean} True if value is classified as a Set object, else false. + * @returns {Boolean} True if value is classified as a Set object, else false. * @example * * isSet(new Set()); - * // -> true + * // => true * * isSet(new WeakSet()); - * // -> false + * // => false */ const isSet = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object Set]'; diff --git a/packages/is/isString/README.md b/packages/is/isString/README.md index 93ef59d0..105193c7 100644 --- a/packages/is/isString/README.md +++ b/packages/is/isString/README.md @@ -12,14 +12,14 @@ Checks if a value is string. **Example** ```js isString(['a', 'b', 'c', 'd']); -// -> false +// => false isString(100); -// -> false +// => false isString('Lorem ipsum dolor sit amet'); -// -> true +// => true isString({ a: 'a', b: 'b' }); -// -> false +// => false ``` diff --git a/packages/is/isString/isString.js b/packages/is/isString/isString.js index c4cf0f0a..6cfc98d1 100644 --- a/packages/is/isString/isString.js +++ b/packages/is/isString/isString.js @@ -4,20 +4,20 @@ * Checks if a value is string. * * @param {*} value The value to check. - * @return {Boolean} True if value is string, else false. + * @returns {Boolean} True if value is string, else false. * @example * * isString(['a', 'b', 'c', 'd']); - * // -> false + * // => false * * isString(100); - * // -> false + * // => false * * isString('Lorem ipsum dolor sit amet'); - * // -> true + * // => true * * isString({ a: 'a', b: 'b' }); - * // -> false + * // => false */ const isString = value => { return typeof value === 'string' || Object.prototype.toString.call(value) === '[object String]'; diff --git a/packages/is/isSymbol/README.md b/packages/is/isSymbol/README.md index eebefe5b..1be9a6ed 100644 --- a/packages/is/isSymbol/README.md +++ b/packages/is/isSymbol/README.md @@ -12,17 +12,17 @@ Checks if a value is classified as a Symbol primitive. **Example** ```js isSymbol(Symbol()); -// -> true +// => true isSymbol(Symbol('foo')); -// -> true +// => true isSymbol(Symbol.for('foo')); -// -> true +// => true isSymbol(Symbol.iterator); -// -> true +// => true isSymbol('foo'); -// -> false +// => false ``` diff --git a/packages/is/isSymbol/isSymbol.js b/packages/is/isSymbol/isSymbol.js index 91603330..c67ea86b 100644 --- a/packages/is/isSymbol/isSymbol.js +++ b/packages/is/isSymbol/isSymbol.js @@ -4,23 +4,23 @@ * Checks if a value is classified as a Symbol primitive. * * @param {*} value The value to check. - * @return {Boolean} True if value is classified as a Symbol primitive, else false. + * @returns {Boolean} True if value is classified as a Symbol primitive, else false. * @example * * isSymbol(Symbol()); - * // -> true + * // => true * * isSymbol(Symbol('foo')); - * // -> true + * // => true * * isSymbol(Symbol.for('foo')); - * // -> true + * // => true * * isSymbol(Symbol.iterator); - * // -> true + * // => true * * isSymbol('foo'); - * // -> false + * // => false */ const isSymbol = value => { return typeof value === 'symbol' || Object.prototype.toString.call(value) === '[object Symbol]'; diff --git a/packages/is/isTrue/README.md b/packages/is/isTrue/README.md index ad39f3eb..826a14cf 100644 --- a/packages/is/isTrue/README.md +++ b/packages/is/isTrue/README.md @@ -12,11 +12,11 @@ Checks if a value is `true` (strict equality). **Example** ```js isTrue(true); -// -> true +// => true isTrue(false); -// -> false +// => false isTrue(); -// -> false +// => false ``` diff --git a/packages/is/isTrue/isTrue.js b/packages/is/isTrue/isTrue.js index 97bc8e02..1fc45e63 100644 --- a/packages/is/isTrue/isTrue.js +++ b/packages/is/isTrue/isTrue.js @@ -4,17 +4,17 @@ * Checks if a value is `true` (strict equality). * * @param {*} value The value to check. - * @return {Boolean} True if the value is true, else false. + * @returns {Boolean} True if the value is true, else false. * @example * * isTrue(true); - * // -> true + * // => true * * isTrue(false); - * // -> false + * // => false * * isTrue(); - * // -> false + * // => false */ const isTrue = value => value === true; diff --git a/packages/is/isTruthy/README.md b/packages/is/isTruthy/README.md index 6f2fb2ce..04eec541 100644 --- a/packages/is/isTruthy/README.md +++ b/packages/is/isTruthy/README.md @@ -12,26 +12,26 @@ Checks if a value is a truthy one. **Example** ```js isTruthy(true); -// -> true +// => true isTruthy(' '); -// -> true +// => true isTruthy(1); -// -> true +// => true isTruthy(false); -// -> false +// => false isTruthy(''); -// -> false +// => false isTruthy(); -// -> false +// => false isTruthy(0); -// -> false +// => false isTruthy(NaN); -// -> false +// => false ``` diff --git a/packages/is/isTruthy/isTruthy.js b/packages/is/isTruthy/isTruthy.js index e1932c01..ba50e37a 100644 --- a/packages/is/isTruthy/isTruthy.js +++ b/packages/is/isTruthy/isTruthy.js @@ -4,32 +4,32 @@ * Checks if a value is a truthy one. * * @param {*} value The value to check. - * @return {Boolean} Returns `true` if the value is truthy, otherwise `false`. + * @returns {Boolean} Returns `true` if the value is truthy, otherwise `false`. * @example * * isTruthy(true); - * // -> true + * // => true * * isTruthy(' '); - * // -> true + * // => true * * isTruthy(1); - * // -> true + * // => true * * isTruthy(false); - * // -> false + * // => false * * isTruthy(''); - * // -> false + * // => false * * isTruthy(); - * // -> false + * // => false * * isTruthy(0); - * // -> false + * // => false * * isTruthy(NaN); - * // -> false + * // => false */ const isTruthy = value => !!value; diff --git a/packages/is/isUndefined/README.md b/packages/is/isUndefined/README.md index 1b335ddc..8b68d222 100644 --- a/packages/is/isUndefined/README.md +++ b/packages/is/isUndefined/README.md @@ -14,14 +14,14 @@ Checks if a value is `undefined`. let foo; isUndefined(foo); -// -> true +// => true isUndefined(null); -// -> false +// => false isUndefined({foo: 'bar'}); -// -> false +// => false isUndefined(); -// -> true +// => true ``` diff --git a/packages/is/isUndefined/isUndefined.js b/packages/is/isUndefined/isUndefined.js index ed0016c6..81d4c816 100644 --- a/packages/is/isUndefined/isUndefined.js +++ b/packages/is/isUndefined/isUndefined.js @@ -4,22 +4,22 @@ * Checks if a value is `undefined`. * * @param {*} value The value to check. - * @return {Boolean} True if the value is `undefined`, else false. + * @returns {Boolean} True if the value is `undefined`, else false. * @example * * let foo; * * isUndefined(foo); - * // -> true + * // => true * * isUndefined(null); - * // -> false + * // => false * * isUndefined({foo: 'bar'}); - * // -> false + * // => false * * isUndefined(); - * // -> true + * // => true */ const isUndefined = value => typeof value === 'undefined'; diff --git a/packages/is/isWeakMap/README.md b/packages/is/isWeakMap/README.md index 78390eca..eb9844be 100644 --- a/packages/is/isWeakMap/README.md +++ b/packages/is/isWeakMap/README.md @@ -12,18 +12,18 @@ Checks if a value is classified as a WeakMap object. **Example** ```js isWeakMap(new WeakMap()); -// -> true +// => true isWeakMap(new Map()); -// -> false +// => false const obj = { foo: 'bar' }; isWeakMap(new WeakMap([[obj, 'foobar']])); -// -> true +// => true isWeakMap([['foo', 'bar'], ['hello', 'world']]); -// -> false +// => false ``` diff --git a/packages/is/isWeakMap/isWeakMap.js b/packages/is/isWeakMap/isWeakMap.js index acb20bb0..59121b3b 100644 --- a/packages/is/isWeakMap/isWeakMap.js +++ b/packages/is/isWeakMap/isWeakMap.js @@ -4,24 +4,24 @@ * Checks if a value is classified as a WeakMap object. * * @param {value} value The value to check. - * @return {Boolean} True if value is classified as a WeakMap object, else false. + * @returns {Boolean} True if value is classified as a WeakMap object, else false. * @example * * isWeakMap(new WeakMap()); - * // -> true + * // => true * * isWeakMap(new Map()); - * // -> false + * // => false * * const obj = { * foo: 'bar' * }; * * isWeakMap(new WeakMap([[obj, 'foobar']])); - * // -> true + * // => true * * isWeakMap([['foo', 'bar'], ['hello', 'world']]); - * // -> false + * // => false */ const isWeakMap = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object WeakMap]'; diff --git a/packages/is/isWeakSet/README.md b/packages/is/isWeakSet/README.md index f62f0600..bc25dfcd 100644 --- a/packages/is/isWeakSet/README.md +++ b/packages/is/isWeakSet/README.md @@ -12,8 +12,8 @@ Checks if a value is classified as a WeakSet object. **Example** ```js isWeakSet(new WeakSet()); -// -> true +// => true isWeakSet(new Set()); -// -> false +// => false ``` diff --git a/packages/is/isWeakSet/isWeakSet.js b/packages/is/isWeakSet/isWeakSet.js index a88512b9..a82c6b55 100644 --- a/packages/is/isWeakSet/isWeakSet.js +++ b/packages/is/isWeakSet/isWeakSet.js @@ -4,14 +4,14 @@ * Checks if a value is classified as a WeakSet object. * * @param {*} value The value to check. - * @return {Boolean} True if value is classified as a WeakSet object, else false. + * @returns {Boolean} True if value is classified as a WeakSet object, else false. * @example * * isWeakSet(new WeakSet()); - * // -> true + * // => true * * isWeakSet(new Set()); - * // -> false + * // => false */ const isWeakSet = value => { return typeof value === 'object' && Object.prototype.toString.call(value) === '[object WeakSet]'; diff --git a/packages/math/average/README.md b/packages/math/average/README.md index 4063375a..f08d0373 100644 --- a/packages/math/average/README.md +++ b/packages/math/average/README.md @@ -13,24 +13,24 @@ Ommits any non number value. **Example** ```js -average(5, 10, 50, -45, 6, 7); // -> 5.5 -average([5, 10, 50, -45, 6, 7]); // -> 5.5 +average(5, 10, 50, -45, 6, 7); // => 5.5 +average([5, 10, 50, -45, 6, 7]); // => 5.5 -average(2, 4, 0, -0); // -> 1.5 -average([2, 4, 0, -0]); // -> +average(2, 4, 0, -0); // => 1.5 +average([2, 4, 0, -0]); // => -average(7); // -> 7 -average([7]); // -> 7 +average(7); // => 7 +average([7]); // => 7 -average(0, -0); // -> 0 -average([0, -0]); // -> 0 +average(0, -0); // => 0 +average([0, -0]); // => 0 -average(); // -> 0 -average([]); // -> 0 +average(); // => 0 +average([]); // => 0 -average(Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo'); // -> 0 -average([Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo']); // -> 0 +average(Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo'); // => 0 +average([Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo']); // => 0 -average(5, 4, null, true, '12', Infinity); // -> 0 -average([5, 4, null, true, '12', Infinity]); // -> 0 +average(5, 4, null, true, '12', Infinity); // => 0 +average([5, 4, null, true, '12', Infinity]); // => 0 ``` diff --git a/packages/math/average/average.js b/packages/math/average/average.js index b7331b57..5b19cf5e 100644 --- a/packages/math/average/average.js +++ b/packages/math/average/average.js @@ -9,26 +9,26 @@ * @returns {Number} The average number of the set of data provided. * @example * - * average(5, 10, 50, -45, 6, 7); // -> 5.5 - * average([5, 10, 50, -45, 6, 7]); // -> 5.5 + * average(5, 10, 50, -45, 6, 7); // => 5.5 + * average([5, 10, 50, -45, 6, 7]); // => 5.5 * - * average(2, 4, 0, -0); // -> 1.5 - * average([2, 4, 0, -0]); // -> + * average(2, 4, 0, -0); // => 1.5 + * average([2, 4, 0, -0]); // => * - * average(7); // -> 7 - * average([7]); // -> 7 + * average(7); // => 7 + * average([7]); // => 7 * - * average(0, -0); // -> 0 - * average([0, -0]); // -> 0 + * average(0, -0); // => 0 + * average([0, -0]); // => 0 * - * average(); // -> 0 - * average([]); // -> 0 + * average(); // => 0 + * average([]); // => 0 * - * average(Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo'); // -> 0 - * average([Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo']); // -> 0 + * average(Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo'); // => 0 + * average([Infinity, -Infinity, 0, -0, null, NaN, undefined, false, true, 'foo']); // => 0 * - * average(5, 4, null, true, '12', Infinity); // -> 0 - * average([5, 4, null, true, '12', Infinity]); // -> 0 + * average(5, 4, null, true, '12', Infinity); // => 0 + * average([5, 4, null, true, '12', Infinity]); // => 0 */ const average = (...nums) => { let sum = 0; diff --git a/packages/math/clamp/README.md b/packages/math/clamp/README.md index 2ea2f367..c5629cb6 100644 --- a/packages/math/clamp/README.md +++ b/packages/math/clamp/README.md @@ -19,20 +19,20 @@ If `min` is greater than `max` the parameters are swapped to support inverted ra **Example** ```js clamp(10, -5, 5); -// -> 5 +// => 5 clamp(-10, -5, 5); -// -> -5 +// => -5 clamp(-15, 0, 100); -// -> 0 +// => 0 clamp(120, 0, 100); -// -> 100 +// => 100 clamp(-5, NaN, 5); // If any of lower or upper bound are `NaN`, they will be converted to `0`. -// -> 0 +// => 0 clamp(120, 100, 0); // The order of lower and upper bounds is reversed (100 > 0) -// -> 100 +// => 100 ``` diff --git a/packages/math/clamp/clamp.js b/packages/math/clamp/clamp.js index 69a355cf..d785c867 100644 --- a/packages/math/clamp/clamp.js +++ b/packages/math/clamp/clamp.js @@ -13,22 +13,22 @@ * @example * * clamp(10, -5, 5); - * // -> 5 + * // => 5 * * clamp(-10, -5, 5); - * // -> -5 + * // => -5 * * clamp(-15, 0, 100); - * // -> 0 + * // => 0 * * clamp(120, 0, 100); - * // -> 100 + * // => 100 * * clamp(-5, NaN, 5); // If any of lower or upper bound are `NaN`, they will be converted to `0`. - * // -> 0 + * // => 0 * * clamp(120, 100, 0); // The order of lower and upper bounds is reversed (100 > 0) - * // -> 100 + * // => 100 */ const clamp = (value, lower, upper) => { if (typeof value !== 'number' || typeof lower !== 'number' || typeof upper !== 'number') { diff --git a/packages/math/degreesToRadians/README.md b/packages/math/degreesToRadians/README.md index 0289bc35..8a68ebb2 100644 --- a/packages/math/degreesToRadians/README.md +++ b/packages/math/degreesToRadians/README.md @@ -16,17 +16,17 @@ Converts degrees to radians. **Example** ```js degreesToRadians(0); -// -> 0 +// => 0 degreesToRadians(90); -// -> 1.5707963267948966 (π / 2) +// => 1.5707963267948966 (π / 2) degreesToRadians(180); -// -> 3.141592653589793 (π) +// => 3.141592653589793 (π) degreesToRadians(270); -// -> 4.71238898038469 (3π / 2) +// => 4.71238898038469 (3π / 2) degreesToRadians(360); -// -> 6.283185307179586 (2π) +// => 6.283185307179586 (2π) ``` diff --git a/packages/math/degreesToRadians/degreesToRadians.js b/packages/math/degreesToRadians/degreesToRadians.js index 992bb00c..1c00a5a6 100644 --- a/packages/math/degreesToRadians/degreesToRadians.js +++ b/packages/math/degreesToRadians/degreesToRadians.js @@ -9,19 +9,19 @@ * @example * * degreesToRadians(0); - * // -> 0 + * // => 0 * * degreesToRadians(90); - * // -> 1.5707963267948966 (π / 2) + * // => 1.5707963267948966 (π / 2) * * degreesToRadians(180); - * // -> 3.141592653589793 (π) + * // => 3.141592653589793 (π) * * degreesToRadians(270); - * // -> 4.71238898038469 (3π / 2) + * // => 4.71238898038469 (3π / 2) * * degreesToRadians(360); - * // -> 6.283185307179586 (2π) + * // => 6.283185307179586 (2π) */ const degreesToRadians = degrees => { if (typeof degrees !== 'number') { @@ -29,6 +29,6 @@ const degreesToRadians = degrees => { } return degrees * Math.PI / 180; -} +}; module.exports = degreesToRadians; diff --git a/packages/math/inRange/README.md b/packages/math/inRange/README.md index cbe1e3f4..6afb714f 100644 --- a/packages/math/inRange/README.md +++ b/packages/math/inRange/README.md @@ -19,17 +19,17 @@ If `min` is greater than `max` the parameters are swapped to support inverted ra **Example** ```js inRange(3, 2, 4); -// -> true +// => true inRange(3, 4, 2); -// -> true (`min` and `max` parameters are swapped) +// => true (`min` and `max` parameters are swapped) inRange(-3, -2, -6); -// -> true +// => true inRange(4, 8, 2); -// -> true +// => true inRange(4.5, 8.2, 2.1); -// -> true +// => true ``` diff --git a/packages/math/inRange/inRange.js b/packages/math/inRange/inRange.js index 58449d89..e58e6317 100644 --- a/packages/math/inRange/inRange.js +++ b/packages/math/inRange/inRange.js @@ -12,19 +12,19 @@ * @example * * inRange(3, 2, 4); - * // -> true + * // => true * * inRange(3, 4, 2); - * // -> true (`min` and `max` parameters are swapped) + * // => true (`min` and `max` parameters are swapped) * * inRange(-3, -2, -6); - * // -> true + * // => true * * inRange(4, 8, 2); - * // -> true + * // => true * * inRange(4.5, 8.2, 2.1); - * // -> true + * // => true */ const inRange = (value, min, max) => { if (typeof value !== 'number' || typeof min !== 'number' || typeof max !== 'number') { diff --git a/packages/math/lerp/README.md b/packages/math/lerp/README.md index 3f69ce3c..15ae860c 100644 --- a/packages/math/lerp/README.md +++ b/packages/math/lerp/README.md @@ -19,17 +19,17 @@ it to a numerical value that the normalized value points to. **Example** ```js lerp(0.75, 0, 365); -// -> 273.75 +// => 273.75 lerp(0.33, 100, 500); -// -> 232 +// => 232 lerp(0, 100, 500); -// -> 100 +// => 100 lerp(1, 100, 500); -// -> 500 +// => 500 lerp(-0.5, 0, 500); -// -> -250 +// => -250 ``` diff --git a/packages/math/lerp/lerp.js b/packages/math/lerp/lerp.js index cc4f390c..4001cbc6 100644 --- a/packages/math/lerp/lerp.js +++ b/packages/math/lerp/lerp.js @@ -12,19 +12,19 @@ * @example * * lerp(0.75, 0, 365); - * // -> 273.75 + * // => 273.75 * * lerp(0.33, 100, 500); - * // -> 232 + * // => 232 * * lerp(0, 100, 500); - * // -> 100 + * // => 100 * * lerp(1, 100, 500); - * // -> 500 + * // => 500 * * lerp(-0.5, 0, 500); - * // -> -250 + * // => -250 */ const lerp = (norm, min, max) => { if (typeof norm !== 'number' || typeof min !== 'number' || typeof max !== 'number') { diff --git a/packages/math/max/README.md b/packages/math/max/README.md index 4806da76..b44676b7 100644 --- a/packages/math/max/README.md +++ b/packages/math/max/README.md @@ -15,26 +15,26 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects **Example** ```js max(5); -// -> 5 +// => 5 max([1, -10, 1024, 1024.5, 29]); -// -> 1024.5 +// => 1024.5 max(5, 10, 154, 4, 8, 87); -// -> 154 +// => 154 max(NaN, 10); -// -> NaN +// => NaN max('', '1'); -// -> 1 +// => 1 max(0, true); -// -> 1 +// => 1 max(false); -// -> 0 +// => 0 max(); -// -> -Infinity +// => -Infinity ``` diff --git a/packages/math/max/max.js b/packages/math/max/max.js index e8d844ed..60b559c5 100644 --- a/packages/math/max/max.js +++ b/packages/math/max/max.js @@ -11,28 +11,28 @@ * @example * * max(5); - * // -> 5 + * // => 5 * * max([1, -10, 1024, 1024.5, 29]); - * // -> 1024.5 + * // => 1024.5 * * max(5, 10, 154, 4, 8, 87); - * // -> 154 + * // => 154 * * max(NaN, 10); - * // -> NaN + * // => NaN * * max('', '1'); - * // -> 1 + * // => 1 * * max(0, true); - * // -> 1 + * // => 1 * * max(false); - * // -> 0 + * // => 0 * * max(); - * // -> -Infinity + * // => -Infinity */ const max = (...nums) => { if (nums.length === 1 && Array.isArray(nums[0])) { diff --git a/packages/math/min/README.md b/packages/math/min/README.md index c42b3dcc..eb60ab4c 100644 --- a/packages/math/min/README.md +++ b/packages/math/min/README.md @@ -15,29 +15,29 @@ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects **Example** ```js min(5); -// -> 5 +// => 5 min([1, -10, 1024, 1024.5, 29]); -// -> -10 +// => -10 min(5, 10, 154, 4, 8, 87); -// -> 4 +// => 4 min(NaN, 10); -// -> NaN +// => NaN min('', '1'); -// -> 0 +// => 0 min(0, true); -// -> 0 +// => 0 min(false); -// -> 0 +// => 0 min(true); -// -> 1 +// => 1 min(); -// -> Infinity +// => Infinity ``` diff --git a/packages/math/min/min.js b/packages/math/min/min.js index c6fcc9f4..86fa51b5 100644 --- a/packages/math/min/min.js +++ b/packages/math/min/min.js @@ -11,31 +11,31 @@ * @example * * min(5); - * // -> 5 + * // => 5 * * min([1, -10, 1024, 1024.5, 29]); - * // -> -10 + * // => -10 * * min(5, 10, 154, 4, 8, 87); - * // -> 4 + * // => 4 * * min(NaN, 10); - * // -> NaN + * // => NaN * * min('', '1'); - * // -> 0 + * // => 0 * * min(0, true); - * // -> 0 + * // => 0 * * min(false); - * // -> 0 + * // => 0 * * min(true); - * // -> 1 + * // => 1 * * min(); - * // -> Infinity + * // => Infinity */ const min = (...nums) => { if (nums.length === 1 && Array.isArray(nums[0])) { diff --git a/packages/math/normalize/README.md b/packages/math/normalize/README.md index 28cc7424..a341bac3 100644 --- a/packages/math/normalize/README.md +++ b/packages/math/normalize/README.md @@ -19,20 +19,20 @@ to a number from 0 to 1 that indicates where it lies in that range. **Example** ```js normalize(23, 0, 33); -// -> 0.696969696969697 +// => 0.696969696969697 normalize(23, 5, 33); -// -> 0.6428571428571429 +// => 0.6428571428571429 normalize(35, 0, 33); -// -> 1.0606060606060606 +// => 1.0606060606060606 normalize(-1, 0, 33); -// -> -0.030303030303030304 +// => -0.030303030303030304 normalize(33, -5, 33); -// -> 1 +// => 1 normalize(-5, -5, 33); -// -> 0 +// => 0 ``` diff --git a/packages/math/normalize/normalize.js b/packages/math/normalize/normalize.js index b63e918d..61140e3e 100644 --- a/packages/math/normalize/normalize.js +++ b/packages/math/normalize/normalize.js @@ -12,22 +12,22 @@ * @example * * normalize(23, 0, 33); - * // -> 0.696969696969697 + * // => 0.696969696969697 * * normalize(23, 5, 33); - * // -> 0.6428571428571429 + * // => 0.6428571428571429 * * normalize(35, 0, 33); - * // -> 1.0606060606060606 + * // => 1.0606060606060606 * * normalize(-1, 0, 33); - * // -> -0.030303030303030304 + * // => -0.030303030303030304 * * normalize(33, -5, 33); - * // -> 1 + * // => 1 * * normalize(-5, -5, 33); - * // -> 0 + * // => 0 */ const normalize = (value, min, max) => { if (typeof value !== 'number' || typeof min !== 'number' || typeof max !== 'number') { diff --git a/packages/math/radiansToDegrees/README.md b/packages/math/radiansToDegrees/README.md index 885fe3a0..59b3c01c 100644 --- a/packages/math/radiansToDegrees/README.md +++ b/packages/math/radiansToDegrees/README.md @@ -16,17 +16,17 @@ Converts radians to degrees. **Example** ```js radiansToDegrees(0); -// -> 0 +// => 0 radiansToDegrees(1.5707963267948966); // π / 2 -// -> 90 +// => 90 radiansToDegrees(3.141592653589793); // π -// -> 180 +// => 180 radiansToDegrees(4.71238898038469); // 3π / 2 -// -> 270 +// => 270 radiansToDegrees(6.283185307179586); // 2π -// -> 360 +// => 360 ``` diff --git a/packages/math/radiansToDegrees/radiansToDegrees.js b/packages/math/radiansToDegrees/radiansToDegrees.js index facff505..eb03a34c 100644 --- a/packages/math/radiansToDegrees/radiansToDegrees.js +++ b/packages/math/radiansToDegrees/radiansToDegrees.js @@ -9,19 +9,19 @@ * @example * * radiansToDegrees(0); - * // -> 0 + * // => 0 * * radiansToDegrees(1.5707963267948966); // π / 2 - * // -> 90 + * // => 90 * * radiansToDegrees(3.141592653589793); // π - * // -> 180 + * // => 180 * * radiansToDegrees(4.71238898038469); // 3π / 2 - * // -> 270 + * // => 270 * * radiansToDegrees(6.283185307179586); // 2π - * // -> 360 + * // => 360 */ const radiansToDegrees = radians => { if (typeof radians !== 'number') { diff --git a/packages/math/randomDist/README.md b/packages/math/randomDist/README.md index 3e554dff..6b5a6260 100644 --- a/packages/math/randomDist/README.md +++ b/packages/math/randomDist/README.md @@ -20,5 +20,5 @@ The higher the iterations, the higher is the possibility the returned value to b **Example** ```js randomDist(0, 100, 200); -// -> 49.27716133759931 +// => 49.27716133759931 ``` diff --git a/packages/math/randomDist/randomDist.js b/packages/math/randomDist/randomDist.js index 0582e614..47c1e3e8 100644 --- a/packages/math/randomDist/randomDist.js +++ b/packages/math/randomDist/randomDist.js @@ -13,7 +13,7 @@ * @example * * randomDist(0, 100, 200); - * // -> 49.27716133759931 + * // => 49.27716133759931 */ const randomDist = (min, max, iterations) => { const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53) - 1; diff --git a/packages/math/randomInt/README.md b/packages/math/randomInt/README.md index a55988ef..1fd6432c 100644 --- a/packages/math/randomInt/README.md +++ b/packages/math/randomInt/README.md @@ -18,5 +18,5 @@ If `min` is greater than `max` the parameters are swapped to support inverted ra **Example** ```js randomInt(3, 8); -// -> Any integer number between 3 (inclusive) and 8 (inclusive). eg 6 +// => Any integer number between 3 (inclusive) and 8 (inclusive). eg 6 ``` diff --git a/packages/math/randomInt/randomInt.js b/packages/math/randomInt/randomInt.js index a2cbc27c..86a6cd7c 100644 --- a/packages/math/randomInt/randomInt.js +++ b/packages/math/randomInt/randomInt.js @@ -11,7 +11,7 @@ * @example * * randomInt(3, 8); - * // -> Any integer number between 3 (inclusive) and 8 (inclusive). eg 6 + * // => Any integer number between 3 (inclusive) and 8 (inclusive). eg 6 */ const randomInt = (min, max) => { if (typeof min !== 'number' || typeof max !== 'number') { diff --git a/packages/math/randomRange/README.md b/packages/math/randomRange/README.md index d828aad5..718e8d73 100644 --- a/packages/math/randomRange/README.md +++ b/packages/math/randomRange/README.md @@ -18,5 +18,5 @@ If `min` is greater than `max` the parameters are swapped to support inverted ra **Example** ```js randomRange(3, 8); -// -> Any number between 3 (inclusive) and 8 (exclusive). eg 5.3304674779064953 +// => Any number between 3 (inclusive) and 8 (exclusive). eg 5.3304674779064953 ``` diff --git a/packages/math/randomRange/randomRange.js b/packages/math/randomRange/randomRange.js index d2e1eeb6..0c2889c9 100644 --- a/packages/math/randomRange/randomRange.js +++ b/packages/math/randomRange/randomRange.js @@ -11,7 +11,7 @@ * @example * * randomRange(3, 8); - * // -> Any number between 3 (inclusive) and 8 (exclusive). eg 5.3304674779064953 + * // => Any number between 3 (inclusive) and 8 (exclusive). eg 5.3304674779064953 */ const randomRange = (min, max) => { if (typeof min !== 'number' || typeof max !== 'number') { diff --git a/packages/math/roundToNearest/README.md b/packages/math/roundToNearest/README.md index 9d91316b..6401a545 100644 --- a/packages/math/roundToNearest/README.md +++ b/packages/math/roundToNearest/README.md @@ -17,17 +17,17 @@ Rounds a number to the nearest multiple of a value provided. **Example** ```js roundToNearest(100, 40); -// -> 120 +// => 120 roundToNearest(140, 40); -// -> 160 +// => 160 roundToNearest(180, 40); -// -> 200 +// => 200 roundToNearest(113, 0); -// -> 113 (0 is converted to 1) +// => 113 (0 is converted to 1) roundToNearest(113, NaN); -// -> 113 (NaN is converted to 1) +// => 113 (NaN is converted to 1) ``` diff --git a/packages/math/roundToNearest/roundToNearest.js b/packages/math/roundToNearest/roundToNearest.js index b8b997af..dcac3f15 100644 --- a/packages/math/roundToNearest/roundToNearest.js +++ b/packages/math/roundToNearest/roundToNearest.js @@ -10,22 +10,22 @@ * @example * * roundToNearest(100, 40); - * // -> 120 + * // => 120 * * roundToNearest(140, 40); - * // -> 160 + * // => 160 * * roundToNearest(180, 40); - * // -> 200 + * // => 200 * * roundToNearest(100, 0); - * // -> NaN + * // => NaN * * roundToNearest(100, NaN); - * // -> NaN + * // => NaN * * roundToNearest(100); - * // -> NaN + * // => NaN */ const roundToNearest = (value, nearest) => { if (typeof value !== 'number' || typeof nearest !== 'number') { diff --git a/packages/math/roundToPlaces/README.md b/packages/math/roundToPlaces/README.md index 10f49c92..8b3afddf 100644 --- a/packages/math/roundToPlaces/README.md +++ b/packages/math/roundToPlaces/README.md @@ -18,32 +18,32 @@ Feed with negative place values to round to powers of 10. **Example** ```js const PI = Math.PI -// -> 3.141592653589793 +// => 3.141592653589793 roundToPlaces(PI, 0); -// -> 3 +// => 3 roundToPlaces(PI, 1); -// -> 3.1 +// => 3.1 roundToPlaces(PI, 2); -// -> 3.14 +// => 3.14 roundToPlaces(PI, 3); -// -> 3.142 +// => 3.142 roundToPlaces(PI, 4); -// -> 3.1416 +// => 3.1416 roundToPlaces(PI, 4.7); -// -> 3.1416 (places is converted to 4) +// => 3.1416 (places is converted to 4) roundToPlaces(123456789, -1); -// -> 123456790 +// => 123456790 roundToPlaces(123456789, -2); -// -> 123456800 +// => 123456800 roundToPlaces(123456789, -3); -// -> 123457000 +// => 123457000 ``` diff --git a/packages/math/roundToPlaces/roundToPlaces.js b/packages/math/roundToPlaces/roundToPlaces.js index dc2fb629..5b4e99d9 100644 --- a/packages/math/roundToPlaces/roundToPlaces.js +++ b/packages/math/roundToPlaces/roundToPlaces.js @@ -11,34 +11,34 @@ * @example * * const PI = Math.PI - * // -> 3.141592653589793 + * // => 3.141592653589793 * * roundToPlaces(PI, 0); - * // -> 3 + * // => 3 * * roundToPlaces(PI, 1); - * // -> 3.1 + * // => 3.1 * * roundToPlaces(PI, 2); - * // -> 3.14 + * // => 3.14 * * roundToPlaces(PI, 3); - * // -> 3.142 + * // => 3.142 * * roundToPlaces(PI, 4); - * // -> 3.1416 + * // => 3.1416 * * roundToPlaces(PI, 4.7); - * // -> 3.1416 (places is converted to 4) + * // => 3.1416 (places is converted to 4) * * roundToPlaces(123456789, -1); - * // -> 123456790 + * // => 123456790 * * roundToPlaces(123456789, -2); - * // -> 123456800 + * // => 123456800 * * roundToPlaces(123456789, -3); - * // -> 123457000 + * // => 123457000 */ const roundToPlaces = (value, places) => { if (typeof value !== 'number' || typeof places !== 'number') { diff --git a/packages/objects/get/README.md b/packages/objects/get/README.md index 4487a913..ba097d7e 100644 --- a/packages/objects/get/README.md +++ b/packages/objects/get/README.md @@ -25,14 +25,14 @@ const object = { }; get(object, 'a.0.b.c'); -// -> 3 +// => 3 get(object, ['a', '0', 'b', 'c']); -// -> 3 +// => 3 get(object, 'a[1].b.c'); -// -> undefined +// => undefined get(object, 'a[1].b.c', 'DEFAULT'); -// -> 'DEFAULT' +// => 'DEFAULT' ``` diff --git a/packages/objects/get/get.js b/packages/objects/get/get.js index 9982319e..f1aca905 100644 --- a/packages/objects/get/get.js +++ b/packages/objects/get/get.js @@ -12,16 +12,16 @@ * const object = { a: [{ b: { c: 3 } }] }; * * get(object, 'a[0]b.c'); - * // -> 3 + * // => 3 * * get(object, ['a', '0', 'b', 'c']); - * // -> 3 + * // => 3 * * get(object, 'a[1].b.c'); - * // -> undefined + * // => undefined * * get(object, 'a[1].b.c', 'DEFAULT'); - * // -> 'DEFAULT' + * // => 'DEFAULT' */ const get = (object, path, defaultValue) => { const keys = String.prototype.split.call(path, /[,[\].]+?/); diff --git a/packages/objects/omit/README.md b/packages/objects/omit/README.md index 911b0576..920f0ed9 100644 --- a/packages/objects/omit/README.md +++ b/packages/objects/omit/README.md @@ -20,17 +20,17 @@ const obj = { }; omit(obj, ['a', 'c']); -// -> { b: 'bbb' } +// => { b: 'bbb' } omit(obj, ['a', 'b', 'c']); -// -> {} +// => {} omit(obj); -// -> { a: 'aaa', b: 'bbb', c: 'ccc' } +// => { a: 'aaa', b: 'bbb', c: 'ccc' } omit(obj, []); -// -> { a: 'aaa', b: 'bbb', c: 'ccc' } +// => { a: 'aaa', b: 'bbb', c: 'ccc' } omit(obj, ['key_not_exists']); -// -> { a: 'aaa', b: 'bbb', c: 'ccc' } +// => { a: 'aaa', b: 'bbb', c: 'ccc' } ``` diff --git a/packages/objects/omit/omit.js b/packages/objects/omit/omit.js index c239cb6f..ca9c737f 100644 --- a/packages/objects/omit/omit.js +++ b/packages/objects/omit/omit.js @@ -15,19 +15,19 @@ * }; * * omit(obj, ['a', 'c']); - * // -> { b: 'bbb' } + * // => { b: 'bbb' } * * omit(obj, ['a', 'b', 'c']); - * // -> {} + * // => {} * * omit(obj); - * // -> { a: 'aaa', b: 'bbb', c: 'ccc' } + * // => { a: 'aaa', b: 'bbb', c: 'ccc' } * * omit(obj, []); - * // -> { a: 'aaa', b: 'bbb', c: 'ccc' } + * // => { a: 'aaa', b: 'bbb', c: 'ccc' } * * omit(obj, ['key_not_exists']); - * // -> { a: 'aaa', b: 'bbb', c: 'ccc' } + * // => { a: 'aaa', b: 'bbb', c: 'ccc' } */ const omit = (obj, props) => { if (!Array.isArray(props) || props.length === 0) { diff --git a/packages/objects/pick/README.md b/packages/objects/pick/README.md index 522226d8..eb78598b 100644 --- a/packages/objects/pick/README.md +++ b/packages/objects/pick/README.md @@ -30,11 +30,11 @@ Object.defineProperties(object, { }); pick(object, ['a', 'c', 'foo']); -// -> { a: 1, c: 3 } +// => { a: 1, c: 3 } pick(object, ['a', 'c', 'foo'], false); -// -> { a: 1, c: 3, foo: 'bar' } +// => { a: 1, c: 3, foo: 'bar' } pick(object, ['d']); -// -> {} +// => {} ``` diff --git a/packages/objects/pick/pick.js b/packages/objects/pick/pick.js index 42514c03..a31c1dcb 100644 --- a/packages/objects/pick/pick.js +++ b/packages/objects/pick/pick.js @@ -21,13 +21,13 @@ * }); * * pick(object, ['a', 'c', 'foo']); - * // -> { a: 1, c: 3 } + * // => { a: 1, c: 3 } * * pick(object, ['a', 'c', 'foo'], false); - * // -> { a: 1, c: 3, foo: 'bar' } + * // => { a: 1, c: 3, foo: 'bar' } * * pick(object, ['d']); - * // -> {} + * // => {} */ const pick = (object, paths, pickOwnKeys) => { const result = {}; diff --git a/packages/objects/pickBy/README.md b/packages/objects/pickBy/README.md index d75b86d6..06137759 100644 --- a/packages/objects/pickBy/README.md +++ b/packages/objects/pickBy/README.md @@ -46,25 +46,25 @@ Object.defineProperties(object, { pickBy(object, function (value) { return typeof value === 'number'; }); -// -> { a: 1, c: 3 } +// => { a: 1, c: 3 } pickBy(object, function (value) { return typeof value === 'number'; }, false); -// -> { a: 1, c: 3, e: 5 } +// => { a: 1, c: 3, e: 5 } pickBy(object, function (value) { return typeof value === 'function'; }); -// -> {} +// => {} pickBy(object, function (_, key) { return key === 'a'; }); -// -> { a: 1 } +// => { a: 1 } pickBy(object, function (_, key) { return key === 'd'; // property "d" is not enumerable }); -// -> {} +// => {} ``` diff --git a/packages/objects/pickBy/pickBy.js b/packages/objects/pickBy/pickBy.js index 6c05c8a9..27db0a76 100644 --- a/packages/objects/pickBy/pickBy.js +++ b/packages/objects/pickBy/pickBy.js @@ -37,27 +37,27 @@ * pickBy(object, function (value) { * return typeof value === 'number'; * }); - * // -> { a: 1, c: 3 } + * // => { a: 1, c: 3 } * * pickBy(object, function (value) { * return typeof value === 'number'; * }, false); - * // -> { a: 1, c: 3, e: 5 } + * // => { a: 1, c: 3, e: 5 } * * pickBy(object, function (value) { * return typeof value === 'function'; * }); - * // -> {} + * // => {} * * pickBy(object, function (_, key) { * return key === 'a'; * }); - * // -> { a: 1 } + * // => { a: 1 } * * pickBy(object, function (_, key) { * return key === 'd'; // property "d" is not enumerable * }); - * // -> {} + * // => {} */ const pickBy = (object, predicate, pickOwnKeys) => { const result = {}; diff --git a/packages/strings/camelCase/README.md b/packages/strings/camelCase/README.md index bb2a1087..3a7b59ec 100755 --- a/packages/strings/camelCase/README.md +++ b/packages/strings/camelCase/README.md @@ -17,32 +17,32 @@ Combines words by capitalizing all words following the first word and removing s **Example** ```js camelCase('the quick brown fox jumps over the lazy dog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('the-quick-brown-fox-jumps-over-the-lazy-dog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('the_quick_brown_fox_jumps_over_the_lazy_dog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('thequickbrownfoxjumpsoverthelazydog'); -// -> 'thequickbrownfoxjumpsoverthelazydog' +// => 'thequickbrownfoxjumpsoverthelazydog' camelCase('theQuickBrownFoxJumpsOverTheLazyDog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('TheQuickBrownFoxJumpsOverTheLazyDog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('The Quick Brown Fox Jumps Over The Lazy Dog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase('theQUICKBrownFoxJumpsOverTheLazyDog'); -// -> 'theQUICKBrownFoxJumpsOverTheLazyDog' +// => 'theQUICKBrownFoxJumpsOverTheLazyDog' camelCase('the - quick ( * brown# )fox:> < jumps; % over , the ^ lazy & dog'); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' camelCase(' () @#$ @# @the quick brown fox jumps over the lazy dog #!#$% <> '); -// -> 'theQuickBrownFoxJumpsOverTheLazyDog' +// => 'theQuickBrownFoxJumpsOverTheLazyDog' ``` diff --git a/packages/strings/camelCase/camelCase.js b/packages/strings/camelCase/camelCase.js index 5c941d69..2108568c 100755 --- a/packages/strings/camelCase/camelCase.js +++ b/packages/strings/camelCase/camelCase.js @@ -6,38 +6,38 @@ * * @param {String} subjectString The string to convert. * @throws {TypeError} Throws if `subjectString` is not string. - * @return {String} Returns the camel cased string. + * @returns {String} Returns the camel cased string. * @example * * camelCase('the quick brown fox jumps over the lazy dog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('the-quick-brown-fox-jumps-over-the-lazy-dog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('the_quick_brown_fox_jumps_over_the_lazy_dog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('thequickbrownfoxjumpsoverthelazydog'); - * // -> 'thequickbrownfoxjumpsoverthelazydog' + * // => 'thequickbrownfoxjumpsoverthelazydog' * * camelCase('theQuickBrownFoxJumpsOverTheLazyDog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('TheQuickBrownFoxJumpsOverTheLazyDog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('The Quick Brown Fox Jumps Over The Lazy Dog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase('theQUICKBrownFoxJumpsOverTheLazyDog'); - * // -> 'theQUICKBrownFoxJumpsOverTheLazyDog' + * // => 'theQUICKBrownFoxJumpsOverTheLazyDog' * * camelCase('the - quick ( * brown# )fox:> < jumps; % over , the ^ lazy & dog'); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' * * camelCase(' () @#$ @# @the quick brown fox jumps over the lazy dog #!#$% <> '); - * // -> 'theQuickBrownFoxJumpsOverTheLazyDog' + * // => 'theQuickBrownFoxJumpsOverTheLazyDog' */ const camelCase = subjectString => { if (typeof subjectString !== 'string') { diff --git a/packages/strings/capitalize/README.md b/packages/strings/capitalize/README.md index 4fdee2ac..773dd100 100755 --- a/packages/strings/capitalize/README.md +++ b/packages/strings/capitalize/README.md @@ -17,11 +17,11 @@ Capitalizes the first character of a string. **Example** ```js capitalize('hello'); -// -> 'Hello' +// => 'Hello' capitalize('hElLo'); // -< 'HElLo' capitalize('hElLo', true); -// -> 'Hello' +// => 'Hello' ``` diff --git a/packages/strings/capitalize/capitalize.js b/packages/strings/capitalize/capitalize.js index 8c27c699..5c637b93 100755 --- a/packages/strings/capitalize/capitalize.js +++ b/packages/strings/capitalize/capitalize.js @@ -6,17 +6,17 @@ * @param {String} subjectString The string to capitalize its first character. * @param {Boolean} [lowerCaseRest=false] If true will lowercase the rest of the string. * @throws {TypeError} If `subjectString` is not string. - * @return {String} A new capitalized string. + * @returns {String} A new capitalized string. * @example * * capitalize('hello'); - * // -> 'Hello' + * // => 'Hello' * * capitalize('hElLo'); * // -< 'HElLo' * * capitalize('hElLo', true); - * // -> 'Hello' + * // => 'Hello' */ const capitalize = (subjectString, lowerCaseRest = false) => { if (typeof subjectString !== 'string') { diff --git a/packages/strings/classnames/README.md b/packages/strings/classnames/README.md index 0bdc5f2e..53298209 100644 --- a/packages/strings/classnames/README.md +++ b/packages/strings/classnames/README.md @@ -12,20 +12,20 @@ Creates a string by conditionally joining classNames together. **Example** ```js classnames('foo', 'bar'); -// -> 'foo bar' +// => 'foo bar' classnames('foo', { bar: true }); -// -> 'foo bar' +// => 'foo bar' classnames('foo', { bar: false }); -// -> 'foo' +// => 'foo' classnames({ foo: true }, { bar: true }); -// -> 'foo bar' +// => 'foo bar' classnames({ foo: true, bar: true }); -// -> 'foo bar' +// => 'foo bar' classnames('foo', 0, false, undefined, null, { bar: 1 }, NaN, { baz: 0 }); // falsy values are ignored -// -> 'foo bar' +// => 'foo bar' ``` diff --git a/packages/strings/classnames/classnames.js b/packages/strings/classnames/classnames.js index 06e9ff71..a788334e 100644 --- a/packages/strings/classnames/classnames.js +++ b/packages/strings/classnames/classnames.js @@ -8,22 +8,22 @@ * @example * * classnames('foo', 'bar'); - * // -> 'foo bar' + * // => 'foo bar' * * classnames('foo', { bar: true }); - * // -> 'foo bar' + * // => 'foo bar' * * classnames('foo', { bar: false }); - * // -> 'foo' + * // => 'foo' * * classnames({ foo: true }, { bar: true }); - * // -> 'foo bar' + * // => 'foo bar' * * classnames({ foo: true, bar: true }); - * // -> 'foo bar' + * // => 'foo bar' * * classnames('foo', 0, false, undefined, null, { bar: 1 }, NaN, { baz: 0 }); // falsy values are ignored - * // -> 'foo bar' + * // => 'foo bar' */ const classnames = (...args) => { const len = args.length; diff --git a/packages/strings/collapseWhitespace/README.md b/packages/strings/collapseWhitespace/README.md index e67c3a9f..5ba9ab26 100644 --- a/packages/strings/collapseWhitespace/README.md +++ b/packages/strings/collapseWhitespace/README.md @@ -16,5 +16,5 @@ Converts all adjacent whitespace characters to a single space. **Example** ```js collapseWhitespace(' Lorem \t ispum dolor sit \t amet. '); -// -> 'Lorem ispum dolor sit amet.' +// => 'Lorem ispum dolor sit amet.' ``` diff --git a/packages/strings/collapseWhitespace/collapseWhitespace.js b/packages/strings/collapseWhitespace/collapseWhitespace.js index c42408ec..e8d98652 100644 --- a/packages/strings/collapseWhitespace/collapseWhitespace.js +++ b/packages/strings/collapseWhitespace/collapseWhitespace.js @@ -5,11 +5,11 @@ * * @param {String} subjectString The string to process. * @throws {TypeError} If `subjectString` is not string. - * @return {String} The final string with all adjacent whitespace converted to single space. + * @returns {String} The final string with all adjacent whitespace converted to single space. * @example * * collapseWhitespace(' Lorem \t ispum dolor sit \t amet. '); - * // -> 'Lorem ispum dolor sit amet.' + * // => 'Lorem ispum dolor sit amet.' */ const collapseWhitespace = subjectString => { if (typeof subjectString !== 'string') { diff --git a/packages/strings/deburr/README.md b/packages/strings/deburr/README.md index 3f984fba..48341463 100644 --- a/packages/strings/deburr/README.md +++ b/packages/strings/deburr/README.md @@ -22,8 +22,8 @@ const str = 'Maître Corbeau, sur un arbre perché,' + 'Lui tint à peu près ce langage.'; deburr(str); -// -> 'Maitre Corbeau, sur un arbre perche,Tenait en son bec un fromage.Maitre Renard, par l’odeur alleche,Lui tint a peu pres ce langage.' +// => 'Maitre Corbeau, sur un arbre perche,Tenait en son bec un fromage.Maitre Renard, par l’odeur alleche,Lui tint a peu pres ce langage.' deburr('déjà vu'); -// -> 'deja vu' +// => 'deja vu' ``` diff --git a/packages/strings/deburr/deburr.js b/packages/strings/deburr/deburr.js index f03831e4..b07e9f5a 100644 --- a/packages/strings/deburr/deburr.js +++ b/packages/strings/deburr/deburr.js @@ -8,7 +8,7 @@ * * @param {String} subjectString The string to deburr. * @throws {TypeError} If `subjectString` is not string. - * @return {String} The deburred string. + * @returns {String} The deburred string. * @example * * const str = 'Maître Corbeau, sur un arbre perché,' + @@ -17,10 +17,10 @@ * 'Lui tint à peu près ce langage.'; * * deburr(str); - * // -> 'Maitre Corbeau, sur un arbre perche,Tenait en son bec un fromage.Maitre Renard, par l’odeur alleche,Lui tint a peu pres ce langage.' + * // => 'Maitre Corbeau, sur un arbre perche,Tenait en son bec un fromage.Maitre Renard, par l’odeur alleche,Lui tint a peu pres ce langage.' * * deburr('déjà vu'); - * // -> 'deja vu' + * // => 'deja vu' */ const deburr = subjectString => { if (typeof subjectString !== 'string') { diff --git a/packages/strings/escapeHTML/README.md b/packages/strings/escapeHTML/README.md index 7ae963be..8572cf77 100755 --- a/packages/strings/escapeHTML/README.md +++ b/packages/strings/escapeHTML/README.md @@ -16,11 +16,11 @@ Escapes a HTML string. **Example** ```js escapeHTML('