@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.
Files changed (259) hide show
  1. package/lib/esm/decorators/storeFn.js +0 -1
  2. package/lib/esm/decorators/storeMerge.js +0 -1
  3. package/lib/esm/decorators/storeSet.js +0 -1
  4. package/lib/esm/errors/UnsupportedDecoratorType.js +0 -1
  5. package/lib/esm/index.js +0 -1
  6. package/lib/esm/types/AnyDecorator.js +0 -1
  7. package/lib/esm/types/DecoratorParameters.js +0 -1
  8. package/lib/esm/types/DecoratorTypes.js +0 -1
  9. package/lib/esm/types/Env.js +0 -1
  10. package/lib/esm/types/Metadata.js +0 -1
  11. package/lib/esm/types/MetadataTypes.js +0 -1
  12. package/lib/esm/types/Relation.js +0 -1
  13. package/lib/esm/types/Store.js +0 -1
  14. package/lib/esm/types/Type.js +0 -1
  15. package/lib/esm/types/ValueOf.js +0 -1
  16. package/lib/esm/utils/AnyToPromise.js +0 -1
  17. package/lib/esm/utils/ancestorOf.js +0 -1
  18. package/lib/esm/utils/ancestorsOf.js +0 -1
  19. package/lib/esm/utils/catchError.js +0 -1
  20. package/lib/esm/utils/classOf.js +0 -1
  21. package/lib/esm/utils/cleanObject.js +0 -1
  22. package/lib/esm/utils/constructorOf.js +0 -1
  23. package/lib/esm/utils/createInstance.js +0 -1
  24. package/lib/esm/utils/decorateMethodsOf.js +0 -1
  25. package/lib/esm/utils/decoratorArgs.js +0 -1
  26. package/lib/esm/utils/decoratorTypeOf.js +0 -1
  27. package/lib/esm/utils/deepClone.js +0 -1
  28. package/lib/esm/utils/deepMerge.js +0 -1
  29. package/lib/esm/utils/descriptorOf.js +0 -1
  30. package/lib/esm/utils/getClassOrSymbol.js +0 -1
  31. package/lib/esm/utils/getConstructorArgNames.js +0 -1
  32. package/lib/esm/utils/getRandomId.js +0 -1
  33. package/lib/esm/utils/getValue.js +0 -1
  34. package/lib/esm/utils/hasJsonMethod.js +0 -1
  35. package/lib/esm/utils/http/getHostInfoFromPort.js +0 -1
  36. package/lib/esm/utils/inheritedDescriptorOf.js +0 -1
  37. package/lib/esm/utils/isArray.js +0 -1
  38. package/lib/esm/utils/isArrowFn.js +0 -1
  39. package/lib/esm/utils/isBoolean.js +0 -1
  40. package/lib/esm/utils/isBuffer.js +0 -1
  41. package/lib/esm/utils/isClass.js +0 -1
  42. package/lib/esm/utils/isCollection.js +0 -1
  43. package/lib/esm/utils/isDate.js +0 -1
  44. package/lib/esm/utils/isEmpty.js +0 -1
  45. package/lib/esm/utils/isEnumerable.js +0 -1
  46. package/lib/esm/utils/isFunction.js +0 -1
  47. package/lib/esm/utils/isInheritedFrom.js +0 -1
  48. package/lib/esm/utils/isMomentObject.js +0 -1
  49. package/lib/esm/utils/isMongooseObject.js +0 -1
  50. package/lib/esm/utils/isNil.js +0 -1
  51. package/lib/esm/utils/isNumber.js +0 -1
  52. package/lib/esm/utils/isObject.js +0 -1
  53. package/lib/esm/utils/isObservable.js +0 -1
  54. package/lib/esm/utils/isPlainObject.js +0 -1
  55. package/lib/esm/utils/isPrimitive.js +0 -1
  56. package/lib/esm/utils/isPromise.js +0 -1
  57. package/lib/esm/utils/isProtectedKey.js +0 -1
  58. package/lib/esm/utils/isRegExp.js +0 -1
  59. package/lib/esm/utils/isSerializable.js +0 -1
  60. package/lib/esm/utils/isStream.js +0 -1
  61. package/lib/esm/utils/isString.js +0 -1
  62. package/lib/esm/utils/isSymbol.js +0 -1
  63. package/lib/esm/utils/methodsOf.js +0 -1
  64. package/lib/esm/utils/nameOf.js +0 -1
  65. package/lib/esm/utils/objectKeys.js +0 -1
  66. package/lib/esm/utils/primitiveOf.js +0 -1
  67. package/lib/esm/utils/prototypeOf.js +0 -1
  68. package/lib/esm/utils/setValue.js +0 -1
  69. package/lib/esm/utils/toMap.js +0 -1
  70. package/lib/esm/utils/toStringConstructor.js +0 -1
  71. package/lib/esm/utils/uniq.js +0 -1
  72. package/lib/esm/utils/useDecorators.js +0 -1
  73. package/lib/esm/utils/useMethodDecorators.js +0 -1
  74. package/package.json +8 -5
  75. package/.barrelsby.json +0 -5
  76. package/lib/esm/decorators/storeFn.js.map +0 -1
  77. package/lib/esm/decorators/storeMerge.js.map +0 -1
  78. package/lib/esm/decorators/storeSet.js.map +0 -1
  79. package/lib/esm/errors/UnsupportedDecoratorType.js.map +0 -1
  80. package/lib/esm/index.js.map +0 -1
  81. package/lib/esm/types/AnyDecorator.js.map +0 -1
  82. package/lib/esm/types/DecoratorParameters.js.map +0 -1
  83. package/lib/esm/types/DecoratorTypes.js.map +0 -1
  84. package/lib/esm/types/Env.js.map +0 -1
  85. package/lib/esm/types/Metadata.js.map +0 -1
  86. package/lib/esm/types/MetadataTypes.js.map +0 -1
  87. package/lib/esm/types/Relation.js.map +0 -1
  88. package/lib/esm/types/Store.js.map +0 -1
  89. package/lib/esm/types/Type.js.map +0 -1
  90. package/lib/esm/types/ValueOf.js.map +0 -1
  91. package/lib/esm/utils/AnyToPromise.js.map +0 -1
  92. package/lib/esm/utils/ancestorOf.js.map +0 -1
  93. package/lib/esm/utils/ancestorsOf.js.map +0 -1
  94. package/lib/esm/utils/catchError.js.map +0 -1
  95. package/lib/esm/utils/classOf.js.map +0 -1
  96. package/lib/esm/utils/cleanObject.js.map +0 -1
  97. package/lib/esm/utils/constructorOf.js.map +0 -1
  98. package/lib/esm/utils/createInstance.js.map +0 -1
  99. package/lib/esm/utils/decorateMethodsOf.js.map +0 -1
  100. package/lib/esm/utils/decoratorArgs.js.map +0 -1
  101. package/lib/esm/utils/decoratorTypeOf.js.map +0 -1
  102. package/lib/esm/utils/deepClone.js.map +0 -1
  103. package/lib/esm/utils/deepMerge.js.map +0 -1
  104. package/lib/esm/utils/descriptorOf.js.map +0 -1
  105. package/lib/esm/utils/getClassOrSymbol.js.map +0 -1
  106. package/lib/esm/utils/getConstructorArgNames.js.map +0 -1
  107. package/lib/esm/utils/getRandomId.js.map +0 -1
  108. package/lib/esm/utils/getValue.js.map +0 -1
  109. package/lib/esm/utils/hasJsonMethod.js.map +0 -1
  110. package/lib/esm/utils/http/getHostInfoFromPort.js.map +0 -1
  111. package/lib/esm/utils/inheritedDescriptorOf.js.map +0 -1
  112. package/lib/esm/utils/isArray.js.map +0 -1
  113. package/lib/esm/utils/isArrowFn.js.map +0 -1
  114. package/lib/esm/utils/isBoolean.js.map +0 -1
  115. package/lib/esm/utils/isBuffer.js.map +0 -1
  116. package/lib/esm/utils/isClass.js.map +0 -1
  117. package/lib/esm/utils/isCollection.js.map +0 -1
  118. package/lib/esm/utils/isDate.js.map +0 -1
  119. package/lib/esm/utils/isEmpty.js.map +0 -1
  120. package/lib/esm/utils/isEnumerable.js.map +0 -1
  121. package/lib/esm/utils/isFunction.js.map +0 -1
  122. package/lib/esm/utils/isInheritedFrom.js.map +0 -1
  123. package/lib/esm/utils/isMomentObject.js.map +0 -1
  124. package/lib/esm/utils/isMongooseObject.js.map +0 -1
  125. package/lib/esm/utils/isNil.js.map +0 -1
  126. package/lib/esm/utils/isNumber.js.map +0 -1
  127. package/lib/esm/utils/isObject.js.map +0 -1
  128. package/lib/esm/utils/isObservable.js.map +0 -1
  129. package/lib/esm/utils/isPlainObject.js.map +0 -1
  130. package/lib/esm/utils/isPrimitive.js.map +0 -1
  131. package/lib/esm/utils/isPromise.js.map +0 -1
  132. package/lib/esm/utils/isProtectedKey.js.map +0 -1
  133. package/lib/esm/utils/isRegExp.js.map +0 -1
  134. package/lib/esm/utils/isSerializable.js.map +0 -1
  135. package/lib/esm/utils/isStream.js.map +0 -1
  136. package/lib/esm/utils/isString.js.map +0 -1
  137. package/lib/esm/utils/isSymbol.js.map +0 -1
  138. package/lib/esm/utils/methodsOf.js.map +0 -1
  139. package/lib/esm/utils/nameOf.js.map +0 -1
  140. package/lib/esm/utils/objectKeys.js.map +0 -1
  141. package/lib/esm/utils/primitiveOf.js.map +0 -1
  142. package/lib/esm/utils/prototypeOf.js.map +0 -1
  143. package/lib/esm/utils/setValue.js.map +0 -1
  144. package/lib/esm/utils/toMap.js.map +0 -1
  145. package/lib/esm/utils/toStringConstructor.js.map +0 -1
  146. package/lib/esm/utils/uniq.js.map +0 -1
  147. package/lib/esm/utils/useDecorators.js.map +0 -1
  148. package/lib/esm/utils/useMethodDecorators.js.map +0 -1
  149. package/src/decorators/storeFn.ts +0 -20
  150. package/src/decorators/storeMerge.ts +0 -8
  151. package/src/decorators/storeSet.ts +0 -8
  152. package/src/errors/UnsupportedDecoratorType.spec.ts +0 -81
  153. package/src/errors/UnsupportedDecoratorType.ts +0 -25
  154. package/src/index.ts +0 -75
  155. package/src/types/AnyDecorator.ts +0 -1
  156. package/src/types/DecoratorParameters.ts +0 -8
  157. package/src/types/DecoratorTypes.ts +0 -10
  158. package/src/types/Env.ts +0 -15
  159. package/src/types/Metadata.spec.ts +0 -142
  160. package/src/types/Metadata.ts +0 -523
  161. package/src/types/MetadataTypes.ts +0 -6
  162. package/src/types/Relation.ts +0 -1
  163. package/src/types/Store.spec.ts +0 -164
  164. package/src/types/Store.ts +0 -175
  165. package/src/types/Type.ts +0 -20
  166. package/src/types/ValueOf.ts +0 -1
  167. package/src/utils/AnyToPromise.spec.ts +0 -159
  168. package/src/utils/AnyToPromise.ts +0 -181
  169. package/src/utils/ObjectUtils.spec.ts +0 -322
  170. package/src/utils/ancestorOf.ts +0 -7
  171. package/src/utils/ancestorsOf.ts +0 -21
  172. package/src/utils/catchError.spec.ts +0 -17
  173. package/src/utils/catchError.ts +0 -15
  174. package/src/utils/classOf.ts +0 -18
  175. package/src/utils/cleanObject.spec.ts +0 -22
  176. package/src/utils/cleanObject.ts +0 -20
  177. package/src/utils/constructorOf.ts +0 -17
  178. package/src/utils/createInstance.ts +0 -5
  179. package/src/utils/decorateMethodsOf.spec.ts +0 -83
  180. package/src/utils/decorateMethodsOf.ts +0 -31
  181. package/src/utils/decoratorArgs.spec.ts +0 -15
  182. package/src/utils/decoratorArgs.ts +0 -6
  183. package/src/utils/decoratorTypeOf.spec.ts +0 -92
  184. package/src/utils/decoratorTypeOf.ts +0 -24
  185. package/src/utils/deepClone.spec.ts +0 -130
  186. package/src/utils/deepClone.ts +0 -85
  187. package/src/utils/deepMerge.spec.ts +0 -223
  188. package/src/utils/deepMerge.ts +0 -85
  189. package/src/utils/descriptorOf.spec.ts +0 -16
  190. package/src/utils/descriptorOf.ts +0 -13
  191. package/src/utils/getClassOrSymbol.ts +0 -6
  192. package/src/utils/getConstructorArgNames.spec.ts +0 -11
  193. package/src/utils/getConstructorArgNames.ts +0 -10
  194. package/src/utils/getRandomId.spec.ts +0 -7
  195. package/src/utils/getRandomId.ts +0 -3
  196. package/src/utils/getValue.spec.ts +0 -62
  197. package/src/utils/getValue.ts +0 -87
  198. package/src/utils/hasJsonMethod.spec.ts +0 -11
  199. package/src/utils/hasJsonMethod.ts +0 -3
  200. package/src/utils/http/getHostInfoFromPort.spec.ts +0 -25
  201. package/src/utils/http/getHostInfoFromPort.ts +0 -20
  202. package/src/utils/inheritedDescriptorOf.ts +0 -13
  203. package/src/utils/isArray.ts +0 -18
  204. package/src/utils/isArrowFn.ts +0 -5
  205. package/src/utils/isBoolean.ts +0 -12
  206. package/src/utils/isBuffer.spec.ts +0 -14
  207. package/src/utils/isBuffer.ts +0 -19
  208. package/src/utils/isClass.spec.ts +0 -15
  209. package/src/utils/isClass.ts +0 -28
  210. package/src/utils/isCollection.ts +0 -20
  211. package/src/utils/isDate.ts +0 -8
  212. package/src/utils/isEmpty.spec.ts +0 -10
  213. package/src/utils/isEmpty.ts +0 -10
  214. package/src/utils/isEnumerable.ts +0 -21
  215. package/src/utils/isFunction.ts +0 -3
  216. package/src/utils/isInheritedFrom.ts +0 -26
  217. package/src/utils/isMomentObject.spec.ts +0 -16
  218. package/src/utils/isMomentObject.ts +0 -3
  219. package/src/utils/isMongooseObject.spec.ts +0 -22
  220. package/src/utils/isMongooseObject.ts +0 -9
  221. package/src/utils/isNil.spec.ts +0 -10
  222. package/src/utils/isNil.ts +0 -3
  223. package/src/utils/isNumber.ts +0 -12
  224. package/src/utils/isObject.ts +0 -3
  225. package/src/utils/isObservable.ts +0 -3
  226. package/src/utils/isPlainObject.spec.ts +0 -10
  227. package/src/utils/isPlainObject.ts +0 -14
  228. package/src/utils/isPrimitive.spec.ts +0 -17
  229. package/src/utils/isPrimitive.ts +0 -26
  230. package/src/utils/isPromise.ts +0 -13
  231. package/src/utils/isProtectedKey.spec.ts +0 -14
  232. package/src/utils/isProtectedKey.ts +0 -7
  233. package/src/utils/isRegExp.ts +0 -3
  234. package/src/utils/isSerializable.spec.ts +0 -14
  235. package/src/utils/isSerializable.ts +0 -9
  236. package/src/utils/isStream.ts +0 -3
  237. package/src/utils/isString.ts +0 -11
  238. package/src/utils/isSymbol.spec.ts +0 -11
  239. package/src/utils/isSymbol.ts +0 -11
  240. package/src/utils/methodsOf.spec.ts +0 -33
  241. package/src/utils/methodsOf.ts +0 -26
  242. package/src/utils/nameOf.ts +0 -27
  243. package/src/utils/objectKeys.spec.ts +0 -10
  244. package/src/utils/objectKeys.ts +0 -5
  245. package/src/utils/primitiveOf.ts +0 -19
  246. package/src/utils/prototypeOf.ts +0 -10
  247. package/src/utils/setValue.spec.ts +0 -60
  248. package/src/utils/setValue.ts +0 -35
  249. package/src/utils/toMap.spec.ts +0 -211
  250. package/src/utils/toMap.ts +0 -44
  251. package/src/utils/toStringConstructor.ts +0 -9
  252. package/src/utils/toStringConstrutor.spec.ts +0 -18
  253. package/src/utils/uniq.spec.ts +0 -8
  254. package/src/utils/uniq.ts +0 -16
  255. package/src/utils/useDecorators.spec.ts +0 -61
  256. package/src/utils/useDecorators.ts +0 -21
  257. package/src/utils/useMethodDecorator.spec.ts +0 -45
  258. package/src/utils/useMethodDecorators.ts +0 -12
  259. package/vitest.config.mts +0 -21
