Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ee-types

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ee-types - npm Package Compare versions

Comparing version 0.1.3 to 1.0.0

.jshintrc

113

lib/types.js

@@ -0,66 +1,89 @@

(function(){
var util = require('util')
, Class = require('ee-class')
, Types
, types
, proto
, type
;
var util = require( "util" )
Class = require( "ee-class" );
var Types = new Class( {
Types = new Class({
init: function(){
[ "string", "number", "boolean", "array", "object", "function", "date", "regexp", "error", "undefined", "buffer", "null" ].forEach( function( type ){
this[ type + "Array" ] = function( arg ){
return this.__array( arg, type );
['string', 'number', 'boolean', 'array', 'object', 'function', 'date', 'regexp', 'error', 'undefined', 'buffer', 'null', 'symbol'].forEach(function(type) {
this[type+'Array'] = function(arg) {
return this.__array(arg, type);
}.bind( this );
if ( type === "string" || type === "number" || type === "boolean" || type === "undefined" ){
this[ type.substr( 0, 1 ) ] = this[ type ].bind( this );
this[ type.substr( 0, 1 ) + "a" ] = this[ type + "Array" ].bind( this );
if (type === 'string' || type === 'number' || type === 'boolean' || type === 'undefined') {
this[type.substr(0, 1)] = this[type].bind(this);
this[type.substr(0, 1) + 'a'] = this[type + 'Array'].bind(this);
}
}.bind( this ) );
}.bind(this));
}
, string: function( arg ){ return typeof arg === "string" || Object.prototype.toString.call( arg ) === "[object String]"; }
, number: function( arg ){ return typeof arg === "number" || Object.prototype.toString.call( arg ) === "[object Number]"; }
, boolean: function( arg ){ return typeof arg === "boolean" || Object.prototype.toString.call( arg ) === "[object Boolean]"; }
, array: function( arg ){ return util.isArray( arg ); }
, object: function( arg ){ return typeof arg === "object" }
, function: function( arg ){ return typeof arg === "function" }
, date: function( arg ){ return util.isDate( arg ); }
, regexp: function( arg ){ return util.isRegExp( arg ); }
, error: function( arg ){ return util.isError( arg ); }
, undefined: function( arg ){ return typeof arg === "undefined" }
, buffer: function( arg ){ return Buffer.isBuffer( arg ); }
, null: function( arg ){ return null === arg; }
, __array: function( arg, type ){
if ( !this.array( arg ) ) return false;
var i = arg.length;
while( i-- ) if ( !this[ type ]( arg[ i ] ) ) return false;
return true;
, string: function(arg){ return typeof arg === 'string' || Object.prototype.toString.call(arg) === '[object String]'; }
, number: function(arg){ return typeof arg === 'number' || Object.prototype.toString.call(arg) === '[object Number]'; }
, boolean: function(arg){ return typeof arg === 'boolean' || Object.prototype.toString.call(arg) === '[object Boolean]'; }
, array: function(arg){ return util.isArray(arg); }
, object: function(arg){ return Object.prototype.toString.call(arg) === '[object Object]'}
, function: function(arg){ return typeof arg === 'function' }
, symbol: function(arg){ return typeof arg === 'symbol' }
, date: function(arg){ return util.isDate(arg); }
, regexp: function(arg){ return util.isRegExp(arg); }
, error: function(arg){ return util.isError(arg); }
, undefined: function(arg){ return typeof arg === 'undefined' }
, buffer: function(arg){ return Buffer.isBuffer(arg); }
, null: function(arg){ return null === arg; }
, __array: function(arg, type) {
// has to an array
if (!this.array(arg)) return false;
// check every item
return arg.every(this[type].bind(this));
}
} );
var types = new Types()
, proto = Object.getPrototypeOf(types);
var type = function( item ){
return types.s( item ) ? "string" :
types.n( item ) ? "number" :
types.b( item ) ? "boolean" :
types.array( item ) ? "array" :
types.function( item ) ? "function" :
types.date( item ) ? "date" :
types.regexp( item ) ? "regexp" :
types.error( item ) ? "error" :
types.buffer( item ) ? "buffer" :
types.null( item ) ? "null" :
types.u( item ) ? "undefined" :
types.object( item ) ? "object" : "unknown";
// instantiate the singleton
types = new Types();
// this is the exported method, it returns
// the type as string
type = function(item) {
return types.s(item) ? 'string' :
types.n(item) ? 'number' :
types.b(item) ? 'boolean' :
types.array(item) ? 'array' :
types.function(item) ? 'function' :
types.date(item) ? 'date' :
types.regexp(item) ? 'regexp' :
types.error(item) ? 'error' :
types.buffer(item) ? 'buffer' :
types.null(item) ? 'null' :
types.u(item) ? 'undefined' :
types.symbol(item) ? 'symbol' :
types.object(item) ? 'object' : 'unknown';
};
// gets its proto
proto = Object.getPrototypeOf(types);
// apply the class methods to the type function
Object.keys(proto).forEach(function(key){

@@ -71,2 +94,3 @@ if (!type[key]) type[key] = types[key].bind(types);

Object.keys(types).forEach(function(key){

@@ -78,2 +102,3 @@ if (!type[key]) type[key] = types[key];

module.exports = type;
module.exports = type;
})();
{
"name": "ee-types"
, "description": "Reliabale type detection"
, "version": "0.1.3"
, "homepage": "https://github.com/eventEmitter/ee-types"
, "author": "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"
, "licence": "MIT"
"name" : "ee-types"
, "description" : "Reliabale type detection"
, "version" : "1.0.0"
, "homepage" : "https://github.com/eventEmitter/ee-types"
, "author" : "Michael van der Weg <michael@joinbox.com> (http://joinbox.com/)"
, "license" : "MIT"
, "repository": {
"url": "https://github.com/eventEmitter/ee-types"
"url" : "https://github.com/eventEmitter/ee-types.git"
, "type" : "git"
}
, "engines": {
"node": "*"
"node" : ">=v0.12.0"
}
, "bugs": {
"url": "https://github.com/eventEmitter/ee-types/issues"
"url" : "https://github.com/eventEmitter/ee-types/issues"
}
, "dependencies": {
"ee-class": "*"
"ee-class" : "1.x.x"
}
, "devDependencies": {}
, "devDependencies": {
"mocha" : "1.17.x"
}
, "optionalDependencies": {}
}
, "keywords" : ["type-detection", "es6"]
, "scripts": {
"test" : "./node_modules/mocha/bin/mocha --reporter spec"
}
}

@@ -5,20 +5,22 @@ # ee-types

## installation
npm install ee-types
## usage
[![npm](https://img.shields.io/npm/dm/ee-types.svg?style=flat-square)](https://www.npmjs.com/package/ee-types)
[![Travis](https://img.shields.io/travis/eventEmitter/ee-types.svg?style=flat-square)](https://travis-ci.org/eventEmitter/ee-types)
[![node](https://img.shields.io/node/v/ee-types.svg?style=flat-square)](https://nodejs.org/)
var type = require( "ee-types" );
## API
type.string( "nope" ); // true
type.strign( new String( "yeah" ) ); // true
type.s( "michael" ); // true
var type = require('ee-types');
type( 2 ) // number
type.string('nope'); // true
type.strign(new String('yeah')); // true
type.s('michael'); // true
type(2) // number
## API

@@ -32,3 +34,3 @@

type.function()
type.object() // array, dates, erors, regexps & sometimes strings, numbers and bools are objects
type.object()
type.date()

@@ -41,2 +43,3 @@ type.error()

type.undefined()
type.symbol()

@@ -52,3 +55,3 @@ shortcut methods

type.stringArray( [ "hi", new String( "name" ), "is", "michael" ] ) // true
type.sa( [ "hi", new String( "name" ), "is", "michael" ] ) // true
type.stringArray([ 'hi', new String('name'), 'is', 'michael' ]) // true
type.sa([ 'hi', new String('name'), 'is', 'michael' ]) // true

@@ -25,3 +25,3 @@

console.log(
console.log(
type( "ee" )

@@ -28,0 +28,0 @@ , type( /f/ )

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc