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

isa.js

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isa.js - npm Package Compare versions

Comparing version 2.2.17 to 2.2.18

237

IsA.js

@@ -1,21 +0,21 @@

var boolTag = '[object Boolean]',
dateTag = '[object Date]',
errorTag = '[object Error]',
funcTag = '[object Function]',
afuncTag = '[object AsyncFunction]',
numberTag = '[object Number]',
objectTag = '[object Object]',
regexpTag = '[object RegExp]',
stringTag = '[object String]'
var boolTag = "[object Boolean]",
dateTag = "[object Date]",
errorTag = "[object Error]",
funcTag = "[object Function]",
afuncTag = "[object AsyncFunction]",
numberTag = "[object Number]",
objectTag = "[object Object]",
regexpTag = "[object RegExp]",
stringTag = "[object String]";
var objectProto = Object.prototype
var objectProto = Object.prototype;
var objToString = objectProto.toString
var fnToString = Function.prototype.toString
var objCtorString = fnToString.call(Object)
var objToString = objectProto.toString;
var fnToString = Function.prototype.toString;
var objCtorString = fnToString.call(Object);
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg
var ARGUMENT_NAMES = /([^\s,]+)/g
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;
var ARGUMENT_NAMES = /([^\s,]+)/g;
var NAME_PATTERN = /([\\.A-Za-z]+)/g
var NAME_PATTERN = /([\\.A-Za-z]+)/g;

