Added mixin
Some checks failed
Build / Build NPM Project (push) Failing after 0s
Build / Tag Version (push) Has been skipped
Build / Publish (push) Has been skipped

This commit is contained in:
2024-04-11 23:19:36 -04:00
parent c8ccc19996
commit 85fc5f3017
7 changed files with 61 additions and 61 deletions

View File

@ -115,7 +115,7 @@ export function flattenObj(obj: any, parent?: any, result: any = {}) {
*/
export function includes(target: any, values: any, allowMissing = false): boolean {
if(target == undefined) return allowMissing;
if(Array.isArray(values)) return values.findIndex((e, i) => !includes(target[i], values[i], allowMissing)) == -1;
if(Array.isArray(values)) return values.findIndex((e: any, i: number) => !includes(target[i], values[i], allowMissing)) == -1;
const type = typeof values;
if(type != typeof target) return false;
if(type == 'object') {
@ -140,3 +140,16 @@ export function isEqual(a: any, b: any): boolean {
if(keys.length != Object.keys(b).length) return false;
return Object.keys(a).every(key => isEqual(a[key], b[key]));
}
export function mixin(target: any, constructors: any[]) {
constructors.forEach(c => {
Object.getOwnPropertyNames(c.prototype).forEach((name) => {
Object.defineProperty(
target.prototype,
name,
Object.getOwnPropertyDescriptor(c.prototype, name) ||
Object.create(null)
);
});
});
}