├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.js ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | 14 | [*.md] 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '5' 5 | - '4' 6 | - '0.12' 7 | - '0.10' 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = function (n) { 3 | return toString.call(n) === '[object Number]' && n < 0; 4 | }; 5 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Kevin Martensson (github.com/kevva) 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-negative", 3 | "version": "2.1.0", 4 | "description": "Check if something is a negative number", 5 | "license": "MIT", 6 | "repository": "kevva/is-negative", 7 | "author": { 8 | "email": "kevinmartensson@gmail.com", 9 | "name": "Kevin Martensson", 10 | "url": "github.com/kevva" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "negative", 23 | "number", 24 | "test", 25 | "check" 26 | ], 27 | "devDependencies": { 28 | "ava": "*", 29 | "xo": "*" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # is-negative [![Build Status](https://travis-ci.org/kevva/is-negative.svg?branch=master)](https://travis-ci.org/kevva/is-negative) 2 | 3 | > Check if something is a negative number 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save is-negative 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const isNegative = require('is-negative'); 17 | 18 | isNegative(-1); 19 | //=> true 20 | 21 | isNegative(1); 22 | //=> false 23 | 24 | isNegative(0); 25 | //=> false 26 | 27 | isNegative('-1'); 28 | //=> false 29 | 30 | isNegative(Number(-1)) 31 | //=> true 32 | ``` 33 | 34 | _Note: This module doesn't consider `-0` to be a negative number. If you want to detect `-0`, use the [`negative-zero`](https://github.com/sindresorhus/negative-zero) module._ 35 | 36 | 37 | ## Related 38 | 39 | - [is-positive](https://github.com/kevva/is-positive) - Check if something is a positive number 40 | 41 | 42 | ## License 43 | 44 | MIT © [Kevin Martensson](http://github.com/kevva) 45 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from './'; 3 | 4 | test(t => { 5 | t.true(m(-1)); 6 | t.false(m(0)); 7 | t.false(m(1)); 8 | t.false(m('-1')); 9 | t.true(m(Number(-1))); 10 | }); 11 | --------------------------------------------------------------------------------