@ekumlin/typescript-toolkit 1.0.0
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/README.md +98 -0
- package/dist/collections.d.mts +7 -0
- package/dist/collections.d.ts +7 -0
- package/dist/collections.js +60 -0
- package/dist/collections.js.map +1 -0
- package/dist/collections.mjs +31 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/dom.d.mts +161 -0
- package/dist/dom.d.ts +161 -0
- package/dist/dom.js +359 -0
- package/dist/dom.js.map +1 -0
- package/dist/dom.mjs +314 -0
- package/dist/dom.mjs.map +1 -0
- package/dist/environment.d.mts +3 -0
- package/dist/environment.d.ts +3 -0
- package/dist/environment.js +33 -0
- package/dist/environment.js.map +1 -0
- package/dist/environment.mjs +6 -0
- package/dist/environment.mjs.map +1 -0
- package/dist/error.d.mts +5 -0
- package/dist/error.d.ts +5 -0
- package/dist/error.js +61 -0
- package/dist/error.js.map +1 -0
- package/dist/error.mjs +33 -0
- package/dist/error.mjs.map +1 -0
- package/dist/http.d.mts +145 -0
- package/dist/http.d.ts +145 -0
- package/dist/http.js +439 -0
- package/dist/http.js.map +1 -0
- package/dist/http.mjs +283 -0
- package/dist/http.mjs.map +1 -0
- package/dist/io.d.mts +244 -0
- package/dist/io.d.ts +244 -0
- package/dist/io.js +521 -0
- package/dist/io.js.map +1 -0
- package/dist/io.mjs +365 -0
- package/dist/io.mjs.map +1 -0
- package/dist/number.d.mts +8 -0
- package/dist/number.d.ts +8 -0
- package/dist/number.js +70 -0
- package/dist/number.js.map +1 -0
- package/dist/number.mjs +40 -0
- package/dist/number.mjs.map +1 -0
- package/dist/promise.d.mts +3 -0
- package/dist/promise.d.ts +3 -0
- package/dist/promise.js +37 -0
- package/dist/promise.js.map +1 -0
- package/dist/promise.mjs +10 -0
- package/dist/promise.mjs.map +1 -0
- package/dist/routing.d.mts +3 -0
- package/dist/routing.d.ts +3 -0
- package/dist/routing.js +43 -0
- package/dist/routing.js.map +1 -0
- package/dist/routing.mjs +16 -0
- package/dist/routing.mjs.map +1 -0
- package/dist/string.d.mts +9 -0
- package/dist/string.d.ts +9 -0
- package/dist/string.js +75 -0
- package/dist/string.js.map +1 -0
- package/dist/string.mjs +45 -0
- package/dist/string.mjs.map +1 -0
- package/dist/time.d.mts +9 -0
- package/dist/time.d.ts +9 -0
- package/dist/time.js +50 -0
- package/dist/time.js.map +1 -0
- package/dist/time.mjs +21 -0
- package/dist/time.mjs.map +1 -0
- package/dist/types.d.mts +11 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +23 -0
- package/dist/types.mjs.map +1 -0
- package/dist/values.d.mts +8 -0
- package/dist/values.d.ts +8 -0
- package/dist/values.js +58 -0
- package/dist/values.js.map +1 -0
- package/dist/values.mjs +30 -0
- package/dist/values.mjs.map +1 -0
- package/package.json +40 -0
package/dist/routing.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/routing/getSlug.ts
|
|
2
|
+
var getSlug = (url) => {
|
|
3
|
+
const parts = url.split("/");
|
|
4
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
5
|
+
const part = parts[i];
|
|
6
|
+
if (!part) {
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
return part;
|
|
10
|
+
}
|
|
11
|
+
return void 0;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
getSlug
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=routing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routing/getSlug.ts"],"sourcesContent":["export const getSlug = (url: string): string | undefined => {\n\tconst parts = url.split(\"/\");\n\n\tfor (let i = parts.length - 1; i >= 0; i--) {\n\t\tconst part = parts[i];\n\n\t\tif (!part) {\n\t\t\tcontinue;\n\t\t}\n\n\t\treturn part;\n\t}\n\n\treturn undefined;\n};\n"],"mappings":";AAAO,IAAM,UAAU,CAAC,QAAoC;AAC3D,QAAM,QAAQ,IAAI,MAAM,GAAG;AAE3B,WAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,UAAM,OAAO,MAAM,CAAC;AAEpB,QAAI,CAAC,MAAM;AACV;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const isUrl: (obj: unknown) => boolean;
|
|
2
|
+
|
|
3
|
+
declare const nbsp: () => string;
|
|
4
|
+
|
|
5
|
+
declare const toReadableFileSize: (bytes: number, useSi?: boolean, decimalPlaces?: number) => string;
|
|
6
|
+
|
|
7
|
+
declare const upperFirst: (value: string) => string;
|
|
8
|
+
|
|
9
|
+
export { isUrl, nbsp, toReadableFileSize, upperFirst };
|
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const isUrl: (obj: unknown) => boolean;
|
|
2
|
+
|
|
3
|
+
declare const nbsp: () => string;
|
|
4
|
+
|
|
5
|
+
declare const toReadableFileSize: (bytes: number, useSi?: boolean, decimalPlaces?: number) => string;
|
|
6
|
+
|
|
7
|
+
declare const upperFirst: (value: string) => string;
|
|
8
|
+
|
|
9
|
+
export { isUrl, nbsp, toReadableFileSize, upperFirst };
|
package/dist/string.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/string/index.ts
|
|
21
|
+
var string_exports = {};
|
|
22
|
+
__export(string_exports, {
|
|
23
|
+
isUrl: () => isUrl,
|
|
24
|
+
nbsp: () => nbsp,
|
|
25
|
+
toReadableFileSize: () => toReadableFileSize,
|
|
26
|
+
upperFirst: () => upperFirst
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(string_exports);
|
|
29
|
+
|
|
30
|
+
// src/types/guards.ts
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var isString = (obj) => typeof obj === "string";
|
|
33
|
+
|
|
34
|
+
// src/string/isUrl.ts
|
|
35
|
+
var isUrl = (obj) => {
|
|
36
|
+
if (!isString(obj)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
new URL(obj);
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/string/nbsp.ts
|
|
48
|
+
var nbsp = () => "\xA0";
|
|
49
|
+
|
|
50
|
+
// src/string/toReadableFileSize.ts
|
|
51
|
+
var toReadableFileSize = (bytes, useSi = false, decimalPlaces = 1) => {
|
|
52
|
+
const threshold = useSi ? 1e3 : 1024;
|
|
53
|
+
if (Math.abs(bytes) < threshold) {
|
|
54
|
+
return `${bytes} B`;
|
|
55
|
+
}
|
|
56
|
+
const units = useSi ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
57
|
+
let u = -1;
|
|
58
|
+
const r = 10 ** decimalPlaces;
|
|
59
|
+
do {
|
|
60
|
+
bytes /= threshold;
|
|
61
|
+
++u;
|
|
62
|
+
} while (Math.round(Math.abs(bytes) * r) / r >= threshold && u < units.length - 1);
|
|
63
|
+
return `${bytes.toFixed(decimalPlaces)} ${units[u]}`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/string/upperFirst.ts
|
|
67
|
+
var upperFirst = (value) => value.length > 1 ? `${value.charAt(0).toLocaleUpperCase()}${value.slice(1)}` : value.toLocaleUpperCase();
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
isUrl,
|
|
71
|
+
nbsp,
|
|
72
|
+
toReadableFileSize,
|
|
73
|
+
upperFirst
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/string/index.ts","../src/types/guards.ts","../src/string/isUrl.ts","../src/string/nbsp.ts","../src/string/toReadableFileSize.ts","../src/string/upperFirst.ts"],"sourcesContent":["export * from \"./isUrl\";\nexport * from \"./nbsp\";\nexport * from \"./toReadableFileSize\";\nexport * from \"./upperFirst\";\n","import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isString } from \"../types\";\n\nexport const isUrl = (obj: unknown): boolean => {\n\tif (!isString(obj)) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tnew URL(obj);\n\t} catch {\n\t\treturn false;\n\t}\n\n\treturn true;\n};\n","export const nbsp = (): string => \"\\u00A0\";\n","export const toReadableFileSize = (\n\tbytes: number,\n\tuseSi: boolean = false,\n\tdecimalPlaces: number = 1,\n): string => {\n\tconst threshold = useSi ? 1000 : 1024;\n\n\tif (Math.abs(bytes) < threshold) {\n\t\treturn `${bytes} B`;\n\t}\n\n\tconst units = useSi\n\t\t? [\"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"]\n\t\t: [\"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"];\n\n\tlet u = -1;\n\tconst r = 10 ** decimalPlaces;\n\n\tdo {\n\t\tbytes /= threshold;\n\t\t++u;\n\t} while (\n\t\tMath.round(Math.abs(bytes) * r) / r >= threshold &&\n\t\tu < units.length - 1\n\t);\n\n\treturn `${bytes.toFixed(decimalPlaces)} ${units[u]}`;\n};\n","export const upperFirst = (value: string): string =>\n\tvalue.length > 1\n\t\t? `${value.charAt(0).toLocaleUpperCase()}${value.slice(1)}`\n\t\t: value.toLocaleUpperCase();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAmBX,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;;;AClBT,IAAM,QAAQ,CAAC,QAA0B;AAC/C,MAAI,CAAC,SAAS,GAAG,GAAG;AACnB,WAAO;AAAA,EACR;AAEA,MAAI;AACH,QAAI,IAAI,GAAG;AAAA,EACZ,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,SAAO;AACR;;;ACdO,IAAM,OAAO,MAAc;;;ACA3B,IAAM,qBAAqB,CACjC,OACA,QAAiB,OACjB,gBAAwB,MACZ;AACZ,QAAM,YAAY,QAAQ,MAAO;AAEjC,MAAI,KAAK,IAAI,KAAK,IAAI,WAAW;AAChC,WAAO,GAAG,KAAK;AAAA,EAChB;AAEA,QAAM,QAAQ,QACX,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI,IAC/C,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAE1D,MAAI,IAAI;AACR,QAAM,IAAI,MAAM;AAEhB,KAAG;AACF,aAAS;AACT,MAAE;AAAA,EACH,SACC,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,aACvC,IAAI,MAAM,SAAS;AAGpB,SAAO,GAAG,MAAM,QAAQ,aAAa,CAAC,IAAI,MAAM,CAAC,CAAC;AACnD;;;AC3BO,IAAM,aAAa,CAAC,UAC1B,MAAM,SAAS,IACZ,GAAG,MAAM,OAAO,CAAC,EAAE,kBAAkB,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC,KACvD,MAAM,kBAAkB;","names":[]}
|
package/dist/string.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/types/guards.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var isString = (obj) => typeof obj === "string";
|
|
4
|
+
|
|
5
|
+
// src/string/isUrl.ts
|
|
6
|
+
var isUrl = (obj) => {
|
|
7
|
+
if (!isString(obj)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
new URL(obj);
|
|
12
|
+
} catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// src/string/nbsp.ts
|
|
19
|
+
var nbsp = () => "\xA0";
|
|
20
|
+
|
|
21
|
+
// src/string/toReadableFileSize.ts
|
|
22
|
+
var toReadableFileSize = (bytes, useSi = false, decimalPlaces = 1) => {
|
|
23
|
+
const threshold = useSi ? 1e3 : 1024;
|
|
24
|
+
if (Math.abs(bytes) < threshold) {
|
|
25
|
+
return `${bytes} B`;
|
|
26
|
+
}
|
|
27
|
+
const units = useSi ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
28
|
+
let u = -1;
|
|
29
|
+
const r = 10 ** decimalPlaces;
|
|
30
|
+
do {
|
|
31
|
+
bytes /= threshold;
|
|
32
|
+
++u;
|
|
33
|
+
} while (Math.round(Math.abs(bytes) * r) / r >= threshold && u < units.length - 1);
|
|
34
|
+
return `${bytes.toFixed(decimalPlaces)} ${units[u]}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/string/upperFirst.ts
|
|
38
|
+
var upperFirst = (value) => value.length > 1 ? `${value.charAt(0).toLocaleUpperCase()}${value.slice(1)}` : value.toLocaleUpperCase();
|
|
39
|
+
export {
|
|
40
|
+
isUrl,
|
|
41
|
+
nbsp,
|
|
42
|
+
toReadableFileSize,
|
|
43
|
+
upperFirst
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=string.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/guards.ts","../src/string/isUrl.ts","../src/string/nbsp.ts","../src/string/toReadableFileSize.ts","../src/string/upperFirst.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isString } from \"../types\";\n\nexport const isUrl = (obj: unknown): boolean => {\n\tif (!isString(obj)) {\n\t\treturn false;\n\t}\n\n\ttry {\n\t\tnew URL(obj);\n\t} catch {\n\t\treturn false;\n\t}\n\n\treturn true;\n};\n","export const nbsp = (): string => \"\\u00A0\";\n","export const toReadableFileSize = (\n\tbytes: number,\n\tuseSi: boolean = false,\n\tdecimalPlaces: number = 1,\n): string => {\n\tconst threshold = useSi ? 1000 : 1024;\n\n\tif (Math.abs(bytes) < threshold) {\n\t\treturn `${bytes} B`;\n\t}\n\n\tconst units = useSi\n\t\t? [\"kB\", \"MB\", \"GB\", \"TB\", \"PB\", \"EB\", \"ZB\", \"YB\"]\n\t\t: [\"KiB\", \"MiB\", \"GiB\", \"TiB\", \"PiB\", \"EiB\", \"ZiB\", \"YiB\"];\n\n\tlet u = -1;\n\tconst r = 10 ** decimalPlaces;\n\n\tdo {\n\t\tbytes /= threshold;\n\t\t++u;\n\t} while (\n\t\tMath.round(Math.abs(bytes) * r) / r >= threshold &&\n\t\tu < units.length - 1\n\t);\n\n\treturn `${bytes.toFixed(decimalPlaces)} ${units[u]}`;\n};\n","export const upperFirst = (value: string): string =>\n\tvalue.length > 1\n\t\t? `${value.charAt(0).toLocaleUpperCase()}${value.slice(1)}`\n\t\t: value.toLocaleUpperCase();\n"],"mappings":";AAAA,SAAS,SAAS;AAmBX,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;;;AClBT,IAAM,QAAQ,CAAC,QAA0B;AAC/C,MAAI,CAAC,SAAS,GAAG,GAAG;AACnB,WAAO;AAAA,EACR;AAEA,MAAI;AACH,QAAI,IAAI,GAAG;AAAA,EACZ,QAAQ;AACP,WAAO;AAAA,EACR;AAEA,SAAO;AACR;;;ACdO,IAAM,OAAO,MAAc;;;ACA3B,IAAM,qBAAqB,CACjC,OACA,QAAiB,OACjB,gBAAwB,MACZ;AACZ,QAAM,YAAY,QAAQ,MAAO;AAEjC,MAAI,KAAK,IAAI,KAAK,IAAI,WAAW;AAChC,WAAO,GAAG,KAAK;AAAA,EAChB;AAEA,QAAM,QAAQ,QACX,CAAC,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,MAAM,IAAI,IAC/C,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAE1D,MAAI,IAAI;AACR,QAAM,IAAI,MAAM;AAEhB,KAAG;AACF,aAAS;AACT,MAAE;AAAA,EACH,SACC,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,aACvC,IAAI,MAAM,SAAS;AAGpB,SAAO,GAAG,MAAM,QAAQ,aAAa,CAAC,IAAI,MAAM,CAAC,CAAC;AACnD;;;AC3BO,IAAM,aAAa,CAAC,UAC1B,MAAM,SAAS,IACZ,GAAG,MAAM,OAAO,CAAC,EAAE,kBAAkB,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC,KACvD,MAAM,kBAAkB;","names":[]}
|
package/dist/time.d.mts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const getDaysInMonth: (month: number, options: {
|
|
2
|
+
isLeapYear: boolean;
|
|
3
|
+
}) => number;
|
|
4
|
+
|
|
5
|
+
declare const is12HourTime: (fmtOrLocale: string | Intl.DateTimeFormat) => boolean;
|
|
6
|
+
|
|
7
|
+
declare const isLeapYear: (year: number) => boolean;
|
|
8
|
+
|
|
9
|
+
export { getDaysInMonth, is12HourTime, isLeapYear };
|
package/dist/time.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const getDaysInMonth: (month: number, options: {
|
|
2
|
+
isLeapYear: boolean;
|
|
3
|
+
}) => number;
|
|
4
|
+
|
|
5
|
+
declare const is12HourTime: (fmtOrLocale: string | Intl.DateTimeFormat) => boolean;
|
|
6
|
+
|
|
7
|
+
declare const isLeapYear: (year: number) => boolean;
|
|
8
|
+
|
|
9
|
+
export { getDaysInMonth, is12HourTime, isLeapYear };
|
package/dist/time.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/time/index.ts
|
|
21
|
+
var time_exports = {};
|
|
22
|
+
__export(time_exports, {
|
|
23
|
+
getDaysInMonth: () => getDaysInMonth,
|
|
24
|
+
is12HourTime: () => is12HourTime,
|
|
25
|
+
isLeapYear: () => isLeapYear
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(time_exports);
|
|
28
|
+
|
|
29
|
+
// src/time/getDaysInMonth.ts
|
|
30
|
+
var getDaysInMonth = (month, options) => new Date(options.isLeapYear ? 2e3 : 2001, month, 0).getDate();
|
|
31
|
+
|
|
32
|
+
// src/types/guards.ts
|
|
33
|
+
var import_zod = require("zod");
|
|
34
|
+
var isString = (obj) => typeof obj === "string";
|
|
35
|
+
|
|
36
|
+
// src/time/is12HourTime.ts
|
|
37
|
+
var is12HourTime = (fmtOrLocale) => {
|
|
38
|
+
const fmt = isString(fmtOrLocale) ? new Intl.DateTimeFormat(fmtOrLocale) : fmtOrLocale;
|
|
39
|
+
return fmt.resolvedOptions().hour12 ?? false;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/time/isLeapYear.ts
|
|
43
|
+
var isLeapYear = (year) => year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
getDaysInMonth,
|
|
47
|
+
is12HourTime,
|
|
48
|
+
isLeapYear
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=time.js.map
|
package/dist/time.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/time/index.ts","../src/time/getDaysInMonth.ts","../src/types/guards.ts","../src/time/is12HourTime.ts","../src/time/isLeapYear.ts"],"sourcesContent":["export * from \"./getDaysInMonth\";\nexport * from \"./is12HourTime\";\nexport * from \"./isLeapYear\";\n","export const getDaysInMonth = (\n\tmonth: number,\n\toptions: { isLeapYear: boolean },\n): number => new Date(options.isLeapYear ? 2000 : 2001, month, 0).getDate();\n","import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isString } from \"../types\";\n\nexport const is12HourTime = (\n\tfmtOrLocale: string | Intl.DateTimeFormat,\n): boolean => {\n\tconst fmt = isString(fmtOrLocale)\n\t\t? new Intl.DateTimeFormat(fmtOrLocale)\n\t\t: fmtOrLocale;\n\treturn fmt.resolvedOptions().hour12 ?? false;\n};\n","export const isLeapYear = (year: number): boolean =>\n\tyear % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,iBAAiB,CAC7B,OACA,YACY,IAAI,KAAK,QAAQ,aAAa,MAAO,MAAM,OAAO,CAAC,EAAE,QAAQ;;;ACH1E,iBAAkB;AAmBX,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;;;AClBT,IAAM,eAAe,CAC3B,gBACa;AACb,QAAM,MAAM,SAAS,WAAW,IAC7B,IAAI,KAAK,eAAe,WAAW,IACnC;AACH,SAAO,IAAI,gBAAgB,EAAE,UAAU;AACxC;;;ACTO,IAAM,aAAa,CAAC,SAC1B,OAAO,QAAQ,KAAM,OAAO,QAAQ,KAAK,OAAO,MAAM;","names":[]}
|
package/dist/time.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/time/getDaysInMonth.ts
|
|
2
|
+
var getDaysInMonth = (month, options) => new Date(options.isLeapYear ? 2e3 : 2001, month, 0).getDate();
|
|
3
|
+
|
|
4
|
+
// src/types/guards.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var isString = (obj) => typeof obj === "string";
|
|
7
|
+
|
|
8
|
+
// src/time/is12HourTime.ts
|
|
9
|
+
var is12HourTime = (fmtOrLocale) => {
|
|
10
|
+
const fmt = isString(fmtOrLocale) ? new Intl.DateTimeFormat(fmtOrLocale) : fmtOrLocale;
|
|
11
|
+
return fmt.resolvedOptions().hour12 ?? false;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/time/isLeapYear.ts
|
|
15
|
+
var isLeapYear = (year) => year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
|
|
16
|
+
export {
|
|
17
|
+
getDaysInMonth,
|
|
18
|
+
is12HourTime,
|
|
19
|
+
isLeapYear
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=time.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/time/getDaysInMonth.ts","../src/types/guards.ts","../src/time/is12HourTime.ts","../src/time/isLeapYear.ts"],"sourcesContent":["export const getDaysInMonth = (\n\tmonth: number,\n\toptions: { isLeapYear: boolean },\n): number => new Date(options.isLeapYear ? 2000 : 2001, month, 0).getDate();\n","import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isString } from \"../types\";\n\nexport const is12HourTime = (\n\tfmtOrLocale: string | Intl.DateTimeFormat,\n): boolean => {\n\tconst fmt = isString(fmtOrLocale)\n\t\t? new Intl.DateTimeFormat(fmtOrLocale)\n\t\t: fmtOrLocale;\n\treturn fmt.resolvedOptions().hour12 ?? false;\n};\n","export const isLeapYear = (year: number): boolean =>\n\tyear % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);\n"],"mappings":";AAAO,IAAM,iBAAiB,CAC7B,OACA,YACY,IAAI,KAAK,QAAQ,aAAa,MAAO,MAAM,OAAO,CAAC,EAAE,QAAQ;;;ACH1E,SAAS,SAAS;AAmBX,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;;;AClBT,IAAM,eAAe,CAC3B,gBACa;AACb,QAAM,MAAM,SAAS,WAAW,IAC7B,IAAI,KAAK,eAAe,WAAW,IACnC;AACH,SAAO,IAAI,gBAAgB,EAAE,UAAU;AACxC;;;ACTO,IAAM,aAAa,CAAC,SAC1B,OAAO,QAAQ,KAAM,OAAO,QAAQ,KAAK,OAAO,MAAM;","names":[]}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const isArray: (obj: unknown) => obj is unknown[];
|
|
2
|
+
declare const isBoolean: (obj: unknown) => obj is boolean;
|
|
3
|
+
declare const isFunction: (obj: unknown) => obj is Function;
|
|
4
|
+
declare const isNull: (obj: unknown) => obj is null;
|
|
5
|
+
declare const isNullOrUndefined: (obj: unknown) => obj is null | undefined;
|
|
6
|
+
declare const isNumber: (obj: unknown) => obj is number;
|
|
7
|
+
declare const isString: (obj: unknown) => obj is string;
|
|
8
|
+
declare const isUndefined: (obj: unknown) => obj is undefined;
|
|
9
|
+
declare const isUnknown: (obj: unknown) => obj is unknown;
|
|
10
|
+
|
|
11
|
+
export { isArray, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isString, isUndefined, isUnknown };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const isArray: (obj: unknown) => obj is unknown[];
|
|
2
|
+
declare const isBoolean: (obj: unknown) => obj is boolean;
|
|
3
|
+
declare const isFunction: (obj: unknown) => obj is Function;
|
|
4
|
+
declare const isNull: (obj: unknown) => obj is null;
|
|
5
|
+
declare const isNullOrUndefined: (obj: unknown) => obj is null | undefined;
|
|
6
|
+
declare const isNumber: (obj: unknown) => obj is number;
|
|
7
|
+
declare const isString: (obj: unknown) => obj is string;
|
|
8
|
+
declare const isUndefined: (obj: unknown) => obj is undefined;
|
|
9
|
+
declare const isUnknown: (obj: unknown) => obj is unknown;
|
|
10
|
+
|
|
11
|
+
export { isArray, isBoolean, isFunction, isNull, isNullOrUndefined, isNumber, isString, isUndefined, isUnknown };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/types/index.ts
|
|
21
|
+
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
isArray: () => isArray,
|
|
24
|
+
isBoolean: () => isBoolean,
|
|
25
|
+
isFunction: () => isFunction,
|
|
26
|
+
isNull: () => isNull,
|
|
27
|
+
isNullOrUndefined: () => isNullOrUndefined,
|
|
28
|
+
isNumber: () => isNumber,
|
|
29
|
+
isString: () => isString,
|
|
30
|
+
isUndefined: () => isUndefined,
|
|
31
|
+
isUnknown: () => isUnknown
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(types_exports);
|
|
34
|
+
|
|
35
|
+
// src/types/guards.ts
|
|
36
|
+
var import_zod = require("zod");
|
|
37
|
+
var isArray = (obj) => Array.isArray(obj);
|
|
38
|
+
var isBoolean = (obj) => obj === true || obj === false;
|
|
39
|
+
var isFunction = (obj) => typeof obj === "function";
|
|
40
|
+
var isNull = (obj) => obj === null;
|
|
41
|
+
var isNullOrUndefined = (obj) => isNull(obj) || isUndefined(obj);
|
|
42
|
+
var isNumber = (obj) => typeof obj === "number";
|
|
43
|
+
var isString = (obj) => typeof obj === "string";
|
|
44
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
45
|
+
var isUnknown = (obj) => import_zod.z.unknown().safeParse(obj).success;
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
isArray,
|
|
49
|
+
isBoolean,
|
|
50
|
+
isFunction,
|
|
51
|
+
isNull,
|
|
52
|
+
isNullOrUndefined,
|
|
53
|
+
isNumber,
|
|
54
|
+
isString,
|
|
55
|
+
isUndefined,
|
|
56
|
+
isUnknown
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/index.ts","../src/types/guards.ts"],"sourcesContent":["export * from \"./guards\";\n","import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAEX,IAAM,UAAU,CAAC,QAAmC,MAAM,QAAQ,GAAG;AAErE,IAAM,YAAY,CAAC,QACzB,QAAQ,QAAQ,QAAQ;AAGlB,IAAM,aAAa,CAAC,QAC1B,OAAO,QAAQ;AAET,IAAM,SAAS,CAAC,QAA8B,QAAQ;AAEtD,IAAM,oBAAoB,CAAC,QACjC,OAAO,GAAG,KAAK,YAAY,GAAG;AAExB,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,cAAc,CAAC,QAC3B,OAAO,QAAQ;AAET,IAAM,YAAY,CAAC,QACzB,aAAE,QAAQ,EAAE,UAAU,GAAG,EAAE;","names":[]}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/types/guards.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var isArray = (obj) => Array.isArray(obj);
|
|
4
|
+
var isBoolean = (obj) => obj === true || obj === false;
|
|
5
|
+
var isFunction = (obj) => typeof obj === "function";
|
|
6
|
+
var isNull = (obj) => obj === null;
|
|
7
|
+
var isNullOrUndefined = (obj) => isNull(obj) || isUndefined(obj);
|
|
8
|
+
var isNumber = (obj) => typeof obj === "number";
|
|
9
|
+
var isString = (obj) => typeof obj === "string";
|
|
10
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
11
|
+
var isUnknown = (obj) => z.unknown().safeParse(obj).success;
|
|
12
|
+
export {
|
|
13
|
+
isArray,
|
|
14
|
+
isBoolean,
|
|
15
|
+
isFunction,
|
|
16
|
+
isNull,
|
|
17
|
+
isNullOrUndefined,
|
|
18
|
+
isNumber,
|
|
19
|
+
isString,
|
|
20
|
+
isUndefined,
|
|
21
|
+
isUnknown
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/guards.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,UAAU,CAAC,QAAmC,MAAM,QAAQ,GAAG;AAErE,IAAM,YAAY,CAAC,QACzB,QAAQ,QAAQ,QAAQ;AAGlB,IAAM,aAAa,CAAC,QAC1B,OAAO,QAAQ;AAET,IAAM,SAAS,CAAC,QAA8B,QAAQ;AAEtD,IAAM,oBAAoB,CAAC,QACjC,OAAO,GAAG,KAAK,YAAY,GAAG;AAExB,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,cAAc,CAAC,QAC3B,OAAO,QAAQ;AAET,IAAM,YAAY,CAAC,QACzB,EAAE,QAAQ,EAAE,UAAU,GAAG,EAAE;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Failure = string | Error;
|
|
2
|
+
type InvariantAssertion = (value: unknown) => asserts value;
|
|
3
|
+
type InvariantAssertionWithMessage = (value: unknown, failure?: Failure | (() => Failure)) => asserts value;
|
|
4
|
+
declare const invariant: InvariantAssertionWithMessage;
|
|
5
|
+
|
|
6
|
+
declare const unreachable: (_: never) => never;
|
|
7
|
+
|
|
8
|
+
export { type InvariantAssertion, type InvariantAssertionWithMessage, invariant, unreachable };
|
package/dist/values.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Failure = string | Error;
|
|
2
|
+
type InvariantAssertion = (value: unknown) => asserts value;
|
|
3
|
+
type InvariantAssertionWithMessage = (value: unknown, failure?: Failure | (() => Failure)) => asserts value;
|
|
4
|
+
declare const invariant: InvariantAssertionWithMessage;
|
|
5
|
+
|
|
6
|
+
declare const unreachable: (_: never) => never;
|
|
7
|
+
|
|
8
|
+
export { type InvariantAssertion, type InvariantAssertionWithMessage, invariant, unreachable };
|
package/dist/values.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/values/index.ts
|
|
21
|
+
var values_exports = {};
|
|
22
|
+
__export(values_exports, {
|
|
23
|
+
invariant: () => invariant,
|
|
24
|
+
unreachable: () => unreachable
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(values_exports);
|
|
27
|
+
|
|
28
|
+
// src/types/guards.ts
|
|
29
|
+
var import_zod = require("zod");
|
|
30
|
+
var isFunction = (obj) => typeof obj === "function";
|
|
31
|
+
var isNull = (obj) => obj === null;
|
|
32
|
+
var isNullOrUndefined = (obj) => isNull(obj) || isUndefined(obj);
|
|
33
|
+
var isString = (obj) => typeof obj === "string";
|
|
34
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
35
|
+
|
|
36
|
+
// src/values/invariant.ts
|
|
37
|
+
var invariant = (value, failure) => {
|
|
38
|
+
if (value === false || isNullOrUndefined(value)) {
|
|
39
|
+
const failureOutput = isFunction(failure) ? failure() : failure;
|
|
40
|
+
if (isString(failureOutput)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
failureOutput || `Assertion failed on value '${value}'.`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
throw failureOutput;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/values/unreachable.ts
|
|
50
|
+
var unreachable = (_) => {
|
|
51
|
+
throw new Error("Unreachable code was reached at runtime.");
|
|
52
|
+
};
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
invariant,
|
|
56
|
+
unreachable
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/values/index.ts","../src/types/guards.ts","../src/values/invariant.ts","../src/values/unreachable.ts"],"sourcesContent":["export * from \"./invariant\";\nexport * from \"./unreachable\";\n","import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isFunction, isNullOrUndefined, isString } from \"../types/guards\";\n\ntype Failure = string | Error;\n\nexport type InvariantAssertion = (value: unknown) => asserts value;\n\nexport type InvariantAssertionWithMessage = (\n\tvalue: unknown,\n\tfailure?: Failure | (() => Failure),\n) => asserts value;\n\nexport const invariant: InvariantAssertionWithMessage = (\n\tvalue,\n\tfailure,\n): asserts value => {\n\tif (value === false || isNullOrUndefined(value)) {\n\t\tconst failureOutput = isFunction(failure) ? failure() : failure;\n\n\t\tif (isString(failureOutput)) {\n\t\t\tthrow new Error(\n\t\t\t\tfailureOutput || `Assertion failed on value '${value}'.`,\n\t\t\t);\n\t\t}\n\n\t\tthrow failureOutput;\n\t}\n};\n","export const unreachable = (_: never): never => {\n\tthrow new Error(\"Unreachable code was reached at runtime.\");\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAQX,IAAM,aAAa,CAAC,QAC1B,OAAO,QAAQ;AAET,IAAM,SAAS,CAAC,QAA8B,QAAQ;AAEtD,IAAM,oBAAoB,CAAC,QACjC,OAAO,GAAG,KAAK,YAAY,GAAG;AAKxB,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,cAAc,CAAC,QAC3B,OAAO,QAAQ;;;ACZT,IAAM,YAA2C,CACvD,OACA,YACmB;AACnB,MAAI,UAAU,SAAS,kBAAkB,KAAK,GAAG;AAChD,UAAM,gBAAgB,WAAW,OAAO,IAAI,QAAQ,IAAI;AAExD,QAAI,SAAS,aAAa,GAAG;AAC5B,YAAM,IAAI;AAAA,QACT,iBAAiB,8BAA8B,KAAK;AAAA,MACrD;AAAA,IACD;AAEA,UAAM;AAAA,EACP;AACD;;;AC1BO,IAAM,cAAc,CAAC,MAAoB;AAC/C,QAAM,IAAI,MAAM,0CAA0C;AAC3D;","names":[]}
|
package/dist/values.mjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/types/guards.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var isFunction = (obj) => typeof obj === "function";
|
|
4
|
+
var isNull = (obj) => obj === null;
|
|
5
|
+
var isNullOrUndefined = (obj) => isNull(obj) || isUndefined(obj);
|
|
6
|
+
var isString = (obj) => typeof obj === "string";
|
|
7
|
+
var isUndefined = (obj) => typeof obj === "undefined";
|
|
8
|
+
|
|
9
|
+
// src/values/invariant.ts
|
|
10
|
+
var invariant = (value, failure) => {
|
|
11
|
+
if (value === false || isNullOrUndefined(value)) {
|
|
12
|
+
const failureOutput = isFunction(failure) ? failure() : failure;
|
|
13
|
+
if (isString(failureOutput)) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
failureOutput || `Assertion failed on value '${value}'.`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
throw failureOutput;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/values/unreachable.ts
|
|
23
|
+
var unreachable = (_) => {
|
|
24
|
+
throw new Error("Unreachable code was reached at runtime.");
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
invariant,
|
|
28
|
+
unreachable
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=values.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/guards.ts","../src/values/invariant.ts","../src/values/unreachable.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const isArray = (obj: unknown): obj is unknown[] => Array.isArray(obj);\n\nexport const isBoolean = (obj: unknown): obj is boolean =>\n\tobj === true || obj === false;\n\n// biome-ignore lint/complexity/noBannedTypes: Generic function-checking type guard.\nexport const isFunction = (obj: unknown): obj is Function =>\n\ttypeof obj === \"function\";\n\nexport const isNull = (obj: unknown): obj is null => obj === null;\n\nexport const isNullOrUndefined = (obj: unknown): obj is null | undefined =>\n\tisNull(obj) || isUndefined(obj);\n\nexport const isNumber = (obj: unknown): obj is number =>\n\ttypeof obj === \"number\";\n\nexport const isString = (obj: unknown): obj is string =>\n\ttypeof obj === \"string\";\n\nexport const isUndefined = (obj: unknown): obj is undefined =>\n\ttypeof obj === \"undefined\";\n\nexport const isUnknown = (obj: unknown): obj is unknown =>\n\tz.unknown().safeParse(obj).success;\n","import { isFunction, isNullOrUndefined, isString } from \"../types/guards\";\n\ntype Failure = string | Error;\n\nexport type InvariantAssertion = (value: unknown) => asserts value;\n\nexport type InvariantAssertionWithMessage = (\n\tvalue: unknown,\n\tfailure?: Failure | (() => Failure),\n) => asserts value;\n\nexport const invariant: InvariantAssertionWithMessage = (\n\tvalue,\n\tfailure,\n): asserts value => {\n\tif (value === false || isNullOrUndefined(value)) {\n\t\tconst failureOutput = isFunction(failure) ? failure() : failure;\n\n\t\tif (isString(failureOutput)) {\n\t\t\tthrow new Error(\n\t\t\t\tfailureOutput || `Assertion failed on value '${value}'.`,\n\t\t\t);\n\t\t}\n\n\t\tthrow failureOutput;\n\t}\n};\n","export const unreachable = (_: never): never => {\n\tthrow new Error(\"Unreachable code was reached at runtime.\");\n};\n"],"mappings":";AAAA,SAAS,SAAS;AAQX,IAAM,aAAa,CAAC,QAC1B,OAAO,QAAQ;AAET,IAAM,SAAS,CAAC,QAA8B,QAAQ;AAEtD,IAAM,oBAAoB,CAAC,QACjC,OAAO,GAAG,KAAK,YAAY,GAAG;AAKxB,IAAM,WAAW,CAAC,QACxB,OAAO,QAAQ;AAET,IAAM,cAAc,CAAC,QAC3B,OAAO,QAAQ;;;ACZT,IAAM,YAA2C,CACvD,OACA,YACmB;AACnB,MAAI,UAAU,SAAS,kBAAkB,KAAK,GAAG;AAChD,UAAM,gBAAgB,WAAW,OAAO,IAAI,QAAQ,IAAI;AAExD,QAAI,SAAS,aAAa,GAAG;AAC5B,YAAM,IAAI;AAAA,QACT,iBAAiB,8BAA8B,KAAK;AAAA,MACrD;AAAA,IACD;AAEA,UAAM;AAAA,EACP;AACD;;;AC1BO,IAAM,cAAc,CAAC,MAAoB;AAC/C,QAAM,IAAI,MAAM,0CAA0C;AAC3D;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ekumlin/typescript-toolkit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": "github:ek68794998/typescript-toolkit.git",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./collections": "./dist/collections.js",
|
|
7
|
+
"./dom": "./dist/dom.js",
|
|
8
|
+
"./environment": "./dist/environment.js",
|
|
9
|
+
"./error": "./dist/error.js",
|
|
10
|
+
"./http": "./dist/http.js",
|
|
11
|
+
"./io": "./dist/io.js",
|
|
12
|
+
"./number": "./dist/number.js",
|
|
13
|
+
"./promise": "./dist/promise.js",
|
|
14
|
+
"./routing": "./dist/routing.js",
|
|
15
|
+
"./string": "./dist/string.js",
|
|
16
|
+
"./time": "./dist/time.js",
|
|
17
|
+
"./types": "./dist/types.js",
|
|
18
|
+
"./values": "./dist/values.js"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"lint": "tsc --noEmit",
|
|
30
|
+
"release": "pnpm build && npm publish",
|
|
31
|
+
"test": "vitest"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"zod": "^4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.13.10",
|
|
38
|
+
"typescript": "5.9.2"
|
|
39
|
+
}
|
|
40
|
+
}
|