Skip to content

Commit

Permalink
updated README for instance function
Browse files Browse the repository at this point in the history
  • Loading branch information
brettlangdon committed Dec 30, 2012
1 parent bb0bee6 commit 8ab79d7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -13,18 +13,23 @@ npm install v8type
### Constants
* `ARRAY` - `'array'`
* `BOOLEAN` - `'boolean'`
* `BOOLEAN_OBJECT` - `'boolean_object'` (`new Boolean(false)`)
* `DATE` - `'date'`
* `FUNCTION - `'function'`
* `NULL` - `'null'`
* `NUMBER` - `'number'`
* `NUMBER_OBJECT` - `'number_object'` (`new Number(1))
* `OBJECT` - `'object'`
* `PRIMITIVE` - `'primitive'` (useful with `v8type.instance` function only)
* `REGEXP` - `'regexp'`
* `STRING` - `'string'`
* `STRING_OBJECT` - `'string_object'` (`new String('v8type')`)
* `UNDEFINED` - `'undefined'`

### Functions
* `of(object)` - returns the type of `object` as a string defined in the corresponding constants above.
* `is(object, type)` - returns `boolean` if `object` matches the string type `type` (string defined in the corresponding constants above).
* `instance(object, type)` - returns `boolean` is `object` is of the type `type` or inherits from `type` (`type` is a string defined in the corresponding constants above).

## Examples

Expand All @@ -41,6 +46,9 @@ console.log(v8type.of(undefined));
console.log(v8type.of(5));
// 'number'

console.log(v8type.of(new Number(5)))
// 'number_object'

console.log(v8type.of('v8type'));
// 'string'

Expand Down Expand Up @@ -72,6 +80,29 @@ v8type.is([], v8type.OBJECT);
// false
```

### instance function
```javascript
var v8type = require('v8type');

v8type.instance([], v8type.ARRAY);
// true

v8type.instance([], v8type.OBJECT);
// true

v8type.instance(5, v8type.OBJECT);
// false

v8type.instance(5, v8type.PRIMITIVE);
// true

v8type.instance(new Number(5), v8type.NUMBER);
// true

v8type.instance(new Number(5), v8type.OBJECT);
// true
```

## License
The MIT License (MIT)
Copyright (c) 2012 Brett Langdon <brett@blangdon.com>
Expand Down

0 comments on commit 8ab79d7

Please sign in to comment.