├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .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 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "node": true, 3 | "esnext": true, 4 | "bitwise": true, 5 | "curly": true, 6 | "immed": true, 7 | "newcap": true, 8 | "noarg": true, 9 | "undef": true, 10 | "unused": "vars", 11 | "strict": true 12 | } 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - 'iojs' 5 | - '0.12' 6 | - '0.10' 7 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var MAX_SAFE_INTEGER = require('max-safe-integer'); 3 | 4 | module.exports = Number.isSafeInteger || function (val) { 5 | return typeof val === 'number' && val === val && val !== Infinity && val !== -Infinity && parseInt(val, 10) === val && Math.abs(val) <= MAX_SAFE_INTEGER; 6 | }; 7 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 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-safe-integer", 3 | "version": "2.0.0", 4 | "description": "ES2015 Number.isSafeInteger() ponyfill", 5 | "license": "MIT", 6 | "repository": "sindresorhus/is-safe-integer", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "http://sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=0.10.0" 14 | }, 15 | "scripts": { 16 | "test": "ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "es2015", 23 | "ponyfill", 24 | "polyfill", 25 | "shim", 26 | "browser", 27 | "number", 28 | "safe", 29 | "is", 30 | "integer" 31 | ], 32 | "dependencies": { 33 | "max-safe-integer": "^1.0.0" 34 | }, 35 | "devDependencies": { 36 | "ava": "*" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Deprecated 2 | 3 | This package is no longer relevant as ES2015 support is widespread. 4 | 5 | --- 6 | 7 | # is-safe-integer [![Build Status](https://travis-ci.org/sindresorhus/is-safe-integer.svg?branch=master)](https://travis-ci.org/sindresorhus/is-safe-integer) 8 | 9 | > ES2015 [`Number.isSafeInteger()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger) [ponyfill](https://ponyfill.com) 10 | 11 | 12 | ## Install 13 | 14 | ``` 15 | $ npm install --save is-safe-integer 16 | ``` 17 | 18 | 19 | ## Usage 20 | 21 | ```js 22 | var isSafeInteger = require('is-safe-integer'); 23 | 24 | isSafeInteger(3); 25 | //=> true 26 | 27 | isSafeInteger(100719925474099143523412); 28 | //=> false 29 | 30 | isSafeInteger(Infinity); 31 | //=> false 32 | ``` 33 | 34 | 35 | ## Related 36 | 37 | - [number-is-integer](https://github.com/sindresorhus/number-is-integer) - ES2015 `Number.isInteger()` ponyfill 38 | 39 | 40 | ## License 41 | 42 | MIT © [Sindre Sorhus](http://sindresorhus.com) 43 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | Number.isSafeInteger = undefined; 4 | const m = require('./'); 5 | 6 | test(t => { 7 | t.true(m(3)); 8 | t.true(m(-3)); 9 | t.true(m(3.0)); 10 | t.true(m(-3.0)); 11 | t.true(m(Math.pow(2, 53) - 1)); 12 | t.false(m(Math.pow(2, 53))); 13 | t.false(m(-Math.pow(2, 53))); 14 | t.false(m(3.1)); 15 | t.false(m(NaN)); 16 | t.false(m(Infinity)); 17 | t.false(m('3')); 18 | }); 19 | --------------------------------------------------------------------------------