├── .gitignore ├── README.md ├── .github └── workflows │ └── node.js.yml ├── smoke.test.js ├── full.test.js ├── package.json └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-ten-thousand 2 | 3 | If you need to know if a number is ten thousand. 4 | 5 | [![NPM link](https://nodei.co/npm/is-ten-thousand.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/is-ten-thousand/) 6 | 7 | Proud to be featured by [Engineer Man](https://youtu.be/PI5wz2pwXIg?t=51): 8 | 9 | [![Thumbnail from Engineer Man's video on "Ridiculous NPM (Node.js) Packages that I wish didn't exist"](https://i3.ytimg.com/vi/PI5wz2pwXIg/maxresdefault.jpg)](https://youtu.be/PI5wz2pwXIg?t=51) 10 | 11 | ## Usage 12 | 13 | Don't. You're not ready. 14 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [10.x, 12.x, 14.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run build --if-present 29 | - run: npm run test 30 | 31 | -------------------------------------------------------------------------------- /smoke.test.js: -------------------------------------------------------------------------------- 1 | const isTenThousand = require("./index"); 2 | const { owoify } = require("owoifyx"); 3 | 4 | console.log(owoify("Hello! Let's run some smoke tests")); 5 | 6 | function getNotTenThousand() { 7 | const number = Math.ceil(Math.random() * 100000); 8 | if (number === 10000) { 9 | return getNotTenThousand(); 10 | } 11 | return number; 12 | } 13 | 14 | const randNum = getNotTenThousand(); 15 | 16 | [true, false].map((shouldDoSomethingAsync) => { 17 | test(`${randNum} is not ten thousand with shouldDoSomethingAsync = ${shouldDoSomethingAsync}`, () => { 18 | if (shouldDoSomethingAsync) { 19 | return isTenThousand(randNum, true).then((result) => 20 | expect(result).toBe(false) 21 | ); 22 | } else { 23 | expect(isTenThousand(randNum)).toBe(false); 24 | } 25 | }); 26 | 27 | test(`10000 is ten thousand with shouldDoSomethingAsync = ${shouldDoSomethingAsync}`, () => { 28 | if (shouldDoSomethingAsync) { 29 | return isTenThousand(10000, true).then((result) => 30 | expect(result).toBe(true) 31 | ); 32 | } else { 33 | expect(isTenThousand(10000)).toBe(true); 34 | } 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /full.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Note: Some numbers are not accounted for. 3 | * I can't prove that they won't return true. 4 | */ 5 | 6 | const isTenThousand = require("./index"); 7 | const { owoify } = require("owoifyx"); 8 | 9 | console.log(owoify("Hello! Let's run some tests")); 10 | 11 | function testIsTenThousand(i) { 12 | [true, false].map((shouldDoSomethingAsync) => { 13 | if (i === 10000) { 14 | test(`${i} is ten thousand with shouldDoSomethingAsync = ${shouldDoSomethingAsync}`, () => { 15 | if (shouldDoSomethingAsync) { 16 | return isTenThousand(i, true) 17 | .then((result) => expect(result).toBe(true)) 18 | .catch((e) => console.log(e, i)); 19 | } else { 20 | expect(isTenThousand(i)).toBe(true); 21 | } 22 | }); 23 | } else { 24 | test(`${i} is not ten thousand with shouldDoSomethingAsync = ${shouldDoSomethingAsync}`, () => { 25 | if (shouldDoSomethingAsync) { 26 | return isTenThousand(i, true) 27 | .then((result) => expect(result).toBe(false)) 28 | .catch((e) => console.log(e, i)); 29 | } else { 30 | expect(isTenThousand(i)).toBe(false); 31 | } 32 | }); 33 | } 34 | }); 35 | } 36 | 37 | Array.apply(null, Array(10001)).map(function (_, i) { 38 | testIsTenThousand(i); 39 | }); 40 | 41 | Array.apply(null, Array(10001)).map(function (_, i) { 42 | testIsTenThousand(i - 10001); 43 | }); 44 | 45 | // just to be sure 46 | testIsTenThousand("10000"); 47 | testIsTenThousand("9999"); 48 | testIsTenThousand("ten thousand"); 49 | testIsTenThousand(10000.1); 50 | testIsTenThousand([10000]); 51 | testIsTenThousand([]); 52 | testIsTenThousand({}); 53 | testIsTenThousand(() => {}); 54 | testIsTenThousand(true); 55 | testIsTenThousand(); 56 | testIsTenThousand(undefined); // basically the same test but whatever 57 | testIsTenThousand(null); 58 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-ten-thousand", 3 | "version": "2.0.0", 4 | "description": "is-thousand isn't 10x enough", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "jest full.test.js", 8 | "smoke": "jest smoke.test.js" 9 | }, 10 | "author": "James Whiteley", 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/james-work-account/is-ten-thousand.git" 14 | }, 15 | "keywords": [ 16 | "original", 17 | "is-ten-thousand", 18 | "is-thousand", 19 | "is-hundred", 20 | "is-ten", 21 | "beauty", 22 | "grace" 23 | ], 24 | "license": "WTFPL", 25 | "bugs": { 26 | "url": "https://github.com/james-work-account/is-ten-thousand/issues" 27 | }, 28 | "homepage": "https://github.com/james-work-account/is-ten-thousand#readme", 29 | "devDependencies": { 30 | "jest": "^27.0.6" 31 | }, 32 | "dependencies": { 33 | "five": "^0.8.0", 34 | "is-array": "^1.0.1", 35 | "is-eq-four": "^1.1.0", 36 | "is-is-odd": "^1.0.2", 37 | "is-match": "^1.0.0", 38 | "is-multiple-of-three-and-five": "^1.0.1", 39 | "is-negative": "^2.1.0", 40 | "is-node": "^1.0.2", 41 | "is-not-negative": "^1.0.3", 42 | "is-not-positive": "^1.0.0", 43 | "is-not-thirteen": "0.0.1", 44 | "is-npm": "^5.0.0", 45 | "is-number": "^7.0.0", 46 | "is-number-like": "^1.0.8", 47 | "is-obj": "^2.0.0", 48 | "is-object": "^1.0.2", 49 | "is-odd": "^3.0.1", 50 | "is-plain-obj": "^3.0.0", 51 | "is-plain-object": "^5.0.0", 52 | "is-positive": "^3.1.0", 53 | "is-string": "^1.0.7", 54 | "is-ten": "^0.1.0", 55 | "is-thirteen": "^2.0.0", 56 | "is-thousand": "0.0.2", 57 | "is-zero": "^1.0.0", 58 | "jquery": "^3.6.0", 59 | "jquery-basic-arithmetic-plugin": "^1.1.0", 60 | "left-pad": "^1.3.0", 61 | "material-design-icons": "^3.0.1", 62 | "owoifyx": "^1.0.3", 63 | "right-pad": "^1.0.1", 64 | "two": "^1.0.1" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const TEN_THOUSAND = 10e3; 4 | const leftPad = require("left-pad"); 5 | 6 | const rightPad = require("right-pad"); 7 | 8 | const isOdd = require("is-odd"); 9 | 10 | const isIsOdd = require("is-is-odd"); 11 | 12 | const isNode = require("is-node"); 13 | 14 | const { isNpm, isYarn, isNpmOrYarn } = require("is-npm"); 15 | 16 | const isArray = require("is-array"); 17 | 18 | const isNumber = require("is-number"); 19 | 20 | const isString = require("is-string"); 21 | 22 | const isNegative = require("is-negative"); 23 | 24 | const isPositive = require("is-positive"); 25 | 26 | const isNotNegative = require("is-not-negative"); 27 | 28 | const isNotPositive = require("is-not-positive"); 29 | 30 | const isObj = require("is-obj"); 31 | 32 | const isPlainObj = require("is-plain-obj"); 33 | 34 | const isObject = require("is-object"); 35 | 36 | const { isPlainObject } = require("is-plain-object"); 37 | 38 | const isNumberLike = require("is-number-like"); 39 | 40 | const isTen = require("is-ten"); 41 | 42 | const isThirteen = require("is-thirteen"); 43 | 44 | const isNotThirteen = require("is-not-thirteen"); 45 | 46 | const isZero = require("is-zero"); 47 | 48 | const is4 = require("is-eq-four"); 49 | 50 | var isMatch = require("is-match"); 51 | 52 | const isMultipleOfThreeAndFive = require("is-multiple-of-three-and-five"); 53 | 54 | global.jQuery = require("jquery"); 55 | 56 | require("jquery-basic-arithmetic-plugin"); 57 | 58 | const two = require("two"); 59 | 60 | const five = require("five"); 61 | 62 | const mainFunctionWotDoesFunctionality = function ( 63 | val, 64 | shouldDoSomethingAsync = false 65 | ) { 66 | const leftPadInput = 10 * (TEN_THOUSAND / 10); 67 | const rightPadInput = leftPadInput - 1 + 1; 68 | 69 | leftPad("required", leftPadInput); 70 | rightPad("required", rightPadInput); 71 | 72 | if (isIsOdd(isOdd)) { 73 | try { 74 | if (shouldDoSomethingAsync) { 75 | return doSomethingAsync().then((_) => checkIsOdd(val)); 76 | } else { 77 | return checkIsOdd(val); 78 | } 79 | } catch (e) { 80 | const stringE = e.toString(); 81 | stringE; 82 | return false; 83 | } 84 | } else { 85 | return false; 86 | } 87 | }; 88 | 89 | const doSomethingAsync = async function () { 90 | return new Promise((resolve) => setTimeout(resolve, 200)); 91 | }; 92 | 93 | const checkIsOdd = function (val) { 94 | if (isOdd(val)) { 95 | return false; 96 | } else { 97 | return checkIsNpmOrYarnOrNode(val); 98 | } 99 | }; 100 | 101 | const checkIsNpmOrYarnOrNode = function (val) { 102 | if (((isNpm || isYarn) && isNpmOrYarn) || isNode) { 103 | return checkNumbers(val); 104 | } else { 105 | throw new Error("I'm not sure how this happened"); 106 | } 107 | }; 108 | 109 | const checkNumbers = function (val) { 110 | if (is4(val)) { 111 | return false; 112 | } else { 113 | if (val === five) { 114 | return false; 115 | } else { 116 | if (val === two) { 117 | return false; 118 | } else { 119 | if (val === five.negative) { 120 | return false; 121 | } else { 122 | if (isTen(val)) { 123 | return false; 124 | } else { 125 | if (isThirteen(val).thirteen()) { 126 | return false; 127 | } else { 128 | if (!isNotThirteen(val)) { 129 | return false; 130 | } else { 131 | if (isZero.isZero(val)) { 132 | return false; 133 | } else { 134 | if (isMultipleOfThreeAndFive(val)) { 135 | return false; 136 | } else { 137 | return checkType(val); 138 | } 139 | } 140 | } 141 | } 142 | } 143 | } 144 | } 145 | } 146 | } 147 | }; 148 | 149 | const checkType = function (val) { 150 | if (isArray(val)) { 151 | return false; 152 | } else { 153 | if (!isNumber(val)) { 154 | return false; 155 | } else { 156 | if (isString(val)) { 157 | return false; 158 | } else { 159 | if (isObj(val)) { 160 | return false; 161 | } else { 162 | if (isPlainObj(val)) { 163 | return false; 164 | } else { 165 | if (isObject(val)) { 166 | return false; 167 | } else { 168 | if (isPlainObject(val)) { 169 | return false; 170 | } else { 171 | if (!isNumberLike(val)) { 172 | return false; 173 | } else { 174 | return checkPolarity(val); 175 | } 176 | } 177 | } 178 | } 179 | } 180 | } 181 | } 182 | } 183 | }; 184 | 185 | const checkPolarity = function (val) { 186 | if (isNegative(val)) { 187 | return false; 188 | } else { 189 | if (isNotPositive(val)) { 190 | return false; 191 | } else { 192 | if (!isPositive(val)) { 193 | return false; 194 | } else { 195 | if (!isNotNegative(val)) { 196 | return false; 197 | } else { 198 | return _isTenThousand(val); 199 | } 200 | } 201 | } 202 | } 203 | }; 204 | 205 | const isNumberWhenParsedManually = function (val) { 206 | try { 207 | return parseInt(val); 208 | } catch (error) { 209 | [error]; // put the error between bars where it belongs 210 | return false; 211 | } 212 | }; 213 | 214 | const _isTenThousand = function (val) { 215 | return ( 216 | !isOdd(val) && 217 | val !== five && 218 | val !== two && 219 | val !== five.negative && 220 | !isTen(val) && 221 | !isThirteen(val).thirteen() && 222 | isNotThirteen(val) && 223 | !isZero.isZero(val) && 224 | !isMultipleOfThreeAndFive(val) && 225 | !isArray(val) && 226 | isNumber(val) && 227 | isNumberWhenParsedManually(val) && 228 | !isString(val) && 229 | isString(val.toString()) && 230 | !isObj(val) && 231 | isObj({ val }) && 232 | !isPlainObj(val) && 233 | isPlainObj({ val }) && 234 | !isObject(val) && 235 | isObject({ val }) && 236 | !isPlainObject(val) && 237 | isPlainObject({ val }) && 238 | isNumberLike(val) && 239 | !isNegative(val) && 240 | isNotNegative(val) && 241 | isPositive(val) && 242 | !isNotPositive(val) && 243 | jQuery.equals(val, TEN_THOUSAND) && 244 | isMatch(new RegExp(TEN_THOUSAND))(val) && 245 | val === TEN_THOUSAND 246 | ); 247 | }; 248 | 249 | module.exports = mainFunctionWotDoesFunctionality; 250 | --------------------------------------------------------------------------------