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

extension-props

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extension-props - npm Package Compare versions

Comparing version 0.9.4 to 0.9.5

lib/errors.d.ts

10

lib/index.d.ts

@@ -0,9 +1,9 @@

import { type as ArrayType } from './types/ArrayType';
import { type as ClassType } from './types/ClassType';
import { type as FunctionType } from './types/FunctionType';
import { type as ObjectType } from './types/ObjectType';
import { type as ArrayType } from './types/ArrayType';
import { type as RegularType } from './types/RegularType';
import { type as StringType } from './types/StringType';
import { type as RegularType } from './types/RegularType';
import { type as FunctionType } from './types/FunctionType';
import { type as ClassType } from './types/ClassType';
export { default as OverridingError } from './errors/OverridingError';
export * from './errors';
export { ObjectType, ArrayType, ClassType, FunctionType, RegularType, StringType };
export declare function extend(): void;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var standard_1 = __importDefault(require("./standard"));
var ArrayType_1 = require("./types/ArrayType");
exports.ArrayType = ArrayType_1.type;
var ClassType_1 = require("./types/ClassType");
exports.ClassType = ClassType_1.type;
var FunctionType_1 = require("./types/FunctionType");
exports.FunctionType = FunctionType_1.type;
var ObjectType_1 = require("./types/ObjectType");
exports.ObjectType = ObjectType_1.type;
var ArrayType_1 = require("./types/ArrayType");
exports.ArrayType = ArrayType_1.type;
var RegularType_1 = require("./types/RegularType");
exports.RegularType = RegularType_1.type;
var StringType_1 = require("./types/StringType");
exports.StringType = StringType_1.type;
var RegularType_1 = require("./types/RegularType");
exports.RegularType = RegularType_1.type;
var FunctionType_1 = require("./types/FunctionType");
exports.FunctionType = FunctionType_1.type;
var ClassType_1 = require("./types/ClassType");
exports.ClassType = ClassType_1.type;
standard_1.default();
var OverridingError_1 = require("./errors/OverridingError");
exports.OverridingError = OverridingError_1.default;
__export(require("./errors"));
function extend() {

@@ -23,0 +20,0 @@ ObjectType_1.extend();

@@ -1,13 +0,10 @@

import {default as standard} from './standard';
import {extend as extendArray, type as ArrayType} from './types/ArrayType';
import {extend as extendClass, type as ClassType} from './types/ClassType';
import {extend as extendFunction, type as FunctionType} from './types/FunctionType';
import {extend as extendObject, type as ObjectType} from './types/ObjectType';
import {extend as extendArray, type as ArrayType} from './types/ArrayType';
import {extend as extendRegular, type as RegularType} from './types/RegularType';
import {extend as extendString, type as StringType} from './types/StringType';
import {extend as extendRegular, type as RegularType} from './types/RegularType';
import {extend as extendFunction, type as FunctionType} from './types/FunctionType';
import {extend as extendClass, type as ClassType} from './types/ClassType';
standard();
export * from './errors';
export {default as OverridingError} from './errors/OverridingError';
export {

@@ -14,0 +11,0 @@ ObjectType,

@@ -1,9 +0,2 @@

/**
* Check value is instance of Array
* @param v the value
* @returns {boolean}
*/
declare function forInstance(v: any): boolean;
declare function isBlank(v: any): boolean;
declare function isNotBlank(v: any): boolean;
import { forInstance, isBlank, isNotBlank } from '../utils/Array';
interface ArrayType<T> {

@@ -10,0 +3,0 @@ equals(v: T[]): boolean;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Check value is instance of Array
* @param v the value
* @returns {boolean}
*/
function forInstance(v) {
return v instanceof Array;
var Array_1 = require("../utils/Array");
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', { value: Array_1.includes });
}
function equals(array) {
if (!(this instanceof Array) || !(array instanceof Array) || this.length !== array.length)
return false;
for (var i = 0, l = this.length; i < l; i++) {
if (typeof this[i] === typeof array[i] && this[i].equals instanceof Function && array[i].equals instanceof Function) {
if (!this[i].equals(array[i]))
return false;
}
else if (this[i] !== array[i])
return false;
}
return true;
}
function virtualGet(i) {
if (!(this instanceof Array) || typeof i !== 'number' || !Number.isInteger(i) || this.length === 0)
return undefined;
if (i >= 0 && i < this.length)
return this[i];
else
return this[((i % this.length) + this.length) % this.length];
}
function insert(i) {
var element = [];
for (var _i = 1; _i < arguments.length; _i++) {
element[_i - 1] = arguments[_i];
}
if (this instanceof Array)
this.splice.apply(this, [i, 0].concat(element));
return this;
}
function lastIndexOf(o) {
if (this instanceof Array) {
for (var i = this.length - 1; i >= 0; i--) {
if (o == this[i] || (o.equals && o.equals(this[i])))
return i;
}
}
return -1;
}
function isEmpty() {
return isBlank(this);
}
function isNotEmpty() {
return isNotBlank(this);
}
function isBlank(v) {
return !(v instanceof Array) || v.length == 0;
}
function isNotBlank(v) {
return v instanceof Array && v.length > 0;
}
function valueOf(v) {
if (!forInstance(v))
if (!Array_1.forInstance(v))
return undefined;
return {
equals: equals.bind(v),
virtualGet: virtualGet.bind(v),
insert: insert.bind(v),
lastIndexOf: lastIndexOf.bind(v),
isEmpty: isEmpty.bind(v),
isNotEmpty: isNotEmpty.bind(v)
equals: Array_1.equals.bind(v),
virtualGet: Array_1.virtualGet.bind(v),
insert: Array_1.insert.bind(v),
lastIndexOf: Array_1.lastIndexOf.bind(v),
isEmpty: Array_1.isEmpty.bind(v),
isNotEmpty: Array_1.isNotEmpty.bind(v)
};
}
exports.type = {
forInstance: forInstance,
isBlank: isBlank,
isNotBlank: isNotBlank,
forInstance: Array_1.forInstance,
isBlank: Array_1.isBlank,
isNotBlank: Array_1.isNotBlank,
valueOf: valueOf
};
function extend() {
Array.isBlank = isBlank;
Array.isNotBlank = isNotBlank;
Array.forInstance = forInstance;
Array.prototype.equals = equals;
Array.prototype.virtualGet = virtualGet;
Array.prototype.insert = insert;
Array.prototype.lastIndexOf = lastIndexOf;
Array.prototype.isEmpty = isEmpty;
Array.prototype.isNotEmpty = isNotEmpty;
Array.isBlank = Array_1.isBlank;
Array.isNotBlank = Array_1.isNotBlank;
Array.forInstance = Array_1.forInstance;
Array.prototype.equals = Array_1.equals;
Array.prototype.virtualGet = Array_1.virtualGet;
Array.prototype.insert = Array_1.insert;
Array.prototype.lastIndexOf = Array_1.lastIndexOf;
Array.prototype.isEmpty = Array_1.isEmpty;
Array.prototype.isNotEmpty = Array_1.isNotEmpty;
}
exports.extend = extend;

@@ -1,59 +0,18 @@

/**
* Check value is instance of Array
* @param v the value
* @returns {boolean}
*/
function forInstance(v: any): boolean {
return v instanceof Array;
}
import {
equals,
forInstance,
includes,
insert,
isBlank,
isEmpty,
isNotBlank,
isNotEmpty,
lastIndexOf,
virtualGet
} from '../utils/Array';
function equals(array: any[]): boolean {
if (!(this instanceof Array) || !(array instanceof Array) || this.length !== array.length) return false;
for (let i = 0, l = this.length; i < l; i++) {
if (typeof this[i] === typeof array[i] && this[i].equals instanceof Function && array[i].equals instanceof Function) {
if (!this[i].equals(array[i])) return false;
} else if (this[i] !== array[i]) return false;
}
return true;
if (!Array.prototype.includes) {
Object.defineProperty(Array.prototype, 'includes', {value: includes});
}
function virtualGet(i: number): any {
if (!(this instanceof Array) || typeof i !== 'number' || !Number.isInteger(i) || this.length === 0)
return undefined;
if (i >= 0 && i < this.length) return this[i];
else return this[((i % this.length) + this.length) % this.length];
}
function insert(i: number, ...element: any[]): any[] {
if (this instanceof Array)
this.splice(i, 0, ...element);
return this;
}
function lastIndexOf(o: any): number {
if (this instanceof Array) {
for (let i = this.length - 1; i >= 0; i--) {
if (o == this[i] || (o.equals && o.equals(this[i]))) return i;
}
}
return -1;
}
function isEmpty(): boolean {
return isBlank(this);
}
function isNotEmpty(): boolean {
return isNotBlank(this);
}
function isBlank(v: any): boolean {
return !(v instanceof Array) || v.length == 0;
}
function isNotBlank(v: any): boolean {
return v instanceof Array && v.length > 0;
}
interface ArrayType<T> {

@@ -60,0 +19,0 @@ equals(v: T[]): boolean;

@@ -1,6 +0,2 @@

declare function forInstance(v: any): boolean;
declare function defineClass(name: string, superClass?: Function, prototype?: Function): any;
declare function isClass(v: any): boolean;
declare function preventOverrideClass(obj: any, classDefinition: any, except?: any[]): boolean;
declare function preventOverrideFunction(obj: any, classDefinition: any, functions: string[]): boolean;
import { classForInstance, defineClass, isClass, isES6Class, preventOverrideClass, preventOverrideFunction } from '../utils/ClassAndFunction';
interface FunctionType {

@@ -14,5 +10,6 @@ defineClass(name: string, superClass?: any): any;

export declare const type: {
forInstance: typeof forInstance;
forInstance: typeof classForInstance;
isClass: typeof isClass;
defineClass: typeof defineClass;
isES6Class: typeof isES6Class;
preventOverrideClass: typeof preventOverrideClass;

@@ -19,0 +16,0 @@ preventOverrideFunction: typeof preventOverrideFunction;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var OverridingError_1 = __importDefault(require("../errors/OverridingError"));
function forInstance(v) {
return v instanceof Function && v.prototype instanceof Object;
}
function inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function defineFunctionClass(name, _superClass, _prototype) {
var temp;
var statements = 'temp = function ' + name + '() {\n';
if (_superClass)
statements += ' var _this = _superClass.apply(this, arguments) || this;\n';
else
statements += ' var _this = this;\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' return _prototype.apply(_this, arguments) || _this;\n';
else {
statements += ' _prototype(arguments);\n' +
' return _this;\n';
}
}
else
statements += ' return _this;\n';
statements += '}';
eval(statements);
return temp;
}
function defineES5Class(name, superClass, prototype) {
var subClass = defineFunctionClass(name, superClass, prototype);
if (superClass && superClass.prototype instanceof Object)
inheritsLoose(subClass, superClass);
return subClass;
}
function defineES6Class(name, _superClass, _prototype) {
var temp;
var statements = 'temp = class ' + name;
if (_superClass && _superClass.prototype instanceof Object)
statements += ' extends _superClass';
statements += ' {\n' +
' constructor() {\n' +
' super(...arguments);\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' _prototype.apply(this, arguments);\n';
else
statements += ' _prototype(arguments);\n';
}
statements += ' }\n' +
'}';
eval(statements);
return temp;
}
function defineClass(name, superClass, prototype) {
var temp;
if (typeof name !== 'string')
return undefined;
try {
temp = defineES6Class(name, superClass, prototype);
}
catch (e) {
temp = defineES5Class(name, superClass, prototype);
}
return temp;
}
function isClass(v) {
if (forInstance(v)) {
var props = Object.getOwnPropertyNames(v);
if (props.includes('arguments') || props.includes('caller'))
return false;
return true;
}
else
return false;
}
function preventOverrideClass(obj, classDefinition, except) {
if (forInstance(obj) && obj['__proto__'] instanceof classDefinition) {
var error = true;
if (except) {
for (var _i = 0, except_1 = except; _i < except_1.length; _i++) {
var i = except_1[_i];
if (obj instanceof i) {
error = false;
break;
}
}
}
if (error) {
throw new OverridingError_1.default('You can\'t override the [ClassName] class.'
.replace('[ClassName]', classDefinition['name']));
}
return true;
}
return false;
}
function dynamicPreventOverrideClass(classDefinition, except) {
return preventOverrideClass(this, classDefinition, except);
}
function preventOverrideFunction(obj, classDefinition, functions) {
if (forInstance(obj) && obj instanceof classDefinition &&
obj['__proto__'] !== undefined && obj['__proto__'] !== null) {
var nObj = this;
while (nObj instanceof classDefinition) {
for (var _i = 0, functions_1 = functions; _i < functions_1.length; _i++) {
var i = functions_1[_i];
if (typeof i === 'string' && nObj.hasOwnProperty(i))
throw new OverridingError_1.default('You can\'t override the [FunctionName] in any subclasses of the [ClassName] class.'
.replace('[FunctionName]', i)
.replace('[ClassName]', classDefinition['name']));
}
nObj = nObj['__proto__'];
}
return true;
}
else
return false;
}
function dynamicPreventOverrideFunction(classDefinition, functions) {
return preventOverrideFunction(this, classDefinition, functions);
}
function subclassOf(superClass) {
return this instanceof Function && this.prototype instanceof superClass;
}
var ClassAndFunction_1 = require("../utils/ClassAndFunction");
function valueOf(v) {
if (!forInstance(v))
if (!ClassAndFunction_1.classForInstance(v))
return undefined;
return {
defineClass: function (name, superClass) {
return defineClass(name, superClass, v);
return ClassAndFunction_1.defineClass(name, superClass, v);
},
preventOverrideClass: dynamicPreventOverrideClass.bind(v),
preventOverrideFunction: dynamicPreventOverrideFunction.bind(v),
subclassOf: subclassOf.bind(v)
preventOverrideClass: ClassAndFunction_1.dynamicPreventOverrideClass.bind(v),
preventOverrideFunction: ClassAndFunction_1.dynamicPreventOverrideFunction.bind(v),
subclassOf: ClassAndFunction_1.subclassOf.bind(v)
};
}
exports.type = {
forInstance: forInstance,
isClass: isClass,
defineClass: defineClass,
preventOverrideClass: preventOverrideClass,
preventOverrideFunction: preventOverrideFunction,
forInstance: ClassAndFunction_1.classForInstance,
isClass: ClassAndFunction_1.isClass,
defineClass: ClassAndFunction_1.defineClass,
isES6Class: ClassAndFunction_1.isES6Class,
preventOverrideClass: ClassAndFunction_1.preventOverrideClass,
preventOverrideFunction: ClassAndFunction_1.preventOverrideFunction,
valueOf: valueOf
};
function extend() {
Function.defineClass = defineClass;
Function.isClass = isClass;
Function.subclassOf = subclassOf;
Object.preventOverrideClass = preventOverrideClass;
Object.preventOverrideFunction = preventOverrideFunction;
Object.prototype.preventOverrideClass = dynamicPreventOverrideClass;
Object.prototype.preventOverrideFunction = dynamicPreventOverrideFunction;
Function.defineClass = ClassAndFunction_1.defineClass;
Function.isClass = ClassAndFunction_1.isClass;
Function.subclassOf = ClassAndFunction_1.subclassOf;
Function.isES6Class = ClassAndFunction_1.isES6Class;
Object.preventOverrideClass = ClassAndFunction_1.preventOverrideClass;
Object.preventOverrideFunction = ClassAndFunction_1.preventOverrideFunction;
Object.prototype.preventOverrideClass = ClassAndFunction_1.dynamicPreventOverrideClass;
Object.prototype.preventOverrideFunction = ClassAndFunction_1.dynamicPreventOverrideFunction;
}
exports.extend = extend;

@@ -1,130 +0,13 @@

import OverridingError from '../errors/OverridingError';
import {
classForInstance,
defineClass,
dynamicPreventOverrideClass,
dynamicPreventOverrideFunction,
isClass,
isES6Class,
preventOverrideClass,
preventOverrideFunction,
subclassOf
} from '../utils/ClassAndFunction';
function forInstance(v: any): boolean {
return v instanceof Function && v.prototype instanceof Object;
}
function inheritsLoose(subClass, superClass): void {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function defineFunctionClass(name: string, _superClass, _prototype?: Function): Function {
let temp;
let statements = 'temp = function ' + name + '() {\n';
if (_superClass)
statements += ' var _this = _superClass.apply(this, arguments) || this;\n';
else
statements += ' var _this = this;\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' return _prototype.apply(_this, arguments) || _this;\n';
else {
statements += ' _prototype(arguments);\n' +
' return _this;\n';
}
} else statements += ' return _this;\n';
statements += '}';
eval(statements);
return temp;
}
function defineES5Class(name: string, superClass, prototype?: Function): Function {
const subClass = defineFunctionClass(name, superClass, prototype);
if (superClass && superClass.prototype instanceof Object)
inheritsLoose(subClass, superClass);
return subClass;
}
function defineES6Class(name: string, _superClass, _prototype?: Function) {
let temp;
let statements = 'temp = class ' + name;
if (_superClass && _superClass.prototype instanceof Object)
statements += ' extends _superClass';
statements += ' {\n' +
' constructor() {\n' +
' super(...arguments);\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' _prototype.apply(this, arguments);\n';
else statements += ' _prototype(arguments);\n';
}
statements += ' }\n' +
'}';
eval(statements);
return temp;
}
function defineClass(name: string, superClass?: Function, prototype?: Function) {
let temp;
if (typeof name !== 'string') return undefined;
try {
temp = defineES6Class(name, superClass, prototype);
} catch (e) {
temp = defineES5Class(name, superClass, prototype);
}
return temp;
}
function isClass(v: any): boolean {
if (forInstance(v)) {
const props: string[] = Object.getOwnPropertyNames(v);
if (props.includes('arguments') || props.includes('caller'))
return false;
return true;
} else return false;
}
function preventOverrideClass(obj: any, classDefinition: any, except?: any[]): boolean {
if (forInstance(obj) && obj['__proto__'] instanceof classDefinition) {
let error = true;
if (except) {
for (let i of except) {
if (obj instanceof i) {
error = false;
break;
}
}
}
if (error) {
throw new OverridingError('You can\'t override the [ClassName] class.'
.replace('[ClassName]', classDefinition['name']));
}
return true;
}
return false;
}
function dynamicPreventOverrideClass(classDefinition: any, except?: any[]): boolean {
return preventOverrideClass(this, classDefinition, except);
}
function preventOverrideFunction(obj: any, classDefinition: any, functions: string[]): boolean {
if (forInstance(obj) && obj instanceof classDefinition &&
obj['__proto__'] !== undefined && obj['__proto__'] !== null) {
let nObj = this;
while (nObj instanceof classDefinition) {
for (let i of functions) {
if (typeof i === 'string' && nObj.hasOwnProperty(i))
throw new OverridingError('You can\'t override the [FunctionName] in any subclasses of the [ClassName] class.'
.replace('[FunctionName]', i)
.replace('[ClassName]', classDefinition['name']));
}
nObj = nObj['__proto__'];
}
return true;
} else return false;
}
function dynamicPreventOverrideFunction(classDefinition: any, functions: string[]): boolean {
return preventOverrideFunction(this, classDefinition, functions);
}
function subclassOf(superClass: any): boolean {
return this instanceof Function && this.prototype instanceof superClass;
}
interface FunctionType {

@@ -141,3 +24,3 @@ defineClass(name: string, superClass?: any);

function valueOf(v: any): FunctionType | undefined {
if (!forInstance(v)) return undefined;
if (!classForInstance(v)) return undefined;
return {

@@ -154,5 +37,6 @@ defineClass(name: string, superClass) {

export const type = {
forInstance,
forInstance: classForInstance,
isClass,
defineClass,
isES6Class,
preventOverrideClass,

@@ -167,2 +51,3 @@ preventOverrideFunction,

Function.subclassOf = subclassOf;
Function.isES6Class = isES6Class;

@@ -169,0 +54,0 @@ Object.preventOverrideClass = preventOverrideClass;

@@ -1,8 +0,2 @@

declare function forInstance(v: any): boolean;
declare function defineFunction(name: string, _prototype?: Function): Function | undefined;
declare function isNormalFunction(f: Function): boolean;
declare function isAsyncFunction(f: Function): boolean;
declare function isSyncFunction(f: Function): boolean;
declare function isArrowFunction(f: Function): boolean;
declare function isNonArrowFunction(f: Function): boolean;
import { defineFunction, functionForInstance, isArrowFunction, isAsyncFunction, isNonArrowFunction, isNormalFunction, isSyncFunction } from '../utils/ClassAndFunction';
interface FunctionType {

@@ -15,3 +9,3 @@ clone(): Function;

export declare const type: {
forInstance: typeof forInstance;
forInstance: typeof functionForInstance;
defineFunction: typeof defineFunction;

@@ -18,0 +12,0 @@ isNormalFunction: typeof isNormalFunction;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ClassType_1 = require("./ClassType");
function forInstance(v) {
return v instanceof Function;
}
function clone() {
if (!(this instanceof Function))
return undefined;
var that = this;
var temp = function temporary() {
return that.apply(this, arguments);
};
var key;
for (key in this) {
if (this.hasOwnProperty(key))
temp[key] = this[key];
}
return temp;
}
function defineFunction(name, _prototype) {
if (typeof name !== 'string')
return undefined;
var temp;
var statements = 'temp = function ' + name + '() {\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' return _prototype.apply(this, arguments)\n';
else
statements += ' return _prototype(arguments)\n';
}
statements += '}';
eval(statements);
return temp;
}
function dynamicDefineFunction(name) {
if (!(this instanceof Function))
return undefined;
return defineFunction(name, this);
}
function defineClass(name, superClass) {
return ClassType_1.type.defineClass(name, superClass, this);
}
function isNormalFunction(f) {
return f instanceof Function && f.prototype !== undefined;
}
function isAsyncFunction(f) {
if (f instanceof Function && f.prototype === undefined) {
try {
return f[Symbol.toStringTag] === 'AsyncFunction';
}
catch (e) {
return /^\s*async/.test(f.toString());
}
}
else
return false;
}
function isSyncFunction(f) {
if (f instanceof Function) {
try {
return f[Symbol.toStringTag] !== 'AsyncFunction';
}
catch (e) {
return !/^\s*async/.test(f.toString());
}
}
else
return false;
}
function isArrowFunction(f) {
if (f instanceof Function && f.prototype === undefined) {
var fstr = f.toString();
if (/^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr))
return false;
return /^[a-zA-Z0-9_]+\s*=>/.test(fstr) || /^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) ||
/^\([^]*\)\s*=>/.test(fstr) || /^\s*async\s*\([^]*\)\s*=>/.test(fstr);
}
else
return false;
}
function isNonArrowFunction(f) {
if (f instanceof Function) {
var fstr = f.toString();
if (f.prototype !== undefined || /^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr))
return true;
return !/^[a-zA-Z0-9_]+\s*=>/.test(fstr) && !/^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) &&
!/^\([^]*\)\s*=>/.test(fstr) && !/^\s*async\s*\([^]*\)\s*=>/.test(fstr);
}
else
return false;
}
var ClassAndFunction_1 = require("../utils/ClassAndFunction");
function valueOf(v) {
if (!forInstance(v) || v.prototype === undefined)
if (!ClassAndFunction_1.functionForInstance(v) || v.prototype === undefined)
return undefined;
return {
clone: clone.bind(v),
defineFunction: defineFunction.bind(v),
defineClass: defineClass.bind(v)
clone: ClassAndFunction_1.clone.bind(v),
defineFunction: ClassAndFunction_1.defineFunction.bind(v),
defineClass: ClassAndFunction_1.dynamicDefineClass.bind(v)
};
}
exports.type = {
forInstance: forInstance,
defineFunction: defineFunction,
isNormalFunction: isNormalFunction,
isAsyncFunction: isAsyncFunction,
isSyncFunction: isSyncFunction,
isArrowFunction: isArrowFunction,
isNonArrowFunction: isNonArrowFunction,
forInstance: ClassAndFunction_1.functionForInstance,
defineFunction: ClassAndFunction_1.defineFunction,
isNormalFunction: ClassAndFunction_1.isNormalFunction,
isAsyncFunction: ClassAndFunction_1.isAsyncFunction,
isSyncFunction: ClassAndFunction_1.isSyncFunction,
isArrowFunction: ClassAndFunction_1.isArrowFunction,
isNonArrowFunction: ClassAndFunction_1.isNonArrowFunction,
valueOf: valueOf
};
function extend() {
Function.defineFunction = defineFunction;
Function.isNormalFunction = isNormalFunction;
Function.isAsyncFunction = isAsyncFunction;
Function.isSyncFunction = isSyncFunction;
Function.isArrowFunction = isArrowFunction;
Function.isNonArrowFunction = isNonArrowFunction;
Function.prototype.clone = clone;
Function.prototype.defineFunction = dynamicDefineFunction;
Function.prototype.defineClass = defineClass;
Function.defineFunction = ClassAndFunction_1.defineFunction;
Function.isNormalFunction = ClassAndFunction_1.isNormalFunction;
Function.isAsyncFunction = ClassAndFunction_1.isAsyncFunction;
Function.isSyncFunction = ClassAndFunction_1.isSyncFunction;
Function.isArrowFunction = ClassAndFunction_1.isArrowFunction;
Function.isNonArrowFunction = ClassAndFunction_1.isNonArrowFunction;
Function.prototype.clone = ClassAndFunction_1.clone;
Function.prototype.defineFunction = ClassAndFunction_1.dynamicDefineFunction;
Function.prototype.defineClass = ClassAndFunction_1.dynamicDefineClass;
}
exports.extend = extend;

@@ -1,87 +0,14 @@

import {type as typeClass} from './ClassType';
import {
clone,
defineFunction,
dynamicDefineClass,
dynamicDefineFunction,
functionForInstance,
isArrowFunction,
isAsyncFunction,
isNonArrowFunction,
isNormalFunction,
isSyncFunction
} from '../utils/ClassAndFunction';
function forInstance(v: any): boolean {
return v instanceof Function;
}
function clone(): Function | undefined {
if (!(this instanceof Function)) return undefined;
const that = this;
const temp = function temporary() {
return that.apply(this, arguments);
};
let key;
for (key in this) {
if (this.hasOwnProperty(key)) temp[key] = this[key];
}
return temp;
}
function defineFunction(name: string, _prototype?: Function): Function | undefined {
if (typeof name !== 'string') return undefined;
let temp;
let statements = 'temp = function ' + name + '() {\n';
if (_prototype instanceof Function) {
if (_prototype.prototype !== undefined)
statements += ' return _prototype.apply(this, arguments)\n';
else statements += ' return _prototype(arguments)\n';
}
statements += '}';
eval(statements);
return temp;
}
function dynamicDefineFunction(name: string): Function | undefined {
if (!(this instanceof Function)) return undefined;
return defineFunction(name, this);
}
function defineClass(name: string, superClass?: Function) {
return typeClass.defineClass(name, superClass, this);
}
function isNormalFunction(f: Function): boolean {
return f instanceof Function && f.prototype !== undefined;
}
function isAsyncFunction(f: Function): boolean {
if (f instanceof Function && f.prototype === undefined) {
try {
return f[Symbol.toStringTag] === 'AsyncFunction';
} catch (e) {
return /^\s*async/.test(f.toString());
}
} else return false;
}
function isSyncFunction(f: Function): boolean {
if (f instanceof Function) {
try {
return f[Symbol.toStringTag] !== 'AsyncFunction';
} catch (e) {
return !/^\s*async/.test(f.toString());
}
} else return false;
}
function isArrowFunction(f: Function): boolean {
if (f instanceof Function && f.prototype === undefined) {
const fstr = f.toString();
if (/^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr))
return false;
return /^[a-zA-Z0-9_]+\s*=>/.test(fstr) || /^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) ||
/^\([^]*\)\s*=>/.test(fstr) || /^\s*async\s*\([^]*\)\s*=>/.test(fstr);
} else return false;
}
function isNonArrowFunction(f: Function): boolean {
if (f instanceof Function) {
const fstr = f.toString();
if (f.prototype !== undefined || /^\s*function/.test(fstr) || /^\s*async\s*function/.test(fstr))
return true;
return !/^[a-zA-Z0-9_]+\s*=>/.test(fstr) && !/^\s*async\s*[a-zA-Z0-9_]+\s*=>/.test(fstr) &&
!/^\([^]*\)\s*=>/.test(fstr) && !/^\s*async\s*\([^]*\)\s*=>/.test(fstr);
} else return false;
}
interface FunctionType {

@@ -96,7 +23,7 @@ clone(): Function;

function valueOf(v: any): FunctionType | undefined {
if (!forInstance(v) || v.prototype === undefined) return undefined;
if (!functionForInstance(v) || v.prototype === undefined) return undefined;
return {
clone: clone.bind(v),
defineFunction: defineFunction.bind(v),
defineClass: defineClass.bind(v)
defineClass: dynamicDefineClass.bind(v)
};

@@ -106,3 +33,3 @@ }

export const type = {
forInstance,
forInstance: functionForInstance,
defineFunction,

@@ -127,3 +54,3 @@ isNormalFunction,

Function.prototype.defineFunction = dynamicDefineFunction;
Function.prototype.defineClass = defineClass;
Function.prototype.defineClass = dynamicDefineClass;
}

@@ -1,10 +0,6 @@

declare function getAllPropertyNames(obj: any): string[];
declare function getAllPropertyDescriptor(obj: any, p: string): any;
declare function getAllPropertyDescriptors(obj: any): any;
declare function isBlank(v: any): boolean;
declare function isNotBlank(v: any): boolean;
import { getAllPropertyDescriptor, getAllPropertyDescriptors, getAllPropertyNames, isBlank, isNotBlank } from '../utils/Object';
export declare const type: {
getAllPropertyNames: typeof getAllPropertyNames;
getAllPropertyDescriptor: typeof getAllPropertyDescriptor;
getAllPropertyDescriptors: typeof getAllPropertyDescriptors;
getAllPropertyNames: typeof getAllPropertyNames;
isBlank: typeof isBlank;

@@ -14,2 +10,1 @@ isNotBlank: typeof isNotBlank;

export declare function extend(): void;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getAllPropertyNames(obj) {
var result = [];
var temp;
var i;
if (obj) {
if (obj.constructor === {}.constructor)
return Object.getOwnPropertyNames(obj);
try {
while (obj.constructor !== Object) {
temp = Object.getOwnPropertyNames(obj);
for (var _i = 0, temp_1 = temp; _i < temp_1.length; _i++) {
i = temp_1[_i];
if (!result.includes(i))
result.push(i);
}
obj = Object.getPrototypeOf(obj);
}
}
catch (e) {
// continue regardless of error
}
}
return result;
}
function getAllPropertyDescriptor(obj, p) {
var names;
var i, temp;
if (obj) {
if (obj.constructor === {}.constructor) {
names = Object.getOwnPropertyNames(obj);
for (var _i = 0, names_1 = names; _i < names_1.length; _i++) {
i = names_1[_i];
if (i == p) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined)
return temp;
}
}
}
else {
try {
while (obj.constructor !== Object) {
names = Object.getOwnPropertyNames(obj);
for (var _a = 0, names_2 = names; _a < names_2.length; _a++) {
i = names_2[_a];
if (i == p) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined)
return temp;
}
}
obj = Object.getPrototypeOf(obj);
}
}
catch (e) {
// continue regardless of error
}
}
}
return undefined;
}
function getAllPropertyDescriptors(obj) {
var result = {};
var names;
var i, temp;
if (obj) {
if (obj.constructor === {}.constructor) {
names = Object.getOwnPropertyNames(obj);
for (var _i = 0, names_3 = names; _i < names_3.length; _i++) {
i = names_3[_i];
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined)
result[i] = temp;
}
}
else {
try {
while (obj.constructor !== Object) {
names = Object.getOwnPropertyNames(obj);
for (var _a = 0, names_4 = names; _a < names_4.length; _a++) {
i = names_4[_a];
if (result[i] === undefined ||
(i === 'constructor' && result[i].constructor !== {}.constructor)) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined)
result[i] = temp;
}
}
obj = Object.getPrototypeOf(obj);
}
}
catch (e) {
// continue regardless of error
}
}
}
return result;
}
function isBlank(v) {
return v === undefined || v === null;
}
function isNotBlank(v) {
return v !== undefined && v !== null;
}
var Object_1 = require("../utils/Object");
exports.type = {
getAllPropertyNames: getAllPropertyNames,
getAllPropertyDescriptor: getAllPropertyDescriptor,
getAllPropertyDescriptors: getAllPropertyDescriptors,
isBlank: isBlank,
isNotBlank: isNotBlank
getAllPropertyDescriptor: Object_1.getAllPropertyDescriptor,
getAllPropertyDescriptors: Object_1.getAllPropertyDescriptors,
getAllPropertyNames: Object_1.getAllPropertyNames,
isBlank: Object_1.isBlank,
isNotBlank: Object_1.isNotBlank
};
function extend() {
Object.getAllPropertyNames = getAllPropertyNames;
Object.getAllPropertyDescriptor = getAllPropertyDescriptor;
Object.getAllPropertyDescriptors = getAllPropertyDescriptors;
Object.isBlank = isBlank;
Object.isNotBlank = isNotBlank;
Object.getAllPropertyDescriptor = Object_1.getAllPropertyDescriptor;
Object.getAllPropertyDescriptors = Object_1.getAllPropertyDescriptors;
Object.getAllPropertyNames = Object_1.getAllPropertyNames;
Object.isBlank = Object_1.isBlank;
Object.isNotBlank = Object_1.isNotBlank;
}
exports.extend = extend;

