@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.
- package/LICENSE +201 -0
- package/README.md +295 -0
- package/dist/convert/buffer-to-string.cjs +8 -0
- package/dist/convert/buffer-to-string.d.ts +1 -0
- package/dist/convert/buffer-to-string.mjs +1 -0
- package/dist/convert/index.cjs +71 -0
- package/dist/convert/index.d.ts +6 -0
- package/dist/convert/index.mjs +1 -0
- package/dist/convert/string-to-uint8-array.cjs +8 -0
- package/dist/convert/string-to-uint8-array.d.ts +7 -0
- package/dist/convert/string-to-uint8-array.mjs +1 -0
- package/dist/convert/to-array.cjs +9 -0
- package/dist/convert/to-array.d.ts +8 -0
- package/dist/convert/to-array.mjs +1 -0
- package/dist/convert/to-string-key.cjs +9 -0
- package/dist/convert/to-string-key.d.ts +7 -0
- package/dist/convert/to-string-key.mjs +1 -0
- package/dist/convert/uint8-array-to-string.cjs +8 -0
- package/dist/convert/uint8-array-to-string.d.ts +13 -0
- package/dist/convert/uint8-array-to-string.mjs +1 -0
- package/dist/convert/utf8-array-to-string.cjs +8 -0
- package/dist/convert/utf8-array-to-string.d.ts +13 -0
- package/dist/convert/utf8-array-to-string.mjs +1 -0
- package/dist/helpers/index.cjs +16 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.mjs +1 -0
- package/dist/helpers/parse-type-definition.cjs +33 -0
- package/dist/helpers/parse-type-definition.d.ts +8 -0
- package/dist/helpers/parse-type-definition.mjs +1 -0
- package/dist/index.cjs +49 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.mjs +1 -0
- package/dist/type-checks/get-object-tag.cjs +8 -0
- package/dist/type-checks/get-object-tag.d.ts +7 -0
- package/dist/type-checks/get-object-tag.mjs +1 -0
- package/dist/type-checks/index.cjs +456 -0
- package/dist/type-checks/index.d.ts +41 -0
- package/dist/type-checks/index.mjs +1 -0
- package/dist/type-checks/is-array-like.cjs +11 -0
- package/dist/type-checks/is-array-like.d.ts +7 -0
- package/dist/type-checks/is-array-like.mjs +1 -0
- package/dist/type-checks/is-async-iterable.cjs +10 -0
- package/dist/type-checks/is-async-iterable.d.ts +7 -0
- package/dist/type-checks/is-async-iterable.mjs +1 -0
- package/dist/type-checks/is-bigint.cjs +9 -0
- package/dist/type-checks/is-bigint.d.ts +16 -0
- package/dist/type-checks/is-bigint.mjs +1 -0
- package/dist/type-checks/is-boolean.cjs +14 -0
- package/dist/type-checks/is-boolean.d.ts +7 -0
- package/dist/type-checks/is-boolean.mjs +1 -0
- package/dist/type-checks/is-buffer.cjs +10 -0
- package/dist/type-checks/is-buffer.d.ts +5 -0
- package/dist/type-checks/is-buffer.mjs +1 -0
- package/dist/type-checks/is-collection.cjs +11 -0
- package/dist/type-checks/is-collection.d.ts +8 -0
- package/dist/type-checks/is-collection.mjs +1 -0
- package/dist/type-checks/is-date.cjs +10 -0
- package/dist/type-checks/is-date.d.ts +16 -0
- package/dist/type-checks/is-date.mjs +1 -0
- package/dist/type-checks/is-deep-key.cjs +26 -0
- package/dist/type-checks/is-deep-key.d.ts +35 -0
- package/dist/type-checks/is-deep-key.mjs +1 -0
- package/dist/type-checks/is-empty-object.cjs +23 -0
- package/dist/type-checks/is-empty-object.d.ts +14 -0
- package/dist/type-checks/is-empty-object.mjs +1 -0
- package/dist/type-checks/is-empty-string.cjs +16 -0
- package/dist/type-checks/is-empty-string.d.ts +7 -0
- package/dist/type-checks/is-empty-string.mjs +1 -0
- package/dist/type-checks/is-empty.cjs +35 -0
- package/dist/type-checks/is-empty.d.ts +8 -0
- package/dist/type-checks/is-empty.mjs +1 -0
- package/dist/type-checks/is-equal.cjs +18 -0
- package/dist/type-checks/is-equal.d.ts +1 -0
- package/dist/type-checks/is-equal.mjs +1 -0
- package/dist/type-checks/is-error.cjs +15 -0
- package/dist/type-checks/is-error.d.ts +17 -0
- package/dist/type-checks/is-error.mjs +1 -0
- package/dist/type-checks/is-file-result.cjs +11 -0
- package/dist/type-checks/is-file-result.d.ts +8 -0
- package/dist/type-checks/is-file-result.mjs +1 -0
- package/dist/type-checks/is-float.cjs +9 -0
- package/dist/type-checks/is-float.d.ts +8 -0
- package/dist/type-checks/is-float.mjs +1 -0
- package/dist/type-checks/is-function.cjs +23 -0
- package/dist/type-checks/is-function.d.ts +10 -0
- package/dist/type-checks/is-function.mjs +1 -0
- package/dist/type-checks/is-integer.cjs +10 -0
- package/dist/type-checks/is-integer.d.ts +8 -0
- package/dist/type-checks/is-integer.mjs +1 -0
- package/dist/type-checks/is-mergeable-object.cjs +14 -0
- package/dist/type-checks/is-mergeable-object.d.ts +1 -0
- package/dist/type-checks/is-mergeable-object.mjs +1 -0
- package/dist/type-checks/is-non-null-object.cjs +10 -0
- package/dist/type-checks/is-non-null-object.d.ts +7 -0
- package/dist/type-checks/is-non-null-object.mjs +1 -0
- package/dist/type-checks/is-not-empty.cjs +17 -0
- package/dist/type-checks/is-not-empty.d.ts +7 -0
- package/dist/type-checks/is-not-empty.mjs +1 -0
- package/dist/type-checks/is-null.cjs +14 -0
- package/dist/type-checks/is-null.d.ts +1 -0
- package/dist/type-checks/is-null.mjs +1 -0
- package/dist/type-checks/is-number.cjs +19 -0
- package/dist/type-checks/is-number.d.ts +15 -0
- package/dist/type-checks/is-number.mjs +1 -0
- package/dist/type-checks/is-object-index.cjs +17 -0
- package/dist/type-checks/is-object-index.d.ts +7 -0
- package/dist/type-checks/is-object-index.mjs +1 -0
- package/dist/type-checks/is-object.cjs +30 -0
- package/dist/type-checks/is-object.d.ts +30 -0
- package/dist/type-checks/is-object.mjs +1 -0
- package/dist/type-checks/is-plain-object.cjs +17 -0
- package/dist/type-checks/is-plain-object.d.ts +50 -0
- package/dist/type-checks/is-plain-object.mjs +1 -0
- package/dist/type-checks/is-primitive.cjs +14 -0
- package/dist/type-checks/is-primitive.d.ts +1 -0
- package/dist/type-checks/is-primitive.mjs +1 -0
- package/dist/type-checks/is-promise.cjs +12 -0
- package/dist/type-checks/is-promise.d.ts +17 -0
- package/dist/type-checks/is-promise.mjs +1 -0
- package/dist/type-checks/is-react-element.cjs +8 -0
- package/dist/type-checks/is-react-element.d.ts +1 -0
- package/dist/type-checks/is-react-element.mjs +1 -0
- package/dist/type-checks/is-ref.cjs +14 -0
- package/dist/type-checks/is-ref.d.ts +8 -0
- package/dist/type-checks/is-ref.mjs +1 -0
- package/dist/type-checks/is-regexp.cjs +10 -0
- package/dist/type-checks/is-regexp.d.ts +16 -0
- package/dist/type-checks/is-regexp.mjs +1 -0
- package/dist/type-checks/is-select-option.cjs +15 -0
- package/dist/type-checks/is-select-option.d.ts +8 -0
- package/dist/type-checks/is-select-option.mjs +1 -0
- package/dist/type-checks/is-set-object.cjs +15 -0
- package/dist/type-checks/is-set-object.d.ts +7 -0
- package/dist/type-checks/is-set-object.mjs +1 -0
- package/dist/type-checks/is-set-string.cjs +16 -0
- package/dist/type-checks/is-set-string.d.ts +7 -0
- package/dist/type-checks/is-set-string.mjs +1 -0
- package/dist/type-checks/is-set.cjs +15 -0
- package/dist/type-checks/is-set.d.ts +7 -0
- package/dist/type-checks/is-set.mjs +1 -0
- package/dist/type-checks/is-string.cjs +14 -0
- package/dist/type-checks/is-string.d.ts +1 -0
- package/dist/type-checks/is-string.mjs +1 -0
- package/dist/type-checks/is-symbol.cjs +14 -0
- package/dist/type-checks/is-symbol.d.ts +1 -0
- package/dist/type-checks/is-symbol.mjs +1 -0
- package/dist/type-checks/is-typed-array.cjs +9 -0
- package/dist/type-checks/is-typed-array.d.ts +1 -0
- package/dist/type-checks/is-typed-array.mjs +1 -0
- package/dist/type-checks/is-typed.cjs +16 -0
- package/dist/type-checks/is-typed.d.ts +8 -0
- package/dist/type-checks/is-typed.mjs +1 -0
- package/dist/type-checks/is-undefined.cjs +8 -0
- package/dist/type-checks/is-undefined.d.ts +1 -0
- package/dist/type-checks/is-undefined.mjs +1 -0
- package/dist/type-checks/property-exists.cjs +17 -0
- package/dist/type-checks/property-exists.d.ts +16 -0
- package/dist/type-checks/property-exists.mjs +1 -0
- package/dist/type-checks/type-detect.cjs +38 -0
- package/dist/type-checks/type-detect.d.ts +1 -0
- package/dist/type-checks/type-detect.mjs +1 -0
- package/dist/utility-types/array.cjs +9 -0
- package/dist/utility-types/array.d.ts +130 -0
- package/dist/utility-types/array.mjs +1 -0
- package/dist/utility-types/async.cjs +1 -0
- package/dist/utility-types/async.d.ts +103 -0
- package/dist/utility-types/async.mjs +0 -0
- package/dist/utility-types/base.cjs +16 -0
- package/dist/utility-types/base.d.ts +325 -0
- package/dist/utility-types/base.mjs +2 -0
- package/dist/utility-types/configuration.cjs +1 -0
- package/dist/utility-types/configuration.d.ts +59 -0
- package/dist/utility-types/configuration.mjs +0 -0
- package/dist/utility-types/file.cjs +12 -0
- package/dist/utility-types/file.d.ts +29 -0
- package/dist/utility-types/file.mjs +1 -0
- package/dist/utility-types/form.cjs +1 -0
- package/dist/utility-types/form.d.ts +35 -0
- package/dist/utility-types/form.mjs +0 -0
- package/dist/utility-types/index.cjs +214 -0
- package/dist/utility-types/index.d.ts +19 -0
- package/dist/utility-types/index.mjs +1 -0
- package/dist/utility-types/json.cjs +1 -0
- package/dist/utility-types/json.d.ts +82 -0
- package/dist/utility-types/json.mjs +0 -0
- package/dist/utility-types/logic.cjs +1 -0
- package/dist/utility-types/logic.d.ts +152 -0
- package/dist/utility-types/logic.mjs +0 -0
- package/dist/utility-types/messages.cjs +13 -0
- package/dist/utility-types/messages.d.ts +24 -0
- package/dist/utility-types/messages.mjs +1 -0
- package/dist/utility-types/navigator.cjs +1 -0
- package/dist/utility-types/navigator.d.ts +40 -0
- package/dist/utility-types/navigator.mjs +0 -0
- package/dist/utility-types/number.cjs +1 -0
- package/dist/utility-types/number.d.ts +198 -0
- package/dist/utility-types/number.mjs +0 -0
- package/dist/utility-types/object.cjs +1 -0
- package/dist/utility-types/object.d.ts +434 -0
- package/dist/utility-types/object.mjs +0 -0
- package/dist/utility-types/package-json.cjs +1 -0
- package/dist/utility-types/package-json.d.ts +504 -0
- package/dist/utility-types/package-json.mjs +0 -0
- package/dist/utility-types/package-manager.cjs +18 -0
- package/dist/utility-types/package-manager.d.ts +14 -0
- package/dist/utility-types/package-manager.mjs +1 -0
- package/dist/utility-types/string.cjs +1 -0
- package/dist/utility-types/string.d.ts +87 -0
- package/dist/utility-types/string.mjs +0 -0
- package/dist/utility-types/system.cjs +1 -0
- package/dist/utility-types/system.d.ts +1 -0
- package/dist/utility-types/system.mjs +0 -0
- package/dist/utility-types/tsconfig.cjs +1 -0
- package/dist/utility-types/tsconfig.d.ts +800 -0
- package/dist/utility-types/tsconfig.mjs +0 -0
- package/dist/utility-types/user.cjs +11 -0
- package/dist/utility-types/user.d.ts +30 -0
- package/dist/utility-types/user.mjs +1 -0
- package/dist/utility-types/utilities.cjs +1 -0
- package/dist/utility-types/utilities.d.ts +53 -0
- package/dist/utility-types/utilities.mjs +0 -0
- package/dist/utility-types/validations.cjs +1 -0
- package/dist/utility-types/validations.d.ts +16 -0
- package/dist/utility-types/validations.mjs +0 -0
- package/package.json +1157 -0
|
@@ -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");
|