Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brettlangdon/v8type
Expose V8 C++ type checking to JS
https://github.com/brettlangdon/v8type
Last synced: about 1 month ago
JSON representation
Expose V8 C++ type checking to JS
- Host: GitHub
- URL: https://github.com/brettlangdon/v8type
- Owner: brettlangdon
- Created: 2012-12-30T20:11:12.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-07-19T18:33:12.000Z (over 11 years ago)
- Last Synced: 2024-11-07T13:14:51.189Z (about 2 months ago)
- Language: C++
- Size: 117 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
v8type
======Module that uses V8 itself to check the type of a given object.
## Installing
```bash
npm install v8type
```## API
### 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
### of function
```javascript
var v8type = require('v8type');console.log(v8type.of([1,2,3,4]));
// 'array'console.log(v8type.of(undefined));
// 'undefined'console.log(v8type.of(5));
// 'number'console.log(v8type.of(new Number(5)))
// 'number_object'console.log(v8type.of('v8type'));
// 'string'console.log(v8type.of(new RegExp('v8type')));
// 'regexp'console.log(v8type.of({}));
// 'object'console.log(v8type.of(function(){}));
// 'function'console.log(v8type.of(new Date()));
// 'date'
```### is function
```javascript
var v8type = require('v8type');v8type.is([1,2,3], v8type.ARRAY);
// truev8type.is({}, v8type.NULL);
// false// Is does not check inheritence
v8type.is([], v8type.OBJECT);
// false
```### instance function
```javascript
var v8type = require('v8type');v8type.instance([], v8type.ARRAY);
// truev8type.instance([], v8type.OBJECT);
// truev8type.instance(5, v8type.OBJECT);
// falsev8type.instance(5, v8type.PRIMITIVE);
// truev8type.instance(new Number(5), v8type.NUMBER);
// truev8type.instance(new Number(5), v8type.OBJECT);
// true
```## License
The MIT License (MIT)
Copyright (c) 2012 Brett LangdonPermission 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.