Comparing version 1.0.0 to 2.0.0
@@ -5,10 +5,7 @@ "use strict"; | ||
For type-checking Javascript values. | ||
@module | ||
@alias t | ||
@module typical | ||
@typicalname t | ||
@example | ||
```js | ||
var t = require("typical"); | ||
``` | ||
*/ | ||
exports.isNumber = isNumber; | ||
@@ -21,21 +18,20 @@ exports.isPlainObject = isPlainObject; | ||
@returns {boolean} | ||
@static | ||
@example | ||
```js | ||
> w.isNumber(0) | ||
> t.isNumber(0) | ||
true | ||
> w.isNumber(1) | ||
> t.isNumber(1) | ||
true | ||
> w.isNumber(1.1) | ||
> t.isNumber(1.1) | ||
true | ||
> w.isNumber(0xff) | ||
> t.isNumber(0xff) | ||
true | ||
> w.isNumber(0644) | ||
> t.isNumber(0644) | ||
true | ||
> w.isNumber(6.2e5) | ||
> t.isNumber(6.2e5) | ||
true | ||
> w.isNumber(NaN) | ||
> t.isNumber(NaN) | ||
false | ||
> w.isNumber(Infinity) | ||
> t.isNumber(Infinity) | ||
false | ||
``` | ||
*/ | ||
@@ -47,17 +43,20 @@ function isNumber(n){ | ||
/** | ||
Returns true if input type is `object` and not an Array | ||
Returns true if input `typeof` is `object` and directly decends from `Object` (and not `Array`, `RegExp` etc.) | ||
@param {*} - the input to test | ||
@returns {boolean} | ||
@static | ||
@example | ||
```js | ||
> w.isPlainObject(new Date()) | ||
> t.isPlainObject({ clive: "hater" }) | ||
true | ||
> w.isPlainObject({ clive: "hater" }) | ||
true | ||
> w.isPlainObject([ 0, 1 ]) | ||
> t.isPlainObject(new Date()) | ||
false | ||
``` | ||
> t.isPlainObject([ 0, 1 ]) | ||
false | ||
> t.isPlainObject(1) | ||
false | ||
> t.isPlainObject(/test/) | ||
false | ||
*/ | ||
function isPlainObject(input){ | ||
return typeof input === "object" && !Array.isArray(input); | ||
} | ||
return typeof input === "object" && input.constructor === Object; | ||
} |
{ | ||
"name": "typical", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "For type-checking Javascript values.", | ||
@@ -21,5 +21,5 @@ "repository": "https://github.com/75lb/typical.git", | ||
"devDependencies": { | ||
"jsdoc-to-markdown": "^0.1.0", | ||
"tape": "^2.13.2" | ||
"jsdoc-to-markdown": "^1.1", | ||
"tape": "^4" | ||
} | ||
} |
@@ -6,7 +6,7 @@ [![view on npm](http://img.shields.io/npm/v/typical.svg)](https://www.npmjs.org/package/typical) | ||
#typical | ||
<a name="module_typical"></a> | ||
## typical | ||
For type-checking Javascript values. | ||
####Example | ||
**Example** | ||
```js | ||
@@ -16,74 +16,61 @@ var t = require("typical"); | ||
* [typical](#module_typical) | ||
* [.isNumber(n)](#module_typical.isNumber) ⇒ <code>boolean</code> | ||
* [.isPlainObject(input)](#module_typical.isPlainObject) ⇒ <code>boolean</code> | ||
**Contents** | ||
* [isNumber(n)](#module_typical.isNumber) | ||
* [isPlainObject(input)](#module_typical.isPlainObject) | ||
<a name="module_typical.isNumber"></a> | ||
###isNumber(n) | ||
### t.isNumber(n) ⇒ <code>boolean</code> | ||
Returns true if input is a number | ||
**Kind**: static method of <code>[typical](#module_typical)</code> | ||
- n `*` the input to test | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| n | <code>\*</code> | the input to test | | ||
**Returns**: `boolean` | ||
####Example | ||
**Example** | ||
```js | ||
> w.isNumber(0) | ||
> t.isNumber(0) | ||
true | ||
> w.isNumber(1) | ||
> t.isNumber(1) | ||
true | ||
> w.isNumber(1.1) | ||
> t.isNumber(1.1) | ||
true | ||
> w.isNumber(0xff) | ||
> t.isNumber(0xff) | ||
true | ||
> w.isNumber(0644) | ||
> t.isNumber(0644) | ||
true | ||
> w.isNumber(6.2e5) | ||
> t.isNumber(6.2e5) | ||
true | ||
> w.isNumber(NaN) | ||
> t.isNumber(NaN) | ||
false | ||
> w.isNumber(Infinity) | ||
> t.isNumber(Infinity) | ||
false | ||
``` | ||
<a name="module_typical.isPlainObject"></a> | ||
###isPlainObject(input) | ||
Returns true if input type is `object` and not an Array | ||
### t.isPlainObject(input) ⇒ <code>boolean</code> | ||
Returns true if input `typeof` is `object` and directly decends from `Object` (and not `Array`, `RegExp` etc.) | ||
**Kind**: static method of <code>[typical](#module_typical)</code> | ||
- input `*` the input to test | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| input | <code>\*</code> | the input to test | | ||
**Returns**: `boolean` | ||
####Example | ||
**Example** | ||
```js | ||
> w.isPlainObject(new Date()) | ||
> t.isPlainObject({ clive: "hater" }) | ||
true | ||
> w.isPlainObject({ clive: "hater" }) | ||
true | ||
> w.isPlainObject([ 0, 1 ]) | ||
> t.isPlainObject(new Date()) | ||
false | ||
> t.isPlainObject([ 0, 1 ]) | ||
false | ||
> t.isPlainObject(1) | ||
false | ||
> t.isPlainObject(/test/) | ||
false | ||
``` | ||
* * * | ||
© 2015 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). |
var test = require("tape"); | ||
var type = require("../"); | ||
test("first", function(t){ | ||
test(".isNumber(value)", function(t){ | ||
t.equal(type.isNumber(0), true); | ||
@@ -16,7 +16,10 @@ t.equal(type.isNumber(1), true); | ||
test("first", function(t){ | ||
t.equal(type.isPlainObject(new Date()), true); | ||
t.equal(type.isPlainObject({ clive: "hater" }), true); | ||
t.equal(type.isPlainObject([ 0, 1 ]), false); | ||
test(".isPlainObject(value)", function(t){ | ||
t.equal(type.isPlainObject({ clive: "hater" }), true, "{} is true"); | ||
t.equal(type.isPlainObject(new Date()), false, "new Date() is false"); | ||
t.equal(type.isPlainObject([ 0, 1 ]), false, "Array is false"); | ||
t.equal(type.isPlainObject(/test/), false, "RegExp is false"); | ||
t.equal(type.isPlainObject(1), false, "1 is false"); | ||
t.equal(type.isPlainObject("one"), false, "'one' is false"); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
5439
78
75