@@ -25,139 +25,180 @@ let Services = {

isHostObject: function (value) {
var result = false
if (value !== null && typeof value.toString !== 'function') {
var result = false;
if (value !== null && typeof value.toString !== "function") {
try {
result = !!(value + '')
result = !!(value + "");
} catch (e) {}
}
return result
return result;
},
isDefined (value) {
return value !== undefined && value !== null
isDefined(value) {
return value !== undefined && value !== null;
},
isIterable (obj) {
if ( !Services.isDefined(obj) )
return false
isIterable(obj) {
if (!Services.isDefined(obj)) return false;
return typeof obj[Symbol.iterator] === 'function'
return typeof obj[Symbol.iterator] === "function";
},
isPromise (p) {
return p && Object.prototype.toString.call(p) === '[object Promise]'
isPromise(p) {
return p && Object.prototype.toString.call(p) === "[object Promise]";
},
isPlainObject: function (value) {
if (!this.isObjectLike(value) || objToString.call(value) !== objectTag || this.isHostObject(value)) {
return false
if (
!this.isObjectLike(value) ||
objToString.call(value) !== objectTag ||
this.isHostObject(value)
) {
return false;
}
var proto = typeof value.constructor === 'function' ? this.getPrototypeOf(value) : objectProto
var proto =
typeof value.constructor === "function"
? this.getPrototypeOf(value)
: objectProto;
if (proto === null) {
return true
return true;
}
var Ctor = proto.constructor
return (typeof Ctor === 'function' && Ctor instanceof Ctor && fnToString.call(Ctor) === objCtorString)
var Ctor = proto.constructor;
return (
typeof Ctor === "function" &&
Ctor instanceof Ctor &&
fnToString.call(Ctor) === objCtorString
);
},
isObjectLike: function (value) {
return !!value && typeof value === 'object'
return !!value && typeof value === "object";
},
isArray: Array.isArray,
isObject: function (value) {
var type = typeof value
return !!value && (type === 'object' || type === 'function')
var type = typeof value;
return !!value && (type === "object" || type === "function");
},
isError: function (value) {
return this.isObjectLike(value) && typeof value.message === 'string' && objToString.call(value) === errorTag
return (
this.isObjectLike(value) &&
typeof value.message === "string" &&
objToString.call(value) === errorTag
);
},
isNumber: function (value) {
return typeof value === 'number' || (this.isObjectLike(value) && objToString.call(value) === numberTag)
return (
typeof value === "number" ||
(this.isObjectLike(value) && objToString.call(value) === numberTag)
);
},
isDate: function (value) {
return this.isObjectLike(value) && objToString.call(value) === dateTag
return this.isObjectLike(value) && objToString.call(value) === dateTag;
},
isFunction: function (value) {
return this.isObject(value) && (objToString.call(value) === funcTag || objToString.call(value) === afuncTag)
return (
this.isObject(value) &&
(objToString.call(value) === funcTag ||
objToString.call(value) === afuncTag)
);
},
isSyncFunction: function (value) {
return this.isObject(value) && objToString.call(value) === funcTag
return this.isObject(value) && objToString.call(value) === funcTag;
},
isAsyncFunction: function (value) {
return this.isObject(value) && objToString.call(value) === afuncTag
return this.isObject(value) && objToString.call(value) === afuncTag;
},
isBoolean: function (value) {
return value === true || value === false || (this.isObjectLike(value) && objToString.call(value) === boolTag)
return (
value === true ||
value === false ||
(this.isObjectLike(value) && objToString.call(value) === boolTag)
);
},
isString: function (value) {
return typeof value === 'string' || ( this.isObjectLike(value) && objToString.call(value) === stringTag)
return (
typeof value === "string" ||
(this.isObjectLike(value) && objToString.call(value) === stringTag)
);
},
isRegExp: function (value) {
return this.isObject(value) && objToString.call(value) === regexpTag
return this.isObject(value) && objToString.call(value) === regexpTag;
},
isPrimitive: function (value) {
return (
Services.isString(value) ||
Services.isBoolean(value) ||
Services.isNumber(value) ||
Services.isDate(value)
);
},
walk: function (object, path, defaultValue) {
if ( !path ) return defaultValue
if (!path) return defaultValue;
let oPath = Array.isArray(path) ? path : path.split('.')
let oPath = Array.isArray(path) ? path : path.split(".");
if ( !object && oPath.length === 0 ) return true
for ( let key of oPath ) {
if ( !object || !object[key] ) return defaultValue
object = object[ key ]
if (!object && oPath.length === 0) return true;
for (let key of oPath) {
if (!object || !object[key]) return defaultValue;
object = object[key];
}
return object || defaultValue
return object || defaultValue;
},
isValidPath: function (object, path) {
return !!Services.walk(object, path, null)
return !!Services.walk(object, path, null);
},
parameterNames: function ( func ) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '')
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES)
if (result === null)
result = []
result = result.map( ( p ) => {
var index = p.indexOf('=')
return (index === -1) ? p : p.substring( 0, index )
} )
result = result.filter( ( p ) => {
return p.length > 0 && p.match( NAME_PATTERN )
} )
return result
parameterNames: function (func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, "");
var result = fnStr
.slice(fnStr.indexOf("(") + 1, fnStr.indexOf(")"))
.match(ARGUMENT_NAMES);
if (result === null) result = [];
result = result.map((p) => {
var index = p.indexOf("=");
return index === -1 ? p : p.substring(0, index);
});
result = result.filter((p) => {
return p.length > 0 && p.match(NAME_PATTERN);
});
return result;
},
pick: function (object, predicate, ignore, target ) {
if (!object)
return {}
pick: function (object, predicate, ignore, target) {
if (!object) return {};
if (!predicate)
predicate = Object.keys( object )
else if (!Array.isArray(predicate))
predicate = Object.keys( predicate )
if (!predicate) predicate = Object.keys(object);
else if (!Array.isArray(predicate)) predicate = Object.keys(predicate);
if (!ignore)
ignore = []
else if (!Array.isArray(ignore))
ignore = Object.keys( ignore )
if (!ignore) ignore = [];
else if (!Array.isArray(ignore)) ignore = Object.keys(ignore);
let res = target || {}
let res = target || {};
for (let key of predicate)
if (!ignore.includes(key) && object.hasOwnProperty(key) )
res[ key ] = object[key]
return res
if (!ignore.includes(key) && object.hasOwnProperty(key))
res[key] = object[key];
return res;
},
functionsOf (obj, asyncOnly = false) {
let res = []
if (!obj) return res
functionsOf(obj, asyncOnly = false) {
let res = [];
if (!obj) return res;
for (let m in obj)
if ( obj[m] && ( asyncOnly ? this.isAsyncFunction( obj[m] ) : this.isFunction( obj[m] ) ) )
res.push( obj[m] )
return res
if (
obj[m] &&
(asyncOnly
? this.isAsyncFunction(obj[m])
: this.isFunction(obj[m]))
)
res.push(obj[m]);
return res;
},
functionNames (obj, asyncOnly = false) {
let res = []
if (!obj) return res
functionNames(obj, asyncOnly = false) {
let res = [];
if (!obj) return res;
for (let m in obj)
if ( obj[m] && (asyncOnly ? this.isAsyncFunction( obj[m] ) : this.isFunction( obj[m] ) ) )
res.push( m )
return res
}
if (
obj[m] &&
(asyncOnly
? this.isAsyncFunction(obj[m])
: this.isFunction(obj[m]))
)
res.push(m);
return res;
},
};
}
module.exports = Services
module.exports = Services;
{
"name": "isa.js",
"version": "2.2.17",
"description": "Very minimal collection is isA functions. isObject, isArray, isDate...",
"homepage": "https://github.com/imrefazekas/isa",
"keywords": [
"validation"
],
"repository": {
"type": "git",
"url": "git://github.com/imrefazekas/isa.git"
},
"bugs": {
"url": "http://github.com/imrefazekas/isa/issues"
},
"author": {
"name": "Imre Fazekas",
"email": "mail@imrefazekas.me"
},
"license": "MIT",
"main": "IsA.js",
"types": "./index.d.ts",
"scripts": {},
"devDependencies": {
"chai": "^4.3.6"
},
"dependencies": {},
"browser": {
"fs": false,
"child_process": false
},
"engines": {
"node": ">= 4.0.0"
}
"name": "isa.js",
"version": "2.2.18",
"description": "Very minimal collection is isA functions. isObject, isArray, isDate...",
"homepage": "https://github.com/imrefazekas/isa",
"keywords": [
"validation"
],
"repository": {
"type": "git",
"url": "git://github.com/imrefazekas/isa.git"
},
"bugs": {
"url": "http://github.com/imrefazekas/isa/issues"
},
"author": {
"name": "Imre Fazekas",
"email": "mail@imrefazekas.me"
},
"license": "MIT",
"main": "IsA.js",
"types": "./index.d.ts",
"scripts": {},
"devDependencies": {
"chai": "^4.5.0"
},
"dependencies": {},
"browser": {
"fs": false,
"child_process": false
},
"engines": {
"node": ">= 4.0.0"
}
}
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