@tsed/core 8.11.0 → 8.11.2-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/decorators/storeFn.js +0 -1
- package/lib/esm/decorators/storeMerge.js +0 -1
- package/lib/esm/decorators/storeSet.js +0 -1
- package/lib/esm/errors/UnsupportedDecoratorType.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/types/AnyDecorator.js +0 -1
- package/lib/esm/types/DecoratorParameters.js +0 -1
- package/lib/esm/types/DecoratorTypes.js +0 -1
- package/lib/esm/types/Env.js +0 -1
- package/lib/esm/types/Metadata.js +0 -1
- package/lib/esm/types/MetadataTypes.js +0 -1
- package/lib/esm/types/Relation.js +0 -1
- package/lib/esm/types/Store.js +0 -1
- package/lib/esm/types/Type.js +0 -1
- package/lib/esm/types/ValueOf.js +0 -1
- package/lib/esm/utils/AnyToPromise.js +0 -1
- package/lib/esm/utils/ancestorOf.js +0 -1
- package/lib/esm/utils/ancestorsOf.js +0 -1
- package/lib/esm/utils/catchError.js +0 -1
- package/lib/esm/utils/classOf.js +0 -1
- package/lib/esm/utils/cleanObject.js +0 -1
- package/lib/esm/utils/constructorOf.js +0 -1
- package/lib/esm/utils/createInstance.js +0 -1
- package/lib/esm/utils/decorateMethodsOf.js +0 -1
- package/lib/esm/utils/decoratorArgs.js +0 -1
- package/lib/esm/utils/decoratorTypeOf.js +0 -1
- package/lib/esm/utils/deepClone.js +0 -1
- package/lib/esm/utils/deepMerge.js +0 -1
- package/lib/esm/utils/descriptorOf.js +0 -1
- package/lib/esm/utils/getClassOrSymbol.js +0 -1
- package/lib/esm/utils/getConstructorArgNames.js +0 -1
- package/lib/esm/utils/getRandomId.js +0 -1
- package/lib/esm/utils/getValue.js +0 -1
- package/lib/esm/utils/hasJsonMethod.js +0 -1
- package/lib/esm/utils/http/getHostInfoFromPort.js +0 -1
- package/lib/esm/utils/inheritedDescriptorOf.js +0 -1
- package/lib/esm/utils/isArray.js +0 -1
- package/lib/esm/utils/isArrowFn.js +0 -1
- package/lib/esm/utils/isBoolean.js +0 -1
- package/lib/esm/utils/isBuffer.js +0 -1
- package/lib/esm/utils/isClass.js +0 -1
- package/lib/esm/utils/isCollection.js +0 -1
- package/lib/esm/utils/isDate.js +0 -1
- package/lib/esm/utils/isEmpty.js +0 -1
- package/lib/esm/utils/isEnumerable.js +0 -1
- package/lib/esm/utils/isFunction.js +0 -1
- package/lib/esm/utils/isInheritedFrom.js +0 -1
- package/lib/esm/utils/isMomentObject.js +0 -1
- package/lib/esm/utils/isMongooseObject.js +0 -1
- package/lib/esm/utils/isNil.js +0 -1
- package/lib/esm/utils/isNumber.js +0 -1
- package/lib/esm/utils/isObject.js +0 -1
- package/lib/esm/utils/isObservable.js +0 -1
- package/lib/esm/utils/isPlainObject.js +0 -1
- package/lib/esm/utils/isPrimitive.js +0 -1
- package/lib/esm/utils/isPromise.js +0 -1
- package/lib/esm/utils/isProtectedKey.js +0 -1
- package/lib/esm/utils/isRegExp.js +0 -1
- package/lib/esm/utils/isSerializable.js +0 -1
- package/lib/esm/utils/isStream.js +0 -1
- package/lib/esm/utils/isString.js +0 -1
- package/lib/esm/utils/isSymbol.js +0 -1
- package/lib/esm/utils/methodsOf.js +0 -1
- package/lib/esm/utils/nameOf.js +0 -1
- package/lib/esm/utils/objectKeys.js +0 -1
- package/lib/esm/utils/primitiveOf.js +0 -1
- package/lib/esm/utils/prototypeOf.js +0 -1
- package/lib/esm/utils/setValue.js +0 -1
- package/lib/esm/utils/toMap.js +0 -1
- package/lib/esm/utils/toStringConstructor.js +0 -1
- package/lib/esm/utils/uniq.js +0 -1
- package/lib/esm/utils/useDecorators.js +0 -1
- package/lib/esm/utils/useMethodDecorators.js +0 -1
- package/package.json +8 -5
- package/.barrelsby.json +0 -5
- package/lib/esm/decorators/storeFn.js.map +0 -1
- package/lib/esm/decorators/storeMerge.js.map +0 -1
- package/lib/esm/decorators/storeSet.js.map +0 -1
- package/lib/esm/errors/UnsupportedDecoratorType.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/types/AnyDecorator.js.map +0 -1
- package/lib/esm/types/DecoratorParameters.js.map +0 -1
- package/lib/esm/types/DecoratorTypes.js.map +0 -1
- package/lib/esm/types/Env.js.map +0 -1
- package/lib/esm/types/Metadata.js.map +0 -1
- package/lib/esm/types/MetadataTypes.js.map +0 -1
- package/lib/esm/types/Relation.js.map +0 -1
- package/lib/esm/types/Store.js.map +0 -1
- package/lib/esm/types/Type.js.map +0 -1
- package/lib/esm/types/ValueOf.js.map +0 -1
- package/lib/esm/utils/AnyToPromise.js.map +0 -1
- package/lib/esm/utils/ancestorOf.js.map +0 -1
- package/lib/esm/utils/ancestorsOf.js.map +0 -1
- package/lib/esm/utils/catchError.js.map +0 -1
- package/lib/esm/utils/classOf.js.map +0 -1
- package/lib/esm/utils/cleanObject.js.map +0 -1
- package/lib/esm/utils/constructorOf.js.map +0 -1
- package/lib/esm/utils/createInstance.js.map +0 -1
- package/lib/esm/utils/decorateMethodsOf.js.map +0 -1
- package/lib/esm/utils/decoratorArgs.js.map +0 -1
- package/lib/esm/utils/decoratorTypeOf.js.map +0 -1
- package/lib/esm/utils/deepClone.js.map +0 -1
- package/lib/esm/utils/deepMerge.js.map +0 -1
- package/lib/esm/utils/descriptorOf.js.map +0 -1
- package/lib/esm/utils/getClassOrSymbol.js.map +0 -1
- package/lib/esm/utils/getConstructorArgNames.js.map +0 -1
- package/lib/esm/utils/getRandomId.js.map +0 -1
- package/lib/esm/utils/getValue.js.map +0 -1
- package/lib/esm/utils/hasJsonMethod.js.map +0 -1
- package/lib/esm/utils/http/getHostInfoFromPort.js.map +0 -1
- package/lib/esm/utils/inheritedDescriptorOf.js.map +0 -1
- package/lib/esm/utils/isArray.js.map +0 -1
- package/lib/esm/utils/isArrowFn.js.map +0 -1
- package/lib/esm/utils/isBoolean.js.map +0 -1
- package/lib/esm/utils/isBuffer.js.map +0 -1
- package/lib/esm/utils/isClass.js.map +0 -1
- package/lib/esm/utils/isCollection.js.map +0 -1
- package/lib/esm/utils/isDate.js.map +0 -1
- package/lib/esm/utils/isEmpty.js.map +0 -1
- package/lib/esm/utils/isEnumerable.js.map +0 -1
- package/lib/esm/utils/isFunction.js.map +0 -1
- package/lib/esm/utils/isInheritedFrom.js.map +0 -1
- package/lib/esm/utils/isMomentObject.js.map +0 -1
- package/lib/esm/utils/isMongooseObject.js.map +0 -1
- package/lib/esm/utils/isNil.js.map +0 -1
- package/lib/esm/utils/isNumber.js.map +0 -1
- package/lib/esm/utils/isObject.js.map +0 -1
- package/lib/esm/utils/isObservable.js.map +0 -1
- package/lib/esm/utils/isPlainObject.js.map +0 -1
- package/lib/esm/utils/isPrimitive.js.map +0 -1
- package/lib/esm/utils/isPromise.js.map +0 -1
- package/lib/esm/utils/isProtectedKey.js.map +0 -1
- package/lib/esm/utils/isRegExp.js.map +0 -1
- package/lib/esm/utils/isSerializable.js.map +0 -1
- package/lib/esm/utils/isStream.js.map +0 -1
- package/lib/esm/utils/isString.js.map +0 -1
- package/lib/esm/utils/isSymbol.js.map +0 -1
- package/lib/esm/utils/methodsOf.js.map +0 -1
- package/lib/esm/utils/nameOf.js.map +0 -1
- package/lib/esm/utils/objectKeys.js.map +0 -1
- package/lib/esm/utils/primitiveOf.js.map +0 -1
- package/lib/esm/utils/prototypeOf.js.map +0 -1
- package/lib/esm/utils/setValue.js.map +0 -1
- package/lib/esm/utils/toMap.js.map +0 -1
- package/lib/esm/utils/toStringConstructor.js.map +0 -1
- package/lib/esm/utils/uniq.js.map +0 -1
- package/lib/esm/utils/useDecorators.js.map +0 -1
- package/lib/esm/utils/useMethodDecorators.js.map +0 -1
- package/src/decorators/storeFn.ts +0 -20
- package/src/decorators/storeMerge.ts +0 -8
- package/src/decorators/storeSet.ts +0 -8
- package/src/errors/UnsupportedDecoratorType.spec.ts +0 -81
- package/src/errors/UnsupportedDecoratorType.ts +0 -25
- package/src/index.ts +0 -75
- package/src/types/AnyDecorator.ts +0 -1
- package/src/types/DecoratorParameters.ts +0 -8
- package/src/types/DecoratorTypes.ts +0 -10
- package/src/types/Env.ts +0 -15
- package/src/types/Metadata.spec.ts +0 -142
- package/src/types/Metadata.ts +0 -523
- package/src/types/MetadataTypes.ts +0 -6
- package/src/types/Relation.ts +0 -1
- package/src/types/Store.spec.ts +0 -164
- package/src/types/Store.ts +0 -175
- package/src/types/Type.ts +0 -20
- package/src/types/ValueOf.ts +0 -1
- package/src/utils/AnyToPromise.spec.ts +0 -159
- package/src/utils/AnyToPromise.ts +0 -181
- package/src/utils/ObjectUtils.spec.ts +0 -322
- package/src/utils/ancestorOf.ts +0 -7
- package/src/utils/ancestorsOf.ts +0 -21
- package/src/utils/catchError.spec.ts +0 -17
- package/src/utils/catchError.ts +0 -15
- package/src/utils/classOf.ts +0 -18
- package/src/utils/cleanObject.spec.ts +0 -22
- package/src/utils/cleanObject.ts +0 -20
- package/src/utils/constructorOf.ts +0 -17
- package/src/utils/createInstance.ts +0 -5
- package/src/utils/decorateMethodsOf.spec.ts +0 -83
- package/src/utils/decorateMethodsOf.ts +0 -31
- package/src/utils/decoratorArgs.spec.ts +0 -15
- package/src/utils/decoratorArgs.ts +0 -6
- package/src/utils/decoratorTypeOf.spec.ts +0 -92
- package/src/utils/decoratorTypeOf.ts +0 -24
- package/src/utils/deepClone.spec.ts +0 -130
- package/src/utils/deepClone.ts +0 -85
- package/src/utils/deepMerge.spec.ts +0 -223
- package/src/utils/deepMerge.ts +0 -85
- package/src/utils/descriptorOf.spec.ts +0 -16
- package/src/utils/descriptorOf.ts +0 -13
- package/src/utils/getClassOrSymbol.ts +0 -6
- package/src/utils/getConstructorArgNames.spec.ts +0 -11
- package/src/utils/getConstructorArgNames.ts +0 -10
- package/src/utils/getRandomId.spec.ts +0 -7
- package/src/utils/getRandomId.ts +0 -3
- package/src/utils/getValue.spec.ts +0 -62
- package/src/utils/getValue.ts +0 -87
- package/src/utils/hasJsonMethod.spec.ts +0 -11
- package/src/utils/hasJsonMethod.ts +0 -3
- package/src/utils/http/getHostInfoFromPort.spec.ts +0 -25
- package/src/utils/http/getHostInfoFromPort.ts +0 -20
- package/src/utils/inheritedDescriptorOf.ts +0 -13
- package/src/utils/isArray.ts +0 -18
- package/src/utils/isArrowFn.ts +0 -5
- package/src/utils/isBoolean.ts +0 -12
- package/src/utils/isBuffer.spec.ts +0 -14
- package/src/utils/isBuffer.ts +0 -19
- package/src/utils/isClass.spec.ts +0 -15
- package/src/utils/isClass.ts +0 -28
- package/src/utils/isCollection.ts +0 -20
- package/src/utils/isDate.ts +0 -8
- package/src/utils/isEmpty.spec.ts +0 -10
- package/src/utils/isEmpty.ts +0 -10
- package/src/utils/isEnumerable.ts +0 -21
- package/src/utils/isFunction.ts +0 -3
- package/src/utils/isInheritedFrom.ts +0 -26
- package/src/utils/isMomentObject.spec.ts +0 -16
- package/src/utils/isMomentObject.ts +0 -3
- package/src/utils/isMongooseObject.spec.ts +0 -22
- package/src/utils/isMongooseObject.ts +0 -9
- package/src/utils/isNil.spec.ts +0 -10
- package/src/utils/isNil.ts +0 -3
- package/src/utils/isNumber.ts +0 -12
- package/src/utils/isObject.ts +0 -3
- package/src/utils/isObservable.ts +0 -3
- package/src/utils/isPlainObject.spec.ts +0 -10
- package/src/utils/isPlainObject.ts +0 -14
- package/src/utils/isPrimitive.spec.ts +0 -17
- package/src/utils/isPrimitive.ts +0 -26
- package/src/utils/isPromise.ts +0 -13
- package/src/utils/isProtectedKey.spec.ts +0 -14
- package/src/utils/isProtectedKey.ts +0 -7
- package/src/utils/isRegExp.ts +0 -3
- package/src/utils/isSerializable.spec.ts +0 -14
- package/src/utils/isSerializable.ts +0 -9
- package/src/utils/isStream.ts +0 -3
- package/src/utils/isString.ts +0 -11
- package/src/utils/isSymbol.spec.ts +0 -11
- package/src/utils/isSymbol.ts +0 -11
- package/src/utils/methodsOf.spec.ts +0 -33
- package/src/utils/methodsOf.ts +0 -26
- package/src/utils/nameOf.ts +0 -27
- package/src/utils/objectKeys.spec.ts +0 -10
- package/src/utils/objectKeys.ts +0 -5
- package/src/utils/primitiveOf.ts +0 -19
- package/src/utils/prototypeOf.ts +0 -10
- package/src/utils/setValue.spec.ts +0 -60
- package/src/utils/setValue.ts +0 -35
- package/src/utils/toMap.spec.ts +0 -211
- package/src/utils/toMap.ts +0 -44
- package/src/utils/toStringConstructor.ts +0 -9
- package/src/utils/toStringConstrutor.spec.ts +0 -18
- package/src/utils/uniq.spec.ts +0 -8
- package/src/utils/uniq.ts +0 -16
- package/src/utils/useDecorators.spec.ts +0 -61
- package/src/utils/useDecorators.ts +0 -21
- package/src/utils/useMethodDecorator.spec.ts +0 -45
- package/src/utils/useMethodDecorators.ts +0 -12
- package/vitest.config.mts +0 -21
package/src/utils/getRandomId.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import {getValue} from "./getValue.js";
|
|
2
|
-
|
|
3
|
-
describe("getValue()", () => {
|
|
4
|
-
it("should return given value when expression is undefined", () => {
|
|
5
|
-
expect(getValue(undefined, {})).toEqual({});
|
|
6
|
-
expect(getValue({}, undefined)).toEqual({});
|
|
7
|
-
});
|
|
8
|
-
it("should return given value when expression is undefined 2", () => {
|
|
9
|
-
expect(getValue(undefined, undefined)).toEqual(undefined);
|
|
10
|
-
});
|
|
11
|
-
it("should return given undefined when expression is given but scope doesn't have value", () => {
|
|
12
|
-
expect(getValue("user", {})).toEqual(undefined);
|
|
13
|
-
expect(getValue({}, "user")).toEqual(undefined);
|
|
14
|
-
});
|
|
15
|
-
it("should return given value when expression is given and scope have value", () => {
|
|
16
|
-
expect(getValue("user", {user: "name"})).toEqual("name");
|
|
17
|
-
expect(getValue({user: "name"}, "user")).toEqual("name");
|
|
18
|
-
});
|
|
19
|
-
it("should return given value when expression is given but scope have value (2)", () => {
|
|
20
|
-
expect(getValue("user.name", {user: {name: "name"}})).toEqual("name");
|
|
21
|
-
expect(getValue({user: {name: "name"}}, "user.name")).toEqual("name");
|
|
22
|
-
});
|
|
23
|
-
it("should return given value when expression is given but scope have value (3)", () => {
|
|
24
|
-
expect(getValue("users.0", {users: [{user: {name: "name"}}]})).toEqual({user: {name: "name"}});
|
|
25
|
-
expect(getValue({users: [{user: {name: "name"}}]}, "users.0")).toEqual({user: {name: "name"}});
|
|
26
|
-
});
|
|
27
|
-
it("should return given value when expression is given but scope have value (4)", () => {
|
|
28
|
-
const map = new Map([["user", "name"]]);
|
|
29
|
-
expect(getValue("user", map)).toEqual("name");
|
|
30
|
-
expect(getValue(map, "user")).toEqual("name");
|
|
31
|
-
});
|
|
32
|
-
it("should return from an object with get method", () => {
|
|
33
|
-
const map = {
|
|
34
|
-
get() {
|
|
35
|
-
return "name";
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
expect(getValue("user", map)).toEqual("name");
|
|
39
|
-
expect(getValue(map, "user")).toEqual("name");
|
|
40
|
-
});
|
|
41
|
-
it("should return undefined", () => {
|
|
42
|
-
expect(getValue("user", undefined)).toEqual(undefined);
|
|
43
|
-
expect(getValue(undefined, "user")).toEqual(undefined);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should return undefined from getter", () => {
|
|
47
|
-
expect(
|
|
48
|
-
getValue(
|
|
49
|
-
{
|
|
50
|
-
get test() {
|
|
51
|
-
return undefined;
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
get() {
|
|
55
|
-
return "test";
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
"test"
|
|
59
|
-
)
|
|
60
|
-
).toEqual(undefined);
|
|
61
|
-
});
|
|
62
|
-
});
|
package/src/utils/getValue.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import {isFunction} from "./isFunction.js";
|
|
2
|
-
import {isObject} from "./isObject.js";
|
|
3
|
-
import {isString} from "./isString.js";
|
|
4
|
-
|
|
5
|
-
const mapOptions = (args: any[]) => {
|
|
6
|
-
const [expression, scope, defaultValue, separator = "."] = args;
|
|
7
|
-
|
|
8
|
-
if (isObject(scope) || isString(expression)) {
|
|
9
|
-
return {
|
|
10
|
-
expression,
|
|
11
|
-
scope,
|
|
12
|
-
defaultValue,
|
|
13
|
-
separator
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
expression: scope,
|
|
19
|
-
scope: expression,
|
|
20
|
-
defaultValue,
|
|
21
|
-
separator
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Get value from scope
|
|
27
|
-
* @param {string} expression
|
|
28
|
-
* @param scope
|
|
29
|
-
* @returns {any}
|
|
30
|
-
*/
|
|
31
|
-
export function getValue<T = any>(scope: any, expression: string | undefined): T | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Get value from scope
|
|
34
|
-
* @param {string} expression
|
|
35
|
-
* @param scope
|
|
36
|
-
* @param defaultValue
|
|
37
|
-
* @param separator
|
|
38
|
-
* @returns {any}
|
|
39
|
-
*/
|
|
40
|
-
export function getValue<T = any>(scope: any, expression: string | undefined, defaultValue: T, separator?: string): T;
|
|
41
|
-
/**
|
|
42
|
-
* Get value from scope
|
|
43
|
-
* @param {string} expression
|
|
44
|
-
* @param scope
|
|
45
|
-
* @returns {any}
|
|
46
|
-
*/
|
|
47
|
-
export function getValue<T = any>(expression: string | undefined, scope: any): T | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Get value from scope
|
|
50
|
-
* @param {string} expression
|
|
51
|
-
* @param scope
|
|
52
|
-
* @param defaultValue
|
|
53
|
-
* @param separator
|
|
54
|
-
* @returns {any}
|
|
55
|
-
*/
|
|
56
|
-
export function getValue<T = any>(expression: string | undefined, scope: any, defaultValue: T, separator?: string): T;
|
|
57
|
-
export function getValue(...args: any[]) {
|
|
58
|
-
const options = mapOptions(args);
|
|
59
|
-
let scope = options.scope;
|
|
60
|
-
const {expression, defaultValue, separator} = options;
|
|
61
|
-
|
|
62
|
-
if (!expression) {
|
|
63
|
-
return scope;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!scope) {
|
|
67
|
-
return defaultValue;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const keys: string[] = expression.split(separator);
|
|
71
|
-
|
|
72
|
-
const getValue = (key: string) => {
|
|
73
|
-
if (scope) {
|
|
74
|
-
if (scope[key] !== undefined || (isObject(scope) && key in scope)) {
|
|
75
|
-
return scope[key];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (isFunction(scope.get)) {
|
|
79
|
-
return scope.get(key);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
while ((scope = getValue(keys.shift()!)) && keys.length) {}
|
|
85
|
-
|
|
86
|
-
return scope === undefined ? defaultValue : scope;
|
|
87
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {hasJsonMethod} from "./hasJsonMethod.js";
|
|
2
|
-
|
|
3
|
-
describe("hasJsonMethod", () => {
|
|
4
|
-
it("should return true if object has toJSON method", () => {
|
|
5
|
-
expect(hasJsonMethod({toJSON: () => {}})).toEqual(true);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it("should return false if object hasn't toJSON method", () => {
|
|
9
|
-
expect(hasJsonMethod({})).toEqual(false);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {getHostInfoFromPort} from "./getHostInfoFromPort.js";
|
|
2
|
-
|
|
3
|
-
describe("buildAddressAndPort()", () => {
|
|
4
|
-
it("should return address and port from a concatened address and port", () => {
|
|
5
|
-
const address = getHostInfoFromPort("http", "0.0.0.0:9000");
|
|
6
|
-
expect(address).toEqual({
|
|
7
|
-
address: "0.0.0.0",
|
|
8
|
-
port: 9000,
|
|
9
|
-
protocol: "http",
|
|
10
|
-
toString: address.toString
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("should return address and port from a port number", () => {
|
|
15
|
-
const address = getHostInfoFromPort("https", 9000);
|
|
16
|
-
expect(address).toEqual({
|
|
17
|
-
address: "0.0.0.0",
|
|
18
|
-
port: 9000,
|
|
19
|
-
protocol: "https",
|
|
20
|
-
toString: address.toString
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(address.toString()).toBe("https://0.0.0.0:9000");
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function getHostInfoFromPort(protocol: string, addressPort: any) {
|
|
2
|
-
let address = "0.0.0.0";
|
|
3
|
-
let port = addressPort;
|
|
4
|
-
|
|
5
|
-
if (typeof addressPort === "string" && addressPort.indexOf(":") > -1) {
|
|
6
|
-
[address, port] = addressPort.split(":");
|
|
7
|
-
port = +port;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
protocol,
|
|
12
|
-
address,
|
|
13
|
-
port: port as number,
|
|
14
|
-
toString() {
|
|
15
|
-
return [`${this.protocol}://${this.address}`, typeof this.port === "number" && this.port].filter(Boolean).join(":");
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type ReturnHostInfoFromPort = ReturnType<typeof getHostInfoFromPort>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {ancestorsOf} from "./ancestorsOf.js";
|
|
2
|
-
|
|
3
|
-
export function inheritedDescriptorOf(target: any, propertyKey: string): PropertyDescriptor | undefined {
|
|
4
|
-
for (const klass of ancestorsOf(target)) {
|
|
5
|
-
const descriptor = Object.getOwnPropertyDescriptor((klass && klass.prototype) || klass, propertyKey)!;
|
|
6
|
-
|
|
7
|
-
if (descriptor) {
|
|
8
|
-
return descriptor;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
package/src/utils/isArray.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Return true if value is an array
|
|
3
|
-
* @param target
|
|
4
|
-
* @returns {boolean}
|
|
5
|
-
*/
|
|
6
|
-
export function isArray<T = any>(target: unknown): target is T[] {
|
|
7
|
-
return Array.isArray(target);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Return true if the clazz is an array.
|
|
12
|
-
* @param target
|
|
13
|
-
* @returns {boolean}
|
|
14
|
-
* @ignore
|
|
15
|
-
*/
|
|
16
|
-
export function isArrayOrArrayClass<T = any>(target: unknown): target is T[] {
|
|
17
|
-
return target === Array || isArray(target);
|
|
18
|
-
}
|
package/src/utils/isArrowFn.ts
DELETED
package/src/utils/isBoolean.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param target
|
|
4
|
-
* @returns {boolean}
|
|
5
|
-
*/
|
|
6
|
-
export function isBoolean(target: any): target is boolean {
|
|
7
|
-
return typeof target === "boolean" || target instanceof Boolean || target === Boolean;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isBooleanOrBooleanClass(target: any): target is boolean {
|
|
11
|
-
return typeof target === "boolean" || target instanceof Boolean || target === Boolean;
|
|
12
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {isBuffer, isUint8Array} from "./isBuffer.js";
|
|
2
|
-
|
|
3
|
-
describe("isBuffer", () => {
|
|
4
|
-
it("should return true", () => {
|
|
5
|
-
expect(isBuffer(Buffer.from(""))).toBeTruthy();
|
|
6
|
-
expect(isBuffer(Buffer)).toBeTruthy();
|
|
7
|
-
expect(isUint8Array(Uint8Array)).toBeTruthy();
|
|
8
|
-
expect(isUint8Array(Uint8Array.from([0, 1]))).toBeTruthy();
|
|
9
|
-
});
|
|
10
|
-
it("should return false", () => {
|
|
11
|
-
expect(isBuffer({})).toBeFalsy();
|
|
12
|
-
expect(isBuffer(undefined)).toBeFalsy();
|
|
13
|
-
});
|
|
14
|
-
});
|
package/src/utils/isBuffer.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {nameOf} from "./nameOf.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Tests to see if the object is Buffer
|
|
5
|
-
* @param target
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
export function isBuffer(target: any): target is Buffer {
|
|
9
|
-
// is Class
|
|
10
|
-
if (target && "isBuffer" in target && typeof target.isBuffer === "function") {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return isUint8Array(target);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function isUint8Array(target: any): target is Uint8Array {
|
|
18
|
-
return !!(target && (target === Uint8Array || target instanceof Uint8Array));
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {isClass} from "./isClass.js";
|
|
2
|
-
|
|
3
|
-
describe("isClass", () => {
|
|
4
|
-
it("should test if a value is a class", () => {
|
|
5
|
-
expect(isClass(class Test {})).toEqual(true);
|
|
6
|
-
expect(isClass(Date)).toEqual(false);
|
|
7
|
-
expect(isClass(undefined)).toEqual(false);
|
|
8
|
-
expect(isClass(Symbol("zertyuio"))).toEqual(false);
|
|
9
|
-
expect(isClass(Number)).toEqual(false);
|
|
10
|
-
expect(isClass(Promise)).toEqual(false);
|
|
11
|
-
expect(isClass(Array)).toEqual(false);
|
|
12
|
-
expect(isClass(Buffer)).toEqual(false);
|
|
13
|
-
expect(isClass(() => {})).toEqual(false);
|
|
14
|
-
});
|
|
15
|
-
});
|
package/src/utils/isClass.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {isArrayOrArrayClass} from "./isArray.js";
|
|
2
|
-
import {isArrowFn} from "./isArrowFn.js";
|
|
3
|
-
import {isBuffer} from "./isBuffer.js";
|
|
4
|
-
import {isDate} from "./isDate.js";
|
|
5
|
-
import {isClassObject} from "./isPlainObject.js";
|
|
6
|
-
import {isPrimitiveOrPrimitiveClass} from "./isPrimitive.js";
|
|
7
|
-
import {isPromise} from "./isPromise.js";
|
|
8
|
-
import {isSymbol} from "./isSymbol.js";
|
|
9
|
-
|
|
10
|
-
export function isClass(target: any) {
|
|
11
|
-
if (!target) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (isArrowFn(target)) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return !(
|
|
20
|
-
isSymbol(target) ||
|
|
21
|
-
isPrimitiveOrPrimitiveClass(target) ||
|
|
22
|
-
isClassObject(target) ||
|
|
23
|
-
isDate(target) ||
|
|
24
|
-
isPromise(target) ||
|
|
25
|
-
isArrayOrArrayClass(target) ||
|
|
26
|
-
isBuffer(target)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {isArrayOrArrayClass} from "./isArray.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Return true if the target.
|
|
5
|
-
* @param target
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
export function isCollection(target: any): boolean {
|
|
9
|
-
return (
|
|
10
|
-
isArrayOrArrayClass(target) ||
|
|
11
|
-
target === Map ||
|
|
12
|
-
target instanceof Map ||
|
|
13
|
-
target === Set ||
|
|
14
|
-
target instanceof Set ||
|
|
15
|
-
target === WeakMap ||
|
|
16
|
-
target instanceof WeakMap ||
|
|
17
|
-
target === WeakSet ||
|
|
18
|
-
target instanceof WeakSet
|
|
19
|
-
);
|
|
20
|
-
}
|
package/src/utils/isDate.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {isEmpty} from "./isEmpty.js";
|
|
2
|
-
|
|
3
|
-
describe("isEmpty", () => {
|
|
4
|
-
it("should return true", () => {
|
|
5
|
-
expect(isEmpty(null)).toBe(true);
|
|
6
|
-
expect(isEmpty(undefined)).toBe(true);
|
|
7
|
-
expect(isEmpty(1)).toBe(false);
|
|
8
|
-
expect(isEmpty("")).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
});
|
package/src/utils/isEmpty.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {classOf} from "./classOf.js";
|
|
2
|
-
import {inheritedDescriptorOf} from "./inheritedDescriptorOf.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param obj
|
|
7
|
-
* @param key
|
|
8
|
-
*/
|
|
9
|
-
export function isEnumerable(obj: any, key: string) {
|
|
10
|
-
const klass = classOf(obj);
|
|
11
|
-
|
|
12
|
-
if (klass) {
|
|
13
|
-
const descriptor = inheritedDescriptorOf(klass, key);
|
|
14
|
-
|
|
15
|
-
if (descriptor) {
|
|
16
|
-
return descriptor.enumerable;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return Object.prototype.propertyIsEnumerable.call(obj, key);
|
|
21
|
-
}
|
package/src/utils/isFunction.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {ancestorOf} from "./ancestorOf.js";
|
|
2
|
-
import {classOf} from "./classOf.js";
|
|
3
|
-
import {nameOf} from "./nameOf.js";
|
|
4
|
-
|
|
5
|
-
export function isInheritedFrom(target: any, from: any, deep = 5): boolean {
|
|
6
|
-
if (!target || !from) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
target = classOf(target);
|
|
11
|
-
from = classOf(from);
|
|
12
|
-
|
|
13
|
-
while (nameOf(target) !== "") {
|
|
14
|
-
if (!deep) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
if (target === from) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
target = ancestorOf(target);
|
|
22
|
-
deep--;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {isMomentObject} from "./isMomentObject.js";
|
|
2
|
-
|
|
3
|
-
describe("isMomentObject", () => {
|
|
4
|
-
it("should return true if object is moment object", () => {
|
|
5
|
-
expect(
|
|
6
|
-
isMomentObject({
|
|
7
|
-
_isAMomentObject: true
|
|
8
|
-
})
|
|
9
|
-
).toEqual(true);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("should return false if object is not moment object", () => {
|
|
13
|
-
expect(isMomentObject({})).toEqual(false);
|
|
14
|
-
expect(isMomentObject(null)).toEqual(false);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {isMongooseObject} from "./isMongooseObject.js";
|
|
2
|
-
|
|
3
|
-
describe("isMongooseObject", () => {
|
|
4
|
-
it("should return true if object is mongoose object", () => {
|
|
5
|
-
expect(
|
|
6
|
-
isMongooseObject({
|
|
7
|
-
toJSON: () => {},
|
|
8
|
-
$isMongooseModelPrototype: true
|
|
9
|
-
})
|
|
10
|
-
).toEqual(true);
|
|
11
|
-
expect(isMongooseObject({_bsontype: true})).toEqual(true);
|
|
12
|
-
});
|
|
13
|
-
it("should return false if object is not mongoose object", () => {
|
|
14
|
-
expect(
|
|
15
|
-
isMongooseObject({
|
|
16
|
-
toJSON: () => {}
|
|
17
|
-
})
|
|
18
|
-
).toEqual(false);
|
|
19
|
-
expect(isMongooseObject({})).toEqual(false);
|
|
20
|
-
expect(isMongooseObject(null)).toEqual(false);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {hasJsonMethod} from "./hasJsonMethod.js";
|
|
2
|
-
|
|
3
|
-
export function isObjectID(obj: any) {
|
|
4
|
-
return obj && obj._bsontype;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function isMongooseObject(obj: any) {
|
|
8
|
-
return !!((hasJsonMethod(obj) && obj.$isMongooseModelPrototype) || isObjectID(obj));
|
|
9
|
-
}
|
package/src/utils/isNil.spec.ts
DELETED
package/src/utils/isNil.ts
DELETED
package/src/utils/isNumber.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* @param target
|
|
4
|
-
* @returns {boolean}
|
|
5
|
-
*/
|
|
6
|
-
export function isNumber(target: any): target is number {
|
|
7
|
-
return typeof target === "number";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isNumberOrNumberClass(target: any): target is number {
|
|
11
|
-
return typeof target === "number" || target instanceof Number || target === Number;
|
|
12
|
-
}
|
package/src/utils/isObject.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {isPlainObject} from "./isPlainObject.js";
|
|
2
|
-
|
|
3
|
-
describe("isPlainObject", () => {
|
|
4
|
-
it("should test if the value is a plain object", () => {
|
|
5
|
-
expect(isPlainObject({})).toEqual(true);
|
|
6
|
-
expect(isPlainObject(class {})).toEqual(false);
|
|
7
|
-
expect(isPlainObject(new (class {})())).toEqual(false);
|
|
8
|
-
expect(isPlainObject(Object)).toEqual(false);
|
|
9
|
-
});
|
|
10
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {classOf} from "./classOf.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param target
|
|
6
|
-
* @returns {boolean}
|
|
7
|
-
*/
|
|
8
|
-
export function isClassObject(target: any): target is Object {
|
|
9
|
-
return target === Object;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isPlainObject(target: any): boolean {
|
|
13
|
-
return isClassObject(classOf(target)) && target !== Object;
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {isPrimitive, isPrimitiveClass} from "./isPrimitive.js";
|
|
2
|
-
|
|
3
|
-
describe("isPrimitive", () => {
|
|
4
|
-
it("should test if an variable content is a primitive", () => {
|
|
5
|
-
expect(isPrimitive("1")).toEqual(true);
|
|
6
|
-
expect(isPrimitive(1)).toEqual(true);
|
|
7
|
-
expect(isPrimitive(true)).toEqual(true);
|
|
8
|
-
expect(isPrimitive({})).toEqual(false);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("should test if a class is String, Number or Boolean", () => {
|
|
12
|
-
expect(isPrimitiveClass(String)).toEqual(true);
|
|
13
|
-
expect(isPrimitiveClass(Number)).toEqual(true);
|
|
14
|
-
expect(isPrimitiveClass(Boolean)).toEqual(true);
|
|
15
|
-
expect(isPrimitiveClass(Date)).toEqual(false);
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/utils/isPrimitive.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import {isBoolean, isBooleanOrBooleanClass} from "./isBoolean.js";
|
|
2
|
-
import {isNumber, isNumberOrNumberClass} from "./isNumber.js";
|
|
3
|
-
import {isString, isStringOrStringClass} from "./isString.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Return true if the given obj is a primitive.
|
|
7
|
-
* @param target
|
|
8
|
-
* @returns {boolean}
|
|
9
|
-
* @ignore
|
|
10
|
-
*/
|
|
11
|
-
export function isPrimitiveOrPrimitiveClass(target: any): boolean {
|
|
12
|
-
return isStringOrStringClass(target) || isNumberOrNumberClass(target) || isBooleanOrBooleanClass(target);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Return true if the given obj is a primitive.
|
|
17
|
-
* @param target
|
|
18
|
-
* @returns {boolean}
|
|
19
|
-
*/
|
|
20
|
-
export function isPrimitive(target: any): boolean {
|
|
21
|
-
return isString(target) || isNumber(target) || isBoolean(target);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function isPrimitiveClass(target: any) {
|
|
25
|
-
return [String, Number, Boolean].includes(target);
|
|
26
|
-
}
|
package/src/utils/isPromise.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests to see if the object is an ES2015 (ES6) Promise
|
|
3
|
-
* @see {@link https://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects}
|
|
4
|
-
* @param target
|
|
5
|
-
* @returns {boolean}
|
|
6
|
-
*/
|
|
7
|
-
export function isPromise<T = any>(target: any): target is Promise<T> {
|
|
8
|
-
return (
|
|
9
|
-
target === Promise ||
|
|
10
|
-
target instanceof Promise ||
|
|
11
|
-
(!!target && typeof target.subscribe !== "function" && typeof target.then === "function")
|
|
12
|
-
);
|
|
13
|
-
}
|