[Pkg-javascript-commits] [node-is-number] 01/08: Import Upstream version 3.0.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Sun Oct 16 12:38:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-is-number.

commit cd450836d4df756e6cbff3ae0d2687d638659fd3
Author: Praveen Arimbrathodiyil <praveen at debian.org>
Date:   Sun Oct 16 17:32:26 2016 +0530

    Import Upstream version 3.0.0
---
 .editorconfig                       |  13 ++
 .eslintrc.json                      | 122 +++++++++++++++++++
 .gitattributes                      |  10 ++
 .gitignore                          |  21 ++++
 .travis.yml                         |  12 ++
 .verb.md                            |  57 +++++++++
 LICENSE                             |  21 ++++
 README.md                           | 115 ++++++++++++++++++
 benchmark/check.js                  |  19 +++
 benchmark/code/current.js           |  13 ++
 benchmark/code/isFinite.js          |  15 +++
 benchmark/code/parseFloat.js        |  15 +++
 benchmark/fixtures/all.js           | 156 ++++++++++++++++++++++++
 benchmark/fixtures/infinity.js      |   1 +
 benchmark/fixtures/null.js          |   1 +
 benchmark/fixtures/number.js        |   1 +
 benchmark/fixtures/string-number.js |   1 +
 benchmark/fixtures/string.js        |   1 +
 benchmark/index.js                  |  11 ++
 benchmark/last.txt                  |   3 +
 benchmark/support.js                | 233 ++++++++++++++++++++++++++++++++++++
 index.js                            |  22 ++++
 package.json                        |  83 +++++++++++++
 test.js                             | 186 ++++++++++++++++++++++++++++
 24 files changed, 1132 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..818e072
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+indent_style = space
+end_of_line = lf
+charset = utf-8
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
+trim_trailing_whitespace = false
+insert_final_newline = false
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..948dbdb
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,122 @@
+{
+  "ecmaFeatures": {
+    "modules": true,
+    "experimentalObjectRestSpread": true
+  },
+
+  "env": {
+    "browser": false,
+    "es6": true,
+    "node": true,
+    "mocha": true
+  },
+
+  "globals": {
+    "document": false,
+    "navigator": false,
+    "window": false
+  },
+
+  "rules": {
+    "accessor-pairs": 2,
+    "arrow-spacing": [2, { "before": true, "after": true }],
+    "block-spacing": [2, "always"],
+    "brace-style": [2, "1tbs", { "allowSingleLine": true }],
+    "comma-dangle": [2, "never"],
+    "comma-spacing": [2, { "before": false, "after": true }],
+    "comma-style": [2, "last"],
+    "constructor-super": 2,
+    "curly": [2, "multi-line"],
+    "dot-location": [2, "property"],
+    "eol-last": 2,
+    "eqeqeq": [2, "allow-null"],
+    "generator-star-spacing": [2, { "before": true, "after": true }],
+    "handle-callback-err": [2, "^(err|error)$" ],
+    "indent": [2, 2, { "SwitchCase": 1 }],
+    "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+    "keyword-spacing": [2, { "before": true, "after": true }],
+    "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
+    "new-parens": 2,
+    "no-array-constructor": 2,
+    "no-caller": 2,
+    "no-class-assign": 2,
+    "no-cond-assign": 2,
+    "no-const-assign": 2,
+    "no-control-regex": 2,
+    "no-debugger": 2,
+    "no-delete-var": 2,
+    "no-dupe-args": 2,
+    "no-dupe-class-members": 2,
+    "no-dupe-keys": 2,
+    "no-duplicate-case": 2,
+    "no-empty-character-class": 2,
+    "no-eval": 2,
+    "no-ex-assign": 2,
+    "no-extend-native": 2,
+    "no-extra-bind": 2,
+    "no-extra-boolean-cast": 2,
+    "no-extra-parens": [2, "functions"],
+    "no-fallthrough": 2,
+    "no-floating-decimal": 2,
+    "no-func-assign": 2,
+    "no-implied-eval": 2,
+    "no-inner-declarations": [2, "functions"],
+    "no-invalid-regexp": 2,
+    "no-irregular-whitespace": 2,
+    "no-iterator": 2,
+    "no-label-var": 2,
+    "no-labels": 2,
+    "no-lone-blocks": 2,
+    "no-mixed-spaces-and-tabs": 2,
+    "no-multi-spaces": 2,
+    "no-multi-str": 2,
+    "no-multiple-empty-lines": [2, { "max": 1 }],
+    "no-native-reassign": 0,
+    "no-negated-in-lhs": 2,
+    "no-new": 2,
+    "no-new-func": 2,
+    "no-new-object": 2,
+    "no-new-require": 2,
+    "no-new-wrappers": 2,
+    "no-obj-calls": 2,
+    "no-octal": 2,
+    "no-octal-escape": 2,
+    "no-proto": 0,
+    "no-redeclare": 2,
+    "no-regex-spaces": 2,
+    "no-return-assign": 2,
+    "no-self-compare": 2,
+    "no-sequences": 2,
+    "no-shadow-restricted-names": 2,
+    "no-spaced-func": 2,
+    "no-sparse-arrays": 2,
+    "no-this-before-super": 2,
+    "no-throw-literal": 2,
+    "no-trailing-spaces": 0,
+    "no-undef": 2,
+    "no-undef-init": 2,
+    "no-unexpected-multiline": 2,
+    "no-unneeded-ternary": [2, { "defaultAssignment": false }],
+    "no-unreachable": 2,
+    "no-unused-vars": [2, { "vars": "all", "args": "none" }],
+    "no-useless-call": 0,
+    "no-with": 2,
+    "one-var": [0, { "initialized": "never" }],
+    "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
+    "padded-blocks": [0, "never"],
+    "quotes": [2, "single", "avoid-escape"],
+    "radix": 2,
+    "semi": [2, "always"],
+    "semi-spacing": [2, { "before": false, "after": true }],
+    "space-before-blocks": [2, "always"],
+    "space-before-function-paren": [2, "never"],
+    "space-in-parens": [2, "never"],
+    "space-infix-ops": 2,
+    "space-unary-ops": [2, { "words": true, "nonwords": false }],
+    "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
+    "use-isnan": 2,
+    "valid-typeof": 2,
+    "wrap-iife": [2, "any"],
+    "yoda": [2, "never"]
+  }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7988154
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+# always ignore files
+*.DS_Store
+*.sublime-*
+
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+
+# npm
+node_modules
+npm-debug.log
+
+# misc
+_gh_pages
+benchmark
+bower_components
+vendor
+temp
+tmp
+TODO.md
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..04a029e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+sudo: false
+language: node_js
+node_js:
+  - node
+  - '6'
+  - '5'
+  - '0.12'
+matrix:
+  fast_finish: true
+  allow_failures:
+    - node_js: '4'
+    - node_js: '0.12'
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..db676bf
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,57 @@
+## Usage
+
+To understand some of the rationale behind the decisions made in this library (and to learn about some oddities of number evaluation in JavaScript), [see this gist][gist]. 
+
+```js
+var isNumber = require('{%= name %}');
+```
+
+### true
+
+See the [tests](./test.js) for more examples.
+
+```js
+isNumber(5e3)      //=> 'true'
+isNumber(0xff)     //=> 'true'
+isNumber(-1.1)     //=> 'true'
+isNumber(0)        //=> 'true'
+isNumber(1)        //=> 'true'
+isNumber(1.1)      //=> 'true'
+isNumber(10)       //=> 'true'
+isNumber(10.10)    //=> 'true'
+isNumber(100)      //=> 'true'
+isNumber('-1.1')   //=> 'true'
+isNumber('0')      //=> 'true'
+isNumber('012')    //=> 'true'
+isNumber('0xff')   //=> 'true'
+isNumber('1')      //=> 'true'
+isNumber('1.1')    //=> 'true'
+isNumber('10')     //=> 'true'
+isNumber('10.10')  //=> 'true'
+isNumber('100')    //=> 'true'
+isNumber('5e3')    //=> 'true'
+isNumber(parseInt('012'))   //=> 'true'
+isNumber(parseFloat('012')) //=> 'true'
+```
+
+### False
+
+See the [tests](./test.js) for more examples.
+
+```js
+isNumber('foo')             //=> 'false'
+isNumber([1])               //=> 'false'
+isNumber([])                //=> 'false'
+isNumber(function () {})    //=> 'false'
+isNumber(Infinity)          //=> 'false'
+isNumber(NaN)               //=> 'false'
+isNumber(new Array('abc'))  //=> 'false'
+isNumber(new Array(2))      //=> 'false'
+isNumber(new Buffer('abc')) //=> 'false'
+isNumber(null)              //=> 'false'
+isNumber(undefined)         //=> 'false'
+isNumber({abc: 'abc'})      //=> 'false'
+```
+
+[infinity]: http://en.wikipedia.org/wiki/Infinity
+[gist]: https://gist.github.com/jonschlinkert/e30c70c713da325d0e81
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..842218c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014-2016, Jon Schlinkert
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..281165d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,115 @@
+# is-number [![NPM version](https://img.shields.io/npm/v/is-number.svg?style=flat)](https://www.npmjs.com/package/is-number) [![NPM downloads](https://img.shields.io/npm/dm/is-number.svg?style=flat)](https://npmjs.org/package/is-number) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-number.svg?style=flat)](https://travis-ci.org/jonschlinkert/is-number)
+
+> Returns true if the value is a number. comprehensive tests.
+
+## Install
+
+Install with [npm](https://www.npmjs.com/):
+
+```sh
+$ npm install --save is-number
+```
+
+## Usage
+
+To understand some of the rationale behind the decisions made in this library (and to learn about some oddities of number evaluation in JavaScript), [see this gist](https://gist.github.com/jonschlinkert/e30c70c713da325d0e81).
+
+```js
+var isNumber = require('is-number');
+```
+
+### true
+
+See the [tests](./test.js) for more examples.
+
+```js
+isNumber(5e3)      //=> 'true'
+isNumber(0xff)     //=> 'true'
+isNumber(-1.1)     //=> 'true'
+isNumber(0)        //=> 'true'
+isNumber(1)        //=> 'true'
+isNumber(1.1)      //=> 'true'
+isNumber(10)       //=> 'true'
+isNumber(10.10)    //=> 'true'
+isNumber(100)      //=> 'true'
+isNumber('-1.1')   //=> 'true'
+isNumber('0')      //=> 'true'
+isNumber('012')    //=> 'true'
+isNumber('0xff')   //=> 'true'
+isNumber('1')      //=> 'true'
+isNumber('1.1')    //=> 'true'
+isNumber('10')     //=> 'true'
+isNumber('10.10')  //=> 'true'
+isNumber('100')    //=> 'true'
+isNumber('5e3')    //=> 'true'
+isNumber(parseInt('012'))   //=> 'true'
+isNumber(parseFloat('012')) //=> 'true'
+```
+
+### False
+
+See the [tests](./test.js) for more examples.
+
+```js
+isNumber('foo')             //=> 'false'
+isNumber([1])               //=> 'false'
+isNumber([])                //=> 'false'
+isNumber(function () {})    //=> 'false'
+isNumber(Infinity)          //=> 'false'
+isNumber(NaN)               //=> 'false'
+isNumber(new Array('abc'))  //=> 'false'
+isNumber(new Array(2))      //=> 'false'
+isNumber(new Buffer('abc')) //=> 'false'
+isNumber(null)              //=> 'false'
+isNumber(undefined)         //=> 'false'
+isNumber({abc: 'abc'})      //=> 'false'
+```
+
+## About
+
+### Related projects
+
+* [even](https://www.npmjs.com/package/even): Get the even numbered items from an array. | [homepage](https://github.com/jonschlinkert/even "Get the even numbered items from an array.")
+* [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.")
+* [is-odd](https://www.npmjs.com/package/is-odd): Returns true if the given number is odd. | [homepage](https://github.com/jonschlinkert/is-odd "Returns true if the given number is odd.")
+* [is-primitive](https://www.npmjs.com/package/is-primitive): Returns `true` if the value is a primitive.  | [homepage](https://github.com/jonschlinkert/is-primitive "Returns `true` if the value is a primitive. ")
+* [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.")
+* [odd](https://www.npmjs.com/package/odd): Get the odd numbered items from an array. | [homepage](https://github.com/jonschlinkert/odd "Get the odd numbered items from an array.")
+
+### Contributing
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
+
+### Building docs
+
+_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
+
+To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
+
+```sh
+$ npm install -g verb verb-generate-readme && verb
+```
+
+### Running tests
+
+Install dev dependencies:
+
+```sh
+$ npm install -d && npm test
+```
+
+### Author
+
+**Jon Schlinkert**
+
+* [github/jonschlinkert](https://github.com/jonschlinkert)
+* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+### License
+
+Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT license](https://github.com/jonschlinkert/is-number/blob/master/LICENSE).
+
+***
+
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.30, on September 10, 2016._
\ No newline at end of file
diff --git a/benchmark/check.js b/benchmark/check.js
new file mode 100644
index 0000000..7b00f3c
--- /dev/null
+++ b/benchmark/check.js
@@ -0,0 +1,19 @@
+'use strict';
+
+var fs = require('fs');
+var chalk = require('chalk');
+var path = require('path');
+
+fs.readdirSync(__dirname + '/code').forEach(function (fp) {
+  if (/\.js$/.test(fp)) {
+    var fn = require(path.resolve(__dirname, 'code', fp));
+    var name = path.basename(fp, path.extname(fp));
+
+    fs.readdirSync(__dirname + '/fixtures').forEach(function (fixture) {
+      fixture = path.resolve(__dirname, 'fixtures', fixture);
+      if (/\.js$/.test(fixture)) {
+        console.log(chalk.bold(name) + ':', fn.apply(null, require(fixture)));
+      }
+    });
+  }
+});
diff --git a/benchmark/code/current.js b/benchmark/code/current.js
new file mode 100644
index 0000000..6950c17
--- /dev/null
+++ b/benchmark/code/current.js
@@ -0,0 +1,13 @@
+'use strict';
+
+var isNumber = require('../..');
+
+module.exports = function(arr) {
+  var len = arr.length;
+  var res = [];
+
+  while (len--) {
+    res.push(isNumber(arr[len]));
+  }
+  return res;
+};
diff --git a/benchmark/code/isFinite.js b/benchmark/code/isFinite.js
new file mode 100644
index 0000000..8b60ab6
--- /dev/null
+++ b/benchmark/code/isFinite.js
@@ -0,0 +1,15 @@
+'use strict';
+
+module.exports = function(arr) {
+  var len = arr.length;
+  var res = [];
+
+  while (len--) {
+    res.push(isNumber(arr[len]));
+  }
+  return res;
+};
+
+function isNumber(n) {
+  return (!!(+n) && !Array.isArray(n)) && isFinite(n) || n === '0'|| n === 0;
+}
diff --git a/benchmark/code/parseFloat.js b/benchmark/code/parseFloat.js
new file mode 100644
index 0000000..1699826
--- /dev/null
+++ b/benchmark/code/parseFloat.js
@@ -0,0 +1,15 @@
+'use strict';
+
+module.exports = function(arr) {
+  var len = arr.length;
+  var res = [];
+
+  while (len--) {
+    res.push(isNumber(arr[len]));
+  }
+  return res;
+};
+
+function isNumber(n) {
+  return !Array.isArray(n) && (n - parseFloat(n) + 1) >= 0;
+}
diff --git a/benchmark/fixtures/all.js b/benchmark/fixtures/all.js
new file mode 100644
index 0000000..271fb8a
--- /dev/null
+++ b/benchmark/fixtures/all.js
@@ -0,0 +1,156 @@
+module.exports = [[
+  0xff,
+  5e3,
+  0,
+  0.1,
+  -0.1,
+  -1.1,
+  37,
+  3.14,
+
+  1,
+  1.1,
+  10,
+  10.10,
+  100,
+  -100,
+
+  '0.1',
+  '-0.1',
+  '-1.1',
+  '0',
+  '012',
+  '0xff',
+  '1',
+  '1.1',
+  '10',
+  '10.10',
+  '100',
+  '5e3',
+  '   56\r\n  ', // issue#3
+
+  Math.LN2,
+  Number(1),
+  new Number(1),
+
+  // 012, Octal literal not allowed in strict mode
+  parseInt('012'),
+  parseFloat('012'),
+  Math.abs(1),
+  Math.acos(1),
+  Math.asin(1),
+  Math.atan(1),
+  Math.atan2(1, 2),
+  Math.ceil(1),
+  Math.cos(1),
+  Math.E,
+  Math.exp(1),
+  Math.floor(1),
+  Math.LN10,
+  Math.LN2,
+  Math.log(1),
+  Math.LOG10E,
+  Math.LOG2E,
+  Math.max(1, 2),
+  Math.min(1, 2),
+  Math.PI,
+  Math.pow(1, 2),
+  Math.pow(5, 5),
+  Math.random(1),
+  Math.round(1),
+  Math.sin(1),
+  Math.sqrt(1),
+  Math.SQRT1_2,
+  Math.SQRT2,
+  Math.tan(1),
+
+  Number.MAX_VALUE,
+  Number.MIN_VALUE,
+
+  '0.0',
+  '0x0',
+  '0e+5',
+  '000',
+  '0.0e-5',
+  '0.0E5',
+
+  +'',
+  +1,
+  +3.14,
+  +37,
+  +5,
+  +[],
+  +Boolean(true),
+  +false,
+  +Math.LN2,
+  +String(100),
+  +true,
+  +null,
+  +Number(1),
+  +new Array(''),
+  +new Array(0),
+  +new Boolean(true),
+  +new Buffer(''),
+  +new Date,
+  +new Date(),
+  +new Number(1),
+
+  // should fail
+  '   ', // issue#3
+  '\r\n\t', // issue#3
+  '',
+  '3a',
+  'abc',
+  'false',
+  'null',
+  'true',
+  'undefined',
+  +'abc',
+  +/foo/,
+  +[1, 2, 4],
+  +function () {},
+  +function() {},
+  +function(){},
+  +Infinity,
+  +Math.sin,
+  +NaN,
+  +new Array('abc'),
+  +new Array(2),
+  +new RegExp('foo'),
+  +new String("abc"),
+  +String('foo'),
+  +undefined,
+  +{a:1},
+  +{},
+  // Symbol('foo'),
+  // Symbol(),
+  // Symbol.iterator,
+  /foo/,
+  [1, 2, 3],
+  [1],
+  [],
+  Boolean(true),
+  false,
+  function () {},
+  function() {},
+  function(){},
+  Infinity,
+  Math.sin,
+  NaN,
+  new Array(''),
+  new Array('abc'),
+  new Array(0),
+  new Boolean(true),
+  new Buffer(''),
+  new Buffer('abc'),
+  new Date(),
+  new RegExp('foo'),
+  new String("abc"),
+  null,
+  String("abc"),
+  true,
+  undefined,
+  {a:1},
+  {abc: 'abc'},
+  {},
+]]
diff --git a/benchmark/fixtures/infinity.js b/benchmark/fixtures/infinity.js
new file mode 100644
index 0000000..0306ef5
--- /dev/null
+++ b/benchmark/fixtures/infinity.js
@@ -0,0 +1 @@
+module.exports = [[Infinity]];
diff --git a/benchmark/fixtures/null.js b/benchmark/fixtures/null.js
new file mode 100644
index 0000000..6984da6
--- /dev/null
+++ b/benchmark/fixtures/null.js
@@ -0,0 +1 @@
+module.exports = [[null]];
diff --git a/benchmark/fixtures/number.js b/benchmark/fixtures/number.js
new file mode 100644
index 0000000..fd28c47
--- /dev/null
+++ b/benchmark/fixtures/number.js
@@ -0,0 +1 @@
+module.exports = [[1]];
diff --git a/benchmark/fixtures/string-number.js b/benchmark/fixtures/string-number.js
new file mode 100644
index 0000000..bc43529
--- /dev/null
+++ b/benchmark/fixtures/string-number.js
@@ -0,0 +1 @@
+module.exports = [['1']];
diff --git a/benchmark/fixtures/string.js b/benchmark/fixtures/string.js
new file mode 100644
index 0000000..1e193c4
--- /dev/null
+++ b/benchmark/fixtures/string.js
@@ -0,0 +1 @@
+module.exports = [['foo']];
diff --git a/benchmark/index.js b/benchmark/index.js
new file mode 100644
index 0000000..161072a
--- /dev/null
+++ b/benchmark/index.js
@@ -0,0 +1,11 @@
+'use strict';
+
+var Suite = require('benchmarked');
+var suite = new Suite({
+  result: false,
+  fixtures: 'fixtures/*.js',
+  code: 'code/*.js',
+  cwd: __dirname,
+});
+
+suite.run();
diff --git a/benchmark/last.txt b/benchmark/last.txt
new file mode 100644
index 0000000..714f248
--- /dev/null
+++ b/benchmark/last.txt
@@ -0,0 +1,3 @@
+current.js x 100,502 ops/sec ±0.80% (94 runs sampled)
+isFinite.js x 91,315 ops/sec ±0.92% (89 runs sampled)
+parseFloat.js x 72,464 ops/sec ±1.17% (91 runs sampled)
diff --git a/benchmark/support.js b/benchmark/support.js
new file mode 100644
index 0000000..f4e8561
--- /dev/null
+++ b/benchmark/support.js
@@ -0,0 +1,233 @@
+console.log('+new Array() //=> ', +new Array());
+console.log('+new Array(0) //=> ', +new Array(0));
+console.log('new Array(0) //=> ', new Array(0));
+console.log('new Array(0)+1 //=> ', new Array(0)+1);
+console.log('+new Array(1) //=> ', +new Array(1));
+console.log('new Array(1)+1 //=> ', new Array(1)+1);
+console.log('+new Array(1)+1 //=> ', +new Array(1)+1);
+console.log('+new Array(2) //=> ', +new Array(2));
+console.log('+new Array(2)+1 //=> ', +new Array(2)+1);
+console.log('+new Array(100)+1 //=> ', +new Array(100)+1);
+console.log('typeof (+new Array(100)+1) === "number" //=> ', typeof (+new Array(100)+1) === 'number');
+
+console.log('isFinite(+new Array()) //=> ', isFinite(+new Array()))
+console.log('isFinite(+new Array(0)) //=> ', isFinite(+new Array(0)))
+console.log('isFinite(new Array(0)) //=> ', isFinite(new Array(0)))
+console.log('isFinite(new Array(0)+1) //=> ', isFinite(new Array(0)+1))
+console.log('isFinite(+new Array(1)) //=> ', isFinite(+new Array(1)))
+console.log('isFinite(new Array(1)+1) //=> ', isFinite(new Array(1)+1))
+console.log('isFinite(+new Array(1)+1) //=> ', isFinite(+new Array(1)+1))
+console.log('isFinite(+new Array(2)) //=> ', isFinite(+new Array(2)))
+console.log('isFinite(+new Array(2)+1) //=> ', isFinite(+new Array(2)+1))
+console.log('isFinite(+new Array(100)+1) //=> ', isFinite(+new Array(100)+1))
+console.log('isFinite(typeof (+new Array(100)+1) === "number") //=> ', isFinite(typeof (+new Array(100)+1) === 'number'))
+
+// Numbers
+typeof 37 === 'number';
+typeof 3.14 === 'number';
+typeof Math.LN2 === 'number';
+typeof Infinity === 'number';
+typeof NaN === 'number'; // Despite being "Not-A-Number"
+typeof Number(1) === 'number'; // but never use this form!
+
+
+// Strings
+typeof "" === 'string';
+typeof "bla" === 'string';
+typeof (typeof 1) === 'string'; // typeof always return a string
+typeof String("abc") === 'string'; // but never use this form!
+
+
+// Booleans
+typeof true === 'boolean';
+typeof false === 'boolean';
+typeof Boolean(true) === 'boolean'; // but never use this form!
+
+
+// Symbols
+typeof Symbol() === 'symbol'
+typeof Symbol('foo') === 'symbol'
+typeof Symbol.iterator === 'symbol'
+
+
+// Undefined
+typeof undefined === 'undefined';
+typeof blabla === 'undefined'; // an undefined variable
+
+
+// Objects
+typeof {a:1} === 'object';
+
+// use Array.isArray or Object.prototype.toString.call
+// to differentiate regular objects from arrays
+typeof [1, 2, 4] === 'object';
+
+typeof new Date() === 'object';
+
+
+// The following is confusing. Don't use!
+typeof new Boolean(true) === 'object';
+typeof new Number(1) === 'object';
+typeof new String("abc") === 'object';
+
+
+// Functions
+typeof function(){} === 'function';
+typeof Math.sin === 'function';
+
+// =======================
+
+// Numbers
+console.log(typeof +37)
+console.log(typeof +3.14)
+console.log(typeof +Math.LN2)
+console.log(typeof +Infinity)
+console.log(typeof +NaN)
+console.log(typeof +Number(1))
+
+
+// Strings
+console.log(typeof +'')
+console.log(typeof +'foo')
+console.log(typeof +(typeof 1))
+console.log(typeof +(typeof 'foo'))
+console.log(typeof +String('foo'))
+console.log(typeof +String(100))
+
+// Booleans
+console.log(typeof +true)
+console.log(typeof +false)
+console.log(typeof +Boolean(true))
+// Undefined
+console.log(typeof +undefined)
+// console.log(typeof +blabla)
+
+
+// Objects
+console.log(typeof +{a:1})
+
+// use Array.isArray or Object.prototype.toString.call
+// to differentiate regular objects from arrays
+console.log(typeof +[1, 2, 4])
+
+console.log(typeof +new Date())
+
+
+// The following is confusing. Don't use!
+console.log(typeof +new Boolean(true))
+console.log(typeof +new Number(1))
+console.log(typeof +new String("abc"))
+
+
+// Functions
+console.log(typeof +function(){})
+console.log(typeof +Math.sin)
+
+console.log(typeof +'foo')
+
+console.log(-new Date)
+console.log(-new Date())
+
+console.log(1 + null)
+console.log(1 + +null)
+console.log(1 + null + '2')
+console.log(1 + null + 2)
+console.log(+null + +null)
+
+console.log(1 + +false)
+console.log(1 + false)
+console.log(1 + true)
+console.log(1 + +true)
+
+console.log(false + false)
+console.log(+false + false)
+console.log(+false + +false)
+
+console.log(false + null)
+console.log(+false + null)
+console.log(+false + +null)
+
+console.log(true + true)
+console.log(+true + true)
+console.log(+true + +true)
+
+console.log(true + false)
+console.log(+true + false)
+console.log(+true + +false)
+console.log(+true + +null)
+
+
+console.log(1 + 2) // 3
+console.log(true + 1)
+console.log(false + false)
+console.log(5 + 'abc')
+console.log('abc' + false)
+console.log('abc' + 'bar')
+console.log(+1 + 2) // 3
+console.log(+true + 1)
+console.log(+false + false)
+console.log(+5 + 'abc')
+console.log(+'abc' + false)
+console.log(+'abc' + 'bar')
+console.log(typeof (+1 + 2) === 'number')
+console.log(typeof (+true + 1) === 'number')
+console.log(typeof (+false + false) === 'number')
+console.log(typeof (+5 + 'abc') === 'number')
+console.log(typeof (+'abc' + false) === 'number')
+console.log(typeof (+'abc' + 'bar') === 'number')
+
+console.log(typeof -true) //=> 'number'
+console.log(typeof -false) //=> 'number'
+console.log(typeof -null) //=> 'number'
+console.log(typeof -undefined) //=> 'number'
+console.log(typeof -{}) //=> 'number'
+console.log(typeof -[]) //=> 'number'
+console.log(typeof -function() {}) //=> 'number'
+console.log(typeof -'foo') //=> 'number'
+console.log(typeof -new Date()) //=> 'number'
+console.log(typeof -new Buffer('')) //=> 'number'
+console.log(typeof -new Array('')) //=> 'number'
+console.log(typeof -NaN) //=> 'number'
+console.log(typeof -Infinity) //=> 'number'
+
+console.log(+true) //=> '1'
+console.log(+false) //=> '0'
+console.log(+null) //=> '0'
+console.log(+undefined) //=> 'NaN'
+console.log(+{}) //=> 'NaN'
+console.log(+[]) //=> '0'
+console.log(+function() {}) //=> 'NaN'
+console.log(+'foo') //=> 'NaN'
+console.log(+new Date()) //=> '1422091853924'
+console.log(+new Buffer('')) //=> '0'
+console.log(+new Array('')) //=> '0'
+console.log(+NaN) //=> 'NaN'
+console.log(+Infinity) //=> 'Infinity'
+
+console.log(!!(+true));
+console.log(!!(+false));
+console.log(!!(+null));
+console.log(!!(+undefined));
+console.log(!!(+{}));
+console.log(!!(+[]));
+console.log(!!(+function() {}));
+console.log(!!(+'foo'));
+console.log(!!(+new Date()));
+console.log(!!(+new Buffer('')));
+console.log(!!(+new Array('')));
+console.log(!!(+NaN));
+console.log(!!(+Infinity));
+console.log()
+console.log(!!(true));
+console.log(!!(false));
+console.log(!!(null));
+console.log(!!(undefined));
+console.log(!!({}));
+console.log(!!([]));
+console.log(!!(function() {}));
+console.log(!!('foo'));
+console.log(!!(new Date()));
+console.log(!!(new Buffer('')));
+console.log(!!(new Array('')));
+console.log(!!(NaN));
+console.log(!!(Infinity));
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..7a2a45b
--- /dev/null
+++ b/index.js
@@ -0,0 +1,22 @@
+/*!
+ * is-number <https://github.com/jonschlinkert/is-number>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+var typeOf = require('kind-of');
+
+module.exports = function isNumber(num) {
+  var type = typeOf(num);
+
+  if (type === 'string') {
+    if (!num.trim()) return false;
+  } else if (type !== 'number') {
+    return false;
+  }
+
+  return (num - num + 1) >= 0;
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..8c1f9ab
--- /dev/null
+++ b/package.json
@@ -0,0 +1,83 @@
+{
+  "name": "is-number",
+  "description": "Returns true if the value is a number. comprehensive tests.",
+  "version": "3.0.0",
+  "homepage": "https://github.com/jonschlinkert/is-number",
+  "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+  "contributors": [
+    "Charlike Mike Reagent (http://www.tunnckocore.tk)",
+    "Jon Schlinkert <jon.schlinkert at sellside.com> (http://twitter.com/jonschlinkert)"
+  ],
+  "repository": "jonschlinkert/is-number",
+  "bugs": {
+    "url": "https://github.com/jonschlinkert/is-number/issues"
+  },
+  "license": "MIT",
+  "files": [
+    "index.js"
+  ],
+  "main": "index.js",
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "mocha"
+  },
+  "dependencies": {
+    "kind-of": "^3.0.2"
+  },
+  "devDependencies": {
+    "benchmarked": "^0.2.5",
+    "chalk": "^1.1.3",
+    "gulp-format-md": "^0.1.10",
+    "mocha": "^3.0.2"
+  },
+  "keywords": [
+    "check",
+    "coerce",
+    "coercion",
+    "integer",
+    "is",
+    "is-nan",
+    "is-num",
+    "is-number",
+    "istype",
+    "kind",
+    "math",
+    "nan",
+    "num",
+    "number",
+    "numeric",
+    "test",
+    "type",
+    "typeof",
+    "value"
+  ],
+  "verb": {
+    "related": {
+      "list": [
+        "even",
+        "is-even",
+        "is-odd",
+        "is-primitive",
+        "kind-of",
+        "odd"
+      ]
+    },
+    "toc": false,
+    "layout": "default",
+    "tasks": [
+      "readme"
+    ],
+    "plugins": [
+      "gulp-format-md"
+    ],
+    "lint": {
+      "reflinks": true
+    },
+    "reflinks": [
+      "verb",
+      "verb-generate-readme"
+    ]
+  }
+}
\ No newline at end of file
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..3cbbc56
--- /dev/null
+++ b/test.js
@@ -0,0 +1,186 @@
+/*!
+ * is-number <https://github.com/jonschlinkert/is-number>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+/* deps: mocha */
+var assert = require('assert');
+var isNumber = require('./');
+
+var shouldPass = [
+  0xff,
+  5e3,
+  0,
+  0.1,
+  -0.1,
+  -1.1,
+  37,
+  3.14,
+
+  1,
+  1.1,
+  10,
+  10.10,
+  100,
+  -100,
+
+  '0.1',
+  '-0.1',
+  '-1.1',
+  '0',
+  '012',
+  '0xff',
+  '1',
+  '1.1',
+  '10',
+  '10.10',
+  '100',
+  '5e3',
+  '   56\r\n  ', // issue#3
+
+  Math.LN2,
+  Number(1),
+  new Number(1),
+
+  // 012, Octal literal not allowed in strict mode
+  parseInt('012'),
+  parseFloat('012'),
+  Math.abs(1),
+  Math.acos(1),
+  Math.asin(1),
+  Math.atan(1),
+  Math.atan2(1, 2),
+  Math.ceil(1),
+  Math.cos(1),
+  Math.E,
+  Math.exp(1),
+  Math.floor(1),
+  Math.LN10,
+  Math.LN2,
+  Math.log(1),
+  Math.LOG10E,
+  Math.LOG2E,
+  Math.max(1, 2),
+  Math.min(1, 2),
+  Math.PI,
+  Math.pow(1, 2),
+  Math.pow(5, 5),
+  Math.random(1),
+  Math.round(1),
+  Math.sin(1),
+  Math.sqrt(1),
+  Math.SQRT1_2,
+  Math.SQRT2,
+  Math.tan(1),
+
+  Number.MAX_VALUE,
+  Number.MIN_VALUE,
+
+  '0.0',
+  '0x0',
+  '0e+5',
+  '000',
+  '0.0e-5',
+  '0.0E5',
+
+  +'',
+  +1,
+  +3.14,
+  +37,
+  +5,
+  +[],
+  +Boolean(true),
+  +false,
+  +Math.LN2,
+  +String(100),
+  +true,
+  +null,
+  +Number(1),
+  +new Array(''),
+  +new Array(0),
+  +new Boolean(true),
+  +new Buffer(''),
+  +new Date,
+  +new Date(),
+  +new Number(1),
+];
+
+var shouldFail = [
+  '   ', // issue#3
+  '\r\n\t', // issue#3
+  '',
+  '3a',
+  'abc',
+  'false',
+  'null',
+  'true',
+  'undefined',
+  +'abc',
+  +/foo/,
+  +[1, 2, 4],
+  +function () {},
+  +function() {},
+  +function(){},
+  +Infinity,
+  +Math.sin,
+  +NaN,
+  +new Array('abc'),
+  +new Array(2),
+  +new RegExp('foo'),
+  +new String("abc"),
+  +String('foo'),
+  +undefined,
+  +{a:1},
+  +{},
+  // Symbol('foo'),
+  // Symbol(),
+  // Symbol.iterator,
+  /foo/,
+  [1, 2, 3],
+  [1],
+  [],
+  Boolean(true),
+  false,
+  function () {},
+  function() {},
+  function(){},
+  Infinity,
+  Math.sin,
+  NaN,
+  new Array(''),
+  new Array('abc'),
+  new Array(0),
+  new Boolean(true),
+  new Buffer(''),
+  new Buffer('abc'),
+  new Date(),
+  new RegExp('foo'),
+  new String("abc"),
+  null,
+  String("abc"),
+  true,
+  undefined,
+  {a:1},
+  {abc: 'abc'},
+  {},
+];
+
+describe('is a number', function () {
+  shouldPass.forEach(function (num) {
+    it('"' + JSON.stringify(num) + '" should be a number', function () {
+      assert.equal(isNumber(num), true);
+    });
+  });
+});
+
+describe('is not a number', function () {
+  shouldFail.forEach(function (num) {
+    it('"' + JSON.stringify(num) + '" should not be a number', function () {
+      assert.equal(isNumber(num), false);
+    });
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-is-number.git



More information about the Pkg-javascript-commits mailing list