@stryke/types 0.0.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 (225) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +295 -0
  3. package/dist/convert/buffer-to-string.cjs +8 -0
  4. package/dist/convert/buffer-to-string.d.ts +1 -0
  5. package/dist/convert/buffer-to-string.mjs +1 -0
  6. package/dist/convert/index.cjs +71 -0
  7. package/dist/convert/index.d.ts +6 -0
  8. package/dist/convert/index.mjs +1 -0
  9. package/dist/convert/string-to-uint8-array.cjs +8 -0
  10. package/dist/convert/string-to-uint8-array.d.ts +7 -0
  11. package/dist/convert/string-to-uint8-array.mjs +1 -0
  12. package/dist/convert/to-array.cjs +9 -0
  13. package/dist/convert/to-array.d.ts +8 -0
  14. package/dist/convert/to-array.mjs +1 -0
  15. package/dist/convert/to-string-key.cjs +9 -0
  16. package/dist/convert/to-string-key.d.ts +7 -0
  17. package/dist/convert/to-string-key.mjs +1 -0
  18. package/dist/convert/uint8-array-to-string.cjs +8 -0
  19. package/dist/convert/uint8-array-to-string.d.ts +13 -0
  20. package/dist/convert/uint8-array-to-string.mjs +1 -0
  21. package/dist/convert/utf8-array-to-string.cjs +8 -0
  22. package/dist/convert/utf8-array-to-string.d.ts +13 -0
  23. package/dist/convert/utf8-array-to-string.mjs +1 -0
  24. package/dist/helpers/index.cjs +16 -0
  25. package/dist/helpers/index.d.ts +1 -0
  26. package/dist/helpers/index.mjs +1 -0
  27. package/dist/helpers/parse-type-definition.cjs +33 -0
  28. package/dist/helpers/parse-type-definition.d.ts +8 -0
  29. package/dist/helpers/parse-type-definition.mjs +1 -0
  30. package/dist/index.cjs +49 -0
  31. package/dist/index.d.ts +12 -0
  32. package/dist/index.mjs +1 -0
  33. package/dist/type-checks/get-object-tag.cjs +8 -0
  34. package/dist/type-checks/get-object-tag.d.ts +7 -0
  35. package/dist/type-checks/get-object-tag.mjs +1 -0
  36. package/dist/type-checks/index.cjs +456 -0
  37. package/dist/type-checks/index.d.ts +41 -0
  38. package/dist/type-checks/index.mjs +1 -0
  39. package/dist/type-checks/is-array-like.cjs +11 -0
  40. package/dist/type-checks/is-array-like.d.ts +7 -0
  41. package/dist/type-checks/is-array-like.mjs +1 -0
  42. package/dist/type-checks/is-async-iterable.cjs +10 -0
  43. package/dist/type-checks/is-async-iterable.d.ts +7 -0
  44. package/dist/type-checks/is-async-iterable.mjs +1 -0
  45. package/dist/type-checks/is-bigint.cjs +9 -0
  46. package/dist/type-checks/is-bigint.d.ts +16 -0
  47. package/dist/type-checks/is-bigint.mjs +1 -0
  48. package/dist/type-checks/is-boolean.cjs +14 -0
  49. package/dist/type-checks/is-boolean.d.ts +7 -0
  50. package/dist/type-checks/is-boolean.mjs +1 -0
  51. package/dist/type-checks/is-buffer.cjs +10 -0
  52. package/dist/type-checks/is-buffer.d.ts +5 -0
  53. package/dist/type-checks/is-buffer.mjs +1 -0
  54. package/dist/type-checks/is-collection.cjs +11 -0
  55. package/dist/type-checks/is-collection.d.ts +8 -0
  56. package/dist/type-checks/is-collection.mjs +1 -0
  57. package/dist/type-checks/is-date.cjs +10 -0
  58. package/dist/type-checks/is-date.d.ts +16 -0
  59. package/dist/type-checks/is-date.mjs +1 -0
  60. package/dist/type-checks/is-deep-key.cjs +26 -0
  61. package/dist/type-checks/is-deep-key.d.ts +35 -0
  62. package/dist/type-checks/is-deep-key.mjs +1 -0
  63. package/dist/type-checks/is-empty-object.cjs +23 -0
  64. package/dist/type-checks/is-empty-object.d.ts +14 -0
  65. package/dist/type-checks/is-empty-object.mjs +1 -0
  66. package/dist/type-checks/is-empty-string.cjs +16 -0
  67. package/dist/type-checks/is-empty-string.d.ts +7 -0
  68. package/dist/type-checks/is-empty-string.mjs +1 -0
  69. package/dist/type-checks/is-empty.cjs +35 -0
  70. package/dist/type-checks/is-empty.d.ts +8 -0
  71. package/dist/type-checks/is-empty.mjs +1 -0
  72. package/dist/type-checks/is-equal.cjs +18 -0
  73. package/dist/type-checks/is-equal.d.ts +1 -0
  74. package/dist/type-checks/is-equal.mjs +1 -0
  75. package/dist/type-checks/is-error.cjs +15 -0
  76. package/dist/type-checks/is-error.d.ts +17 -0
  77. package/dist/type-checks/is-error.mjs +1 -0
  78. package/dist/type-checks/is-file-result.cjs +11 -0
  79. package/dist/type-checks/is-file-result.d.ts +8 -0
  80. package/dist/type-checks/is-file-result.mjs +1 -0
  81. package/dist/type-checks/is-float.cjs +9 -0
  82. package/dist/type-checks/is-float.d.ts +8 -0
  83. package/dist/type-checks/is-float.mjs +1 -0
  84. package/dist/type-checks/is-function.cjs +23 -0
  85. package/dist/type-checks/is-function.d.ts +10 -0
  86. package/dist/type-checks/is-function.mjs +1 -0
  87. package/dist/type-checks/is-integer.cjs +10 -0
  88. package/dist/type-checks/is-integer.d.ts +8 -0
  89. package/dist/type-checks/is-integer.mjs +1 -0
  90. package/dist/type-checks/is-mergeable-object.cjs +14 -0
  91. package/dist/type-checks/is-mergeable-object.d.ts +1 -0
  92. package/dist/type-checks/is-mergeable-object.mjs +1 -0
  93. package/dist/type-checks/is-non-null-object.cjs +10 -0
  94. package/dist/type-checks/is-non-null-object.d.ts +7 -0
  95. package/dist/type-checks/is-non-null-object.mjs +1 -0
  96. package/dist/type-checks/is-not-empty.cjs +17 -0
  97. package/dist/type-checks/is-not-empty.d.ts +7 -0
  98. package/dist/type-checks/is-not-empty.mjs +1 -0
  99. package/dist/type-checks/is-null.cjs +14 -0
  100. package/dist/type-checks/is-null.d.ts +1 -0
  101. package/dist/type-checks/is-null.mjs +1 -0
  102. package/dist/type-checks/is-number.cjs +19 -0
  103. package/dist/type-checks/is-number.d.ts +15 -0
  104. package/dist/type-checks/is-number.mjs +1 -0
  105. package/dist/type-checks/is-object-index.cjs +17 -0
  106. package/dist/type-checks/is-object-index.d.ts +7 -0
  107. package/dist/type-checks/is-object-index.mjs +1 -0
  108. package/dist/type-checks/is-object.cjs +30 -0
  109. package/dist/type-checks/is-object.d.ts +30 -0
  110. package/dist/type-checks/is-object.mjs +1 -0
  111. package/dist/type-checks/is-plain-object.cjs +17 -0
  112. package/dist/type-checks/is-plain-object.d.ts +50 -0
  113. package/dist/type-checks/is-plain-object.mjs +1 -0
  114. package/dist/type-checks/is-primitive.cjs +14 -0
  115. package/dist/type-checks/is-primitive.d.ts +1 -0
  116. package/dist/type-checks/is-primitive.mjs +1 -0
  117. package/dist/type-checks/is-promise.cjs +12 -0
  118. package/dist/type-checks/is-promise.d.ts +17 -0
  119. package/dist/type-checks/is-promise.mjs +1 -0
  120. package/dist/type-checks/is-react-element.cjs +8 -0
  121. package/dist/type-checks/is-react-element.d.ts +1 -0
  122. package/dist/type-checks/is-react-element.mjs +1 -0
  123. package/dist/type-checks/is-ref.cjs +14 -0
  124. package/dist/type-checks/is-ref.d.ts +8 -0
  125. package/dist/type-checks/is-ref.mjs +1 -0
  126. package/dist/type-checks/is-regexp.cjs +10 -0
  127. package/dist/type-checks/is-regexp.d.ts +16 -0
  128. package/dist/type-checks/is-regexp.mjs +1 -0
  129. package/dist/type-checks/is-select-option.cjs +15 -0
  130. package/dist/type-checks/is-select-option.d.ts +8 -0
  131. package/dist/type-checks/is-select-option.mjs +1 -0
  132. package/dist/type-checks/is-set-object.cjs +15 -0
  133. package/dist/type-checks/is-set-object.d.ts +7 -0
  134. package/dist/type-checks/is-set-object.mjs +1 -0
  135. package/dist/type-checks/is-set-string.cjs +16 -0
  136. package/dist/type-checks/is-set-string.d.ts +7 -0
  137. package/dist/type-checks/is-set-string.mjs +1 -0
  138. package/dist/type-checks/is-set.cjs +15 -0
  139. package/dist/type-checks/is-set.d.ts +7 -0
  140. package/dist/type-checks/is-set.mjs +1 -0
  141. package/dist/type-checks/is-string.cjs +14 -0
  142. package/dist/type-checks/is-string.d.ts +1 -0
  143. package/dist/type-checks/is-string.mjs +1 -0
  144. package/dist/type-checks/is-symbol.cjs +14 -0
  145. package/dist/type-checks/is-symbol.d.ts +1 -0
  146. package/dist/type-checks/is-symbol.mjs +1 -0
  147. package/dist/type-checks/is-typed-array.cjs +9 -0
  148. package/dist/type-checks/is-typed-array.d.ts +1 -0
  149. package/dist/type-checks/is-typed-array.mjs +1 -0
  150. package/dist/type-checks/is-typed.cjs +16 -0
  151. package/dist/type-checks/is-typed.d.ts +8 -0
  152. package/dist/type-checks/is-typed.mjs +1 -0
  153. package/dist/type-checks/is-undefined.cjs +8 -0
  154. package/dist/type-checks/is-undefined.d.ts +1 -0
  155. package/dist/type-checks/is-undefined.mjs +1 -0
  156. package/dist/type-checks/property-exists.cjs +17 -0
  157. package/dist/type-checks/property-exists.d.ts +16 -0
  158. package/dist/type-checks/property-exists.mjs +1 -0
  159. package/dist/type-checks/type-detect.cjs +38 -0
  160. package/dist/type-checks/type-detect.d.ts +1 -0
  161. package/dist/type-checks/type-detect.mjs +1 -0
  162. package/dist/utility-types/array.cjs +9 -0
  163. package/dist/utility-types/array.d.ts +130 -0
  164. package/dist/utility-types/array.mjs +1 -0
  165. package/dist/utility-types/async.cjs +1 -0
  166. package/dist/utility-types/async.d.ts +103 -0
  167. package/dist/utility-types/async.mjs +0 -0
  168. package/dist/utility-types/base.cjs +16 -0
  169. package/dist/utility-types/base.d.ts +325 -0
  170. package/dist/utility-types/base.mjs +2 -0
  171. package/dist/utility-types/configuration.cjs +1 -0
  172. package/dist/utility-types/configuration.d.ts +59 -0
  173. package/dist/utility-types/configuration.mjs +0 -0
  174. package/dist/utility-types/file.cjs +12 -0
  175. package/dist/utility-types/file.d.ts +29 -0
  176. package/dist/utility-types/file.mjs +1 -0
  177. package/dist/utility-types/form.cjs +1 -0
  178. package/dist/utility-types/form.d.ts +35 -0
  179. package/dist/utility-types/form.mjs +0 -0
  180. package/dist/utility-types/index.cjs +214 -0
  181. package/dist/utility-types/index.d.ts +19 -0
  182. package/dist/utility-types/index.mjs +1 -0
  183. package/dist/utility-types/json.cjs +1 -0
  184. package/dist/utility-types/json.d.ts +82 -0
  185. package/dist/utility-types/json.mjs +0 -0
  186. package/dist/utility-types/logic.cjs +1 -0
  187. package/dist/utility-types/logic.d.ts +152 -0
  188. package/dist/utility-types/logic.mjs +0 -0
  189. package/dist/utility-types/messages.cjs +13 -0
  190. package/dist/utility-types/messages.d.ts +24 -0
  191. package/dist/utility-types/messages.mjs +1 -0
  192. package/dist/utility-types/navigator.cjs +1 -0
  193. package/dist/utility-types/navigator.d.ts +40 -0
  194. package/dist/utility-types/navigator.mjs +0 -0
  195. package/dist/utility-types/number.cjs +1 -0
  196. package/dist/utility-types/number.d.ts +198 -0
  197. package/dist/utility-types/number.mjs +0 -0
  198. package/dist/utility-types/object.cjs +1 -0
  199. package/dist/utility-types/object.d.ts +434 -0
  200. package/dist/utility-types/object.mjs +0 -0
  201. package/dist/utility-types/package-json.cjs +1 -0
  202. package/dist/utility-types/package-json.d.ts +504 -0
  203. package/dist/utility-types/package-json.mjs +0 -0
  204. package/dist/utility-types/package-manager.cjs +18 -0
  205. package/dist/utility-types/package-manager.d.ts +14 -0
  206. package/dist/utility-types/package-manager.mjs +1 -0
  207. package/dist/utility-types/string.cjs +1 -0
  208. package/dist/utility-types/string.d.ts +87 -0
  209. package/dist/utility-types/string.mjs +0 -0
  210. package/dist/utility-types/system.cjs +1 -0
  211. package/dist/utility-types/system.d.ts +1 -0
  212. package/dist/utility-types/system.mjs +0 -0
  213. package/dist/utility-types/tsconfig.cjs +1 -0
  214. package/dist/utility-types/tsconfig.d.ts +800 -0
  215. package/dist/utility-types/tsconfig.mjs +0 -0
  216. package/dist/utility-types/user.cjs +11 -0
  217. package/dist/utility-types/user.d.ts +30 -0
  218. package/dist/utility-types/user.mjs +1 -0
  219. package/dist/utility-types/utilities.cjs +1 -0
  220. package/dist/utility-types/utilities.d.ts +53 -0
  221. package/dist/utility-types/utilities.mjs +0 -0
  222. package/dist/utility-types/validations.cjs +1 -0
  223. package/dist/utility-types/validations.d.ts +16 -0
  224. package/dist/utility-types/validations.mjs +0 -0
  225. package/package.json +1157 -0
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isUndefined = void 0;
7
+ const isUndefined = n => n === void 0;
8
+ exports.isUndefined = isUndefined;
@@ -0,0 +1 @@
1
+ export declare const isUndefined: (value: unknown) => value is undefined;
@@ -0,0 +1 @@
1
+ export const isUndefined=n=>n===void 0;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.propertyUnsafe = exports.propertyExists = void 0;
7
+ var _isObject = require("./is-object.cjs");
8
+ const propertyExists = (r, t) => {
9
+ try {
10
+ return (0, _isObject.isObject)(r) && t in r;
11
+ } catch {
12
+ return !1;
13
+ }
14
+ },
15
+ propertyUnsafe = (r, t) => propertyExists(r, t) && !(Object.hasOwnProperty.call(r, t) && Object.propertyIsEnumerable.call(r, t));
16
+ exports.propertyUnsafe = propertyUnsafe;
17
+ exports.propertyExists = propertyExists;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Check if the provided object has the provided property
3
+ *
4
+ * @param object - The object to check
5
+ * @param propertyKey - The property to check
6
+ * @returns An indicator specifying if the object has the provided property
7
+ */
8
+ export declare const propertyExists: (object: any, propertyKey: PropertyKey) => boolean;
9
+ /**
10
+ * Check if the provided object has the provided property and if it's safe to merge
11
+ *
12
+ * @param object - The object to check
13
+ * @param propertyKey - The property to check
14
+ * @returns An indicator specifying if the object has the provided property and if it's safe to merge
15
+ */
16
+ export declare const propertyUnsafe: (object: any, propertyKey: PropertyKey) => boolean;
@@ -0,0 +1 @@
1
+ import{isObject as e}from"./is-object";export const propertyExists=(r,t)=>{try{return e(r)&&t in r}catch{return!1}},propertyUnsafe=(r,t)=>propertyExists(r,t)&&!(Object.hasOwnProperty.call(r,t)&&Object.propertyIsEnumerable.call(r,t));
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.typeDetect = typeDetect;
7
+ var _isBuffer = require("./is-buffer.cjs");
8
+ const a = (t => (typeof globalThis == "object" || Object.defineProperty(t, "typeDetectGlobalObject", {
9
+ get() {
10
+ return this;
11
+ },
12
+ configurable: !0
13
+ }), globalThis))(Object.prototype);
14
+ function typeDetect(t) {
15
+ if ((0, _isBuffer.isBuffer)(t)) return "Buffer";
16
+ const r = typeof t;
17
+ if (r !== "object") return r;
18
+ if (t === null) return "null";
19
+ if (t === a) return "global";
20
+ if (Array.isArray(t) && (Symbol.toStringTag === void 0 || !(Symbol.toStringTag in t))) return "Array";
21
+ if (typeof globalThis == "object" && globalThis !== null) {
22
+ if (typeof globalThis.location == "object" && t === globalThis.location) return "Location";
23
+ if (typeof globalThis.document == "object" && t === globalThis.document) return "Document";
24
+ if (typeof globalThis.navigator == "object") {
25
+ if (typeof globalThis.navigator.mimeTypes == "object" && t === globalThis.navigator.mimeTypes) return "MimeTypeArray";
26
+ if (typeof globalThis.navigator.plugins == "object" && t === globalThis.navigator.plugins) return "PluginArray";
27
+ }
28
+ if ((typeof globalThis.HTMLElement == "function" || typeof globalThis.HTMLElement == "object") && t instanceof globalThis.HTMLElement) {
29
+ if (t.tagName === "BLOCKQUOTE") return "HTMLQuoteElement";
30
+ if (t.tagName === "TD") return "HTMLTableDataCellElement";
31
+ if (t.tagName === "TH") return "HTMLTableHeaderCellElement";
32
+ }
33
+ }
34
+ const o = Symbol.toStringTag !== void 0 && t[Symbol.toStringTag];
35
+ if (typeof o == "string") return o;
36
+ const e = Object.getPrototypeOf(t);
37
+ return e === RegExp.prototype ? "RegExp" : e === Date.prototype ? "Date" : typeof Promise < "u" && e === Promise.prototype ? "Promise" : typeof Set < "u" && e === Set.prototype ? "Set" : typeof Map < "u" && e === Map.prototype ? "Map" : typeof WeakSet < "u" && e === WeakSet.prototype ? "WeakSet" : typeof WeakMap < "u" && e === WeakMap.prototype ? "WeakMap" : typeof DataView < "u" && e === DataView.prototype ? "DataView" : typeof Map < "u" && e === Object.getPrototypeOf(new Map().entries()) ? "Map Iterator" : typeof Set < "u" && e === Object.getPrototypeOf(new Set().entries()) ? "Set Iterator" : typeof Array.prototype[Symbol.iterator] == "function" && e === Object.getPrototypeOf([][Symbol.iterator]()) ? "Array Iterator" : Symbol.iterator !== void 0 && typeof String.prototype[Symbol.iterator] == "function" && Object.getPrototypeOf(""[Symbol.iterator]()) && e === Object.getPrototypeOf(""[Symbol.iterator]()) ? "String Iterator" : e === null ? "Object" : Object.prototype.toString.call(t).slice(8, -1);
38
+ }
@@ -0,0 +1 @@
1
+ export declare function typeDetect(obj: unknown): string;
@@ -0,0 +1 @@
1
+ import{isBuffer as n}from"./is-buffer";const a=(t=>(typeof globalThis=="object"||Object.defineProperty(t,"typeDetectGlobalObject",{get(){return this},configurable:!0}),globalThis))(Object.prototype);export function typeDetect(t){if(n(t))return"Buffer";const r=typeof t;if(r!=="object")return r;if(t===null)return"null";if(t===a)return"global";if(Array.isArray(t)&&(Symbol.toStringTag===void 0||!(Symbol.toStringTag in t)))return"Array";if(typeof globalThis=="object"&&globalThis!==null){if(typeof globalThis.location=="object"&&t===globalThis.location)return"Location";if(typeof globalThis.document=="object"&&t===globalThis.document)return"Document";if(typeof globalThis.navigator=="object"){if(typeof globalThis.navigator.mimeTypes=="object"&&t===globalThis.navigator.mimeTypes)return"MimeTypeArray";if(typeof globalThis.navigator.plugins=="object"&&t===globalThis.navigator.plugins)return"PluginArray"}if((typeof globalThis.HTMLElement=="function"||typeof globalThis.HTMLElement=="object")&&t instanceof globalThis.HTMLElement){if(t.tagName==="BLOCKQUOTE")return"HTMLQuoteElement";if(t.tagName==="TD")return"HTMLTableDataCellElement";if(t.tagName==="TH")return"HTMLTableHeaderCellElement"}}const o=Symbol.toStringTag!==void 0&&t[Symbol.toStringTag];if(typeof o=="string")return o;const e=Object.getPrototypeOf(t);return e===RegExp.prototype?"RegExp":e===Date.prototype?"Date":typeof Promise<"u"&&e===Promise.prototype?"Promise":typeof Set<"u"&&e===Set.prototype?"Set":typeof Map<"u"&&e===Map.prototype?"Map":typeof WeakSet<"u"&&e===WeakSet.prototype?"WeakSet":typeof WeakMap<"u"&&e===WeakMap.prototype?"WeakMap":typeof DataView<"u"&&e===DataView.prototype?"DataView":typeof Map<"u"&&e===Object.getPrototypeOf(new Map().entries())?"Map Iterator":typeof Set<"u"&&e===Object.getPrototypeOf(new Set().entries())?"Set Iterator":typeof Array.prototype[Symbol.iterator]=="function"&&e===Object.getPrototypeOf([][Symbol.iterator]())?"Array Iterator":Symbol.iterator!==void 0&&typeof String.prototype[Symbol.iterator]=="function"&&Object.getPrototypeOf(""[Symbol.iterator]())&&e===Object.getPrototypeOf(""[Symbol.iterator]())?"String Iterator":e===null?"Object":Object.prototype.toString.call(t).slice(8,-1)}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.filterEmpty = void 0;
7
+ var _typeChecks = require("../type-checks/index.cjs");
8
+ const filterEmpty = (e = []) => e.filter(n => !(0, _typeChecks.isEmpty)(n));
9
+ exports.filterEmpty = filterEmpty;
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Matches any array or array-like object.
3
+ *
4
+ * @category Array
5
+ */
6
+ export type Arrayable<T> = T | T[];
7
+ export type UnknownArray = readonly unknown[];
8
+ /**
9
+ * Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
10
+ *
11
+ * @category Array
12
+ */
13
+ export type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array;
14
+ /**
15
+ * Infer the length of the given array `<T>`.
16
+ *
17
+ * Check out {@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f | this article} for more information.
18
+ */
19
+ export type ArrayLength<T extends readonly unknown[]> = T extends {
20
+ readonly length: infer L;
21
+ } ? L : never;
22
+ /**
23
+ * Extract the element of an array that also works for array union.
24
+ *
25
+ * Returns `never` if T is not an array.
26
+ *
27
+ * It creates a type-safe way to access the element type of `unknown` type.
28
+ */
29
+ export type ArrayElement<T> = T extends readonly unknown[] ? T[0] : never;
30
+ /**
31
+ * Provides all values for a constant array or tuple.
32
+ *
33
+ * Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety with their values.
34
+ *
35
+ * @example
36
+ * ```
37
+ * import type {ArrayValues, ArrayIndices} from 'type-fest';
38
+ *
39
+ * const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
40
+ *
41
+ * type WeekdayName = ArrayValues<typeof weekdays>;
42
+ * type Weekday = ArrayIndices<typeof weekdays>;
43
+ *
44
+ * const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
45
+ * ```
46
+ *
47
+ * @see {@link ArrayIndices}
48
+ *
49
+ * @category Array
50
+ */
51
+ export type ArrayValues<T extends readonly unknown[]> = T[number];
52
+ /**
53
+ * Provides valid indices for a constant array or tuple.
54
+ *
55
+ * Use-case: This type is useful when working with constant arrays or tuples and you want to enforce type-safety for accessing elements by their indices.
56
+ *
57
+ * @example
58
+ * ```
59
+ * import type {ArrayIndices, ArrayValues} from 'type-fest';
60
+ *
61
+ * const weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as const;
62
+ *
63
+ * type Weekday = ArrayIndices<typeof weekdays>;
64
+ * type WeekdayName = ArrayValues<typeof weekdays>;
65
+ *
66
+ * const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
67
+ * ```
68
+ *
69
+ * @see {@link ArrayValues}
70
+ *
71
+ * @category Array
72
+ */
73
+ export type ArrayIndices<Element extends readonly unknown[]> = Exclude<Partial<Element>["length"], Element["length"]>;
74
+ /**
75
+ * Matches any unknown array or tuple.
76
+ */
77
+ export type UnknownArrayOrTuple = readonly [...unknown[]];
78
+ /**
79
+ * Extracts the type of the first element of an array or tuple.
80
+ */
81
+ export type FirstArrayElement<TArray extends UnknownArrayOrTuple> = TArray extends readonly [infer THead, ...unknown[]] ? THead : never;
82
+ /**
83
+ * Extracts the type of the last element of an array.
84
+ *
85
+ * Use-case: Defining the return type of functions that extract the last element of an array, for example [`lodash.last`](https://lodash.com/docs/4.17.15#last).
86
+ *
87
+ * @example
88
+ * ```
89
+ * import type {LastArrayElement} from 'type-fest';
90
+ *
91
+ * declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;
92
+ *
93
+ * const array = ['foo', 2];
94
+ *
95
+ * typeof lastOf(array);
96
+ * //=> number
97
+ *
98
+ * const array = ['foo', 2] as const;
99
+ *
100
+ * typeof lastOf(array);
101
+ * //=> 2
102
+ * ```
103
+ *
104
+ * @category Array
105
+ * @category Template literal
106
+ */
107
+ export type LastArrayElement<Elements extends readonly unknown[], ElementBeforeTailingSpreadElement = never> = Elements extends readonly [] ? ElementBeforeTailingSpreadElement : Elements extends readonly [...infer _U, infer V] ? V : Elements extends readonly [infer U, ...infer V] ? LastArrayElement<V, U> : Elements extends readonly (infer U)[] ? ElementBeforeTailingSpreadElement | U : never;
108
+ /**
109
+ * Returns the static, fixed-length portion of the given array, excluding variable-length parts.
110
+ *
111
+ * @example
112
+ * ```
113
+ * type A = [string, number, boolean, ...string[]];
114
+ * type B = StaticPartOfArray<A>;
115
+ * //=> [string, number, boolean]
116
+ * ```
117
+ */
118
+ export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> = T extends unknown ? number extends T["length"] ? T extends readonly [infer U, ...infer V] ? StaticPartOfArray<V, [...Result, U]> : Result : T : never;
119
+ /**
120
+ * Returns the variable, non-fixed-length portion of the given array, excluding static-length parts.
121
+ *
122
+ * @example
123
+ * ```
124
+ * type A = [string, number, boolean, ...string[]];
125
+ * type B = VariablePartOfArray<A>;
126
+ * //=> string[]
127
+ * ```
128
+ */
129
+ export type VariablePartOfArray<T extends UnknownArray> = T extends unknown ? T extends readonly [...StaticPartOfArray<T>, ...infer U] ? U : [] : never;
130
+ export declare const filterEmpty: <T>(values?: (T | null | undefined)[]) => T[];
@@ -0,0 +1 @@
1
+ import{isEmpty as r}from"../type-checks";export const filterEmpty=(e=[])=>e.filter(n=>!r(n));
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,103 @@
1
+ import type { FunctionLike, IsUnknown } from "./base";
2
+ /**
3
+ * Get the type of the value that a promise resolves to.
4
+ *
5
+ * @example
6
+ * ```
7
+ * import type {Awaited} from 'type-fest';
8
+ *
9
+ * const value: Awaited<Promise<string>> = 'foo';
10
+ * ```
11
+ *
12
+ * @category Async
13
+ */
14
+ export type Awaitable<T> = T | PromiseLike<T>;
15
+ /**
16
+ * Create a function type with a return type of your choice and the same parameters as the given function type.
17
+ *
18
+ * Use-case: You want to define a wrapped function that returns something different while receiving the same parameters. For example, you might want to wrap a function that can throw an error into one that will return `undefined` instead.
19
+ *
20
+ * @example
21
+ * ```
22
+ * import type {SetReturnType} from 'type-fest';
23
+ *
24
+ * type MyFunctionThatCanThrow = (foo: SomeType, bar: unknown) => SomeOtherType;
25
+ *
26
+ * type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | undefined>;
27
+ * //=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
28
+ * ```
29
+ *
30
+ * @category Function
31
+ */
32
+ export type SetReturnType<Function_ extends (...arguments_: any[]) => any, TypeToReturn> = Function_ extends (this: infer ThisArgument, ...arguments_: infer Arguments) => any ? IsUnknown<ThisArgument> extends true ? (...arguments_: Arguments) => TypeToReturn : (this: ThisArgument, ...arguments_: Arguments) => TypeToReturn : (...arguments_: Parameters<Function_>) => TypeToReturn;
33
+ export type AsyncFunction = (...arguments_: any[]) => Promise<unknown>;
34
+ /**
35
+ * Unwrap the return type of a function that returns a `Promise`.
36
+ *
37
+ * There has been [discussion](https://github.com/microsoft/TypeScript/pull/35998) about implementing this type in TypeScript.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * import type {AsyncReturnType} from 'type-fest';
42
+ * import {asyncFunction} from 'api';
43
+ *
44
+ * // This type resolves to the unwrapped return type of `asyncFunction`.
45
+ * type Value = AsyncReturnType<typeof asyncFunction>;
46
+ *
47
+ * async function doSomething(value: Value) {}
48
+ *
49
+ * asyncFunction().then(value => doSomething(value));
50
+ * ```
51
+ *
52
+ * @category Async
53
+ */
54
+ export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>;
55
+ /**
56
+ * Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types.
57
+ *
58
+ * Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type.
59
+ *
60
+ * @example
61
+ * ```
62
+ * import type {Asyncify} from 'type-fest';
63
+ *
64
+ * // Synchronous function.
65
+ * function getFooSync(someArg: SomeType): Foo {
66
+ * // …
67
+ * }
68
+ *
69
+ * type AsyncifiedFooGetter = Asyncify<typeof getFooSync>;
70
+ * //=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>;
71
+ *
72
+ * // Same as `getFooSync` but asynchronous.
73
+ * const getFooAsync: AsyncifiedFooGetter = (someArg) => {
74
+ * // TypeScript now knows that `someArg` is `SomeType` automatically.
75
+ * // It also knows that this function must return `Promise<Foo>`.
76
+ * // If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.".
77
+ *
78
+ * // …
79
+ * }
80
+ * ```
81
+ *
82
+ * @category Async
83
+ */
84
+ export type Asyncify<Function_ extends FunctionLike> = SetReturnType<Function_, Promise<Awaited<ReturnType<Function_>>>>;
85
+ /**
86
+ * Get the result type of a `Promise`
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * import { Await } from '@stryke/types'
91
+ *
92
+ * const promise = new Promise<string>((res, rej) => res('x'))
93
+ *
94
+ * type test0 = C.Await<typeof promise> // string
95
+ * type test1 = C.Await<Promise<number>> // number
96
+ * ```
97
+ *
98
+ * @param P - A promise
99
+ * @returns [[Any]]
100
+ *
101
+ * @category Async
102
+ */
103
+ export type Await<P extends any> = P extends Promise<infer A> ? A : P;
File without changes
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.TYPE_SET = exports.TYPE_OBJECT = exports.TYPE_MAP = exports.TYPE_ARRAY = exports.TYPE_ARGUMENTS = exports.NEWLINE_STRING = exports.EMPTY_STRING = exports.EMPTY_OBJECT = exports.$NestedValue = void 0;
7
+ const EMPTY_STRING = exports.EMPTY_STRING = "",
8
+ NEWLINE_STRING = exports.NEWLINE_STRING = `\r
9
+ `,
10
+ EMPTY_OBJECT = exports.EMPTY_OBJECT = {},
11
+ TYPE_ARGUMENTS = exports.TYPE_ARGUMENTS = "Arguments",
12
+ TYPE_ARRAY = exports.TYPE_ARRAY = "Array",
13
+ TYPE_OBJECT = exports.TYPE_OBJECT = "Object",
14
+ TYPE_MAP = exports.TYPE_MAP = "Map",
15
+ TYPE_SET = exports.TYPE_SET = "Set",
16
+ $NestedValue = exports.$NestedValue = Symbol("NestedValue");