diff --git a/.gitignore b/.gitignore index e920c16..c78f780 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ node_modules # Optional REPL history .node_repl_history + +# Typescript output +dist/ diff --git a/index.js b/index.js deleted file mode 100644 index 7217e44..0000000 --- a/index.js +++ /dev/null @@ -1,16 +0,0 @@ -var eightStrings = [ - "viii", - "eight", - "вісім", - "ocho", -]; - -var inArray = function(value, array) { - return array.indexOf(value) > -1; -} - -var eight = function(value) { - return (value == 8) || ((typeof value === "string") && inArray(value.toLowerCase(), eightStrings)); -} - -module.exports = eight; diff --git a/package.json b/package.json index 315d207..9228c18 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,11 @@ "name": "is-eight", "version": "8.0.18", "description": "Checks if a number is equal to 8", - "main": "index.js", + "main": "dist/index.js", "scripts": { - "test": "mocha --reporter list" + "test": "mocha --reporter list", + "build": "tsc", + "prepublishOnly": "tsc" }, "repository": { "type": "git", @@ -19,6 +21,8 @@ "author": "ua2004", "license": "WTFPL", "devDependencies": { - "mocha": "^2.4.5" + "@types/node": "^12.12.35", + "mocha": "^2.4.5", + "typescript": "^3.8.3" } } diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..4cc3242 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,13 @@ +const eightStrings:string[] = [ + "viii", + "eight", + "вісім", + "ocho", +]; + +const isEight = (value: number|string): boolean => { + if (value == 8) return true; + return(typeof value === 'string' && eightStrings.indexOf(value.toLowerCase())!==-1); +} + +module.exports = isEight; diff --git a/test/is-eight-test.js b/test/is-eight-test.js index c94ebc7..a3a6fc6 100644 --- a/test/is-eight-test.js +++ b/test/is-eight-test.js @@ -1,4 +1,4 @@ -var eight = require('../index.js'); +var eight = require('../'); var assert = require("assert"); describe('The is-eight package', function() { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..7e4ae7e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "esModuleInterop": true, + "target": "es5", + + "strict": true, + "noFallthroughCasesInSwitch": true, + "experimentalDecorators": true, + + "moduleResolution": "node", + "sourceMap": true, + "outDir": "dist", + "baseUrl": ".", + "paths": { + "*": [ + "src/types/*" + ] + }, + "lib": [ + "ES5" + ], + "declaration": true + }, + "include": [ + "src/**/*" + ] +}