appolo-utils
Advanced tools
Comparing version 0.0.38 to 0.0.39
@@ -26,2 +26,4 @@ "use strict"; | ||
exports.Enums = enums_1.Enums; | ||
const functions_1 = require("./lib/functions"); | ||
exports.Functions = functions_1.Functions; | ||
const util_1 = require("./lib/util"); | ||
@@ -28,0 +30,0 @@ exports.Util = util_1.Util; |
18
index.ts
@@ -12,2 +12,3 @@ import {Numbers} from "./lib/numbers" | ||
import {Enums} from "./lib/enums" | ||
import {Functions} from "./lib/functions" | ||
import {Util} from "./lib/util" | ||
@@ -18,4 +19,19 @@ import {ReflectMetadata} from "./lib/reflectMetadata" | ||
export {Numbers, Strings, Hash, Objects, Arrays, Classes, Guid, Promises, Time, Util, Files, Enums, Deferred,ReflectMetadata} | ||
export { | ||
Numbers, | ||
Strings, | ||
Hash, | ||
Objects, | ||
Arrays, | ||
Classes, | ||
Guid, | ||
Promises, | ||
Time, | ||
Util, | ||
Files, | ||
Enums, | ||
Deferred, | ||
ReflectMetadata, Functions | ||
} | ||
@@ -22,4 +22,44 @@ "use strict"; | ||
} | ||
static findReflectData(symbol, exported) { | ||
for (let i = 0, len = (exported ? exported.length : 0); i < len; i++) { | ||
let result = Reflect.getOwnMetadata(symbol, exported[i].fn); | ||
if (result !== undefined) { | ||
return Object.assign({}, exported[i], { metaData: result }); | ||
} | ||
} | ||
return null; | ||
} | ||
static findAllReflectData(symbol, exported) { | ||
let results = []; | ||
for (let i = 0, len = (exported ? exported.length : 0); i < len; i++) { | ||
let result = Reflect.getOwnMetadata(symbol, exported[i].fn); | ||
if (result !== undefined) { | ||
results.push(Object.assign({}, exported[i], { metaData: result })); | ||
} | ||
} | ||
return results; | ||
} | ||
static setMetadata(key, value, target, propertyKey) { | ||
if (propertyKey) { | ||
Reflect.defineMetadata(key, value, target.constructor, propertyKey); | ||
} | ||
else { | ||
Reflect.defineMetadata(key, value, target.constructor); | ||
} | ||
} | ||
static getOwnMetadata(symbol, klass, propertyName, defaultValue) { | ||
let value = Reflect.getOwnMetadata(symbol, klass, propertyName); | ||
if (!value && defaultValue != undefined) { | ||
value = defaultValue; | ||
Reflect.defineMetadata(symbol, value, klass, propertyName); | ||
} | ||
return value; | ||
} | ||
static decorateMetadata(key, value) { | ||
return function (target, propertyKey) { | ||
ReflectMetadata.setMetadata(key, value, propertyKey ? target.constructor : target, propertyKey); | ||
}; | ||
} | ||
} | ||
exports.ReflectMetadata = ReflectMetadata; | ||
//# sourceMappingURL=ReflectMetadata.js.map |
@@ -25,2 +25,57 @@ import {Objects} from "../index"; | ||
} | ||
public static findReflectData<T, K extends { fn: Function }>(symbol: Symbol | string, exported: K[]): K & { metaData: T } { | ||
for (let i = 0, len = (exported ? exported.length : 0); i < len; i++) { | ||
let result = Reflect.getOwnMetadata(symbol, exported[i].fn); | ||
if (result !== undefined) { | ||
return {...exported[i], metaData: result} | ||
} | ||
} | ||
return null; | ||
} | ||
public static findAllReflectData<T, K extends { fn: Function }>(symbol: Symbol | string, exported: K[]): (K & { metaData: T })[] { | ||
let results = []; | ||
for (let i = 0, len = (exported ? exported.length : 0); i < len; i++) { | ||
let result = Reflect.getOwnMetadata(symbol, exported[i].fn); | ||
if (result !== undefined) { | ||
results.push({...exported[i], metaData: result}) | ||
} | ||
} | ||
return results; | ||
} | ||
public static setMetadata(key: string | Symbol, value: any, target: any, propertyKey?: string) { | ||
if (propertyKey) { | ||
Reflect.defineMetadata(key, value, target.constructor, propertyKey) | ||
} else { | ||
Reflect.defineMetadata(key, value, target.constructor) | ||
} | ||
} | ||
public static getOwnMetadata<T>(symbol: Symbol | string, klass: any, propertyName?: string, defaultValue?: T): T { | ||
let value = Reflect.getOwnMetadata(symbol, klass, propertyName); | ||
if (!value && defaultValue != undefined) { | ||
value = defaultValue; | ||
Reflect.defineMetadata(symbol, value, klass, propertyName); | ||
} | ||
return value | ||
} | ||
public static decorateMetadata(key: string | Symbol, value: any) { | ||
return function (target: any, propertyKey?: string) { | ||
ReflectMetadata.setMetadata(key, value, propertyKey ? target.constructor : target, propertyKey); | ||
} | ||
} | ||
} |
@@ -41,2 +41,4 @@ export class Time { | ||
} | ||
} |
@@ -15,2 +15,3 @@ "use strict"; | ||
const ReflectMetadata_1 = require("./ReflectMetadata"); | ||
const functions_1 = require("./functions"); | ||
class Util { | ||
@@ -50,2 +51,5 @@ static get numbers() { | ||
} | ||
static get functions() { | ||
return functions_1.Functions; | ||
} | ||
static get Metadata() { | ||
@@ -52,0 +56,0 @@ return ReflectMetadata_1.ReflectMetadata; |
@@ -13,2 +13,3 @@ import {Numbers} from "./numbers"; | ||
import {ReflectMetadata} from "./ReflectMetadata"; | ||
import {Functions} from "./functions"; | ||
@@ -60,2 +61,6 @@ export class Util { | ||
public static get functions(): typeof Functions { | ||
return Functions | ||
} | ||
public static get Metadata(): typeof ReflectMetadata{ | ||
@@ -62,0 +67,0 @@ return ReflectMetadata |
@@ -17,3 +17,3 @@ { | ||
"main": "./index.js", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"license": "MIT", | ||
@@ -20,0 +20,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94151
47
1697