@@ -1,7 +0,0 @@
1
- import {getRandomId} from "./getRandomId.js";
2
-
3
- describe("getRandomId", () => {
4
- it("should return random id", () => {
5
- expect(getRandomId()).not.toEqual(getRandomId());
6
- });
7
- });
@@ -1,3 +0,0 @@
1
- export function getRandomId() {
2
- return `e${Math.random().toString(36).substring(7)}`;
3
- }
@@ -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
- });
@@ -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,3 +0,0 @@
1
- export function hasJsonMethod(obj: any) {
2
- return obj && typeof obj.toJSON === "function";
3
- }
@@ -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
- }
@@ -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
- }
@@ -1,5 +0,0 @@
1
- import {isFunction} from "./isFunction.js";
2
-
3
- export function isArrowFn(target: any): target is Function {
4
- return target && isFunction(target) && !target.prototype;
5
- }
@@ -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
- });
@@ -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
- });
@@ -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
- }
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * @param target
4
- * @returns {boolean}
5
- */
6
- export function isDate(target: any): target is Date {
7
- return target === Date || (target instanceof Date && !isNaN(+target));
8
- }
@@ -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
- });
@@ -1,10 +0,0 @@
1
- import {isNil} from "./isNil.js";
2
-
3
- /**
4
- * Return true if the value is an empty string, null or undefined.
5
- * @param value
6
- * @returns {boolean}
7
- */
8
- export function isEmpty(value: any): boolean {
9
- return value === "" || isNil(value);
10
- }
@@ -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
- }
@@ -1,3 +0,0 @@
1
- export function isFunction(target: any): target is Function {
2
- return typeof target === "function";
3
- }
@@ -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,3 +0,0 @@
1
- export function isMomentObject(obj: any) {
2
- return !!(obj && obj?._isAMomentObject);
3
- }
@@ -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
- }
@@ -1,10 +0,0 @@
1
- import {isNil} from "./isNil.js";
2
-
3
- describe("isNil", () => {
4
- it("should return true", () => {
5
- expect(isNil(null)).toBe(true);
6
- expect(isNil(undefined)).toBe(true);
7
- expect(isNil(1)).toBe(false);
8
- expect(isNil("")).toBe(false);
9
- });
10
- });
@@ -1,3 +0,0 @@
1
- export function isNil(value: any): boolean {
2
- return value === undefined || value === null;
3
- }
@@ -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
- }
@@ -1,3 +0,0 @@
1
- export function isObject(target: any): target is object {
2
- return typeof target === "object";
3
- }
@@ -1,3 +0,0 @@
1
- export function isObservable<T>(obj: any): boolean {
2
- return !!obj && typeof obj.lift === "function" && typeof obj.subscribe === "function";
3
- }
@@ -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
- });
@@ -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
- }
@@ -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
- }