├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "eslint:recommended" 4 | ], 5 | 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | 13 | "parserOptions":{ 14 | "ecmaVersion": 9, 15 | "sourceType": "module", 16 | "ecmaFeatures": { 17 | "modules": true, 18 | "experimentalObjectRestSpread": true 19 | } 20 | }, 21 | 22 | "globals": { 23 | "document": false, 24 | "navigator": false, 25 | "window": false 26 | }, 27 | 28 | "rules": { 29 | "accessor-pairs": 2, 30 | "arrow-spacing": [2, { "before": true, "after": true }], 31 | "block-spacing": [2, "always"], 32 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 33 | "comma-dangle": [2, "never"], 34 | "comma-spacing": [2, { "before": false, "after": true }], 35 | "comma-style": [2, "last"], 36 | "constructor-super": 2, 37 | "curly": [2, "multi-line"], 38 | "dot-location": [2, "property"], 39 | "eol-last": 2, 40 | "eqeqeq": [2, "allow-null"], 41 | "generator-star-spacing": [2, { "before": true, "after": true }], 42 | "handle-callback-err": [2, "^(err|error)$" ], 43 | "indent": [2, 2, { "SwitchCase": 1 }], 44 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 45 | "keyword-spacing": [2, { "before": true, "after": true }], 46 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 47 | "new-parens": 2, 48 | "no-array-constructor": 2, 49 | "no-caller": 2, 50 | "no-class-assign": 2, 51 | "no-cond-assign": 2, 52 | "no-const-assign": 2, 53 | "no-control-regex": 2, 54 | "no-debugger": 2, 55 | "no-delete-var": 2, 56 | "no-dupe-args": 2, 57 | "no-dupe-class-members": 2, 58 | "no-dupe-keys": 2, 59 | "no-duplicate-case": 2, 60 | "no-empty-character-class": 2, 61 | "no-eval": 2, 62 | "no-ex-assign": 2, 63 | "no-extend-native": 2, 64 | "no-extra-bind": 2, 65 | "no-extra-boolean-cast": 2, 66 | "no-extra-parens": [2, "functions"], 67 | "no-fallthrough": 2, 68 | "no-floating-decimal": 2, 69 | "no-func-assign": 2, 70 | "no-implied-eval": 2, 71 | "no-inner-declarations": [2, "functions"], 72 | "no-invalid-regexp": 2, 73 | "no-irregular-whitespace": 2, 74 | "no-iterator": 2, 75 | "no-label-var": 2, 76 | "no-labels": 2, 77 | "no-lone-blocks": 2, 78 | "no-mixed-spaces-and-tabs": 2, 79 | "no-multi-spaces": 2, 80 | "no-multi-str": 2, 81 | "no-multiple-empty-lines": [2, { "max": 1 }], 82 | "no-native-reassign": 0, 83 | "no-negated-in-lhs": 2, 84 | "no-new": 2, 85 | "no-new-func": 2, 86 | "no-new-object": 2, 87 | "no-new-require": 2, 88 | "no-new-wrappers": 2, 89 | "no-obj-calls": 2, 90 | "no-octal": 2, 91 | "no-octal-escape": 2, 92 | "no-proto": 0, 93 | "no-redeclare": 2, 94 | "no-regex-spaces": 2, 95 | "no-return-assign": 2, 96 | "no-self-compare": 2, 97 | "no-sequences": 2, 98 | "no-shadow-restricted-names": 2, 99 | "no-spaced-func": 2, 100 | "no-sparse-arrays": 2, 101 | "no-this-before-super": 2, 102 | "no-throw-literal": 2, 103 | "no-trailing-spaces": 0, 104 | "no-undef": 2, 105 | "no-undef-init": 2, 106 | "no-unexpected-multiline": 2, 107 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 108 | "no-unreachable": 2, 109 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 110 | "no-useless-call": 0, 111 | "no-with": 2, 112 | "one-var": [0, { "initialized": "never" }], 113 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 114 | "padded-blocks": [0, "never"], 115 | "quotes": [2, "single", "avoid-escape"], 116 | "radix": 2, 117 | "semi": [2, "always"], 118 | "semi-spacing": [2, { "before": false, "after": true }], 119 | "space-before-blocks": [2, "always"], 120 | "space-before-function-paren": [2, "never"], 121 | "space-in-parens": [2, "never"], 122 | "space-infix-ops": 2, 123 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 124 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 125 | "use-isnan": 2, 126 | "valid-typeof": 2, 127 | "wrap-iife": [2, "any"], 128 | "yoda": [2, "never"] 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | .idea 4 | .vscode 5 | *.sublime-* 6 | 7 | # test related, or directories generated by tests 8 | test/actual 9 | actual 10 | coverage 11 | .nyc* 12 | 13 | # npm 14 | node_modules 15 | npm-debug.log 16 | 17 | # yarn 18 | yarn.lock 19 | yarn-error.log 20 | 21 | # misc 22 | _gh_pages 23 | _draft 24 | _drafts 25 | bower_components 26 | vendor 27 | temp 28 | tmp 29 | TODO.md 30 | package-lock.json -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '10' 9 | - '9' 10 | - '8' 11 | - '7' 12 | - '6' 13 | - '5' 14 | - '4' 15 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | Works with strings or numbers. 4 | 5 | ```js 6 | const isOdd = require('{%= name %}'); 7 | 8 | console.log(isOdd('1')); //=> true 9 | console.log(isOdd('3')); //=> true 10 | 11 | console.log(isOdd(0)); //=> false 12 | console.log(isOdd(2)); //=> false 13 | ``` 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-odd [![NPM version](https://img.shields.io/npm/v/is-odd.svg?style=flat)](https://www.npmjs.com/package/is-odd) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-odd.svg?style=flat)](https://npmjs.org/package/is-odd) [![NPM total downloads](https://img.shields.io/npm/dt/is-odd.svg?style=flat)](https://npmjs.org/package/is-odd) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-odd.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-odd) 2 | 3 | > Returns true if the given number is odd, and is an integer that does not exceed the JavaScript MAXIMUM_SAFE_INTEGER. 4 | 5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save is-odd 13 | ``` 14 | 15 | ## Usage 16 | 17 | Works with strings or numbers. 18 | 19 | ```js 20 | const isOdd = require('is-odd'); 21 | 22 | console.log(isOdd('1')); //=> true 23 | console.log(isOdd('3')); //=> true 24 | 25 | console.log(isOdd(0)); //=> false 26 | console.log(isOdd(2)); //=> false 27 | ``` 28 | 29 | ## About 30 | 31 |
32 | Contributing 33 | 34 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 35 | 36 |
37 | 38 |
39 | Running Tests 40 | 41 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 42 | 43 | ```sh 44 | $ npm install && npm test 45 | ``` 46 | 47 |
48 | 49 |
50 | Building docs 51 | 52 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 53 | 54 | To generate the readme, run the following command: 55 | 56 | ```sh 57 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 58 | ``` 59 | 60 |
61 | 62 | ### Related projects 63 | 64 | You might also be interested in these projects: 65 | 66 | * [exponential-moving-average](https://www.npmjs.com/package/exponential-moving-average): Calculate an exponential moving average from an array of numbers. | [homepage](https://github.com/jonschlinkert/exponential-moving-average "Calculate an exponential moving average from an array of numbers.") 67 | * [is-even](https://www.npmjs.com/package/is-even): Return true if the given number is even. | [homepage](https://github.com/jonschlinkert/is-even "Return true if the given number is even.") 68 | * [sma](https://www.npmjs.com/package/sma): Calculate the simple moving average of an array. | [homepage](https://github.com/doowb/sma "Calculate the simple moving average of an array.") 69 | 70 | ### Contributors 71 | 72 | | **Commits** | **Contributor** | 73 | | --- | --- | 74 | | 20 | [jonschlinkert](https://github.com/jonschlinkert) | 75 | | 2 | [dym-sh](https://github.com/dym-sh) | 76 | | 1 | [Semigradsky](https://github.com/Semigradsky) | 77 | | 1 | [realityking](https://github.com/realityking) | 78 | 79 | ### Author 80 | 81 | **Jon Schlinkert** 82 | 83 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) 84 | * [GitHub Profile](https://github.com/jonschlinkert) 85 | * [Twitter Profile](https://twitter.com/jonschlinkert) 86 | 87 | ### License 88 | 89 | Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). 90 | Released under the [MIT License](LICENSE). 91 | 92 | *** 93 | 94 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 31, 2018._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-odd 3 | * 4 | * Copyright (c) 2015-2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | const isNumber = require('is-number'); 11 | 12 | module.exports = function isOdd(value) { 13 | const n = Math.abs(value); 14 | if (!isNumber(n)) { 15 | throw new TypeError('expected a number'); 16 | } 17 | if (!Number.isInteger(n)) { 18 | throw new Error('expected an integer'); 19 | } 20 | if (!Number.isSafeInteger(n)) { 21 | throw new Error('value exceeds maximum safe integer'); 22 | } 23 | return (n % 2) === 1; 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-odd", 3 | "description": "Returns true if the given number is odd, and is an integer that does not exceed the JavaScript MAXIMUM_SAFE_INTEGER.", 4 | "version": "3.0.1", 5 | "homepage": "https://github.com/jonschlinkert/is-odd", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Dmitry Semigradsky (http://brainstorage.me/semigradsky)", 9 | "DYM (https://dym.sh)", 10 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 11 | "Rouven Weßling (www.rouvenwessling.de)" 12 | ], 13 | "repository": "jonschlinkert/is-odd", 14 | "bugs": { 15 | "url": "https://github.com/jonschlinkert/is-odd/issues" 16 | }, 17 | "license": "MIT", 18 | "files": [ 19 | "index.js" 20 | ], 21 | "main": "index.js", 22 | "engines": { 23 | "node": ">=4" 24 | }, 25 | "scripts": { 26 | "test": "mocha" 27 | }, 28 | "dependencies": { 29 | "is-number": "^6.0.0" 30 | }, 31 | "devDependencies": { 32 | "gulp-format-md": "^1.0.0", 33 | "mocha": "^3.5.3" 34 | }, 35 | "keywords": [ 36 | "array", 37 | "count", 38 | "even", 39 | "filter", 40 | "integer", 41 | "is", 42 | "math", 43 | "numeric", 44 | "odd", 45 | "string" 46 | ], 47 | "verb": { 48 | "toc": false, 49 | "layout": "default", 50 | "tasks": [ 51 | "readme" 52 | ], 53 | "plugins": [ 54 | "gulp-format-md" 55 | ], 56 | "related": { 57 | "list": [ 58 | "exponential-moving-average", 59 | "is-even", 60 | "sma" 61 | ] 62 | }, 63 | "lint": { 64 | "reflinks": true 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | const assert = require('assert'); 5 | const isOdd = require('./'); 6 | 7 | describe('isOdd', function() { 8 | it('should return true if the number is odd:', function() { 9 | assert(!isOdd(0)); 10 | assert(!isOdd(2)); 11 | assert(isOdd(1)); 12 | assert(isOdd(3)); 13 | assert(isOdd(-1)); 14 | assert(isOdd(-3)); 15 | assert(isOdd(1.0e0)); 16 | assert(isOdd(9007199254740991)); 17 | }); 18 | 19 | it('should work with strings:', function() { 20 | assert(!isOdd('0')); 21 | assert(!isOdd('2')); 22 | assert(isOdd('1')); 23 | assert(isOdd('3')); 24 | assert(isOdd('1.0e0')); 25 | assert(isOdd('9007199254740991')); 26 | }); 27 | 28 | it('should throw an error when an invalid value is passed', function() { 29 | assert.throws(() => isOdd(), /expected a number/); 30 | assert.throws(() => isOdd('foo'), /expected a number/); 31 | assert.throws(() => isOdd('1.1e0'), /expected an integer/); 32 | assert.throws(() => isOdd('9007199254740992'), /value exceeds maximum safe integer/); 33 | assert.throws(() => isOdd(9007199254740992), /value exceeds maximum safe integer/); 34 | }); 35 | }); 36 | --------------------------------------------------------------------------------