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

doublescore

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doublescore - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

84

index.js

@@ -13,2 +13,6 @@ "use strict";

function isNumber( arg ) {
return typeof arg === 'number' && !isNaN( arg );
}
function isArray( arg ) {

@@ -19,3 +23,3 @@ return myArray.isArray( arg );

function isObject( arg ) {
return typeof arg === 'object' && !Array.isArray( arg ) && arg !== null;
return typeof arg === 'object' && !Array.isArray( arg ) && !(arg instanceof Number) && arg !== null;
}

@@ -25,8 +29,15 @@

if ( arg instanceof Number ) {
arg = arg * 1;
}
// handle exceptions that typeof doesn't handle
if ( arg === null ) {
return 'null';
}
else if ( Array.isArray( arg ) ) {
} else if ( isArray( arg ) ) {
return 'array';
} else if ( arg instanceof Date ) {
return 'date';
} else if ( arg instanceof RegExp ) {
return 'regex';
}

@@ -38,6 +49,10 @@

if ( type === 'number' ) {
if ( Math.ceil( arg ) > Math.floor( arg ) ) {
if ( isNaN( arg ) ) {
type = 'not-a-number';
} else if ( Infinity === arg ) {
type = 'infinity';
} else if ( Math.ceil( arg ) > Math.floor( arg ) ) {
type = 'float';
}
else {
} else {
type = 'integer';

@@ -65,18 +80,15 @@ }

target = new Date( arg.toISOString() );
}
else if ( isArray( arg ) ) {
} else if ( isArray( arg ) ) {
target = [];
for ( var i = 0; i < arg.length; i++ ) {
target[i] = clone( arg[i] );
target[ i ] = clone( arg[ i ] );
}
}
else if ( isObject( arg ) ) {
} else if ( isObject( arg ) ) {
target = {};
for ( var field in arg ) {
if ( arg.hasOwnProperty( field ) ) {
target[field] = clone( arg[field] );
target[ field ] = clone( arg[ field ] );
}
}
}
else { // functions, etc. not clonable, and will pass through, though for primitives like strings and numbers, arg is cloning
} else { // functions, etc. not clonable, and will pass through, though for primitives like strings and numbers, arg is cloning
target = arg;

@@ -105,3 +117,3 @@ }

var source = arguments[i];
var source = arguments[ i ];

@@ -141,3 +153,3 @@ // mixin the source differently depending on what is in the destination

// recurse mixin differently depending on what the target value is
switch ( getType( target[field] ) ) {
switch ( getType( target[ field ] ) ) {

@@ -148,3 +160,3 @@ // for any non-objects, do this

switch ( getType( source[field] ) ) {
switch ( getType( source[ field ] ) ) {
case 'undefined':

@@ -154,6 +166,6 @@ // NO-OP undefined doesn't override anything

case 'null':
target[field] = null;
target[ field ] = null;
break;
default:
target[field] = clone( source[field] );
target[ field ] = clone( source[ field ] );
break;

@@ -167,3 +179,3 @@ }

target[field] = mixin( target[field], source[field] );
target[ field ] = mixin( target[ field ], source[ field ] );

@@ -222,22 +234,25 @@ break;

return {
isObject: function() {
return isObject( obj );
clone: function() {
return clone( obj );
},
isArray: function() {
getType: function() {
return getType( obj );
},
isArray: function() {
return isArray( obj );
},
getType: function() {
return getType( obj );
isNumber: function() {
return isNumber( obj );
},
mixin: function() {
var args = [obj];
isObject: function() {
return isObject( obj );
},
mixin: function() {
var args = [ obj ];
for ( var i in arguments ) {
if ( arguments.hasOwnProperty( i ) ) {
args.push( arguments[i] );
args.push( arguments[ i ] );
}
}
return mixin.apply( module.exports, args );
},
clone: function() {
return clone( obj );
}

@@ -247,6 +262,7 @@ };

module.exports.mixin = mixin;
module.exports.clone = clone;
module.exports.getType = getType;
module.exports.isArray = isArray;
module.exports.isNumber = isNumber;
module.exports.isObject = isObject;
module.exports.isArray = isArray;
module.exports.getType = getType;
module.exports.mixin = mixin;

@@ -5,3 +5,3 @@ {

"author": "Anthony Hildoer <anthony@bluerival.com>",
"version": "0.0.3",
"version": "0.1.0",
"repository": {

@@ -11,2 +11,5 @@ "type": "git",

},
"scripts": {
"test": "node_modules/mocha/bin/mocha -b -u bdd test/default"
},
"keywords": [

@@ -21,3 +24,3 @@ "object",

"devDependencies": {
"mocha": "~1"
"mocha": "2.3.4"
},

@@ -24,0 +27,0 @@ "engines": {

@@ -24,26 +24,43 @@ "use strict";

it( 'should handle integers', function() {
assert.equal( __.getType( 1 ), 'integer' );
assert.equal( __.getType( -1 ), 'integer' );
assert.equal( __.getType( 0 ), 'integer' );
assert.equal( __.getType( 0.0 ), 'integer' );
assert.equal( __.getType( Number.MAX_VALUE ), 'integer' );
assert.equal( __.getType( -Number.MAX_VALUE ), 'integer' );
[
1,
-1,
0,
0.0,
-0,
-0.0,
Number.MAX_VALUE,
-Number.MAX_VALUE,
new Number( 1 ),
new Number( -1 ),
-(new Number( 1 )),
new Number( 0 ),
new Number( -0 ),
-(new Number( 0 )),
new Number( 0.0 ),
new Number( -0.0 ),
-(new Number( 0.0 ))
].forEach( function( val ) {
assert.equal( __.getType( val ), 'integer' );
assert.equal( __( val ).getType(), 'integer' );
} );
assert.equal( __( 1 ).getType(), 'integer' );
assert.equal( __( -1 ).getType(), 'integer' );
assert.equal( __( 0 ).getType(), 'integer' );
assert.equal( __( 0.0 ).getType(), 'integer' );
assert.equal( __( Number.MAX_VALUE ).getType(), 'integer' );
assert.equal( __( -Number.MAX_VALUE ).getType(), 'integer' );
} );
it( 'should handle floats', function() {
assert.equal( __.getType( 1.1 ), 'float' );
assert.equal( __.getType( -1.1 ), 'float' );
assert.equal( __.getType( Number.MIN_VALUE ), 'float' );
assert.equal( __.getType( -Number.MIN_VALUE ), 'float' );
assert.equal( __( 1.1 ).getType(), 'float' );
assert.equal( __( -1.1 ).getType(), 'float' );
assert.equal( __( Number.MIN_VALUE ).getType(), 'float' );
assert.equal( __( -Number.MIN_VALUE ).getType(), 'float' );
[
1.1,
-1.1,
0.1,
-0.1,
Number.MIN_VALUE,
-Number.MIN_VALUE,
new Number( 10.1 ),
new Number( -10.1 ),
-(new Number( 10.1 )),
].forEach( function( val ) {
assert.equal( __.getType( val ), 'float' );
assert.equal( __( val ).getType(), 'float' );
} );
} );

@@ -59,4 +76,6 @@

it( 'should handle arrays', function() {
assert.equal( __.getType( new Array() ), 'array' );
assert.equal( __.getType( [] ), 'array' );
assert.equal( __.getType( [ "one", "two", "three" ] ), 'array' );
assert.equal( __( new Array() ).getType(), 'array' );
assert.equal( __( [] ).getType(), 'array' );

@@ -78,23 +97,21 @@ assert.equal( __( [ "one", "two", "three" ] ).getType(), 'array' );

describe( 'should handle any other kind of object:', function() {
it( 'should handle Date', function() {
assert.equal( __.getType( new Date() ), 'date' );
assert.equal( __( new Date() ).getType(), 'date' );
} );
it( 'new Date()', function() {
assert.equal( __.getType( new Date() ), 'object' );
} );
it( 'should handle RegExp', function() {
assert.equal( __.getType( new RegExp() ), 'regex' );
assert.equal( __( new RegExp() ).getType(), 'regex' );
assert.equal( __.getType( /regex/ ), 'regex' );
assert.equal( __( /regex/ ).getType(), 'regex' );
} );
it( 'new RegExp()', function() {
assert.equal( __.getType( new RegExp() ), 'object' );
} );
it( 'new Date()', function() {
assert.equal( __( new Date() ).getType(), 'object' );
} );
it( 'new RegExp()', function() {
assert.equal( __( new RegExp() ).getType(), 'object' );
} );
it( 'should handle objects from custom class new function()', function() {
var c = function() {
};
assert.equal( __.getType( new c() ), 'object' );
assert.equal( __( new c() ).getType(), 'object' );
} );
} );

@@ -28,2 +28,12 @@ "use strict";

it( 'should return false for Infinity', function() {
assert.equal( __.isArray( Infinity ), false );
assert.equal( __( Infinity ).isArray(), false );
} );
it( 'should return false for NaN', function() {
assert.equal( __.isArray( NaN ), false );
assert.equal( __( NaN ).isArray(), false );
} );
it( 'should return false for a string', function() {

@@ -30,0 +40,0 @@ assert.equal( __.isArray( "string" ), false );

@@ -18,9 +18,17 @@ "use strict";

assert.equal( __.isObject( null ), false );
assert.equal( __( null ).isObject(), false );
} );
it( 'should return false for Infinity', function() {
assert.equal( __.isObject( Infinity ), false );
assert.equal( __( Infinity ).isObject(), false );
} );
it( 'should return false for NaN', function() {
assert.equal( __.isObject( NaN ), false );
assert.equal( __( NaN ).isObject(), false );
} );
it( 'should return false for UNDEFINED', function() {
assert.equal( __.isObject( undefined ), false );
assert.equal( __( undefined ).isObject(), false );

@@ -71,3 +79,3 @@ } );

describe( 'should return true for any kind of object:', function() {
describe( 'should return true for any other kind of object:', function() {

@@ -74,0 +82,0 @@ it( 'new Date()', function() {

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