@lvchengbin/is
Advanced tools
Comparing version 0.0.18 to 0.0.19
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.is = factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.is = factory()); | ||
}(this, (function () { 'use strict'; | ||
function isArguments (obj) { return ({}).toString.call( obj ) === '[object Arguments]'; } | ||
function isArguments (obj) { return ({}).toString.call( obj ) === '[object Arguments]'; } | ||
function isArray (obj) { return Array.isArray( obj ); } | ||
function isArray (obj) { return Array.isArray( obj ); } | ||
/** | ||
* async function | ||
* | ||
* @syntax: | ||
* async function() {} | ||
* async () => {} | ||
* async x() => {} | ||
* | ||
* @compatibility | ||
* IE: no | ||
* Edge: >= 15 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
/** | ||
* async function | ||
* | ||
* @syntax: | ||
* async function() {} | ||
* async () => {} | ||
* async x() => {} | ||
* | ||
* @compatibility | ||
* IE: no | ||
* Edge: >= 15 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
function isAsyncFunction (fn) { return ( {} ).toString.call( fn ) === '[object AsyncFunction]'; } | ||
function isAsyncFunction (fn) { return ( {} ).toString.call( fn ) === '[object AsyncFunction]'; } | ||
function isFunction (fn) { return ({}).toString.call( fn ) === '[object Function]' || isAsyncFunction( fn ); } | ||
function isFunction (fn) { return ({}).toString.call( fn ) === '[object Function]' || isAsyncFunction( fn ); } | ||
/** | ||
* arrow function | ||
* | ||
* Syntax: () => {} | ||
* | ||
* IE : no | ||
* Android : >= 5.0 | ||
*/ | ||
/** | ||
* arrow function | ||
* | ||
* Syntax: () => {} | ||
* | ||
* IE : no | ||
* Android : >= 5.0 | ||
*/ | ||
function arrowFunction (fn) { | ||
if( !isFunction( fn ) ) { return false; } | ||
return /^(?:function)?\s*\(?[\w\s,]*\)?\s*=>/.test( fn.toString() ); | ||
} | ||
function arrowFunction (fn) { | ||
if( !isFunction( fn ) ) { return false; } | ||
return /^(?:function)?\s*\(?[\w\s,]*\)?\s*=>/.test( fn.toString() ); | ||
} | ||
function isBoolean (s) { return typeof s === 'boolean'; } | ||
function isBoolean (s) { return typeof s === 'boolean'; } | ||
function date (date) { return ({}).toString.call( date ) === '[object Date]'; } | ||
function date (date) { return ({}).toString.call( date ) === '[object Date]'; } | ||
function email (str) { return /^(([^#$%&*!+-/=?^`{|}~<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test( str ); } | ||
function email (str) { return /^(([^#$%&*!+-/=?^`{|}~<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test( str ); } | ||
function isString (str) { return typeof str === 'string' || str instanceof String; } | ||
function isString (str) { return typeof str === 'string' || str instanceof String; } | ||
function isObject (obj) { return obj && typeof obj === 'object' && !Array.isArray( obj ); } | ||
function isObject (obj) { return obj && typeof obj === 'object' && !Array.isArray( obj ); } | ||
function empty (obj) { | ||
if( isArray( obj ) || isString( obj ) ) { | ||
return !obj.length; | ||
function empty (obj) { | ||
if( isArray( obj ) || isString( obj ) ) { | ||
return !obj.length; | ||
} | ||
if( isObject( obj ) ) { | ||
return !Object.keys( obj ).length; | ||
} | ||
return !obj; | ||
} | ||
if( isObject( obj ) ) { | ||
return !Object.keys( obj ).length; | ||
} | ||
return !obj; | ||
} | ||
function error (e) { return ({}).toString.call( e ) === '[object Error]'; } | ||
function error (e) { return ({}).toString.call( e ) === '[object Error]'; } | ||
function isFalse ( obj, generalized ) { | ||
if ( generalized === void 0 ) generalized = true; | ||
function isFalse ( obj, generalized ) { | ||
if ( generalized === void 0 ) generalized = true; | ||
if( isBoolean( obj ) || !generalized ) { return !obj; } | ||
if( isString( obj ) ) { | ||
return [ 'false', 'no', '0', '', 'nay', 'n', 'disagree' ].indexOf( obj.toLowerCase() ) > -1; | ||
if( isBoolean( obj ) || !generalized ) { return !obj; } | ||
if( isString( obj ) ) { | ||
return [ 'false', 'no', '0', '', 'nay', 'n', 'disagree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !obj; | ||
} | ||
return !obj; | ||
} | ||
function isNumber ( n, strict ) { | ||
if ( strict === void 0 ) strict = false; | ||
function isNumber ( n, strict ) { | ||
if ( strict === void 0 ) strict = false; | ||
if( ({}).toString.call( n ).toLowerCase() === '[object number]' ) { | ||
return true; | ||
if( ({}).toString.call( n ).toLowerCase() === '[object number]' ) { | ||
return true; | ||
} | ||
if( strict ) { return false; } | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
} | ||
if( strict ) { return false; } | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
} | ||
function isInteger ( n, strict ) { | ||
if ( strict === void 0 ) strict = false; | ||
function isInteger ( n, strict ) { | ||
if ( strict === void 0 ) strict = false; | ||
if( isNumber( n, true ) ) { return n % 1 === 0; } | ||
if( isNumber( n, true ) ) { return n % 1 === 0; } | ||
if( strict ) { return false; } | ||
if( strict ) { return false; } | ||
if( isString( n ) ) { | ||
if( n === '-0' ) { return true; } | ||
return n.indexOf( '.' ) < 0 && String( parseInt( n ) ) === n; | ||
} | ||
if( isString( n ) ) { | ||
if( n === '-0' ) { return true; } | ||
return n.indexOf( '.' ) < 0 && String( parseInt( n ) ) === n; | ||
} | ||
return false; | ||
} | ||
/** | ||
* iterable | ||
* | ||
* @compatibility | ||
* | ||
* IE: no | ||
* Edge: >= 13 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
function iterable (obj) { | ||
try { | ||
return isFunction( obj[ Symbol.iterator ] ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
} | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
/** | ||
* iterable | ||
* | ||
* @compatibility | ||
* | ||
* IE: no | ||
* Edge: >= 13 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
function plainObject (obj) { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
function iterable (obj) { | ||
try { | ||
return isFunction( obj[ Symbol.iterator ] ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
var key; | ||
for( key in obj ) {} // eslint-disable-line | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
} | ||
function isPlainObject (obj) { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
function promise (p) { return p && isFunction( p.then ); } | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
function regexp (reg) { return ({}).toString.call( reg ) === '[object RegExp]'; } | ||
var key; | ||
for( key in obj ) {} // eslint-disable-line | ||
function isTrue ( obj, generalized ) { | ||
if ( generalized === void 0 ) generalized = true; | ||
if( isBoolean( obj ) || !generalized ) { return !!obj; } | ||
if( isString( obj ) ) { | ||
return [ 'true', 'yes', 'ok', '1', 'yea', 'yep', 'y', 'agree' ].indexOf( obj.toLowerCase() ) > -1; | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
} | ||
return !!obj; | ||
} | ||
function isUndefined() { | ||
return arguments.length > 0 && typeof arguments[ 0 ] === 'undefined'; | ||
} | ||
function promise (p) { return p && isFunction( p.then ); } | ||
function ipv4 (ip) { | ||
if( !isString( ip ) ) { return false; } | ||
var pieces = ip.split( '.' ); | ||
if( pieces.length !== 4 ) { return false; } | ||
function regexp (reg) { return ({}).toString.call( reg ) === '[object RegExp]'; } | ||
for( var i$1 = 0, list = pieces; i$1 < list.length; i$1 += 1 ) { | ||
var i = list[i$1]; | ||
function isTrue ( obj, generalized ) { | ||
if ( generalized === void 0 ) generalized = true; | ||
if( !isInteger( i ) ) { return false; } | ||
if( i < 0 || i > 255 ) { return false; } | ||
if( isBoolean( obj ) || !generalized ) { return !!obj; } | ||
if( isString( obj ) ) { | ||
return [ 'true', 'yes', 'ok', '1', 'yea', 'yep', 'y', 'agree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !!obj; | ||
} | ||
return true; | ||
} | ||
/** | ||
* <user>:<password> can only be supported with FTP scheme on IE9/10/11 | ||
*/ | ||
function isUndefined() { | ||
return arguments.length > 0 && typeof arguments[ 0 ] === 'undefined'; | ||
} | ||
function url (url) { | ||
if( !isString( url ) ) { return false; } | ||
function ipv4 (ip) { | ||
if( !isString( ip ) ) { return false; } | ||
var pieces = ip.split( '.' ); | ||
if( pieces.length !== 4 ) { return false; } | ||
if( !/^(https?|ftp):\/\//i.test( url ) ) { return false; } | ||
var a = document.createElement( 'a' ); | ||
a.href = url; | ||
for( var i$1 = 0, list = pieces; i$1 < list.length; i$1 += 1 ) { | ||
var i = list[i$1]; | ||
/** | ||
* In IE, sometimes a.protocol would be an unknown type | ||
* Getting a.protocol will throw Error: Invalid argument in IE | ||
*/ | ||
try { | ||
if( !isString( a.protocol ) ) { return false; } | ||
} catch( e ) { | ||
return false; | ||
if( !isInteger( i ) ) { return false; } | ||
if( i < 0 || i > 255 ) { return false; } | ||
} | ||
return true; | ||
} | ||
if( !/^(https?|ftp):/i.test( a.protocol ) ) { return false; } | ||
/** | ||
* In IE, invalid IP address could be a valid hostname | ||
* <user>:<password> can only be supported with FTP scheme on IE9/10/11 | ||
*/ | ||
if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !ipv4( a.hostname ) ) { return false; } | ||
return true; | ||
} | ||
function url (url) { | ||
if( !isString( url ) ) { return false; } | ||
function isNode (s) { return ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ); } | ||
if( !/^(https?|ftp):\/\//i.test( url ) ) { return false; } | ||
var a = document.createElement( 'a' ); | ||
a.href = url; | ||
function textNode (node) { return node && node.nodeType === 3 && isNode( node ); } | ||
/** | ||
* In IE, sometimes a.protocol would be an unknown type | ||
* Getting a.protocol will throw Error: Invalid argument in IE | ||
*/ | ||
try { | ||
if( !isString( a.protocol ) ) { return false; } | ||
} catch( e ) { | ||
return false; | ||
} | ||
function elementNode (node) { return node && node.nodeType === 1 && isNode( node ); } | ||
if( !/^(https?|ftp):/i.test( a.protocol ) ) { return false; } | ||
function fragmentNode (node) { return node && node.nodeType === 11 && isNode( node ); } | ||
/** | ||
* In IE, invalid IP address is allowed | ||
*/ | ||
if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !ipv4( a.hostname ) ) { return false; } | ||
function isWindow (obj) { return obj && obj === obj.window; } | ||
return true; | ||
} | ||
function isClass (obj) { return isFunction( obj ) && /^\s*class\s+/.test( obj.toString() ); } | ||
function isNode (s) { return ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ); } | ||
function ipv6 (ip) { | ||
/** | ||
* An IPv6 address should have at least one colon(:) | ||
*/ | ||
if( ip.indexOf( ':' ) < 0 ) { return false; } | ||
function textNode (node) { return node && node.nodeType === 3 && isNode( node ); } | ||
/** | ||
* An IPv6 address can start or end with '::', but cannot start or end with a single colon. | ||
*/ | ||
if( /(^:[^:])|([^:]:$)/.test( ip ) ) { return false; } | ||
function elementNode (node) { return node && node.nodeType === 1 && isNode( node ); } | ||
/** | ||
* An IPv6 address should consist of colon(:), dot(.) and hexadecimel | ||
*/ | ||
if( !/^[0-9A-Fa-f:.]{2,}$/.test( ip ) ) { return false; } | ||
function fragmentNode (node) { return node && node.nodeType === 11 && isNode( node ); } | ||
/** | ||
* An IPv6 address should not have any sequence like: | ||
* 1. a hexadecimal that it's length greater than 4 | ||
* 2. three or more continous colons | ||
* 3. two or more continous dots | ||
*/ | ||
if( /[0-9A-Fa-f]{5,}|:{3,}|\.{2,}/.test( ip ) ) { return false; } | ||
function isWindow (obj) { return obj && obj === obj.window; } | ||
/** | ||
* In an IPv6 address, the "::" can only appear once. | ||
*/ | ||
if( ip.split( '::' ).length > 2 ) { return false; } | ||
function isClass (obj) { return isFunction( obj ) && /^\s*class\s+/.test( obj.toString() ); } | ||
/** | ||
* if the IPv6 address is in mixed form. | ||
*/ | ||
if( ip.indexOf( '.' ) > -1 ) { | ||
var lastColon = ip.lastIndexOf( ':' ); | ||
var hexadecimal = ip.substr( 0, lastColon ); | ||
var decimal = ip.substr( lastColon + 1 ); | ||
function ipv6 (ip) { | ||
/** | ||
* the decimal part should be an valid IPv4 address. | ||
* An IPv6 address should have at least one colon(:) | ||
*/ | ||
if( !ipv4( decimal ) ) { return false; } | ||
if( ip.indexOf( ':' ) < 0 ) { return false; } | ||
/** | ||
* the length of the hexadecimal part should less than 6. | ||
* An IPv6 address can start or end with '::', but cannot start or end with a single colon. | ||
*/ | ||
if( hexadecimal.split( ':' ).length > 6 ) { return false; } | ||
} else { | ||
if( /(^:[^:])|([^:]:$)/.test( ip ) ) { return false; } | ||
/** | ||
* An IPv6 address that is not in mixed form can at most have 8 hexadecimal sequences. | ||
* An IPv6 address should consist of colon(:), dot(.) and hexadecimel | ||
*/ | ||
if( ip.split( ':' ).length > 8 ) { return false; } | ||
if( !/^[0-9A-Fa-f:.]{2,}$/.test( ip ) ) { return false; } | ||
/** | ||
* An IPv6 address should not have any sequence like: | ||
* 1. a hexadecimal that it's length greater than 4 | ||
* 2. three or more continous colons | ||
* 3. two or more continous dots | ||
*/ | ||
if( /[0-9A-Fa-f]{5,}|:{3,}|\.{2,}/.test( ip ) ) { return false; } | ||
/** | ||
* In an IPv6 address, the "::" can only appear once. | ||
*/ | ||
if( ip.split( '::' ).length > 2 ) { return false; } | ||
/** | ||
* if the IPv6 address is in mixed form. | ||
*/ | ||
if( ip.indexOf( '.' ) > -1 ) { | ||
var lastColon = ip.lastIndexOf( ':' ); | ||
var hexadecimal = ip.substr( 0, lastColon ); | ||
var decimal = ip.substr( lastColon + 1 ); | ||
/** | ||
* the decimal part should be an valid IPv4 address. | ||
*/ | ||
if( !ipv4( decimal ) ) { return false; } | ||
/** | ||
* the length of the hexadecimal part should less than 6. | ||
*/ | ||
if( hexadecimal.split( ':' ).length > 6 ) { return false; } | ||
} else { | ||
/** | ||
* An IPv6 address that is not in mixed form can at most have 8 hexadecimal sequences. | ||
*/ | ||
if( ip.split( ':' ).length > 8 ) { return false; } | ||
} | ||
return true; | ||
} | ||
return true; | ||
} | ||
function isIP (ip) { return ipv4( ip ) || ipv6( ip ); } | ||
function ip (ip) { return ipv4( ip ) || ipv6( ip ); } | ||
/** | ||
* Private IPv4 address | ||
* | ||
* 10.0.0.0 ~ 10.255.255.255 | ||
* 172.16.0.0 ~ 172.31.255.255 | ||
* 192.168.0.0 ~ 192.168.255.255 | ||
*/ | ||
/** | ||
* Private IPv4 address | ||
* | ||
* 10.0.0.0 ~ 10.255.255.255 | ||
* 172.16.0.0 ~ 172.31.255.255 | ||
* 192.168.0.0 ~ 192.168.255.255 | ||
*/ | ||
function isPrivateIPv4 (ip) { | ||
if( !ipv4( ip ) ) { return false; } | ||
if( /^10\..*/.test( ip ) ) { return true; } | ||
if( /^192\.168\..*/.test( ip ) ) { return true; } | ||
if( /^172\.(1[6-9]|2[0-9]|3[0-1])\..*/.test( ip ) ) { return true; } | ||
return false; | ||
} | ||
function generator (fn) { | ||
try { | ||
return new Function( 'fn', 'return fn.constructor === (function*(){}).constructor' )( fn ); | ||
} catch( e ) { | ||
function privateIPv4 (ip) { | ||
if( !ipv4( ip ) ) { return false; } | ||
if( /^10\..*/.test( ip ) ) { return true; } | ||
if( /^192\.168\..*/.test( ip ) ) { return true; } | ||
if( /^172\.(1[6-9]|2[0-9]|3[0-1])\..*/.test( ip ) ) { return true; } | ||
return false; | ||
} | ||
} | ||
var is = { | ||
arguments : isArguments, | ||
array: isArray, | ||
arrowFunction: arrowFunction, | ||
asyncFunction: isAsyncFunction, | ||
boolean : isBoolean, | ||
date: date, | ||
email: email, | ||
empty: empty, | ||
error: error, | ||
false : isFalse, | ||
function : isFunction, | ||
integer: isInteger, | ||
iterable: iterable, | ||
number: isNumber, | ||
object: isObject, | ||
plainObject: plainObject, | ||
promise: promise, | ||
regexp: regexp, | ||
string: isString, | ||
true : isTrue, | ||
undefined : isUndefined, | ||
url: url, | ||
node: isNode, | ||
textNode: textNode, | ||
elementNode: elementNode, | ||
fragmentNode: fragmentNode, | ||
window : isWindow, | ||
class : isClass, | ||
ip : isIP, | ||
ipv4 : ipv4, | ||
ipv6 : ipv6, | ||
privateIPv4 : isPrivateIPv4, | ||
generator: generator | ||
}; | ||
function generator (fn) { | ||
try { | ||
return new Function( 'fn', 'return fn.constructor === (function*(){}).constructor' )( fn ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
} | ||
return is; | ||
function oneDimensionalArray ( arr, strict ) { | ||
if( !isArray( arr ) ) { return false; } | ||
for( var i = 0, list = arr; i < list.length; i += 1 ) { | ||
var item = list[i]; | ||
if( !item ) { continue; } | ||
if( strict && isPlainObject( item ) ) { return false; } | ||
if( isArray( item ) ) { return false; } | ||
} | ||
return true; | ||
} | ||
var is = { | ||
arguments : isArguments, | ||
array: isArray, | ||
arrowFunction: arrowFunction, | ||
asyncFunction: isAsyncFunction, | ||
boolean : isBoolean, | ||
date: date, | ||
email: email, | ||
empty: empty, | ||
error: error, | ||
false : isFalse, | ||
function : isFunction, | ||
integer: isInteger, | ||
iterable: iterable, | ||
number: isNumber, | ||
object: isObject, | ||
plainObject: isPlainObject, | ||
promise: promise, | ||
regexp: regexp, | ||
string: isString, | ||
true : isTrue, | ||
undefined : isUndefined, | ||
url: url, | ||
node: isNode, | ||
textNode: textNode, | ||
elementNode: elementNode, | ||
fragmentNode: fragmentNode, | ||
window : isWindow, | ||
class : isClass, | ||
ip: ip, | ||
ipv4: ipv4, | ||
ipv6: ipv6, | ||
privateIPv4: privateIPv4, | ||
generator: generator, | ||
oneDimensionalArray: oneDimensionalArray | ||
}; | ||
return is; | ||
}))); |
@@ -90,3 +90,3 @@ 'use strict'; | ||
return false; | ||
} | ||
}; | ||
@@ -114,3 +114,3 @@ /** | ||
var plainObject = obj => { | ||
var isPlainObject = obj => { | ||
if( !isObject( obj ) ) { | ||
@@ -186,3 +186,3 @@ return false; | ||
/** | ||
* In IE, invalid IP address could be a valid hostname | ||
* In IE, invalid IP address is allowed | ||
*/ | ||
@@ -194,3 +194,3 @@ if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !ipv4( a.hostname ) ) return false; | ||
var isNode = 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' ); | ||
@@ -261,3 +261,3 @@ var textNode = node => node && node.nodeType === 3 && isNode( node ); | ||
var isIP = ip => ipv4( ip ) || ipv6( ip ); | ||
var ip = ip => ipv4( ip ) || ipv6( ip ); | ||
@@ -272,3 +272,3 @@ /** | ||
var isPrivateIPv4 = ip => { | ||
var privateIPv4 = ip => { | ||
if( !ipv4( ip ) ) return false; | ||
@@ -287,4 +287,15 @@ if( /^10\..*/.test( ip ) ) return true; | ||
} | ||
} | ||
}; | ||
var oneDimensionalArray = ( arr, strict ) => { | ||
if( !isArray( arr ) ) return false; | ||
for( const item of arr ) { | ||
if( !item ) continue; | ||
if( strict && isPlainObject( item ) ) return false; | ||
if( isArray( item ) ) return false; | ||
} | ||
return true; | ||
}; | ||
var is = { | ||
@@ -306,3 +317,3 @@ arguments : isArguments, | ||
object: isObject, | ||
plainObject, | ||
plainObject: isPlainObject, | ||
promise, | ||
@@ -320,9 +331,10 @@ regexp, | ||
class : isClass, | ||
ip : isIP, | ||
ipv4 : ipv4, | ||
ipv6 : ipv6, | ||
privateIPv4 : isPrivateIPv4, | ||
generator | ||
ip, | ||
ipv4, | ||
ipv6, | ||
privateIPv4, | ||
generator, | ||
oneDimensionalArray | ||
}; | ||
module.exports = is; |
516
dist/is.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.IS = factory()); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.IS = factory()); | ||
}(this, (function () { 'use strict'; | ||
var isArguments = obj => ({}).toString.call( obj ) === '[object Arguments]'; | ||
var isArguments = obj => ({}).toString.call( obj ) === '[object Arguments]'; | ||
var isArray = obj => Array.isArray( obj ); | ||
var isArray = obj => Array.isArray( obj ); | ||
/** | ||
* async function | ||
* | ||
* @syntax: | ||
* async function() {} | ||
* async () => {} | ||
* async x() => {} | ||
* | ||
* @compatibility | ||
* IE: no | ||
* Edge: >= 15 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
/** | ||
* async function | ||
* | ||
* @syntax: | ||
* async function() {} | ||
* async () => {} | ||
* async x() => {} | ||
* | ||
* @compatibility | ||
* IE: no | ||
* Edge: >= 15 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
var isAsyncFunction = fn => ( {} ).toString.call( fn ) === '[object AsyncFunction]'; | ||
var isAsyncFunction = fn => ( {} ).toString.call( fn ) === '[object AsyncFunction]'; | ||
var isFunction = fn => ({}).toString.call( fn ) === '[object Function]' || isAsyncFunction( fn ); | ||
var isFunction = fn => ({}).toString.call( fn ) === '[object Function]' || isAsyncFunction( fn ); | ||
/** | ||
* arrow function | ||
* | ||
* Syntax: () => {} | ||
* | ||
* IE : no | ||
* Android : >= 5.0 | ||
*/ | ||
/** | ||
* arrow function | ||
* | ||
* Syntax: () => {} | ||
* | ||
* IE : no | ||
* Android : >= 5.0 | ||
*/ | ||
var arrowFunction = fn => { | ||
if( !isFunction( fn ) ) return false; | ||
return /^(?:function)?\s*\(?[\w\s,]*\)?\s*=>/.test( fn.toString() ); | ||
}; | ||
var arrowFunction = fn => { | ||
if( !isFunction( fn ) ) return false; | ||
return /^(?:function)?\s*\(?[\w\s,]*\)?\s*=>/.test( fn.toString() ); | ||
}; | ||
var isBoolean = s => typeof s === 'boolean'; | ||
var isBoolean = s => typeof s === 'boolean'; | ||
var date = date => ({}).toString.call( date ) === '[object Date]'; | ||
var date = date => ({}).toString.call( date ) === '[object Date]'; | ||
var email = str => /^(([^#$%&*!+-/=?^`{|}~<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test( str ); | ||
var email = str => /^(([^#$%&*!+-/=?^`{|}~<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i.test( str ); | ||
var isString = str => typeof str === 'string' || str instanceof String; | ||
var isString = str => typeof str === 'string' || str instanceof String; | ||
var isObject = obj => obj && typeof obj === 'object' && !Array.isArray( obj ); | ||
var isObject = obj => obj && typeof obj === 'object' && !Array.isArray( obj ); | ||
var empty = obj => { | ||
if( isArray( obj ) || isString( obj ) ) { | ||
return !obj.length; | ||
} | ||
if( isObject( obj ) ) { | ||
return !Object.keys( obj ).length; | ||
} | ||
return !obj; | ||
}; | ||
var empty = obj => { | ||
if( isArray( obj ) || isString( obj ) ) { | ||
return !obj.length; | ||
} | ||
if( isObject( obj ) ) { | ||
return !Object.keys( obj ).length; | ||
} | ||
return !obj; | ||
}; | ||
var error = e => ({}).toString.call( e ) === '[object Error]'; | ||
var error = e => ({}).toString.call( e ) === '[object Error]'; | ||
var isFalse = ( obj, generalized = true ) => { | ||
if( isBoolean( obj ) || !generalized ) return !obj; | ||
if( isString( obj ) ) { | ||
return [ 'false', 'no', '0', '', 'nay', 'n', 'disagree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !obj; | ||
}; | ||
var isFalse = ( obj, generalized = true ) => { | ||
if( isBoolean( obj ) || !generalized ) return !obj; | ||
if( isString( obj ) ) { | ||
return [ 'false', 'no', '0', '', 'nay', 'n', 'disagree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !obj; | ||
}; | ||
var isNumber = ( n, strict = false ) => { | ||
if( ({}).toString.call( n ).toLowerCase() === '[object number]' ) { | ||
return true; | ||
} | ||
if( strict ) return false; | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
}; | ||
var isNumber = ( n, strict = false ) => { | ||
if( ({}).toString.call( n ).toLowerCase() === '[object number]' ) { | ||
return true; | ||
} | ||
if( strict ) return false; | ||
return !isNaN( parseFloat( n ) ) && isFinite( n ) && !/\.$/.test( n ); | ||
}; | ||
var isInteger = ( n, strict = false ) => { | ||
var isInteger = ( n, strict = false ) => { | ||
if( isNumber( n, true ) ) return n % 1 === 0; | ||
if( isNumber( n, true ) ) return n % 1 === 0; | ||
if( strict ) return false; | ||
if( strict ) return false; | ||
if( isString( n ) ) { | ||
if( n === '-0' ) return true; | ||
return n.indexOf( '.' ) < 0 && String( parseInt( n ) ) === n; | ||
} | ||
if( isString( n ) ) { | ||
if( n === '-0' ) return true; | ||
return n.indexOf( '.' ) < 0 && String( parseInt( n ) ) === n; | ||
} | ||
return false; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* iterable | ||
* | ||
* @compatibility | ||
* | ||
* IE: no | ||
* Edge: >= 13 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
/** | ||
* iterable | ||
* | ||
* @compatibility | ||
* | ||
* IE: no | ||
* Edge: >= 13 | ||
* Android: >= 5.0 | ||
* | ||
*/ | ||
var iterable = obj => { | ||
try { | ||
return isFunction( obj[ Symbol.iterator ] ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
}; | ||
var iterable = obj => { | ||
try { | ||
return isFunction( obj[ Symbol.iterator ] ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
}; | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
// https://github.com/jquery/jquery/blob/2d4f53416e5f74fa98e0c1d66b6f3c285a12f0ce/test/data/jquery-1.9.1.js#L480 | ||
var plainObject = obj => { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
var isPlainObject = obj => { | ||
if( !isObject( obj ) ) { | ||
return false; | ||
} | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
try { | ||
if( obj.constructor && !({}).hasOwnProperty.call( obj, 'constructor' ) && !({}).hasOwnProperty.call( obj.constructor.prototype, 'isPrototypeOf' ) ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
} catch( e ) { | ||
return false; | ||
} | ||
let key; | ||
for( key in obj ) {} // eslint-disable-line | ||
let key; | ||
for( key in obj ) {} // eslint-disable-line | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
}; | ||
return key === undefined || ({}).hasOwnProperty.call( obj, key ); | ||
}; | ||
var promise = p => p && isFunction( p.then ); | ||
var promise = p => p && isFunction( p.then ); | ||
var regexp = reg => ({}).toString.call( reg ) === '[object RegExp]'; | ||
var regexp = reg => ({}).toString.call( reg ) === '[object RegExp]'; | ||
var isTrue = ( obj, generalized = true ) => { | ||
if( isBoolean( obj ) || !generalized ) return !!obj; | ||
if( isString( obj ) ) { | ||
return [ 'true', 'yes', 'ok', '1', 'yea', 'yep', 'y', 'agree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !!obj; | ||
}; | ||
var isTrue = ( obj, generalized = true ) => { | ||
if( isBoolean( obj ) || !generalized ) return !!obj; | ||
if( isString( obj ) ) { | ||
return [ 'true', 'yes', 'ok', '1', 'yea', 'yep', 'y', 'agree' ].indexOf( obj.toLowerCase() ) > -1; | ||
} | ||
return !!obj; | ||
}; | ||
function isUndefined() { | ||
return arguments.length > 0 && typeof arguments[ 0 ] === 'undefined'; | ||
} | ||
var ipv4 = ip => { | ||
if( !isString( ip ) ) return false; | ||
const pieces = ip.split( '.' ); | ||
if( pieces.length !== 4 ) return false; | ||
for( const i of pieces ) { | ||
if( !isInteger( i ) ) return false; | ||
if( i < 0 || i > 255 ) return false; | ||
function isUndefined() { | ||
return arguments.length > 0 && typeof arguments[ 0 ] === 'undefined'; | ||
} | ||
return true; | ||
}; | ||
/** | ||
* <user>:<password> can only be supported with FTP scheme on IE9/10/11 | ||
*/ | ||
var ipv4 = ip => { | ||
if( !isString( ip ) ) return false; | ||
const pieces = ip.split( '.' ); | ||
if( pieces.length !== 4 ) return false; | ||
var url = url => { | ||
if( !isString( url ) ) return false; | ||
for( const i of pieces ) { | ||
if( !isInteger( i ) ) return false; | ||
if( i < 0 || i > 255 ) return false; | ||
} | ||
return true; | ||
}; | ||
if( !/^(https?|ftp):\/\//i.test( url ) ) return false; | ||
const a = document.createElement( 'a' ); | ||
a.href = url; | ||
/** | ||
* In IE, sometimes a.protocol would be an unknown type | ||
* Getting a.protocol will throw Error: Invalid argument in IE | ||
* <user>:<password> can only be supported with FTP scheme on IE9/10/11 | ||
*/ | ||
try { | ||
if( !isString( a.protocol ) ) return false; | ||
} catch( e ) { | ||
return false; | ||
} | ||
if( !/^(https?|ftp):/i.test( a.protocol ) ) return false; | ||
var url = url => { | ||
if( !isString( url ) ) return false; | ||
/** | ||
* In IE, invalid IP address could be a valid hostname | ||
*/ | ||
if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !ipv4( a.hostname ) ) return false; | ||
if( !/^(https?|ftp):\/\//i.test( url ) ) return false; | ||
const a = document.createElement( 'a' ); | ||
a.href = url; | ||
return true; | ||
}; | ||
/** | ||
* In IE, sometimes a.protocol would be an unknown type | ||
* Getting a.protocol will throw Error: Invalid argument in IE | ||
*/ | ||
try { | ||
if( !isString( a.protocol ) ) return false; | ||
} catch( e ) { | ||
return false; | ||
} | ||
var isNode = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ) | ||
if( !/^(https?|ftp):/i.test( a.protocol ) ) return false; | ||
var textNode = node => node && node.nodeType === 3 && isNode( node ); | ||
/** | ||
* In IE, invalid IP address is allowed | ||
*/ | ||
if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !ipv4( a.hostname ) ) return false; | ||
var elementNode = node => node && node.nodeType === 1 && isNode( node ); | ||
return true; | ||
}; | ||
var fragmentNode = node => node && node.nodeType === 11 && isNode( node ); | ||
var isNode = s => ( typeof Node === 'object' ? s instanceof Node : s && typeof s === 'object' && typeof s.nodeType === 'number' && typeof s.nodeName === 'string' ); | ||
var isWindow = obj => obj && obj === obj.window; | ||
var textNode = node => node && node.nodeType === 3 && isNode( node ); | ||
var isClass = obj => isFunction( obj ) && /^\s*class\s+/.test( obj.toString() ); | ||
var elementNode = node => node && node.nodeType === 1 && isNode( node ); | ||
var ipv6 = ip => { | ||
/** | ||
* An IPv6 address should have at least one colon(:) | ||
*/ | ||
if( ip.indexOf( ':' ) < 0 ) return false; | ||
var fragmentNode = node => node && node.nodeType === 11 && isNode( node ); | ||
/** | ||
* An IPv6 address can start or end with '::', but cannot start or end with a single colon. | ||
*/ | ||
if( /(^:[^:])|([^:]:$)/.test( ip ) ) return false; | ||
var isWindow = obj => obj && obj === obj.window; | ||
/** | ||
* An IPv6 address should consist of colon(:), dot(.) and hexadecimel | ||
*/ | ||
if( !/^[0-9A-Fa-f:.]{2,}$/.test( ip ) ) return false; | ||
var isClass = obj => isFunction( obj ) && /^\s*class\s+/.test( obj.toString() ); | ||
/** | ||
* An IPv6 address should not have any sequence like: | ||
* 1. a hexadecimal that it's length greater than 4 | ||
* 2. three or more continous colons | ||
* 3. two or more continous dots | ||
*/ | ||
if( /[0-9A-Fa-f]{5,}|:{3,}|\.{2,}/.test( ip ) ) return false; | ||
var ipv6 = ip => { | ||
/** | ||
* An IPv6 address should have at least one colon(:) | ||
*/ | ||
if( ip.indexOf( ':' ) < 0 ) return false; | ||
/** | ||
* In an IPv6 address, the "::" can only appear once. | ||
*/ | ||
if( ip.split( '::' ).length > 2 ) return false; | ||
/** | ||
* An IPv6 address can start or end with '::', but cannot start or end with a single colon. | ||
*/ | ||
if( /(^:[^:])|([^:]:$)/.test( ip ) ) return false; | ||
/** | ||
* if the IPv6 address is in mixed form. | ||
*/ | ||
if( ip.indexOf( '.' ) > -1 ) { | ||
const lastColon = ip.lastIndexOf( ':' ); | ||
const hexadecimal = ip.substr( 0, lastColon ); | ||
const decimal = ip.substr( lastColon + 1 ); | ||
/** | ||
* the decimal part should be an valid IPv4 address. | ||
* An IPv6 address should consist of colon(:), dot(.) and hexadecimel | ||
*/ | ||
if( !ipv4( decimal ) ) return false; | ||
if( !/^[0-9A-Fa-f:.]{2,}$/.test( ip ) ) return false; | ||
/** | ||
* the length of the hexadecimal part should less than 6. | ||
* An IPv6 address should not have any sequence like: | ||
* 1. a hexadecimal that it's length greater than 4 | ||
* 2. three or more continous colons | ||
* 3. two or more continous dots | ||
*/ | ||
if( hexadecimal.split( ':' ).length > 6 ) return false; | ||
} else { | ||
if( /[0-9A-Fa-f]{5,}|:{3,}|\.{2,}/.test( ip ) ) return false; | ||
/** | ||
* An IPv6 address that is not in mixed form can at most have 8 hexadecimal sequences. | ||
* In an IPv6 address, the "::" can only appear once. | ||
*/ | ||
if( ip.split( ':' ).length > 8 ) return false; | ||
} | ||
return true; | ||
}; | ||
if( ip.split( '::' ).length > 2 ) return false; | ||
var isIP = ip => ipv4( ip ) || ipv6( ip ); | ||
/** | ||
* if the IPv6 address is in mixed form. | ||
*/ | ||
if( ip.indexOf( '.' ) > -1 ) { | ||
const lastColon = ip.lastIndexOf( ':' ); | ||
const hexadecimal = ip.substr( 0, lastColon ); | ||
const decimal = ip.substr( lastColon + 1 ); | ||
/** | ||
* the decimal part should be an valid IPv4 address. | ||
*/ | ||
if( !ipv4( decimal ) ) return false; | ||
/** | ||
* Private IPv4 address | ||
* | ||
* 10.0.0.0 ~ 10.255.255.255 | ||
* 172.16.0.0 ~ 172.31.255.255 | ||
* 192.168.0.0 ~ 192.168.255.255 | ||
*/ | ||
/** | ||
* the length of the hexadecimal part should less than 6. | ||
*/ | ||
if( hexadecimal.split( ':' ).length > 6 ) return false; | ||
} else { | ||
/** | ||
* An IPv6 address that is not in mixed form can at most have 8 hexadecimal sequences. | ||
*/ | ||
if( ip.split( ':' ).length > 8 ) return false; | ||
} | ||
return true; | ||
}; | ||
var isPrivateIPv4 = ip => { | ||
if( !ipv4( ip ) ) return false; | ||
if( /^10\..*/.test( ip ) ) return true; | ||
if( /^192\.168\..*/.test( ip ) ) return true; | ||
if( /^172\.(1[6-9]|2[0-9]|3[0-1])\..*/.test( ip ) ) return true; | ||
return false; | ||
}; | ||
var ip = ip => ipv4( ip ) || ipv6( ip ); | ||
var generator = fn => { | ||
try { | ||
return new Function( 'fn', 'return fn.constructor === (function*(){}).constructor' )( fn ); | ||
} catch( e ) { | ||
/** | ||
* Private IPv4 address | ||
* | ||
* 10.0.0.0 ~ 10.255.255.255 | ||
* 172.16.0.0 ~ 172.31.255.255 | ||
* 192.168.0.0 ~ 192.168.255.255 | ||
*/ | ||
var privateIPv4 = ip => { | ||
if( !ipv4( ip ) ) return false; | ||
if( /^10\..*/.test( ip ) ) return true; | ||
if( /^192\.168\..*/.test( ip ) ) return true; | ||
if( /^172\.(1[6-9]|2[0-9]|3[0-1])\..*/.test( ip ) ) return true; | ||
return false; | ||
} | ||
} | ||
}; | ||
var is = { | ||
arguments : isArguments, | ||
array: isArray, | ||
arrowFunction, | ||
asyncFunction: isAsyncFunction, | ||
boolean : isBoolean, | ||
date, | ||
email, | ||
empty, | ||
error, | ||
false : isFalse, | ||
function : isFunction, | ||
integer: isInteger, | ||
iterable, | ||
number: isNumber, | ||
object: isObject, | ||
plainObject, | ||
promise, | ||
regexp, | ||
string: isString, | ||
true : isTrue, | ||
undefined : isUndefined, | ||
url, | ||
node: isNode, | ||
textNode, | ||
elementNode, | ||
fragmentNode, | ||
window : isWindow, | ||
class : isClass, | ||
ip : isIP, | ||
ipv4 : ipv4, | ||
ipv6 : ipv6, | ||
privateIPv4 : isPrivateIPv4, | ||
generator | ||
}; | ||
var generator = fn => { | ||
try { | ||
return new Function( 'fn', 'return fn.constructor === (function*(){}).constructor' )( fn ); | ||
} catch( e ) { | ||
return false; | ||
} | ||
}; | ||
return is; | ||
var oneDimensionalArray = ( arr, strict ) => { | ||
if( !isArray( arr ) ) return false; | ||
for( const item of arr ) { | ||
if( !item ) continue; | ||
if( strict && isPlainObject( item ) ) return false; | ||
if( isArray( item ) ) return false; | ||
} | ||
return true; | ||
}; | ||
var is = { | ||
arguments : isArguments, | ||
array: isArray, | ||
arrowFunction, | ||
asyncFunction: isAsyncFunction, | ||
boolean : isBoolean, | ||
date, | ||
email, | ||
empty, | ||
error, | ||
false : isFalse, | ||
function : isFunction, | ||
integer: isInteger, | ||
iterable, | ||
number: isNumber, | ||
object: isObject, | ||
plainObject: isPlainObject, | ||
promise, | ||
regexp, | ||
string: isString, | ||
true : isTrue, | ||
undefined : isUndefined, | ||
url, | ||
node: isNode, | ||
textNode, | ||
elementNode, | ||
fragmentNode, | ||
window : isWindow, | ||
class : isClass, | ||
ip, | ||
ipv4, | ||
ipv6, | ||
privateIPv4, | ||
generator, | ||
oneDimensionalArray | ||
}; | ||
return is; | ||
}))); |
{ | ||
"name": "@lvchengbin/is", | ||
"version": "0.0.18", | ||
"description": "A library, which is possible to be imported as ES6 module separately, for checking the type of a value.", | ||
"keywords": "is check types es6", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:LvChengbin/is.git" | ||
}, | ||
"devDependencies": { | ||
"@lvchengbin/promise": "^1.1.5", | ||
"buble": "^0.19.3", | ||
"eslint": "^4.14.0", | ||
"jasmine-core": "^2.8.0", | ||
"karma": "^2.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-jasmine": "^1.1.1", | ||
"karma-rollup-preprocessor": "^5.0.2", | ||
"optimist": "^0.6.1", | ||
"pre-commit": "^1.2.2", | ||
"puppeteer": "^0.13.0", | ||
"rollup": "^0.53.3", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-node-resolve": "^3.0.2" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"test": "karma start", | ||
"test-basic": "karma start --file=test/basic.spec.js", | ||
"test-basic-es5": "karma start --file=test/basic.spec.js --es5=true", | ||
"test-advanced": "karma start --file=test/advanced.spec.js", | ||
"prepublish": "npm run build", | ||
"lint": "eslint ./ --cache --ignore-path .eslintignore", | ||
"precommit-msg": "echo 'Pre-commit checks...' && exit 0" | ||
}, | ||
"pre-commit": [ | ||
"precommit-msg", | ||
"lint" | ||
], | ||
"main": "dist/is.cjs.js", | ||
"jsnext:main": "src/is.js", | ||
"author": "LvChengbin", | ||
"license": "MIT", | ||
"dependencies": {} | ||
"name": "@lvchengbin/is", | ||
"version": "0.0.19", | ||
"description": "A library, which is possible to be imported as ES6 module separately, for checking the type of a value.", | ||
"keywords": "is check types es6", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:LvChengbin/is.git" | ||
}, | ||
"devDependencies": { | ||
"@lvchengbin/promise": "^1.1.7", | ||
"buble": "^0.19.3", | ||
"eslint": "^4.19.1", | ||
"jasmine-core": "^2.99.1", | ||
"karma": "^2.0.4", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-jasmine": "^1.1.2", | ||
"karma-rollup-preprocessor": "^5.1.1", | ||
"optimist": "^0.6.1", | ||
"pre-commit": "^1.2.2", | ||
"puppeteer": "^0.13.0", | ||
"rollup": "^0.53.4", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-node-resolve": "^3.3.0" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"test": "karma start", | ||
"test-basic": "karma start --file=test/basic.spec.js", | ||
"test-basic-es5": "karma start --file=test/basic.spec.js --es5=true", | ||
"test-advanced": "karma start --file=test/advanced.spec.js", | ||
"prepublish": "npm run build", | ||
"lint": "eslint ./ --cache --ignore-path .eslintignore", | ||
"precommit-msg": "echo 'Pre-commit checks...' && exit 0" | ||
}, | ||
"pre-commit": [ | ||
"precommit-msg", | ||
"lint" | ||
], | ||
"main": "dist/is.cjs.js", | ||
"jsnext:main": "src/is.js", | ||
"author": "LvChengbin", | ||
"license": "MIT", | ||
"dependencies": {} | ||
} |
@@ -79,2 +79,3 @@ # Is | ||
| is.elementNode | import isElementNode from '@lvchengbin/is/src/element-node' | | ||
| is.fragmentNode | import isFragmentNode from '@lvchengbin/is/src/fragment-node' | | ||
| is.window | import isWindow from '@lvchengbin/is/src/window' | | ||
@@ -86,2 +87,3 @@ | is.class | import isClass from '@lvchengbin/is/src/class' | | ||
| is.generator | import isGenerator from '@lvchengbin/is/src/generator' | | ||
| is.oneDimensionalArray | import isOneDimensionalArray from '@lvchengbin/is/src/one-dimensional-array | | ||
@@ -88,0 +90,0 @@ ### is.date |
@@ -29,7 +29,8 @@ import isArguments from './arguments'; | ||
import isClass from './class'; | ||
import isIP from './ip'; | ||
import isIPv4 from './ipv4'; | ||
import isIPv6 from './ipv6'; | ||
import isPrivateIPv4 from './private-ipv4'; | ||
import ip from './ip'; | ||
import ipv4 from './ipv4'; | ||
import ipv6 from './ipv6'; | ||
import privateIPv4 from './private-ipv4'; | ||
import generator from './generator'; | ||
import oneDimensionalArray from './one-dimensional-array'; | ||
@@ -65,7 +66,8 @@ export default { | ||
class : isClass, | ||
ip : isIP, | ||
ipv4 : isIPv4, | ||
ipv6 : isIPv6, | ||
privateIPv4 : isPrivateIPv4, | ||
generator | ||
ip, | ||
ipv4, | ||
ipv6, | ||
privateIPv4, | ||
generator, | ||
oneDimensionalArray | ||
}; |
@@ -28,3 +28,3 @@ import isString from './string'; | ||
/** | ||
* In IE, invalid IP address could be a valid hostname | ||
* In IE, invalid IP address is allowed | ||
*/ | ||
@@ -31,0 +31,0 @@ if( /^(\d+\.){3}\d+$/.test( a.hostname ) && !isIPv4( a.hostname ) ) return false; |
62655
48
1205
135