@@ -1,106 +0,13 @@

function getAllPropertyNames(obj: any): string[] {
let result: string[] = [];
let temp: string[];
let i;
import {
getAllPropertyDescriptor,
getAllPropertyDescriptors,
getAllPropertyNames,
isBlank,
isNotBlank
} from '../utils/Object';
if (obj) {
if (obj.constructor === {}.constructor)
return Object.getOwnPropertyNames(obj);
try {
while (obj.constructor !== Object) {
temp = Object.getOwnPropertyNames(obj);
for (i of temp) {
if (!result.includes(i))
result.push(i);
}
obj = Object.getPrototypeOf(obj);
}
} catch (e) {
// continue regardless of error
}
}
return result;
}
function getAllPropertyDescriptor(obj: any, p: string): any {
let names: any[];
let i, temp;
if (obj) {
if (obj.constructor === {}.constructor) {
names = Object.getOwnPropertyNames(obj);
for(i of names) {
if(i == p) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined) return temp;
}
}
} else {
try {
while (obj.constructor !== Object) {
names = Object.getOwnPropertyNames(obj);
for (i of names) {
if (i == p) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if (temp !== undefined) return temp;
}
}
obj = Object.getPrototypeOf(obj);
}
} catch (e) {
// continue regardless of error
}
}
}
return undefined;
}
function getAllPropertyDescriptors(obj: any): any {
let result: any = {};
let names: string[];
let i, temp;
if (obj) {
if (obj.constructor === {}.constructor) {
names = Object.getOwnPropertyNames(obj);
for(i of names) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if(temp !== undefined) result[i] = temp;
}
} else {
try {
while (obj.constructor !== Object) {
names = Object.getOwnPropertyNames(obj);
for (i of names) {
if (result[i] === undefined ||
(i === 'constructor' && result[i].constructor !== {}.constructor)) {
temp = Object.getOwnPropertyDescriptor(obj, i);
if(temp !== undefined) result[i] = temp;
}
}
obj = Object.getPrototypeOf(obj);
}
} catch (e) {
// continue regardless of error
}
}
}
return result;
}
function isBlank(v: any): boolean {
return v === undefined || v === null;
}
function isNotBlank(v: any): boolean {
return v !== undefined && v !== null;
}
export const type = {
getAllPropertyNames,
getAllPropertyDescriptor,
getAllPropertyDescriptors,
getAllPropertyNames,
isBlank,

@@ -111,7 +18,7 @@ isNotBlank

export function extend() {
Object.getAllPropertyNames = getAllPropertyNames;
Object.getAllPropertyDescriptor = getAllPropertyDescriptor;
Object.getAllPropertyDescriptors = getAllPropertyDescriptors;
Object.getAllPropertyNames = getAllPropertyNames;
Object.isBlank = isBlank;
Object.isNotBlank = isNotBlank;
}

@@ -1,17 +0,5 @@

declare function forInstance(v: any): boolean;
/**
*
* @param str
* @returns {string|void | string | never} a string of Regular
*/
declare function escape(str: string): string;
/**
*
* @param str
* @returns {string} a string of Regular
*/
declare function matchWords(str: string): string;
import { escape, matchWords, regularForInstance } from '../utils/StringAndRegular';
declare function valueOf(v: RegExp): {} | null;
export declare const type: {
forInstance: typeof forInstance;
forInstance: typeof regularForInstance;
escape: typeof escape;

@@ -18,0 +6,0 @@ matchWords: typeof matchWords;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function forInstance(v) {
return v instanceof RegExp;
}
/**
*
* @param str
* @returns {string|void | string | never} a string of Regular
*/
function escape(str) {
if (typeof str !== 'string' || str.length === 0)
return '';
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}
/**
*
* @param str
* @returns {string} a string of Regular
*/
function matchWords(str) {
if (typeof str !== 'string' || str.length === 0)
return '';
var s = str.trim().replace(/ +/g, ' ');
if (s.length === 0)
return '';
return '(' + s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
.replace(/ /g, ')|(') + ')';
}
var StringAndRegular_1 = require("../utils/StringAndRegular");
function valueOf(v) {
if (!forInstance(v))
if (!StringAndRegular_1.regularForInstance(v))
return null;

@@ -36,13 +10,12 @@ return {};

exports.type = {
forInstance: forInstance,
escape: escape,
matchWords: matchWords,
forInstance: StringAndRegular_1.regularForInstance,
escape: StringAndRegular_1.escape,
matchWords: StringAndRegular_1.matchWords,
valueOf: valueOf
};
function extend() {
RegExp.escape = escape;
RegExp.matchWords = matchWords;
RegExp.forInstance = forInstance;
RegExp.escape = StringAndRegular_1.escape;
RegExp.matchWords = StringAndRegular_1.matchWords;
RegExp.forInstance = StringAndRegular_1.regularForInstance;
}
exports.extend = extend;
;

@@ -1,30 +0,5 @@

function forInstance(v: any): boolean {
return v instanceof RegExp;
}
import {escape, matchWords, regularForInstance} from '../utils/StringAndRegular';
/**
*
* @param str
* @returns {string|void | string | never} a string of Regular
*/
function escape(str: string): string {
if (typeof str !== 'string' || str.length === 0) return '';
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
}
/**
*
* @param str
* @returns {string} a string of Regular
*/
function matchWords(str: string): string {
if (typeof str !== 'string' || str.length === 0) return '';
let s = str.trim().replace(/ +/g, ' ');
if (s.length === 0) return '';
return '(' + s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
.replace(/ /g, ')|(') + ')';
}
function valueOf(v: RegExp) {
if (!forInstance(v)) return null;
if (!regularForInstance(v)) return null;
return {};

@@ -34,3 +9,3 @@ }

export const type = {
forInstance,
forInstance: regularForInstance,
escape,

@@ -44,3 +19,3 @@ matchWords,

RegExp.matchWords = matchWords;
RegExp.forInstance = forInstance;
};
RegExp.forInstance = regularForInstance;
}

@@ -1,14 +0,2 @@

declare function forInstance(v: any): boolean;
/**
* Check string is blank
*
* @returns {boolean}
*/
declare function isBlank(v: any): boolean;
/**
* Check string is not blank
*
* @returns {boolean}
*/
declare function isNotBlank(v: any): boolean;
import { isBlank, isNotBlank, stringForInstance } from '../utils/StringAndRegular';
interface StringType {

@@ -24,3 +12,3 @@ equals(v: any): boolean;

space: string;
forInstance: typeof forInstance;
forInstance: typeof stringForInstance;
isBlank: typeof isBlank;

@@ -27,0 +15,0 @@ isNotBlank: typeof isNotBlank;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var empty = '';
var space = ' ';
function forInstance(v) {
return typeof v === 'string';
}
/**
* Compare equals with the specified string.
*
* @param v the specified string.
* @returns {boolean} true, if two string is equally.
*/
function equals(v) {
return typeof this === 'string' && typeof v === 'string' && this == v;
}
function equalsIgnoreCase(v) {
if (typeof this !== 'string' || typeof v !== 'string')
return false;
return this.toLowerCase() == v.toLowerCase();
}
/**
* Check string is empty
*
* @returns {boolean}
*/
function isEmpty() {
return isBlank(this);
}
/**
* Check string is not empty
*
* @returns {boolean}
*/
function isNotEmpty() {
return isNotBlank(this);
}
/**
* Check string is blank
*
* @returns {boolean}
*/
function isBlank(v) {
return typeof v !== 'string' || v.length === 0;
}
/**
* Check string is not blank
*
* @returns {boolean}
*/
function isNotBlank(v) {
return typeof v === 'string' && v.length > 0;
}
var StringAndRegular_1 = require("../utils/StringAndRegular");
function valueOf(v) {
if (!forInstance(v))
if (!StringAndRegular_1.stringForInstance(v))
return undefined;
return {
equals: equals.bind(v),
equalsIgnoreCase: equalsIgnoreCase.bind(v),
isEmpty: isEmpty.bind(v),
isNotEmpty: isNotEmpty.bind(v)
equals: StringAndRegular_1.equals.bind(v),
equalsIgnoreCase: StringAndRegular_1.equalsIgnoreCase.bind(v),
isEmpty: StringAndRegular_1.isEmpty.bind(v),
isNotEmpty: StringAndRegular_1.isNotEmpty.bind(v)
};
}
exports.type = {
empty: empty,
space: space,
forInstance: forInstance,
isBlank: isBlank,
isNotBlank: isNotBlank,
empty: StringAndRegular_1.empty,
space: StringAndRegular_1.space,
forInstance: StringAndRegular_1.stringForInstance,
isBlank: StringAndRegular_1.isBlank,
isNotBlank: StringAndRegular_1.isNotBlank,
valueOf: valueOf
};
function extend() {
String.empty = empty;
String.empty = empty;
String.isBlank = isBlank;
String.isNotBlank = isNotBlank;
String.forInstance = forInstance;
String.prototype.equals = equals;
String.prototype.equalsIgnoreCase = equalsIgnoreCase;
String.prototype.isEmpty = isEmpty;
String.prototype.isNotEmpty = isNotEmpty;
String.empty = StringAndRegular_1.empty;
String.empty = StringAndRegular_1.empty;
String.isBlank = StringAndRegular_1.isBlank;
String.isNotBlank = StringAndRegular_1.isNotBlank;
String.forInstance = StringAndRegular_1.stringForInstance;
String.prototype.equals = StringAndRegular_1.equals;
String.prototype.equalsIgnoreCase = StringAndRegular_1.equalsIgnoreCase;
String.prototype.isEmpty = StringAndRegular_1.isEmpty;
String.prototype.isNotEmpty = StringAndRegular_1.isNotEmpty;
}
exports.extend = extend;

@@ -1,59 +0,13 @@

const empty = '';
const space = ' ';
import {
empty,
equals,
equalsIgnoreCase,
isBlank,
isEmpty,
isNotBlank,
isNotEmpty,
space,
stringForInstance
} from '../utils/StringAndRegular';
function forInstance(v: any): boolean {
return typeof v === 'string';
}
/**
* Compare equals with the specified string.
*
* @param v the specified string.
* @returns {boolean} true, if two string is equally.
*/
function equals(v: any): boolean {
return typeof this === 'string' && typeof v === 'string' && this == v;
}
function equalsIgnoreCase(v: string): boolean {
if (typeof this !== 'string' || typeof v !== 'string') return false;
return this.toLowerCase() == v.toLowerCase();
}
/**
* Check string is empty
*
* @returns {boolean}
*/
function isEmpty(): boolean {
return isBlank(this);
}
/**
* Check string is not empty
*
* @returns {boolean}
*/
function isNotEmpty(): boolean {
return isNotBlank(this);
}
/**
* Check string is blank
*
* @returns {boolean}
*/
function isBlank(v: any): boolean {
return typeof v !== 'string' || v.length === 0;
}
/**
* Check string is not blank
*
* @returns {boolean}
*/
function isNotBlank(v: any): boolean {
return typeof v === 'string' && v.length > 0;
}
interface StringType {

@@ -70,3 +24,3 @@ equals(v: any): boolean;

function valueOf(v: string): StringType | undefined {
if (!forInstance(v)) return undefined;
if (!stringForInstance(v)) return undefined;
return {

@@ -83,3 +37,3 @@ equals: equals.bind(v),

space,
forInstance,
forInstance: stringForInstance,
isBlank,

@@ -95,3 +49,3 @@ isNotBlank,

String.isNotBlank = isNotBlank;
String.forInstance = forInstance;
String.forInstance = stringForInstance;

@@ -98,0 +52,0 @@ String.prototype.equals = equals;

@@ -48,2 +48,3 @@ interface String {

defineClass(name: string, superClass?: any, prototype?: Function);
isES6Class(v: any): boolean;
defineFunction(name: string, _prototype?: Function): Function | undefined;

@@ -50,0 +51,0 @@ getAllPropertyNames(obj: any): string[];

{
"name": "extension-props",
"version": "0.9.4",
"version": "0.9.5",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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