@lvchengbin/is
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -53,3 +53,3 @@ (function (global, factory) { | ||
var isObject = (function (obj) { | ||
return obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object'; | ||
return obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj); | ||
}); | ||
@@ -88,3 +88,3 @@ | ||
if (strict) return false; | ||
return !isNaN(n) && !/\.$/.test(n); | ||
return !isNaN(parseFloat(n)) && isFinite(n) && !/\.$/.test(n); | ||
}); | ||
@@ -116,2 +116,23 @@ | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
var plainObject = (function (obj) { | ||
if (!isObject(obj)) { | ||
return false; | ||
} | ||
try { | ||
if (obj.constructor && !{}.hasOwnProperty.call(obj, 'constructor') && !{}.hasOwnProperty.call(obj.constructor.prototype, 'isPrototypeOf')) { | ||
return false; | ||
} | ||
} catch (e) { | ||
return false; | ||
} | ||
var key = void 0; | ||
for (key in obj) {} // eslint-disable-line | ||
return key === undefined || {}.hasOwnProperty.call(obj, key); | ||
}); | ||
var promise = (function (p) { | ||
@@ -148,6 +169,18 @@ return p && isFunction(p.then); | ||
var node = (function (s) { | ||
var isNode = (function (s) { | ||
return (typeof Node === 'undefined' ? 'undefined' : _typeof(Node)) === 'object' ? s instanceof Node : s && (typeof s === 'undefined' ? 'undefined' : _typeof(s)) === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string'; | ||
}); | ||
var textNode = (function (node) { | ||
return isNode(node) && node.nodeType === 3; | ||
}); | ||
var elementNode = (function (node) { | ||
return isNode(node) && node.nodeType === 1; | ||
}); | ||
var isWindow = (function (obj) { | ||
return obj && obj === obj.window; | ||
}); | ||
var is = { | ||
@@ -169,2 +202,3 @@ arguments: isArguments, | ||
object: isObject, | ||
plainObject: plainObject, | ||
promise: promise, | ||
@@ -176,3 +210,6 @@ regexp: regexp, | ||
url: url, | ||
node: node | ||
node: isNode, | ||
textNode: textNode, | ||
elementNode: elementNode, | ||
window: isWindow | ||
}; | ||
@@ -179,0 +216,0 @@ |
@@ -24,3 +24,3 @@ 'use strict'; | ||
var isObject = obj => obj && ( typeof obj === 'object' ); | ||
var isObject = obj => obj && typeof obj === 'object' && !Array.isArray( obj ); | ||
@@ -52,3 +52,3 @@ var empty = obj => { | ||
if( strict ) return false; | ||
return !isNaN( n ) && !/\.$/.test( n ); | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
}; | ||
@@ -78,2 +78,23 @@ | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
var plainObject = obj => { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
let key; | ||
for( key in obj ) {} // eslint-disable-line | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
}; | ||
var promise = p => p && isFunction( p.then ); | ||
@@ -103,4 +124,10 @@ | ||
var node = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ) | ||
var isNode = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ) | ||
var textNode = node => isNode( node ) && node.nodeType === 3; | ||
var elementNode = node => isNode( node ) && node.nodeType === 1; | ||
var isWindow = obj => obj && obj === obj.window; | ||
var is = { | ||
@@ -122,2 +149,3 @@ arguments : isArguments, | ||
object: isObject, | ||
plainObject, | ||
promise, | ||
@@ -129,5 +157,8 @@ regexp, | ||
url, | ||
node | ||
node: isNode, | ||
textNode, | ||
elementNode, | ||
window : isWindow | ||
}; | ||
module.exports = is; |
@@ -28,3 +28,3 @@ (function (global, factory) { | ||
var isObject = obj => obj && ( typeof obj === 'object' ); | ||
var isObject = obj => obj && typeof obj === 'object' && !Array.isArray( obj ); | ||
@@ -56,3 +56,3 @@ var empty = obj => { | ||
if( strict ) return false; | ||
return !isNaN( n ) && !/\.$/.test( n ); | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
}; | ||
@@ -82,2 +82,23 @@ | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
var plainObject = obj => { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
let key; | ||
for( key in obj ) {} // eslint-disable-line | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
}; | ||
var promise = p => p && isFunction( p.then ); | ||
@@ -107,4 +128,10 @@ | ||
var node = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ) | ||
var isNode = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ) | ||
var textNode = node => isNode( node ) && node.nodeType === 3; | ||
var elementNode = node => isNode( node ) && node.nodeType === 1; | ||
var isWindow = obj => obj && obj === obj.window; | ||
var is = { | ||
@@ -126,2 +153,3 @@ arguments : isArguments, | ||
object: isObject, | ||
plainObject, | ||
promise, | ||
@@ -133,3 +161,6 @@ regexp, | ||
url, | ||
node | ||
node: isNode, | ||
textNode, | ||
elementNode, | ||
window : isWindow | ||
}; | ||
@@ -136,0 +167,0 @@ |
{ | ||
"name": "@lvchengbin/is", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A library, which is possible to be imported as ES6 module separately, for checking the type of a value.", | ||
@@ -5,0 +5,0 @@ "keywords": "is check types es6", |
@@ -162,2 +162,8 @@ # Is | ||
### is.plainObject | ||
```js | ||
import isPlainObject from '@lvchengbin/is/src/plain-object'; | ||
``` | ||
### is.promise | ||
@@ -209,1 +215,19 @@ | ||
``` | ||
### is.textNode | ||
```js | ||
impor isTextNode from '@lvchengbin/is/src/text-node'; | ||
``` | ||
### is.elementNode | ||
```js | ||
impor isElementNode from '@lvchengbin/is/src/element-node'; | ||
``` | ||
### is.window | ||
```js | ||
import isWindow from '@lvchengbin/is/src/window'; | ||
``` |
@@ -16,2 +16,3 @@ import isArguments from './arguments'; | ||
import object from './object'; | ||
import plainObject from './plain-object'; | ||
import promise from './promise'; | ||
@@ -24,2 +25,5 @@ import regexp from './regexp'; | ||
import node from './node'; | ||
import textNode from './text-node'; | ||
import elementNode from './element-node'; | ||
import isWindow from './window'; | ||
@@ -42,2 +46,3 @@ export default { | ||
object, | ||
plainObject, | ||
promise, | ||
@@ -49,3 +54,6 @@ regexp, | ||
url, | ||
node | ||
node, | ||
textNode, | ||
elementNode, | ||
window : isWindow | ||
}; |
@@ -6,3 +6,3 @@ export default ( n, strict = false ) => { | ||
if( strict ) return false; | ||
return !isNaN( n ) && !/\.$/.test( n ); | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
}; |
@@ -1,1 +0,1 @@ | ||
export default obj => obj && ( typeof obj === 'object' ); | ||
export default obj => obj && typeof obj === 'object' && !Array.isArray( obj ); |
@@ -149,2 +149,11 @@ import is from '../src/is'; | ||
it( 'is.plainObject', () => { | ||
expect( is.plainObject( {} ) ).toBeTruthy(); | ||
expect( is.plainObject( { constructor : 1 } ) ).toBeTruthy(); | ||
expect( is.plainObject( new Object ) ).toBeTruthy(); | ||
expect( is.plainObject( new Date ) ).toBeFalsy(); | ||
expect( is.plainObject( [] ) ).toBeFalsy(); | ||
expect( is.plainObject( Promise.resolve() ) ).toBeFalsy(); | ||
} ); | ||
it( 'is.promise', () => { | ||
@@ -212,2 +221,24 @@ expect( is.promise( new Promise( () => {} ) ) ).toBeTruthy(); | ||
} ); | ||
it( 'is.textNode', () => { | ||
expect( is.textNode( document.createTextNode( 'ab' ) ) ).toBeTruthy(); | ||
const div = document.createElement( 'div' ); | ||
div.innerHTML = 'abc'; | ||
expect( is.textNode( div.firstChild ) ).toBeTruthy(); | ||
expect( is.textNode( div ) ).toBeFalsy(); | ||
expect( is.textNode( '' ) ).toBeFalsy(); | ||
} ); | ||
it( 'is.elementNode', () => { | ||
expect( is.elementNode( document.createElement( 'div' ) ) ).toBeTruthy(); | ||
expect( is.elementNode( document.createTextNode( 'div' ) ) ).toBeFalsy(); | ||
expect( is.elementNode( {} ) ).toBeFalsy(); | ||
} ); | ||
it( 'is.window', () => { | ||
expect( is.window( window ) ).toBeTruthy(); | ||
const iframe = document.createElement( 'iframe' ); | ||
document.body.appendChild( iframe ); | ||
expect( is.window( iframe.contentWindow ) ).toBeTruthy(); | ||
} ); | ||
} ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41393
40
930
232