From 279051ed9bdf5cd63d291efc2e5701402ae29c00 Mon Sep 17 00:00:00 2001 From: Halvor Holsten Strand Date: Sat, 11 May 2019 00:01:00 +0200 Subject: [PATCH] Added rewire to get full test coverage. Edited overly verbose tests to more readable (and maintainable) format. --- README.md | 5 + package-lock.json | 479 +++++++++++++++++++++++++++++++++++++- package.json | 6 +- test/norwegian-numbers.ts | 222 ++++++++---------- tsconfig.json | 7 +- 5 files changed, 589 insertions(+), 130 deletions(-) diff --git a/README.md b/README.md index 279c13d..28af04c 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ The distribution was created by the following commands: ## Changes +### 1.0.8 + +* Added TypeScript declaration +* Added code coverage metrics and additional tests + ### 1.0.7 * Added JSDoc diff --git a/package-lock.json b/package-lock.json index 23952bd..dfb858d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "norwegian-numbers", - "version": "1.0.7", + "version": "1.0.8", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -142,6 +142,12 @@ "integrity": "sha512-1axi39YdtBI7z957vdqXI4Ac25e7YihYQtJa+Clnxg1zTJEaIRbndt71O3sP4GAMgiAm0pY26/b9BrY4MR/PMw==", "dev": true }, + "@types/rewire": { + "version": "2.5.28", + "resolved": "https://registry.npmjs.org/@types/rewire/-/rewire-2.5.28.tgz", + "integrity": "sha512-uD0j/AQOa5le7afuK+u+woi8jNKF1vf3DN0H7LCJhft/lNNibUr7VcAesdgtWfEKveZol3ZG1CJqwx2Bhrnl8w==", + "dev": true + }, "acorn": { "version": "6.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", @@ -166,6 +172,12 @@ "uri-js": "^4.2.2" } }, + "ajv-keywords": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", + "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", + "dev": true + }, "ansi-colors": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", @@ -268,6 +280,65 @@ "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==", "dev": true }, + "babel-code-frame": { + "version": "6.26.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", + "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", + "dev": true, + "requires": { + "chalk": "^1.1.3", + "esutils": "^2.0.2", + "js-tokens": "^3.0.2" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "dev": true + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + } + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -323,6 +394,23 @@ "write-file-atomic": "^2.4.2" } }, + "caller-path": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz", + "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", + "dev": true, + "requires": { + "callsites": "^0.2.0" + }, + "dependencies": { + "callsites": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-0.2.0.tgz", + "integrity": "sha1-r6uWJikQp/M8GaV3WCXGnzTjUMo=", + "dev": true + } + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -398,6 +486,12 @@ "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", "dev": true }, + "circular-json": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", + "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==", + "dev": true + }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -424,6 +518,12 @@ "wrap-ansi": "^2.0.0" } }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", + "dev": true + }, "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", @@ -473,6 +573,18 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, "convert-source-map": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz", @@ -1091,6 +1203,23 @@ "function-bind": "^1.1.1" } }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + } + } + }, "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -1271,6 +1400,12 @@ "has": "^1.0.1" } }, + "is-resolvable": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz", + "integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==", + "dev": true + }, "is-stream": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", @@ -1292,6 +1427,12 @@ "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", "dev": true }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -1886,6 +2027,12 @@ "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -2142,12 +2289,24 @@ "find-up": "^3.0.0" } }, + "pluralize": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", + "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", + "dev": true + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", "integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=", "dev": true }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "dev": true + }, "progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", @@ -2209,6 +2368,21 @@ "read-pkg": "^3.0.0" } }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, "regexpp": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", @@ -2264,6 +2438,24 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, + "require-uncached": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", + "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", + "dev": true, + "requires": { + "caller-path": "^0.1.0", + "resolve-from": "^1.0.0" + }, + "dependencies": { + "resolve-from": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-1.0.1.tgz", + "integrity": "sha1-Jsv+k10a7uq7Kbw/5a6wHpPUQiY=", + "dev": true + } + } + }, "requizzle": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.2.tgz", @@ -2298,6 +2490,255 @@ "signal-exit": "^3.0.2" } }, + "rewire": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/rewire/-/rewire-4.0.1.tgz", + "integrity": "sha512-+7RQ/BYwTieHVXetpKhT11UbfF6v1kGhKFrtZN7UDL2PybMsSt/rpLWeEUGF5Ndsl1D5BxiCB14VDJyoX+noYw==", + "dev": true, + "requires": { + "eslint": "^4.19.1" + }, + "dependencies": { + "acorn": { + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", + "dev": true + }, + "acorn-jsx": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", + "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "dev": true, + "requires": { + "acorn": "^3.0.4" + }, + "dependencies": { + "acorn": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", + "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", + "dev": true + } + } + }, + "ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "dev": true, + "requires": { + "co": "^4.6.0", + "fast-deep-equal": "^1.0.0", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.3.0" + } + }, + "chardet": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", + "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", + "dev": true + }, + "cross-spawn": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", + "integrity": "sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk=", + "dev": true, + "requires": { + "lru-cache": "^4.0.1", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "eslint": { + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", + "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", + "dev": true, + "requires": { + "ajv": "^5.3.0", + "babel-code-frame": "^6.22.0", + "chalk": "^2.1.0", + "concat-stream": "^1.6.0", + "cross-spawn": "^5.1.0", + "debug": "^3.1.0", + "doctrine": "^2.1.0", + "eslint-scope": "^3.7.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^3.5.4", + "esquery": "^1.0.0", + "esutils": "^2.0.2", + "file-entry-cache": "^2.0.0", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.0.1", + "ignore": "^3.3.3", + "imurmurhash": "^0.1.4", + "inquirer": "^3.0.6", + "is-resolvable": "^1.0.0", + "js-yaml": "^3.9.1", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.4", + "minimatch": "^3.0.2", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "pluralize": "^7.0.0", + "progress": "^2.0.0", + "regexpp": "^1.0.1", + "require-uncached": "^1.0.3", + "semver": "^5.3.0", + "strip-ansi": "^4.0.0", + "strip-json-comments": "~2.0.1", + "table": "4.0.2", + "text-table": "~0.2.0" + } + }, + "eslint-scope": { + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", + "integrity": "sha512-W+B0SvF4gamyCTmUc+uITPY0989iXVfKvhwtmJocTaYoc/3khEHmEmvfY/Gn9HA9VV75jrQECsHizkNw1b68FA==", + "dev": true, + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "espree": { + "version": "3.5.4", + "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", + "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "dev": true, + "requires": { + "acorn": "^5.5.0", + "acorn-jsx": "^3.0.0" + } + }, + "external-editor": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", + "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", + "dev": true, + "requires": { + "chardet": "^0.4.0", + "iconv-lite": "^0.4.17", + "tmp": "^0.0.33" + } + }, + "fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", + "dev": true + }, + "file-entry-cache": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-2.0.0.tgz", + "integrity": "sha1-w5KZDD5oR4PYOLjISkXYoEhFg2E=", + "dev": true, + "requires": { + "flat-cache": "^1.2.1", + "object-assign": "^4.0.1" + } + }, + "flat-cache": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-1.3.4.tgz", + "integrity": "sha512-VwyB3Lkgacfik2vhqR4uv2rvebqmDvFu4jlN/C1RzWoJEo8I7z4Q404oiqYCkq41mni8EzQnm95emU9seckwtg==", + "dev": true, + "requires": { + "circular-json": "^0.3.1", + "graceful-fs": "^4.1.2", + "rimraf": "~2.6.2", + "write": "^0.2.1" + } + }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==", + "dev": true + }, + "inquirer": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", + "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", + "dev": true, + "requires": { + "ansi-escapes": "^3.0.0", + "chalk": "^2.0.0", + "cli-cursor": "^2.1.0", + "cli-width": "^2.0.0", + "external-editor": "^2.0.4", + "figures": "^2.0.0", + "lodash": "^4.3.0", + "mute-stream": "0.0.7", + "run-async": "^2.2.0", + "rx-lite": "^4.0.8", + "rx-lite-aggregates": "^4.0.8", + "string-width": "^2.1.0", + "strip-ansi": "^4.0.0", + "through": "^2.3.6" + } + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", + "dev": true + }, + "regexpp": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", + "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", + "dev": true + }, + "slice-ansi": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz", + "integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==", + "dev": true, + "requires": { + "is-fullwidth-code-point": "^2.0.0" + } + }, + "table": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", + "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "dev": true, + "requires": { + "ajv": "^5.2.3", + "ajv-keywords": "^2.1.0", + "chalk": "^2.1.0", + "lodash": "^4.17.4", + "slice-ansi": "1.0.0", + "string-width": "^2.1.1" + } + }, + "write": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/write/-/write-0.2.1.tgz", + "integrity": "sha1-X8A4KOJkzqP+kUVUdvejxWbLB1c=", + "dev": true, + "requires": { + "mkdirp": "^0.5.1" + } + } + } + }, "rimraf": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", @@ -2316,6 +2757,21 @@ "is-promise": "^2.1.0" } }, + "rx-lite": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", + "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", + "dev": true + }, + "rx-lite-aggregates": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", + "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", + "dev": true, + "requires": { + "rx-lite": "*" + } + }, "rxjs": { "version": "6.5.2", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.2.tgz", @@ -2476,6 +2932,15 @@ "strip-ansi": "^4.0.0" } }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", @@ -2670,6 +3135,12 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, "typescript": { "version": "3.4.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.5.tgz", @@ -2708,6 +3179,12 @@ "punycode": "^2.1.0" } }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, "uuid": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", diff --git a/package.json b/package.json index 067a6a0..b7248e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "norwegian-numbers", - "version": "1.0.7", + "version": "1.0.8", "description": "Make and verify official Norwegian numbers like: KID-nummer, organisasjonsnummer, fødselsnummer, kontonummer.", "main": "dist/norwegian-numbers.js", "scripts": { @@ -28,14 +28,16 @@ "devDependencies": { "@types/chai": "^4.1.7", "@types/mocha": "^5.2.6", + "@types/rewire": "^2.5.28", "chai": "^4.2.0", "coveralls": "^3.0.3", "eslint": "^5.16.0", "jsdoc": "^3.6.1", "mocha": "^6.1.4", "nyc": "^14.1.1", + "rewire": "^4.0.1", "ts-node": "^8.1.0", "typescript": "^3.4.5" }, "dependencies": {} -} \ No newline at end of file +} diff --git a/test/norwegian-numbers.ts b/test/norwegian-numbers.ts index 4b3abc8..48479ee 100644 --- a/test/norwegian-numbers.ts +++ b/test/norwegian-numbers.ts @@ -1,5 +1,6 @@ import { expect } from 'chai'; import 'mocha'; +import rewire from 'rewire'; import { makeKidNumber, verifyKidNumber, @@ -11,165 +12,136 @@ import { verifyBirthNumber, } from '../src/norwegian-numbers'; -describe('Testing of makeKidNumber and verifyKidNumber', function () { - context('makeKidNumber 234567', function () { - it('should return 2345676', function () { - expect(makeKidNumber('234567')).to.equal('2345676') - expect(verifyKidNumber('2345676')).to.be.true - }) +context('Testing of makeKidNumber and verifyKidNumber', function () { + it('234567 should return 2345676 and verify', function () { + expect(makeKidNumber('234567')).to.equal('2345676') + expect(verifyKidNumber('2345676')).to.be.true }) - context('makeKidNumber 0', function () { - it('should return 00', function () { - expect(makeKidNumber('0')).to.equal('00') - expect(verifyKidNumber('00')).to.be.true - }) + it('0 should return 00 and verify', function () { + expect(makeKidNumber('0')).to.equal('00') + expect(verifyKidNumber('00')).to.be.true }) - context('makeKidNumber abc', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('abc') - }).to.throw(Error, 'Value "abc" was not an integer.') - expect(verifyKidNumber('abc')).to.be.false - }) + it('abc should throw error and not verify', function () { + expect(function () { + makeKidNumber('abc') + }).to.throw(Error, 'Value "abc" was not an integer.') + expect(verifyKidNumber('abc')).to.be.false }) - context('makeKidNumber blank', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('') - }).to.throw(Error, 'Invalid value length for "". Must be from 1 to 24 characters, inclusive.') - expect(verifyKidNumber('')).to.be.false - }) + it('blank should throw error and not verify', function () { + expect(function () { + makeKidNumber('') + }).to.throw(Error, 'Invalid value length for "". Must be from 1 to 24 characters, inclusive.') + expect(verifyKidNumber('')).to.be.false }) - context('makeKidNumber 01234567890123456789012345', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('01234567890123456789012345') - }).to.throw(Error, 'Invalid value length for "01234567890123456789012345". Must be from 1 to 24 characters, inclusive.') - expect(verifyKidNumber('01234567890123456789012345')).to.be.false - }) + it('01234567890123456789012345 should throw error nad not verify', function () { + expect(function () { + makeKidNumber('01234567890123456789012345') + }).to.throw(Error, 'Invalid value length for "01234567890123456789012345". Must be from 1 to 24 characters, inclusive.') + expect(verifyKidNumber('01234567890123456789012345')).to.be.false }) - context('makeKidNumber (MOD11) 1234567890', function () { - it('should return 12345678903', function () { - expect(makeKidNumber('1234567890', 'MOD11')).to.equal('12345678903') - expect(verifyKidNumber('12345678903', 'MOD11')).to.be.true - }) + it('1234567890 (MOD11) should return 12345678903 and verify', function () { + expect(makeKidNumber('1234567890', 'MOD11')).to.equal('12345678903') + expect(verifyKidNumber('12345678903', 'MOD11')).to.be.true }) - context('makeKidNumber (MOD11) 31', function () { - it('should return 310', function () { - expect(makeKidNumber('31', 'MOD11')).to.equal('310') - expect(verifyKidNumber('310', 'MOD11')).to.be.true - }) + it('31 (MOD11) should return 310 and verify', function () { + expect(makeKidNumber('31', 'MOD11')).to.equal('310') + expect(verifyKidNumber('310', 'MOD11')).to.be.true }) - context('makeKidNumber (MOD11) 40', function () { - it('should return 40-', function () { - expect(makeKidNumber('40', 'MOD11')).to.equal('40-') - expect(verifyKidNumber('40-', 'MOD11')).to.be.true - }) + it('40 (MOD11) should return 40- and verify', function () { + expect(makeKidNumber('40', 'MOD11')).to.equal('40-') + expect(verifyKidNumber('40-', 'MOD11')).to.be.true }) - context('makeKidNumber (MOD11) abc', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('abc', 'MOD11') - }).to.throw(Error, 'Value "abc" was not an integer.') - expect(verifyKidNumber('abc', 'MOD11')).to.be.false - }) + it('abc (MOD11) should throw error and not verify', function () { + expect(function () { + makeKidNumber('abc', 'MOD11') + }).to.throw(Error, 'Value "abc" was not an integer.') + expect(verifyKidNumber('abc', 'MOD11')).to.be.false }) - context('makeKidNumber (MOD11) blank', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('', 'MOD11') - }).to.throw(Error, 'Invalid value length for "". Must be from 1 to 24 characters, inclusive.') - expect(verifyKidNumber('', 'MOD11')).to.be.false - }) + it('blank (MOD11) should throw error', function () { + expect(function () { + makeKidNumber('', 'MOD11') + }).to.throw(Error, 'Invalid value length for "". Must be from 1 to 24 characters, inclusive.') + expect(verifyKidNumber('', 'MOD11')).to.be.false }) - context('makeKidNumber (WRONGMOD)', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('1234', 'WRONGMOD') - }).to.throw(Error, 'Invalid mode "WRONGMOD".') - expect(verifyKidNumber('', 'MOD11')).to.be.false - }) + it('WRONGMOD should throw error and not verify', function () { + expect(function () { + makeKidNumber('1234', 'WRONGMOD') + }).to.throw(Error, 'Invalid mode "WRONGMOD".') + expect(verifyKidNumber('', 'MOD11')).to.be.false }) - context('makeKidNumber (MOD11) 01234567890123456789012345', function () { - it('should throw error', function () { - expect(function () { - makeKidNumber('01234567890123456789012345', 'MOD11') - }).to.throw(Error, 'Invalid value length for "01234567890123456789012345". Must be from 1 to 24 characters, inclusive.') - expect(verifyKidNumber('01234567890123456789012345', 'MOD11')).to.be.false - }) + it('01234567890123456789012345 (MOD11) should throw error and not verify', function () { + expect(function () { + makeKidNumber('01234567890123456789012345', 'MOD11') + }).to.throw(Error, 'Invalid value length for "01234567890123456789012345". Must be from 1 to 24 characters, inclusive.') + expect(verifyKidNumber('01234567890123456789012345', 'MOD11')).to.be.false }) }) -describe('Testing of makeAccountNumber and verifyAccountNumber', function () { - context('makeAccountNumber 1234567890', function () { - it('should return 12345678903', function () { - expect(makeAccountNumber('1234567890')).to.equal('12345678903') - expect(verifyAccountNumber('12345678903')).to.be.true - }) +context('Testing of makeAccountNumber and verifyAccountNumber', function () { + it('1234567890 should return 12345678903 and verify', function () { + expect(makeAccountNumber('1234567890')).to.equal('12345678903') + expect(verifyAccountNumber('12345678903')).to.be.true }) - context('makeAccountNumber 0000002001', function () { - it('should throw error', function () { - expect(function () { - makeAccountNumber('0000002001') - }).to.throw(Error, 'Rejected due to invalid control digit.') - expect(verifyAccountNumber('0000002001-')).to.be.false - }) + it('0000002001 should throw error and not verify', function () { + expect(function () { + makeAccountNumber('0000002001') + }).to.throw(Error, 'Rejected due to invalid control digit.') + expect(verifyAccountNumber('0000002001-')).to.be.false }) }) -describe('Testing of makeOrganisationNumber and verifyOrganisationNumber', function () { - context('makeOrganisationNumber 12345678', function () { - it('should return 123456785', function () { - expect(makeOrganisationNumber('12345678')).to.equal('123456785') - expect(verifyOrganisationNumber('123456785')).to.be.true - }) +context('Testing of makeOrganisationNumber and verifyOrganisationNumber', function () { + it('12345678 should return 123456785 and verify ', function () { + expect(makeOrganisationNumber('12345678')).to.equal('123456785') + expect(verifyOrganisationNumber('123456785')).to.be.true }) - context('makeOrganisationNumber 00002001', function () { - it('should throw error', function () { - expect(function () { - makeOrganisationNumber('00002001') - }).to.throw(Error, 'Rejected due to invalid control digit.') - expect(verifyOrganisationNumber('0000002001-')).to.be.false - }) + it('00002001 should throw error and not verify', function () { + expect(function () { + makeOrganisationNumber('00002001') + }).to.throw(Error, 'Rejected due to invalid control digit.') + expect(verifyOrganisationNumber('0000002001-')).to.be.false }) }) -describe('Testing of makeBirthNumber and verifyBirthNumber', function () { - context('makeBirthNumber 311299567', function () { - it('should return 31129956715', function () { - expect(makeBirthNumber('311299567')).to.equal('31129956715') - expect(verifyBirthNumber('31129956715')).to.be.true - }) - }) - - context('makeBirthNumber 000000021', function () { - it('should throw error', function () { - expect(function () { - makeBirthNumber('000000021') - }).to.throw(Error, 'Rejected due to invalid control digit.') - expect(verifyBirthNumber('000000021-2')).to.be.false - }) - }) - - context('makeBirthNumber 101000000', function () { - it('should throw error', function () { - expect(function () { - makeBirthNumber('101000000') - }).to.throw(Error, 'Rejected due to invalid control digit.') - expect(verifyBirthNumber('1010000002-')).to.be.false - }) +context('Testing of makeBirthNumber and verifyBirthNumber', function () { + it('311299567 should return 31129956715 and verify', function () { + expect(makeBirthNumber('311299567')).to.equal('31129956715') + expect(verifyBirthNumber('31129956715')).to.be.true + }) + + it('000000021 should throw error and not verify', function () { + expect(function () { + makeBirthNumber('000000021') + }).to.throw(Error, 'Rejected due to invalid control digit.') + expect(verifyBirthNumber('000000021-2')).to.be.false + }) + + it('101000000 should throw error and not verify', function () { + expect(function () { + makeBirthNumber('101000000') + }).to.throw(Error, 'Rejected due to invalid control digit.') + expect(verifyBirthNumber('1010000002-')).to.be.false + }) +}) + +context('makeMod10ControlDigit', function () { + const nnRewired = rewire('../src/norwegian-numbers') + const makeMod10ControlDigit = nnRewired.__get__('makeMod10ControlDigit') + + it('75 should return 4', function () { + expect(makeMod10ControlDigit('75', [3, 4])).to.equal(4) }) }) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 83138ce..40faf5d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,9 @@ "noImplicitAny": true, "declaration": true, "outDir": "dist", + "esModuleInterop": true, }, - "include": ["src/**/*"], -} + "include": [ + "src/**/*" + ], +} \ No newline at end of file