extension-props
Advanced tools
Comparing version 0.9.6 to 0.9.7
@@ -5,6 +5,6 @@ import { type as ArrayType } from './types/ArrayType'; | ||
import { type as ObjectType } from './types/ObjectType'; | ||
import { type as RegularType } from './types/RegularType'; | ||
import { type as RegexType } from './types/RegexType'; | ||
import { type as StringType } from './types/StringType'; | ||
export * from './errors'; | ||
export { ObjectType, ArrayType, ClassType, FunctionType, RegularType, StringType }; | ||
export { ObjectType, ArrayType, ClassType, FunctionType, RegexType, StringType }; | ||
export declare function extend(): void; |
@@ -14,4 +14,4 @@ "use strict"; | ||
exports.ObjectType = ObjectType_1.type; | ||
var RegularType_1 = require("./types/RegularType"); | ||
exports.RegularType = RegularType_1.type; | ||
var RegexType_1 = require("./types/RegexType"); | ||
exports.RegexType = RegexType_1.type; | ||
var StringType_1 = require("./types/StringType"); | ||
@@ -25,5 +25,5 @@ exports.StringType = StringType_1.type; | ||
FunctionType_1.extend(); | ||
RegularType_1.extend(); | ||
RegexType_1.extend(); | ||
StringType_1.extend(); | ||
} | ||
exports.extend = extend; |
@@ -5,3 +5,3 @@ import {extend as extendArray, type as ArrayType} from './types/ArrayType'; | ||
import {extend as extendObject, type as ObjectType} from './types/ObjectType'; | ||
import {extend as extendRegular, type as RegularType} from './types/RegularType'; | ||
import {extend as extendRegular, type as RegexType} from './types/RegexType'; | ||
import {extend as extendString, type as StringType} from './types/StringType'; | ||
@@ -16,3 +16,3 @@ | ||
FunctionType, | ||
RegularType, | ||
RegexType, | ||
StringType | ||
@@ -19,0 +19,0 @@ }; |
@@ -1,7 +0,7 @@ | ||
import { classForInstance, defineClass, isClass, isES6Class, preventOverrideClass, preventOverrideFunction } from '../utils/ClassAndFunction'; | ||
import { classForInstance, defineClass, isClass, isES6Class, preventInheritingClass, preventOverrideFunction } from '../utils/ClassAndFunction'; | ||
interface FunctionType { | ||
defineClass(name: string, superClass?: any): any; | ||
preventOverrideClass(classDefinition: any, except?: any[]): boolean; | ||
defineClass(name: string, prototype?: Function): any; | ||
preventInheritingClass(classDefinition: any, except?: any[]): boolean; | ||
preventOverrideFunction(classDefinition: any, functions: string[]): boolean; | ||
subclassOf(superClass: any): boolean; | ||
subclassOf(superclass: any): boolean; | ||
} | ||
@@ -14,3 +14,3 @@ declare function valueOf(v: any): FunctionType | undefined; | ||
isES6Class: typeof isES6Class; | ||
preventOverrideClass: typeof preventOverrideClass; | ||
preventInheritingClass: typeof preventInheritingClass; | ||
preventOverrideFunction: typeof preventOverrideFunction; | ||
@@ -17,0 +17,0 @@ valueOf: typeof valueOf; |
@@ -5,9 +5,9 @@ "use strict"; | ||
function valueOf(v) { | ||
if (!ClassAndFunction_1.classForInstance(v)) | ||
if (!ClassAndFunction_1.classForInstance(v) && !(v instanceof Object)) | ||
return undefined; | ||
return { | ||
defineClass: function (name, superClass) { | ||
return ClassAndFunction_1.defineClass(name, superClass, v); | ||
defineClass: function (name, prototype) { | ||
return ClassAndFunction_1.defineClass(name, v, prototype); | ||
}, | ||
preventOverrideClass: ClassAndFunction_1.dynamicPreventOverrideClass.bind(v), | ||
preventInheritingClass: ClassAndFunction_1.dynamicPreventInheritingClass.bind(v), | ||
preventOverrideFunction: ClassAndFunction_1.dynamicPreventOverrideFunction.bind(v), | ||
@@ -22,3 +22,3 @@ subclassOf: ClassAndFunction_1.subclassOf.bind(v) | ||
isES6Class: ClassAndFunction_1.isES6Class, | ||
preventOverrideClass: ClassAndFunction_1.preventOverrideClass, | ||
preventInheritingClass: ClassAndFunction_1.preventInheritingClass, | ||
preventOverrideFunction: ClassAndFunction_1.preventOverrideFunction, | ||
@@ -32,7 +32,9 @@ valueOf: valueOf | ||
Function.isES6Class = ClassAndFunction_1.isES6Class; | ||
Object.preventOverrideClass = ClassAndFunction_1.preventOverrideClass; | ||
Function.classForInstance = ClassAndFunction_1.classForInstance; | ||
Object.preventInheritingClass = ClassAndFunction_1.preventInheritingClass; | ||
Object.preventOverrideFunction = ClassAndFunction_1.preventOverrideFunction; | ||
Object.prototype.preventOverrideClass = ClassAndFunction_1.dynamicPreventOverrideClass; | ||
Function.prototype.defineClass = ClassAndFunction_1.dynamicDefineClass; | ||
Object.prototype.preventInheritingClass = ClassAndFunction_1.dynamicPreventInheritingClass; | ||
Object.prototype.preventOverrideFunction = ClassAndFunction_1.dynamicPreventOverrideFunction; | ||
} | ||
exports.extend = extend; |
import { | ||
classForInstance, | ||
defineClass, | ||
dynamicPreventOverrideClass, | ||
dynamicDefineClass, | ||
dynamicPreventInheritingClass, | ||
dynamicPreventOverrideFunction, | ||
isClass, | ||
isES6Class, | ||
preventOverrideClass, | ||
preventInheritingClass, | ||
preventOverrideFunction, | ||
@@ -14,18 +15,18 @@ subclassOf | ||
interface FunctionType { | ||
defineClass(name: string, superClass?: any); | ||
defineClass(name: string, prototype?: Function); | ||
preventOverrideClass(classDefinition: any, except?: any[]): boolean; | ||
preventInheritingClass(classDefinition: any, except?: any[]): boolean; | ||
preventOverrideFunction(classDefinition: any, functions: string[]): boolean; | ||
subclassOf(superClass: any): boolean; | ||
subclassOf(superclass: any): boolean; | ||
} | ||
function valueOf(v: any): FunctionType | undefined { | ||
if (!classForInstance(v)) return undefined; | ||
if (!classForInstance(v) && !(v instanceof Object)) return undefined; | ||
return { | ||
defineClass(name: string, superClass) { | ||
return defineClass(name, superClass, v); | ||
defineClass(name: string, prototype?: Function) { | ||
return defineClass(name, v, prototype); | ||
}, | ||
preventOverrideClass: dynamicPreventOverrideClass.bind(v), | ||
preventInheritingClass: dynamicPreventInheritingClass.bind(v), | ||
preventOverrideFunction: dynamicPreventOverrideFunction.bind(v), | ||
@@ -41,3 +42,3 @@ subclassOf: subclassOf.bind(v) | ||
isES6Class, | ||
preventOverrideClass, | ||
preventInheritingClass, | ||
preventOverrideFunction, | ||
@@ -52,8 +53,11 @@ valueOf | ||
Function.isES6Class = isES6Class; | ||
Function.classForInstance = classForInstance; | ||
Object.preventOverrideClass = preventOverrideClass; | ||
Object.preventInheritingClass = preventInheritingClass; | ||
Object.preventOverrideFunction = preventOverrideFunction; | ||
Object.prototype.preventOverrideClass = dynamicPreventOverrideClass; | ||
Function.prototype.defineClass = dynamicDefineClass; | ||
Object.prototype.preventInheritingClass = dynamicPreventInheritingClass; | ||
Object.prototype.preventOverrideFunction = dynamicPreventOverrideFunction; | ||
} |
import { defineFunction, functionForInstance, isArrowFunction, isAsyncFunction, isCallable, isNonArrowFunction, isNormalFunction, isSyncFunction } from '../utils/ClassAndFunction'; | ||
interface FunctionType { | ||
clone(): Function; | ||
defineClass(name: string, superClass?: any): any; | ||
defineFunction(name: string): Function | undefined; | ||
@@ -6,0 +5,0 @@ } |
@@ -9,4 +9,3 @@ "use strict"; | ||
clone: ClassAndFunction_1.clone.bind(v), | ||
defineFunction: ClassAndFunction_1.defineFunction.bind(v), | ||
defineClass: ClassAndFunction_1.dynamicDefineClass.bind(v) | ||
defineFunction: ClassAndFunction_1.dynamicDefineFunction.bind(v) | ||
}; | ||
@@ -33,6 +32,6 @@ } | ||
Function.isNonArrowFunction = ClassAndFunction_1.isNonArrowFunction; | ||
Function.functionForInstance = ClassAndFunction_1.functionForInstance; | ||
Function.prototype.clone = ClassAndFunction_1.clone; | ||
Function.prototype.defineFunction = ClassAndFunction_1.dynamicDefineFunction; | ||
Function.prototype.defineClass = ClassAndFunction_1.dynamicDefineClass; | ||
} | ||
exports.extend = extend; |
import { | ||
clone, | ||
defineFunction, | ||
dynamicDefineClass, | ||
dynamicDefineFunction, | ||
@@ -18,4 +17,2 @@ functionForInstance, | ||
defineClass(name: string, superClass?: any); | ||
defineFunction(name: string): Function | undefined; | ||
@@ -28,4 +25,3 @@ } | ||
clone: clone.bind(v), | ||
defineFunction: defineFunction.bind(v), | ||
defineClass: dynamicDefineClass.bind(v) | ||
defineFunction: dynamicDefineFunction.bind(v) | ||
}; | ||
@@ -54,6 +50,6 @@ } | ||
Function.isNonArrowFunction = isNonArrowFunction; | ||
Function.functionForInstance = functionForInstance; | ||
Function.prototype.clone = clone; | ||
Function.prototype.defineFunction = dynamicDefineFunction; | ||
Function.prototype.defineClass = dynamicDefineClass; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { isBlank, isNotBlank, stringForInstance } from '../utils/StringAndRegular'; | ||
import { isBlank, isNotBlank, replaceAll, replacePlaceholders, stringForInstance } from '../utils/StringAndRegex'; | ||
interface StringType { | ||
@@ -7,2 +7,4 @@ equals(v: any): boolean; | ||
isNotEmpty(): boolean; | ||
replaceAll(search: any, replacement: any): string; | ||
replacePlaceholders(map: any): string; | ||
} | ||
@@ -17,4 +19,6 @@ declare function valueOf(v: string): StringType | undefined; | ||
valueOf: typeof valueOf; | ||
replaceAll: typeof replaceAll; | ||
replacePlaceholders: typeof replacePlaceholders; | ||
}; | ||
export declare function extend(): void; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var StringAndRegular_1 = require("../utils/StringAndRegular"); | ||
var StringAndRegex_1 = require("../utils/StringAndRegex"); | ||
function valueOf(v) { | ||
if (!StringAndRegular_1.stringForInstance(v)) | ||
if (!StringAndRegex_1.stringForInstance(v)) | ||
return undefined; | ||
return { | ||
equals: StringAndRegular_1.equals.bind(v), | ||
equalsIgnoreCase: StringAndRegular_1.equalsIgnoreCase.bind(v), | ||
isEmpty: StringAndRegular_1.isEmpty.bind(v), | ||
isNotEmpty: StringAndRegular_1.isNotEmpty.bind(v) | ||
equals: StringAndRegex_1.equals.bind(v), | ||
equalsIgnoreCase: StringAndRegex_1.equalsIgnoreCase.bind(v), | ||
isEmpty: StringAndRegex_1.isEmpty.bind(v), | ||
isNotEmpty: StringAndRegex_1.isNotEmpty.bind(v), | ||
replaceAll: StringAndRegex_1.dynamicReplaceAll.bind(v), | ||
replacePlaceholders: StringAndRegex_1.dynamicReplacePlaceholders.bind(v) | ||
}; | ||
} | ||
exports.type = { | ||
empty: StringAndRegular_1.empty, | ||
space: StringAndRegular_1.space, | ||
forInstance: StringAndRegular_1.stringForInstance, | ||
isBlank: StringAndRegular_1.isBlank, | ||
isNotBlank: StringAndRegular_1.isNotBlank, | ||
valueOf: valueOf | ||
empty: StringAndRegex_1.empty, | ||
space: StringAndRegex_1.space, | ||
forInstance: StringAndRegex_1.stringForInstance, | ||
isBlank: StringAndRegex_1.isBlank, | ||
isNotBlank: StringAndRegex_1.isNotBlank, | ||
valueOf: valueOf, | ||
replaceAll: StringAndRegex_1.replaceAll, | ||
replacePlaceholders: StringAndRegex_1.replacePlaceholders | ||
}; | ||
function extend() { | ||
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; | ||
String.empty = StringAndRegex_1.empty; | ||
String.empty = StringAndRegex_1.empty; | ||
String.isBlank = StringAndRegex_1.isBlank; | ||
String.isNotBlank = StringAndRegex_1.isNotBlank; | ||
String.forInstance = StringAndRegex_1.stringForInstance; | ||
String.replaceAll = StringAndRegex_1.replaceAll; | ||
String.replacePlaceholders = StringAndRegex_1.replacePlaceholders; | ||
String.prototype.equals = StringAndRegex_1.equals; | ||
String.prototype.equalsIgnoreCase = StringAndRegex_1.equalsIgnoreCase; | ||
String.prototype.isEmpty = StringAndRegex_1.isEmpty; | ||
String.prototype.isNotEmpty = StringAndRegex_1.isNotEmpty; | ||
String.prototype.replaceAll = StringAndRegex_1.dynamicReplaceAll; | ||
String.prototype.replacePlaceholders = StringAndRegex_1.dynamicReplacePlaceholders; | ||
} | ||
exports.extend = extend; |
import { | ||
dynamicReplaceAll, | ||
dynamicReplacePlaceholders, | ||
empty, | ||
@@ -9,5 +11,7 @@ equals, | ||
isNotEmpty, | ||
replaceAll, | ||
replacePlaceholders, | ||
space, | ||
stringForInstance | ||
} from '../utils/StringAndRegular'; | ||
} from '../utils/StringAndRegex'; | ||
@@ -22,2 +26,6 @@ interface StringType { | ||
isNotEmpty(): boolean; | ||
replaceAll(search, replacement): string; | ||
replacePlaceholders(map: any): string; | ||
} | ||
@@ -31,3 +39,5 @@ | ||
isEmpty: isEmpty.bind(v), | ||
isNotEmpty: isNotEmpty.bind(v) | ||
isNotEmpty: isNotEmpty.bind(v), | ||
replaceAll: dynamicReplaceAll.bind(v), | ||
replacePlaceholders: dynamicReplacePlaceholders.bind(v) | ||
}; | ||
@@ -42,3 +52,5 @@ } | ||
isNotBlank, | ||
valueOf | ||
valueOf, | ||
replaceAll, | ||
replacePlaceholders | ||
}; | ||
@@ -52,2 +64,4 @@ | ||
String.forInstance = stringForInstance; | ||
String.replaceAll = replaceAll; | ||
String.replacePlaceholders = replacePlaceholders; | ||
@@ -58,2 +72,4 @@ String.prototype.equals = equals; | ||
String.prototype.isNotEmpty = isNotEmpty; | ||
String.prototype.replaceAll = dynamicReplaceAll; | ||
String.prototype.replacePlaceholders = dynamicReplacePlaceholders; | ||
} |
@@ -6,2 +6,4 @@ interface String { | ||
isNotEmpty(): boolean; | ||
replaceAll(search, replacement): string; | ||
replacePlaceholders(map: any): string; | ||
} | ||
@@ -15,2 +17,4 @@ | ||
forInstance(v: any): boolean; | ||
replaceAll(str, search, replacement): string | undefined; | ||
replacePlaceholders(str: string, map: any): string | undefined; | ||
} | ||
@@ -22,3 +26,3 @@ | ||
virtualGet(i: number): T; | ||
insert(index: number, ...element: T[]): T[]; | ||
insert(i: number, ...elements: T[]): T[]; | ||
lastIndexOf(o: T): number; | ||
@@ -36,2 +40,3 @@ isEmpty(): boolean; | ||
interface RegExpConstructor { | ||
forInstance(v: any): boolean; | ||
escape(str: string): string; | ||
@@ -44,5 +49,5 @@ matchWords(str: string): string; | ||
clone(): Function | undefined; | ||
defineClass(name: string, superClass?: any); | ||
defineClass(name: string, prototype?: Function); | ||
defineFunction(name: string): Function | undefined; | ||
subclassOf(superClass: any): boolean; | ||
subclassOf(superclass: any): boolean; | ||
} | ||
@@ -52,3 +57,5 @@ | ||
isClass(v: any): boolean; | ||
defineClass(name: string, superClass?: any, prototype?: Function); | ||
classForInstance(v: any): boolean; | ||
functionForInstance(v: any): boolean; | ||
defineClass(name: string, superclass?: any, prototype?: Function); | ||
isES6Class(v: any): boolean; | ||
@@ -66,3 +73,3 @@ defineFunction(name: string, _prototype?: Function): Function | undefined; | ||
interface Object { | ||
preventOverrideClass(classDefinition: any, except?: any[]): boolean; | ||
preventInheritingClass(classDefinition: any, except?: any[]): boolean; | ||
preventOverrideFunction(classDefinition: any, functions: string[]): boolean; | ||
@@ -77,4 +84,4 @@ } | ||
getAllPropertyDescriptors(obj: any): any; | ||
preventOverrideClass(obj: any, classDefinition: any, except?: any[]): boolean; | ||
preventInheritingClass(obj: any, classDefinition: any, except?: any[]): boolean; | ||
preventOverrideFunction(obj: any, classDefinition: any, functions: string[]): boolean; | ||
} |
@@ -9,3 +9,3 @@ /** | ||
export declare function virtualGet(i: number): any; | ||
export declare function insert(i: number, ...element: any[]): any[]; | ||
export declare function insert(i: number, ...elements: any[]): any[]; | ||
export declare function lastIndexOf(o: any): number; | ||
@@ -12,0 +12,0 @@ export declare function isEmpty(): boolean; |
@@ -36,8 +36,8 @@ "use strict"; | ||
function insert(i) { | ||
var element = []; | ||
var elements = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
element[_i - 1] = arguments[_i]; | ||
elements[_i - 1] = arguments[_i]; | ||
} | ||
if (this instanceof Array) | ||
this.splice.apply(this, [i, 0].concat(element)); | ||
this.splice.apply(this, [i, 0].concat(elements)); | ||
return this; | ||
@@ -44,0 +44,0 @@ } |
@@ -28,5 +28,5 @@ /** | ||
export function insert(i: number, ...element: any[]): any[] { | ||
export function insert(i: number, ...elements: any[]): any[] { | ||
if (this instanceof Array) | ||
this.splice(i, 0, ...element); | ||
this.splice(i, 0, ...elements); | ||
return this; | ||
@@ -33,0 +33,0 @@ } |
export declare function functionForInstance(v: any): boolean; | ||
export declare function classForInstance(v: any): boolean; | ||
export declare function inheritsLoose(subClass: any, superClass: any): void; | ||
export declare function defineFunctionClass(name: string, _superClass: any, _prototype?: Function): Function; | ||
export declare function defineES5Class(name: string, superClass: any, prototype?: Function): Function; | ||
export declare function defineES6Class(name: string, _superClass: any, _prototype?: Function): any; | ||
export declare function inheritsLoose(subclass: any, superclass: any): void; | ||
export declare function defineFunctionClass(name: string, _superclass: any, _prototype?: Function): Function; | ||
export declare function defineES5Class(name: string, superclass: any, prototype?: Function): Function; | ||
export declare function defineES6Class(name: string, _superclass: any, _prototype?: Function): any; | ||
export declare function defineClass(name: string, superClass?: Function, prototype?: Function): any; | ||
export declare function dynamicDefineClass(name: string, prototype?: Function): any; | ||
export declare const OverridingError: any; | ||
export declare function isClass(v: any): boolean; | ||
export declare function preventOverrideClass(obj: any, classDefinition: any, except?: any[]): boolean; | ||
export declare function dynamicPreventOverrideClass(classDefinition: any, except?: any[]): boolean; | ||
export declare function preventInheritingClass(obj: any, classDefinition: any, except?: any[]): boolean; | ||
export declare function dynamicPreventInheritingClass(classDefinition: any, except?: any[]): boolean; | ||
export declare function preventOverrideFunction(obj: any, classDefinition: any, functions: string[]): boolean; | ||
export declare function dynamicPreventOverrideFunction(classDefinition: any, functions: string[]): boolean; | ||
export declare function subclassOf(superClass: any): boolean; | ||
export declare function subclassOf(superclass: any): boolean; | ||
export declare function isES6Class(c: any): boolean; | ||
@@ -19,3 +20,2 @@ export declare function clone(): Function | undefined; | ||
export declare function dynamicDefineFunction(name: string): Function | undefined; | ||
export declare function dynamicDefineClass(name: string, superClass?: Function): any; | ||
export declare function isNormalFunction(f: Function): boolean; | ||
@@ -22,0 +22,0 @@ export declare function isAsyncFunction(f: Function): boolean; |
@@ -11,13 +11,13 @@ "use strict"; | ||
exports.classForInstance = classForInstance; | ||
function inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
function inheritsLoose(subclass, superclass) { | ||
subclass.prototype = Object.create(superclass.prototype); | ||
subclass.prototype.constructor = subclass; | ||
subclass.__proto__ = superclass; | ||
} | ||
exports.inheritsLoose = inheritsLoose; | ||
function defineFunctionClass(name, _superClass, _prototype) { | ||
function defineFunctionClass(name, _superclass, _prototype) { | ||
var temp; | ||
var statements = 'temp = function ' + name + '() {\n'; | ||
if (_superClass) | ||
statements += ' var _this = _superClass.apply(this, arguments) || this;\n'; | ||
if (_superclass) | ||
statements += ' var _this = _superclass.apply(this, arguments) || this;\n'; | ||
else | ||
@@ -40,14 +40,14 @@ statements += ' var _this = this;\n'; | ||
exports.defineFunctionClass = defineFunctionClass; | ||
function defineES5Class(name, superClass, prototype) { | ||
var subClass = defineFunctionClass(name, superClass, prototype); | ||
if (superClass && superClass.prototype instanceof Object) | ||
inheritsLoose(subClass, superClass); | ||
function defineES5Class(name, superclass, prototype) { | ||
var subClass = defineFunctionClass(name, superclass, prototype); | ||
if (superclass && superclass.prototype instanceof Object) | ||
inheritsLoose(subClass, superclass); | ||
return subClass; | ||
} | ||
exports.defineES5Class = defineES5Class; | ||
function defineES6Class(name, _superClass, _prototype) { | ||
function defineES6Class(name, _superclass, _prototype) { | ||
var temp; | ||
var statements = 'temp = class ' + name; | ||
if (_superClass && _superClass.prototype instanceof Object) | ||
statements += ' extends _superClass'; | ||
if (_superclass && _superclass.prototype instanceof Object) | ||
statements += ' extends _superclass'; | ||
statements += ' {\n' + | ||
@@ -81,2 +81,6 @@ ' constructor() {\n' + | ||
exports.defineClass = defineClass; | ||
function dynamicDefineClass(name, prototype) { | ||
return defineClass(name, this, prototype); | ||
} | ||
exports.dynamicDefineClass = dynamicDefineClass; | ||
exports.OverridingError = defineClass('OverridingError', Error, function () { | ||
@@ -96,3 +100,3 @@ this.name = 'Overriding Error'; | ||
exports.isClass = isClass; | ||
function preventOverrideClass(obj, classDefinition, except) { | ||
function preventInheritingClass(obj, classDefinition, except) { | ||
if (classForInstance(classDefinition) && obj instanceof Object && obj['__proto__'] instanceof classDefinition) { | ||
@@ -113,3 +117,3 @@ var i = void 0; | ||
if (error) { | ||
throw new exports.OverridingError('You can\'t override the [ClassName] class.' | ||
throw new exports.OverridingError('You can\'t inheriting the [ClassName] class.' | ||
.replace('[ClassName]', classDefinition['name'])); | ||
@@ -121,7 +125,7 @@ } | ||
} | ||
exports.preventOverrideClass = preventOverrideClass; | ||
function dynamicPreventOverrideClass(classDefinition, except) { | ||
return preventOverrideClass(this, classDefinition, except); | ||
exports.preventInheritingClass = preventInheritingClass; | ||
function dynamicPreventInheritingClass(classDefinition, except) { | ||
return preventInheritingClass(this, classDefinition, except); | ||
} | ||
exports.dynamicPreventOverrideClass = dynamicPreventOverrideClass; | ||
exports.dynamicPreventInheritingClass = dynamicPreventInheritingClass; | ||
function preventOverrideFunction(obj, classDefinition, functions) { | ||
@@ -154,4 +158,4 @@ if (classForInstance(classDefinition) && obj instanceof Object && obj['__proto__'] instanceof classDefinition) { | ||
exports.dynamicPreventOverrideFunction = dynamicPreventOverrideFunction; | ||
function subclassOf(superClass) { | ||
return this instanceof Function && this.prototype instanceof superClass; | ||
function subclassOf(superclass) { | ||
return this instanceof Function && this.prototype instanceof superclass; | ||
} | ||
@@ -205,6 +209,2 @@ exports.subclassOf = subclassOf; | ||
exports.dynamicDefineFunction = dynamicDefineFunction; | ||
function dynamicDefineClass(name, superClass) { | ||
return defineClass(name, superClass, this); | ||
} | ||
exports.dynamicDefineClass = dynamicDefineClass; | ||
function isNormalFunction(f) { | ||
@@ -211,0 +211,0 @@ return f instanceof Function && !isES6Class(f) && f.prototype !== undefined; |
@@ -9,13 +9,13 @@ export function functionForInstance(v: any): boolean { | ||
export function inheritsLoose(subClass, superClass): void { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
export function inheritsLoose(subclass, superclass): void { | ||
subclass.prototype = Object.create(superclass.prototype); | ||
subclass.prototype.constructor = subclass; | ||
subclass.__proto__ = superclass; | ||
} | ||
export function defineFunctionClass(name: string, _superClass, _prototype?: Function): Function { | ||
export 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'; | ||
if (_superclass) | ||
statements += ' var _this = _superclass.apply(this, arguments) || this;\n'; | ||
else | ||
@@ -36,14 +36,14 @@ statements += ' var _this = this;\n'; | ||
export function defineES5Class(name: string, superClass, prototype?: Function): Function { | ||
const subClass = defineFunctionClass(name, superClass, prototype); | ||
if (superClass && superClass.prototype instanceof Object) | ||
inheritsLoose(subClass, superClass); | ||
export 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; | ||
} | ||
export function defineES6Class(name: string, _superClass, _prototype?: Function) { | ||
export function defineES6Class(name: string, _superclass, _prototype?: Function) { | ||
let temp; | ||
let statements = 'temp = class ' + name; | ||
if (_superClass && _superClass.prototype instanceof Object) | ||
statements += ' extends _superClass'; | ||
if (_superclass && _superclass.prototype instanceof Object) | ||
statements += ' extends _superclass'; | ||
statements += ' {\n' + | ||
@@ -74,2 +74,6 @@ ' constructor() {\n' + | ||
export function dynamicDefineClass(name: string, prototype?: Function) { | ||
return defineClass(name, this, prototype); | ||
} | ||
export const OverridingError = defineClass('OverridingError', Error, function () { | ||
@@ -88,3 +92,3 @@ this.name = 'Overriding Error'; | ||
export function preventOverrideClass(obj: any, classDefinition: any, except?: any[]): boolean { | ||
export function preventInheritingClass(obj: any, classDefinition: any, except?: any[]): boolean { | ||
if (classForInstance(classDefinition) && obj instanceof Object && obj['__proto__'] instanceof classDefinition) { | ||
@@ -104,3 +108,3 @@ let i; | ||
if (error) { | ||
throw new OverridingError('You can\'t override the [ClassName] class.' | ||
throw new OverridingError('You can\'t inheriting the [ClassName] class.' | ||
.replace('[ClassName]', classDefinition['name'])); | ||
@@ -113,4 +117,4 @@ } | ||
export function dynamicPreventOverrideClass(classDefinition: any, except?: any[]): boolean { | ||
return preventOverrideClass(this, classDefinition, except); | ||
export function dynamicPreventInheritingClass(classDefinition: any, except?: any[]): boolean { | ||
return preventInheritingClass(this, classDefinition, except); | ||
} | ||
@@ -144,4 +148,4 @@ | ||
export function subclassOf(superClass: any): boolean { | ||
return this instanceof Function && this.prototype instanceof superClass; | ||
export function subclassOf(superclass: any): boolean { | ||
return this instanceof Function && this.prototype instanceof superclass; | ||
} | ||
@@ -188,6 +192,2 @@ | ||
export function dynamicDefineClass(name: string, superClass?: Function) { | ||
return defineClass(name, superClass, this); | ||
} | ||
export function isNormalFunction(f: Function): boolean { | ||
@@ -194,0 +194,0 @@ return f instanceof Function && !isES6Class(f) && f.prototype !== undefined; |
{ | ||
"name": "extension-props", | ||
"version": "0.9.6", | ||
"version": "0.9.7", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
237
README.md
# extension-props | ||
A utility library delivering some additional utility functions. | ||
## Installation | ||
@@ -7,4 +10,236 @@ | ||
npm install extension-props | ||
# or | ||
# or | ||
yarn add extension-props | ||
``` | ||
## Usage | ||
You can use this utilities by two way: | ||
- Use utility functions through the provided objects likes ObjectType, ArrayType, ClassType, FunctionType, RegexType, StringType. _(Recommend)_ | ||
```js | ||
const { | ||
ObjectType, | ||
ArrayType, | ||
ClassType, | ||
FunctionType, | ||
RegexType, | ||
StringType | ||
} = require('extension-props'); | ||
``` | ||
- Load additional utility functions into global objects likes String, Function, Object, Array, RegExp. | ||
```js | ||
require('extension-props').extend(); | ||
``` | ||
### String | ||
- `forInstance(str)`: checks whether v is a string. | ||
- _Variations:_ | ||
- `StringType.forInstance(str)` | ||
- `String.forInstance(str)` | ||
- `isBlank(str)`: return true, if v string is blank. | ||
- _Variations:_ | ||
- `StringType.isBlank(str)` | ||
- `String.isBlank(str)` | ||
- `isNotBlank(str)`: return true, if v string is not blank. | ||
- _Variations:_ | ||
- `StringType.isBlank(str)` | ||
- `String.isBlank(str)` | ||
- `isEmpty()`: checks a string is empty. | ||
- _Variations:_ | ||
- `StringType.valueOf(str).isEmpty()` | ||
- `String.prototype.isEmpty()` | ||
- `isNotEmpty()`: checks a string is not empty. | ||
- _Variations:_ | ||
- `StringType.valueOf(str).isNotEmpty()` | ||
- `String.prototype.isNotEmpty()` | ||
- `equals(another)`: checks a string is equals with another string. | ||
- _Variations:_ | ||
- `StringType.valueOf(str).equals(another)` | ||
- `String.prototype.equals(another)` | ||
- `equalsIgnoreCase(another)`: checks a string is equals with another string on the basis of content of the string irrespective of case of the string. | ||
- _Variations:_ | ||
- `StringType.valueOf(str).equalsIgnoreCase(another)` | ||
- `String.prototype.equalsIgnoreCase(another)` | ||
- `replaceAll(str, search, replacement)`: returns a new string with all matches of a pattern replaced by a replacement. | ||
- _Variations:_ | ||
- `StringType.replaceAll(str, search, replacement)` | ||
- `String.replaceAll(str, search, replacement)` | ||
- `StringType.valueOf(str).replaceAll(search, replacement)` | ||
- `String.prototype.replaceAll(search, replacement)` | ||
- `replacePlaceholders(str, map)`: returns a new string with all matches of each key in the map replaced by its value. | ||
- _Variations:_ | ||
- `StringType.replacePlaceholders(str, map)` | ||
- `String.replacePlaceholders(str, map)` | ||
- `StringType.valueOf(str).replacePlaceholders(map)` | ||
- `String.prototype.replacePlaceholders(map)` | ||
### Function | ||
- `forInstance(func)`: checks whether f is a function. | ||
- _Variations:_ | ||
- `FunctionType.forInstance(func)` | ||
- `Function.functionForInstance(func)` | ||
- `defineFunction(name, prototype)`: define a function with dynamic name. | ||
- _Variations:_ | ||
- `FunctionType.defineFunction(name, prototype)` | ||
- `Function.defineFunction(name, prototype)` | ||
- `FunctionType.valueOf(prototype).defineFunction(name)` | ||
- `Function.prototype.defineFunction(name)` | ||
- `name`: is the name of the function. | ||
- `prototype` (option): is a function that determines the content of the function being created. | ||
+ returns a function. | ||
- `isCallable(func)`: checks whether f function is callable. | ||
- _Variations:_ | ||
- `FunctionType.isCallable(func)` | ||
- `Function.isCallable(func)` | ||
- `isNormalFunction(func)`: checks whether f is a normal function, that means that f is not an async function nor an arrow function. | ||
- _Variations:_ | ||
- `FunctionType.isNormalFunction(func)` | ||
- `Function.isNormalFunction(func)` | ||
- `isAsyncFunction(func)`: checks whether f is an async function. | ||
- _Variations:_ | ||
- `FunctionType.isAsyncFunction(func)` | ||
- `Function.isAsyncFunction(func)` | ||
- `isSyncFunction(func)`: checks whether f is a sync function (negative of isAsyncFunction). | ||
- _Variations:_ | ||
- `FunctionType.isSyncFunction(func)` | ||
- `Function.isSyncFunction(func)` | ||
- `isArrowFunction(func)`: checks whether f is an arrow function. | ||
- _Variations:_ | ||
- `FunctionType.isArrowFunction(func)` | ||
- `Function.isArrowFunction(func)` | ||
- `isNonArrowFunction(func)`: negative of isArrowFunction. | ||
- _Variations:_ | ||
- `FunctionType.isNonArrowFunction(func)` | ||
- `Function.isNonArrowFunction(func)` | ||
- `clone()`: clone a function. | ||
- _Variations:_ | ||
- `FunctionType.valueOf(func).clone()` | ||
- `Function.prototype.clone()` | ||
### Class | ||
- `forInstance(cls)`: checks whether c is a class. | ||
- _Variations:_ | ||
- `ClassType.forInstance(cls)` | ||
- `Function.classForInstance(cls)` | ||
- `defineClass(name, superclass, prototype)`: define a class with dynamic name. | ||
- _Variations:_ | ||
- `ClassType.defineClass(name, superclass, prototype)` | ||
- `Function.defineClass(name, superclass, prototype)` | ||
- `ClassType.valueOf(superclass).defineClass(name, prototype)` | ||
- `Function.prototype.defineClass(name, prototype)` | ||
- `name`: is the name of the class. | ||
- `superclass` (option): specify a super class. | ||
- `prototype` (option): is a function that determines the content of constructor of the class being created. | ||
- return a class. | ||
- `isES6Class(cls)`: checks whether c is an es6 class. | ||
- _Variations:_ | ||
- `ClassType.isES6Class(cls)` | ||
- `Function.isES6Class(cls)` | ||
- `preventInheritingClass(obj, classDefinition, except)`: prevent inheriting class. | ||
- _Variations:_ | ||
- `ClassType.preventInheritingClass(obj, classDefinition, except)` | ||
- `Object.preventInheritingClass(obj, classDefinition, except)` | ||
- `ClassType.valueOf(obj).preventInheritingClass(classDefinition, except)` | ||
- `Object.prototype.preventInheritingClass(classDefinition, except)` | ||
- `obj`: is an instance of subclass of classDefinition class. | ||
- `classDefinition`: is a superclass. | ||
- `except` (option): is white list, designate classes that are allowed to inherit. | ||
- throw a OverridingError exception, if obj is an instance of a class, and it is not allowed to inherit the classDefinition class. | ||
- return false, if obj is an instance of a class, and it is not subclass of classDefinition class. | ||
- return true, if obj is an instance of a class, and it is allowed to inherit the classDefinition class. | ||
- _Recommended:_ Put this function into the constructor. | ||
- `preventOverrideFunction(obj, classDefinition, functions)`: prevent overriding of functions. | ||
- _Variations:_ | ||
- `ClassType.preventOverrideFunction(obj, classDefinition, functions)` | ||
- `Object.preventOverrideFunction(obj, classDefinition, functions)` | ||
- `ClassType.valueOf(obj).preventOverrideFunction(classDefinition, functions)` | ||
- `Object.prototype.preventOverrideFunction(classDefinition, functions)` | ||
- `obj`: is an instance of subclass of classDefinition class. | ||
- `classDefinition`: is a superclass. | ||
- `functions`: is an array of functions need to prevent override. | ||
- throw a OverridingError exception, if obj contains a function, and it is not allowed to override in the subclass of the classDefinition class. | ||
- return false, if obj is an instance of a class, and it is not subclass of classDefinition class. | ||
- return true, if no function is prevented, it is contained in subclasses. | ||
- _Recommended:_ Put this function into the constructor. | ||
### Object | ||
- `getAllPropertyDescriptor(obj)`: returns an array of all properties of a given object. | ||
- _Variations:_ | ||
- `ObjectType.getAllPropertyDescriptor(obj)` | ||
- `Object.getAllPropertyDescriptor(obj)` | ||
- `getAllPropertyDescriptor(obj, prop)`: returns a property descriptor for a property of a given object. | ||
- _Variations:_ | ||
- `ObjectType.getAllPropertyDescriptor(obj, prop)` | ||
- `Object.getAllPropertyDescriptor(obj, prop)` | ||
- `getAllPropertyDescriptors(obj)`: returns an array of all property descriptors of a given object. | ||
- _Variations:_ | ||
- `ObjectType.getAllPropertyDescriptors(obj)` | ||
- `Object.getAllPropertyDescriptors(obj)` | ||
- `isBlank(obj)`: return true, if obj = undefined or obj = null. | ||
- _Variations:_ | ||
- `ObjectType.isBlank(obj)` | ||
- `Object.isBlank(obj)` | ||
- `isNotBlank(obj)`: return true, if obj != undefined and obj != null. | ||
- _Variations:_ | ||
- `ObjectType.isNotBlank(obj)` | ||
- `Object.isNotBlank(obj)` | ||
### Regex | ||
- `forInstance(reg)`: checks whether v is a regex. | ||
- _Variations:_ | ||
- `RegexType.forInstance(reg)` | ||
- `RegExp.forInstance(reg)` | ||
- `escape(str)`: escape regex expression special characters. | ||
- _Variations:_ | ||
- `RegexType.escape(str)` | ||
- `RegExp.escape(str)` | ||
- `matchWords(str)`: create a regex string for checks match with the words in str string. | ||
- _Variations:_ | ||
- `RegexType.matchWords(str)` | ||
- `RegExp.matchWords(str)` | ||
### Array | ||
- `forInstance(arr)`: checks whether v is a array. | ||
- _Variations:_ | ||
- `ArrayType.forInstance(arr)` | ||
- `Array.forInstance(arr)` | ||
- `isBlank(arr)`: return true, if v array is blank. | ||
- _Variations:_ | ||
- `ArrayType.isBlank(arr)` | ||
- `Array.isBlank(arr)` | ||
- `isNotBlank(arr)`: return true, if v array is not blank. | ||
- _Variations:_ | ||
- `ArrayType.isNotBlank(arr)` | ||
- `Array.isNotBlank(arr)` | ||
- `isEmpty()`: checks a array is empty. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).isEmpty()` | ||
- `Array.prototype.isEmpty()` | ||
- `isNotEmpty()`: checks a array is not empty. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).isNotEmpty()` | ||
- `Array.prototype.isNotEmpty()` | ||
- `equals(another)`: checks a array is equals with another array. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).equals(another)` | ||
- `Array.prototype.equals(another)` | ||
- `virtualGet(index)`: get value at index. You will still get a value even if the index is out of bounds. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).virtualGet(index)` | ||
- `Array.prototype.virtualGet(index)` | ||
- `insert(index, ...elements)`: insert elements into the specified position. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).insert(index, ...elements)` | ||
- `Array.prototype.insert(index, ...elements)` | ||
- `lastIndexOf(element)`: returns the last index at which a given element can be found in the array, or -1 if it is not present. | ||
- _Variations:_ | ||
- `ArrayType.valueOf(str).lastIndexOf(element)` | ||
- `Array.prototype.lastIndexOf(element)` |
78504
1817
245