@noeldemartin/utils 0.7.3 → 0.8.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/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/fluent/FluentArray.d.ts +48 -0
- package/dist/fluent/FluentArray.js +48 -0
- package/dist/fluent/FluentArray.js.map +1 -0
- package/dist/fluent/FluentObject.d.ts +16 -0
- package/dist/fluent/FluentObject.js +45 -0
- package/dist/fluent/FluentObject.js.map +1 -0
- package/dist/fluent/FluentString.d.ts +21 -0
- package/dist/fluent/FluentString.js +28 -0
- package/dist/fluent/FluentString.js.map +1 -0
- package/dist/fluent/facade.d.ts +17 -0
- package/dist/fluent/facade.js +45 -0
- package/dist/fluent/facade.js.map +1 -0
- package/dist/fluent/index.d.ts +29 -0
- package/dist/fluent/index.js +41 -0
- package/dist/fluent/index.js.map +1 -0
- package/dist/fluent/invade.d.ts +6 -0
- package/dist/fluent/invade.js +8 -0
- package/dist/fluent/invade.js.map +1 -0
- package/dist/fluent/lazyFacade.d.ts +16 -0
- package/dist/fluent/lazyFacade.js +67 -0
- package/dist/fluent/lazyFacade.js.map +1 -0
- package/dist/fluent/noop.d.ts +4 -0
- package/dist/fluent/noop.js +6 -0
- package/dist/fluent/noop.js.map +1 -0
- package/dist/fluent/required.d.ts +5 -0
- package/dist/fluent/required.js +32 -0
- package/dist/fluent/required.js.map +1 -0
- package/dist/fluent/tap.d.ts +7 -0
- package/dist/fluent/tap.js +22 -0
- package/dist/fluent/tap.js.map +1 -0
- package/dist/fluent/value.d.ts +5 -0
- package/dist/fluent/value.js +8 -0
- package/dist/fluent/value.js.map +1 -0
- package/dist/fluent/when.d.ts +6 -0
- package/dist/fluent/when.js +11 -0
- package/dist/fluent/when.js.map +1 -0
- package/dist/helpers/InMemoryStorageService.d.ts +8 -0
- package/dist/helpers/InMemoryStorageService.js +16 -0
- package/dist/helpers/InMemoryStorageService.js.map +1 -0
- package/dist/helpers/IndexedDBMap.d.ts +17 -0
- package/dist/helpers/IndexedDBMap.js +52 -0
- package/dist/helpers/IndexedDBMap.js.map +1 -0
- package/dist/helpers/JSError.d.ts +14 -0
- package/dist/helpers/JSError.js +14 -0
- package/dist/helpers/JSError.js.map +1 -0
- package/dist/helpers/ListenersManager.d.ts +15 -0
- package/dist/helpers/ListenersManager.js +23 -0
- package/dist/helpers/ListenersManager.js.map +1 -0
- package/dist/helpers/MagicObject.d.ts +29 -0
- package/dist/helpers/MagicObject.js +77 -0
- package/dist/helpers/MagicObject.js.map +1 -0
- package/dist/helpers/ObjectsMap.d.ts +28 -0
- package/dist/helpers/ObjectsMap.js +86 -0
- package/dist/helpers/ObjectsMap.js.map +1 -0
- package/dist/helpers/PromisedValue.d.ts +32 -0
- package/dist/helpers/PromisedValue.js +68 -0
- package/dist/helpers/PromisedValue.js.map +1 -0
- package/dist/helpers/Semaphore.d.ts +14 -0
- package/dist/helpers/Semaphore.js +45 -0
- package/dist/helpers/Semaphore.js.map +1 -0
- package/dist/helpers/Storage.d.ts +17 -0
- package/dist/helpers/Storage.js +39 -0
- package/dist/helpers/Storage.js.map +1 -0
- package/dist/helpers/array_helpers.d.ts +57 -0
- package/dist/helpers/array_helpers.js +208 -0
- package/dist/helpers/array_helpers.js.map +1 -0
- package/dist/helpers/boolean_helpers.d.ts +4 -0
- package/dist/helpers/boolean_helpers.js +10 -0
- package/dist/helpers/boolean_helpers.js.map +1 -0
- package/dist/helpers/caching_helpers.d.ts +17 -0
- package/dist/helpers/caching_helpers.js +55 -0
- package/dist/helpers/caching_helpers.js.map +1 -0
- package/dist/helpers/chaos_helpers.d.ts +6 -0
- package/dist/helpers/chaos_helpers.js +11 -0
- package/dist/helpers/chaos_helpers.js.map +1 -0
- package/dist/helpers/date_helpers.d.ts +4 -0
- package/dist/helpers/date_helpers.js +15 -0
- package/dist/helpers/date_helpers.js.map +1 -0
- package/dist/helpers/deprecated.d.ts +24 -0
- package/dist/helpers/env.d.ts +9 -0
- package/dist/helpers/env.js +42 -0
- package/dist/helpers/env.js.map +1 -0
- package/dist/helpers/error_helpers.d.ts +12 -0
- package/dist/helpers/error_helpers.js +20 -0
- package/dist/helpers/error_helpers.js.map +1 -0
- package/dist/helpers/escape_helpers.d.ts +5 -0
- package/dist/helpers/escape_helpers.js +11 -0
- package/dist/helpers/escape_helpers.js.map +1 -0
- package/dist/helpers/file_helpers.d.ts +4 -0
- package/dist/helpers/file_helpers.js +16 -0
- package/dist/helpers/file_helpers.js.map +1 -0
- package/dist/helpers/format_helpers.d.ts +7 -0
- package/dist/helpers/format_helpers.js +28 -0
- package/dist/helpers/format_helpers.js.map +1 -0
- package/dist/helpers/hash_helpers.d.ts +4 -0
- package/dist/helpers/hash_helpers.js +156 -0
- package/dist/helpers/hash_helpers.js.map +1 -0
- package/dist/helpers/identity_helpers.d.ts +5 -0
- package/dist/helpers/identity_helpers.js +15 -0
- package/dist/helpers/identity_helpers.js.map +1 -0
- package/dist/helpers/location_helpers.d.ts +8 -0
- package/dist/helpers/location_helpers.js +37 -0
- package/dist/helpers/location_helpers.js.map +1 -0
- package/dist/helpers/logical_helpers.d.ts +4 -0
- package/dist/helpers/logical_helpers.js +13 -0
- package/dist/helpers/logical_helpers.js.map +1 -0
- package/dist/helpers/math_helpers.d.ts +5 -0
- package/dist/helpers/math_helpers.js +12 -0
- package/dist/helpers/math_helpers.js.map +1 -0
- package/dist/helpers/mixin_helpers.d.ts +20 -0
- package/dist/helpers/mixin_helpers.js +43 -0
- package/dist/helpers/mixin_helpers.js.map +1 -0
- package/dist/helpers/network_helpers.d.ts +4 -0
- package/dist/helpers/network_helpers.js +8 -0
- package/dist/helpers/network_helpers.js.map +1 -0
- package/dist/helpers/object_helpers.d.ts +58 -0
- package/dist/helpers/object_helpers.js +179 -0
- package/dist/helpers/object_helpers.js.map +1 -0
- package/dist/helpers/promise_helpers.d.ts +10 -0
- package/dist/helpers/promise_helpers.js +25 -0
- package/dist/helpers/promise_helpers.js.map +1 -0
- package/dist/helpers/replacements-scope.js +21 -0
- package/dist/helpers/replacements-scope.js.map +1 -0
- package/dist/helpers/replacements.d.ts +5 -0
- package/dist/helpers/replacements.js +34 -0
- package/dist/helpers/replacements.js.map +1 -0
- package/dist/helpers/runtime_helpers.d.ts +4 -0
- package/dist/helpers/runtime_helpers.js +8 -0
- package/dist/helpers/runtime_helpers.js.map +1 -0
- package/dist/helpers/string_helpers.d.ts +17 -0
- package/dist/helpers/string_helpers.js +42 -0
- package/dist/helpers/string_helpers.js.map +1 -0
- package/dist/helpers/time_constants.d.ts +15 -0
- package/dist/helpers/time_constants.js +17 -0
- package/dist/helpers/time_constants.js.map +1 -0
- package/dist/helpers/time_helpers.d.ts +24 -0
- package/dist/helpers/time_helpers.js +57 -0
- package/dist/helpers/time_helpers.js.map +1 -0
- package/dist/helpers/url_helpers.d.ts +24 -0
- package/dist/helpers/url_helpers.js +90 -0
- package/dist/helpers/url_helpers.js.map +1 -0
- package/dist/helpers/value_helpers.d.ts +7 -0
- package/dist/helpers/value_helpers.js +11 -0
- package/dist/helpers/value_helpers.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +49 -0
- package/dist/types/arrays.d.ts +12 -0
- package/dist/types/classes.d.ts +12 -0
- package/dist/types/helpers.d.ts +36 -0
- package/dist/types/helpers.js +6 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/objects.d.ts +8 -0
- package/package.json +38 -52
- package/src/fluent/FluentArray.test.ts +2 -9
- package/src/fluent/FluentArray.ts +6 -5
- package/src/fluent/FluentObject.ts +2 -4
- package/src/fluent/FluentString.test.ts +1 -8
- package/src/fluent/FluentString.ts +0 -2
- package/src/fluent/facade.test.ts +16 -4
- package/src/fluent/facade.ts +6 -4
- package/src/fluent/index.test.ts +3 -8
- package/src/fluent/index.ts +3 -3
- package/src/fluent/invade.test.ts +1 -5
- package/src/fluent/invade.ts +1 -1
- package/src/fluent/lazyFacade.test.ts +191 -0
- package/src/fluent/lazyFacade.ts +115 -0
- package/src/fluent/required.test.ts +1 -5
- package/src/fluent/required.ts +2 -4
- package/src/fluent/tap.test.ts +2 -9
- package/src/fluent/tap.ts +4 -3
- package/src/fluent/value.test.ts +1 -4
- package/src/fluent/when.test.ts +1 -6
- package/src/fluent/when.ts +2 -2
- package/src/helpers/InMemoryStorageService.ts +13 -0
- package/src/helpers/IndexedDBMap.ts +0 -2
- package/src/helpers/JSError.test.ts +1 -6
- package/src/helpers/JSError.ts +0 -2
- package/src/helpers/ListenersManager.test.ts +3 -7
- package/src/helpers/ListenersManager.ts +2 -4
- package/src/helpers/MagicObject.test.ts +14 -8
- package/src/helpers/MagicObject.ts +12 -3
- package/src/helpers/ObjectsMap.test.ts +1 -3
- package/src/helpers/ObjectsMap.ts +1 -5
- package/src/helpers/PromisedValue.test.ts +1 -3
- package/src/helpers/PromisedValue.ts +5 -6
- package/src/helpers/Semaphore.test.ts +6 -10
- package/src/helpers/Semaphore.ts +0 -2
- package/src/helpers/Storage.test.ts +47 -0
- package/src/helpers/Storage.ts +11 -19
- package/src/helpers/array_helpers.test.ts +127 -38
- package/src/helpers/array_helpers.ts +137 -78
- package/src/helpers/caching_helpers.test.ts +1 -3
- package/src/helpers/caching_helpers.ts +2 -2
- package/src/helpers/date_helpers.test.ts +1 -4
- package/src/helpers/date_helpers.ts +1 -1
- package/src/helpers/env.ts +5 -1
- package/src/helpers/error_helpers.test.ts +9 -8
- package/src/helpers/error_helpers.ts +11 -11
- package/src/helpers/format_helpers.test.ts +2 -4
- package/src/helpers/hash_helpers.test.ts +1 -4
- package/src/helpers/hash_helpers.ts +3 -3
- package/src/helpers/identity_helpers.test.ts +1 -3
- package/src/helpers/index.ts +3 -0
- package/src/helpers/logical_helpers.test.ts +1 -3
- package/src/helpers/logical_helpers.ts +1 -1
- package/src/helpers/math_helpers.test.ts +1 -3
- package/src/helpers/mixin_helpers.stubs.ts +1 -13
- package/src/helpers/mixin_helpers.test.ts +2 -7
- package/src/helpers/mixin_helpers.ts +6 -9
- package/src/helpers/object_helpers.test.ts +32 -19
- package/src/helpers/object_helpers.ts +43 -21
- package/src/helpers/promise_helpers.test.ts +1 -4
- package/src/helpers/promise_helpers.ts +9 -9
- package/src/helpers/replacements-scope.ts +15 -0
- package/src/helpers/replacements.test.ts +23 -0
- package/src/helpers/replacements.ts +52 -0
- package/src/helpers/runtime_helpers.ts +3 -3
- package/src/helpers/string_helpers.test.ts +3 -5
- package/src/helpers/time_constants.ts +13 -0
- package/src/helpers/time_helpers.ts +35 -0
- package/src/helpers/url_helpers.test.ts +12 -4
- package/src/helpers/url_helpers.ts +9 -15
- package/src/helpers/value_helpers.test.ts +12 -0
- package/src/helpers/value_helpers.ts +6 -0
- package/src/types/arrays.test.ts +1 -4
- package/src/types/classes.ts +1 -0
- package/src/types/helpers.test.ts +1 -6
- package/src/types/helpers.ts +6 -5
- package/src/types/objects.test.ts +1 -4
- package/src/types/objects.ts +3 -3
- package/dist/noeldemartin-utils.d.ts +0 -901
- package/dist/noeldemartin-utils.js +0 -1473
- package/dist/noeldemartin-utils.js.map +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/helpers/url_helpers.d.ts
|
|
2
|
+
export interface UrlParts {
|
|
3
|
+
protocol?: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
port?: string;
|
|
6
|
+
path?: string;
|
|
7
|
+
query?: string;
|
|
8
|
+
fragment?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function requireUrlParentDirectory(url: string): string;
|
|
11
|
+
export declare function requireUrlDirectoryName(url: string): string;
|
|
12
|
+
export declare function requireUrlParse(url: string): UrlParts;
|
|
13
|
+
export declare function urlResolve(...parts: string[]): string;
|
|
14
|
+
export declare function urlResolveDirectory(...parts: string[]): string;
|
|
15
|
+
export declare function urlRoot(url: string): string;
|
|
16
|
+
export declare function urlParentDirectory(url: string): string | null;
|
|
17
|
+
export declare function urlDirectoryName(url: string): string | null;
|
|
18
|
+
export declare function urlFileName(url: string): string;
|
|
19
|
+
export declare function urlParse(url: string): UrlParts | null;
|
|
20
|
+
export declare function urlClean(url: string, includedParts: { [part in keyof UrlParts]?: boolean; }): string;
|
|
21
|
+
export declare function urlRoute(url: string): string;
|
|
22
|
+
export declare function validUrl(url: string): string | null;
|
|
23
|
+
//#endregion
|
|
24
|
+
//# sourceMappingURL=url_helpers.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { fail } from "./error_helpers.js";
|
|
2
|
+
//#region src/helpers/url_helpers.ts
|
|
3
|
+
function requireUrlParentDirectory(url) {
|
|
4
|
+
return urlParentDirectory(url) ?? fail(`Failed getting parent directory from '${url}'`);
|
|
5
|
+
}
|
|
6
|
+
function requireUrlDirectoryName(url) {
|
|
7
|
+
return urlDirectoryName(url) ?? fail(`Failed getting directory name from '${url}'`);
|
|
8
|
+
}
|
|
9
|
+
function requireUrlParse(url) {
|
|
10
|
+
return urlParse(url) ?? fail(`Failed parsing url from '${url}'`);
|
|
11
|
+
}
|
|
12
|
+
function urlResolve(...parts) {
|
|
13
|
+
if (parts.length === 0) return "";
|
|
14
|
+
let url = parts[0];
|
|
15
|
+
for (const part of parts.slice(1)) url = new URL(part, url).toString();
|
|
16
|
+
return url;
|
|
17
|
+
}
|
|
18
|
+
function urlResolveDirectory(...parts) {
|
|
19
|
+
const url = urlResolve(...parts);
|
|
20
|
+
return url.endsWith("/") ? url : url + "/";
|
|
21
|
+
}
|
|
22
|
+
function urlRoot(url) {
|
|
23
|
+
const protocolIndex = url.indexOf("://") + 3;
|
|
24
|
+
const pathIndex = url.substr(protocolIndex).indexOf("/");
|
|
25
|
+
return pathIndex !== -1 ? url.substring(0, protocolIndex + pathIndex) : url;
|
|
26
|
+
}
|
|
27
|
+
function urlParentDirectory(url) {
|
|
28
|
+
if (url.endsWith("/")) url = url.substring(0, url.length - 1);
|
|
29
|
+
if (urlRoot(url) === url) return null;
|
|
30
|
+
const pathIndex = url.lastIndexOf("/");
|
|
31
|
+
return pathIndex !== -1 ? url.substr(0, pathIndex + 1) : null;
|
|
32
|
+
}
|
|
33
|
+
function urlDirectoryName(url) {
|
|
34
|
+
if (!url.endsWith("/")) url = urlParentDirectory(url) ?? url + "/";
|
|
35
|
+
const rootPathUrl = url.slice(0, -1);
|
|
36
|
+
if (urlRoot(url) === rootPathUrl) return null;
|
|
37
|
+
return urlFileName(rootPathUrl);
|
|
38
|
+
}
|
|
39
|
+
function urlFileName(url) {
|
|
40
|
+
const pathIndex = url.lastIndexOf("/");
|
|
41
|
+
return (pathIndex !== -1 ? url.slice(pathIndex + 1) : "").replace(/#.*$/, "").replace(/\?.*$/, "");
|
|
42
|
+
}
|
|
43
|
+
function urlParse(url) {
|
|
44
|
+
const match = url.trim().match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);
|
|
45
|
+
if (!match) return null;
|
|
46
|
+
const host = match[4] || "";
|
|
47
|
+
const [domain, port] = host.indexOf(":") === -1 ? [host] : host.split(":");
|
|
48
|
+
return {
|
|
49
|
+
protocol: match[2] || void 0,
|
|
50
|
+
domain: domain || void 0,
|
|
51
|
+
port: port || void 0,
|
|
52
|
+
path: match[5] || void 0,
|
|
53
|
+
query: match[7] || void 0,
|
|
54
|
+
fragment: match[9] || void 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function urlClean(url, includedParts) {
|
|
58
|
+
const parts = urlParse(url);
|
|
59
|
+
if (!parts) return url;
|
|
60
|
+
for (const [part, value] of Object.entries(parts)) parts[part] = includedParts[part] !== false ? value || "" : "";
|
|
61
|
+
return [
|
|
62
|
+
parts.protocol ? `${parts.protocol}://` : "",
|
|
63
|
+
parts.domain ?? "",
|
|
64
|
+
parts.port ? `:${parts.port}` : "",
|
|
65
|
+
parts.path ?? "",
|
|
66
|
+
parts.query ? `?${parts.query}` : "",
|
|
67
|
+
parts.fragment ? `#${parts.fragment}` : ""
|
|
68
|
+
].join("");
|
|
69
|
+
}
|
|
70
|
+
function urlRoute(url) {
|
|
71
|
+
return urlClean(url, {
|
|
72
|
+
protocol: true,
|
|
73
|
+
domain: true,
|
|
74
|
+
port: true,
|
|
75
|
+
path: true,
|
|
76
|
+
query: false,
|
|
77
|
+
fragment: false
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function validUrl(url) {
|
|
81
|
+
try {
|
|
82
|
+
return new URL(url.trim()).toString();
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
export { requireUrlDirectoryName, requireUrlParentDirectory, requireUrlParse, urlClean, urlDirectoryName, urlFileName, urlParentDirectory, urlParse, urlResolve, urlResolveDirectory, urlRoot, urlRoute, validUrl };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=url_helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url_helpers.js","names":[],"sources":["../../src/helpers/url_helpers.ts"],"sourcesContent":["import { fail } from './error_helpers';\n\nexport interface UrlParts {\n protocol?: string;\n domain?: string;\n port?: string;\n path?: string;\n query?: string;\n fragment?: string;\n}\n\nexport function requireUrlParentDirectory(url: string): string {\n return urlParentDirectory(url) ?? fail(`Failed getting parent directory from '${url}'`);\n}\n\nexport function requireUrlDirectoryName(url: string): string {\n return urlDirectoryName(url) ?? fail(`Failed getting directory name from '${url}'`);\n}\n\nexport function requireUrlParse(url: string): UrlParts {\n return urlParse(url) ?? fail(`Failed parsing url from '${url}'`);\n}\n\nexport function urlResolve(...parts: string[]): string {\n if (parts.length === 0) {\n return '';\n }\n\n let url = parts[0];\n\n for (const part of parts.slice(1)) {\n url = new URL(part, url).toString();\n }\n\n return url;\n}\n\nexport function urlResolveDirectory(...parts: string[]): string {\n const url = urlResolve(...parts);\n\n return url.endsWith('/') ? url : url + '/';\n}\n\nexport function urlRoot(url: string): string {\n const protocolIndex = url.indexOf('://') + 3;\n const pathIndex = url.substr(protocolIndex).indexOf('/');\n\n return pathIndex !== -1 ? url.substring(0, protocolIndex + pathIndex) : url;\n}\n\nexport function urlParentDirectory(url: string): string | null {\n if (url.endsWith('/')) url = url.substring(0, url.length - 1);\n\n if (urlRoot(url) === url) return null;\n\n const pathIndex = url.lastIndexOf('/');\n\n return pathIndex !== -1 ? url.substr(0, pathIndex + 1) : null;\n}\n\nexport function urlDirectoryName(url: string): string | null {\n if (!url.endsWith('/')) url = urlParentDirectory(url) ?? url + '/';\n\n const rootPathUrl = url.slice(0, -1);\n\n if (urlRoot(url) === rootPathUrl) return null;\n\n return urlFileName(rootPathUrl);\n}\n\nexport function urlFileName(url: string): string {\n const pathIndex = url.lastIndexOf('/');\n const fileName = pathIndex !== -1 ? url.slice(pathIndex + 1) : '';\n\n return fileName.replace(/#.*$/, '').replace(/\\?.*$/, '');\n}\n\nexport function urlParse(url: string): UrlParts | null {\n const match = url.trim().match(/^(([^:/?#]+):)?(\\/\\/([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?/);\n\n if (!match) return null;\n\n const host = match[4] || '';\n const [domain, port]: string[] = host.indexOf(':') === -1 ? [host] : host.split(':');\n\n return {\n protocol: match[2] || undefined,\n domain: domain || undefined,\n port: port || undefined,\n path: match[5] || undefined,\n query: match[7] || undefined,\n fragment: match[9] || undefined,\n };\n}\n\nexport function urlClean(url: string, includedParts: { [part in keyof UrlParts]?: boolean }): string {\n const parts = urlParse(url);\n\n if (!parts) return url;\n\n for (const [part, value] of Object.entries(parts) as [keyof UrlParts, string?][]) {\n parts[part] = includedParts[part] !== false ? value || '' : '';\n }\n\n return [\n parts.protocol ? `${parts.protocol}://` : '',\n parts.domain ?? '',\n parts.port ? `:${parts.port}` : '',\n parts.path ?? '',\n parts.query ? `?${parts.query}` : '',\n parts.fragment ? `#${parts.fragment}` : '',\n ].join('');\n}\n\nexport function urlRoute(url: string): string {\n return urlClean(url, {\n protocol: true,\n domain: true,\n port: true,\n path: true,\n query: false,\n fragment: false,\n });\n}\n\nexport function validUrl(url: string): string | null {\n try {\n return new URL(url.trim()).toString();\n } catch {\n return null;\n }\n}\n"],"mappings":";;AAWA,SAAgB,0BAA0B,KAAqB;CAC3D,OAAO,mBAAmB,GAAG,KAAK,KAAK,yCAAyC,IAAI,EAAE;AAC1F;AAEA,SAAgB,wBAAwB,KAAqB;CACzD,OAAO,iBAAiB,GAAG,KAAK,KAAK,uCAAuC,IAAI,EAAE;AACtF;AAEA,SAAgB,gBAAgB,KAAuB;CACnD,OAAO,SAAS,GAAG,KAAK,KAAK,4BAA4B,IAAI,EAAE;AACnE;AAEA,SAAgB,WAAW,GAAG,OAAyB;CACnD,IAAI,MAAM,WAAW,GACjB,OAAO;CAGX,IAAI,MAAM,MAAM;CAEhB,KAAK,MAAM,QAAQ,MAAM,MAAM,CAAC,GAC5B,MAAM,IAAI,IAAI,MAAM,GAAG,CAAC,CAAC,SAAS;CAGtC,OAAO;AACX;AAEA,SAAgB,oBAAoB,GAAG,OAAyB;CAC5D,MAAM,MAAM,WAAW,GAAG,KAAK;CAE/B,OAAO,IAAI,SAAS,GAAG,IAAI,MAAM,MAAM;AAC3C;AAEA,SAAgB,QAAQ,KAAqB;CACzC,MAAM,gBAAgB,IAAI,QAAQ,KAAK,IAAI;CAC3C,MAAM,YAAY,IAAI,OAAO,aAAa,CAAC,CAAC,QAAQ,GAAG;CAEvD,OAAO,cAAc,KAAK,IAAI,UAAU,GAAG,gBAAgB,SAAS,IAAI;AAC5E;AAEA,SAAgB,mBAAmB,KAA4B;CAC3D,IAAI,IAAI,SAAS,GAAG,GAAG,MAAM,IAAI,UAAU,GAAG,IAAI,SAAS,CAAC;CAE5D,IAAI,QAAQ,GAAG,MAAM,KAAK,OAAO;CAEjC,MAAM,YAAY,IAAI,YAAY,GAAG;CAErC,OAAO,cAAc,KAAK,IAAI,OAAO,GAAG,YAAY,CAAC,IAAI;AAC7D;AAEA,SAAgB,iBAAiB,KAA4B;CACzD,IAAI,CAAC,IAAI,SAAS,GAAG,GAAG,MAAM,mBAAmB,GAAG,KAAK,MAAM;CAE/D,MAAM,cAAc,IAAI,MAAM,GAAG,EAAE;CAEnC,IAAI,QAAQ,GAAG,MAAM,aAAa,OAAO;CAEzC,OAAO,YAAY,WAAW;AAClC;AAEA,SAAgB,YAAY,KAAqB;CAC7C,MAAM,YAAY,IAAI,YAAY,GAAG;CAGrC,QAFiB,cAAc,KAAK,IAAI,MAAM,YAAY,CAAC,IAAI,GAAA,CAE/C,QAAQ,QAAQ,EAAE,CAAC,CAAC,QAAQ,SAAS,EAAE;AAC3D;AAEA,SAAgB,SAAS,KAA8B;CACnD,MAAM,QAAQ,IAAI,KAAK,CAAC,CAAC,MAAM,6DAA6D;CAE5F,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,CAAC,QAAQ,QAAkB,KAAK,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,IAAI,KAAK,MAAM,GAAG;CAEnF,OAAO;EACH,UAAU,MAAM,MAAM,KAAA;EACtB,QAAQ,UAAU,KAAA;EAClB,MAAM,QAAQ,KAAA;EACd,MAAM,MAAM,MAAM,KAAA;EAClB,OAAO,MAAM,MAAM,KAAA;EACnB,UAAU,MAAM,MAAM,KAAA;CAC1B;AACJ;AAEA,SAAgB,SAAS,KAAa,eAA+D;CACjG,MAAM,QAAQ,SAAS,GAAG;CAE1B,IAAI,CAAC,OAAO,OAAO;CAEnB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,KAAK,GAC5C,MAAM,QAAQ,cAAc,UAAU,QAAQ,SAAS,KAAK;CAGhE,OAAO;EACH,MAAM,WAAW,GAAG,MAAM,SAAS,OAAO;EAC1C,MAAM,UAAU;EAChB,MAAM,OAAO,IAAI,MAAM,SAAS;EAChC,MAAM,QAAQ;EACd,MAAM,QAAQ,IAAI,MAAM,UAAU;EAClC,MAAM,WAAW,IAAI,MAAM,aAAa;CAC5C,CAAC,CAAC,KAAK,EAAE;AACb;AAEA,SAAgB,SAAS,KAAqB;CAC1C,OAAO,SAAS,KAAK;EACjB,UAAU;EACV,QAAQ;EACR,MAAM;EACN,MAAM;EACN,OAAO;EACP,UAAU;CACd,CAAC;AACL;AAEA,SAAgB,SAAS,KAA4B;CACjD,IAAI;EACA,OAAO,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,SAAS;CACxC,QAAQ;EACJ,OAAO;CACX;AACJ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Truthy } from "../types/helpers.js";
|
|
2
|
+
//#region src/helpers/value_helpers.d.ts
|
|
3
|
+
export type EvaluatesTo<T> = T | (() => T);
|
|
4
|
+
export declare function evaluate<T>(value: EvaluatesTo<T>): T;
|
|
5
|
+
export declare function isTruthy<T>(value: T): value is Truthy<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=value_helpers.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/helpers/value_helpers.ts
|
|
2
|
+
function evaluate(value) {
|
|
3
|
+
return typeof value === "function" ? value() : value;
|
|
4
|
+
}
|
|
5
|
+
function isTruthy(value) {
|
|
6
|
+
return Boolean(value);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { evaluate, isTruthy };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=value_helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value_helpers.js","names":[],"sources":["../../src/helpers/value_helpers.ts"],"sourcesContent":["import type { Truthy } from '@noeldemartin/utils/types';\n\nexport type EvaluatesTo<T> = T | (() => T);\n\nexport function evaluate<T>(value: EvaluatesTo<T>): T {\n return typeof value === 'function' ? (value as () => T)() : value;\n}\n\nexport function isTruthy<T>(value: T): value is Truthy<T> {\n return Boolean(value);\n}\n"],"mappings":";AAIA,SAAgB,SAAY,OAA0B;CAClD,OAAO,OAAO,UAAU,aAAc,MAAkB,IAAI;AAChE;AAEA,SAAgB,SAAY,OAA8B;CACtD,OAAO,QAAQ,KAAK;AACxB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import IndexedDBMap from "./helpers/IndexedDBMap.js";
|
|
2
|
+
import { Branded, ClassInstance, Closure, ClosureArgs, ClosureResult, Equals, Falsy, GetObjectMethods, GetOptionalKeys, GetRequiredKeys, IsAny, IsPlainObject, KeyOf, Nullable, NullableOptional, NullablePartial, ObjectValues, OnlyKnownProperties, Override, Pretty, SubPartial, Truthy, TypeGuard, Use, VoidClosure, Writable, __brand } from "./types/helpers.js";
|
|
3
|
+
import { Constructor, ReplaceConstructorArgs } from "./types/classes.js";
|
|
4
|
+
import { Facade, FacadeExtension, FacadeMethods, extendFacadeMethods, facade, getFacadeInstance, isFacade } from "./fluent/facade.js";
|
|
5
|
+
import _default, { StorageService } from "./helpers/Storage.js";
|
|
6
|
+
import InMemoryStorageService from "./helpers/InMemoryStorageService.js";
|
|
7
|
+
import JSError, { JSErrorOptions, RuntimeErrorClass } from "./helpers/JSError.js";
|
|
8
|
+
import ListenersManager, { ListenerEvents, ListenerPayload, Listeners } from "./helpers/ListenersManager.js";
|
|
9
|
+
import MagicObject, { MagicObjectConstructor, MagicObjectProxy } from "./helpers/MagicObject.js";
|
|
10
|
+
import ObjectsMap, { ObjectKeyExtractor } from "./helpers/ObjectsMap.js";
|
|
11
|
+
import PromisedValue, { PromisedValueRejectListener, PromisedValueResetListener, PromisedValueResolveListener } from "./helpers/PromisedValue.js";
|
|
12
|
+
import Semaphore from "./helpers/Semaphore.js";
|
|
13
|
+
import { DeepKeyOf, DeepRequired, DeepValue, _Decrement } from "./types/objects.js";
|
|
14
|
+
import { ArrayFrom, ArraySortCompare, ArraySortDirection, ArraySortFieldDirection, arrayChunk, arrayClear, arrayDiff, arrayEquals, arrayFilter, arrayFind, arrayFirst, arrayFlatMap, arrayFrom, arrayGroupBy, arrayIsEmpty, arrayProject, arrayPull, arrayRandomItem, arrayRandomItems, arrayRemove, arrayRemoveIndex, arrayReplace, arrayReversed, arrayShuffled, arraySorted, arraySwap, arrayUnique, arrayWhere, arrayWithItemAt, arrayWithout, arrayWithoutIndex, arrayWithoutIndexes, arrayZip, hasItems, range, reduceBy, shuffle } from "./helpers/array_helpers.js";
|
|
15
|
+
import { parseBoolean } from "./helpers/boolean_helpers.js";
|
|
16
|
+
import { ArrayDeepItem, ArrayIncludes, ArrayItem, CollapseTupleUnion, RequiredTuple, Tuple, _CollapseTupleUnionRecursion, _RequiredTupleRecursion, _TupleRecursion } from "./types/arrays.js";
|
|
17
|
+
import { asyncMemo, getAsyncMemo, getMemo, getWeakMemo, memo, once, resetAsyncMemo, resetMemo, resetWeakMemo, setAsyncMemo, setMemo, setWeakMemo, weakMemo } from "./helpers/caching_helpers.js";
|
|
18
|
+
import { randomInt } from "./helpers/chaos_helpers.js";
|
|
19
|
+
import { parseDate } from "./helpers/date_helpers.js";
|
|
20
|
+
import { GetOptionalKeysWithoutEmpty, GetRequiredKeysWithoutEmpty, ObjectWithoutEmpty, ReplaceEmpty, ValueWithoutEmpty } from "./helpers/deprecated.js";
|
|
21
|
+
import { applyStrictChecks, forceEnv, getEnv, isDevelopment, isProduction, isTesting } from "./helpers/env.js";
|
|
22
|
+
import { EvaluatesTo, evaluate, isTruthy } from "./helpers/value_helpers.js";
|
|
23
|
+
import { assert, catchError, fail } from "./helpers/error_helpers.js";
|
|
24
|
+
import { escapeHtmlEntities, escapeRegexText } from "./helpers/escape_helpers.js";
|
|
25
|
+
import { downloadFile } from "./helpers/file_helpers.js";
|
|
26
|
+
import { FormatCodeBlockOptions, formatCodeBlock } from "./helpers/format_helpers.js";
|
|
27
|
+
import { md5 } from "./helpers/hash_helpers.js";
|
|
28
|
+
import { shortId, uuid } from "./helpers/identity_helpers.js";
|
|
29
|
+
import { deleteLocationQueryParameters, getLocationQueryParameter, getLocationQueryParameters, hasLocationQueryParameter, updateLocationQueryParameters } from "./helpers/location_helpers.js";
|
|
30
|
+
import { compare } from "./helpers/logical_helpers.js";
|
|
31
|
+
import { clamp, round } from "./helpers/math_helpers.js";
|
|
32
|
+
import { Cr, applyMixins, mixed, mixedWithoutTypes, usesMixin } from "./helpers/mixin_helpers.js";
|
|
33
|
+
import { isSuccessfulResponse } from "./helpers/network_helpers.js";
|
|
34
|
+
import { GetObjectKeys, GetObjectValues, GetOptionalKeysWithout, GetRequiredKeysWithout, Inverted, Obj, ObjectWithout, ReplaceValues, ValueWithout, deepAssign, deepEquals, deepGet, deepSet, getClassMethods, invert, isArray, isConstructor, isEmpty, isInstanceOf, isIterable, isNullable, isObject, isPlainObject, isPromiseLike, isString, isSubclassOf, monkeyPatch, objectDeepClone, objectEntries, objectFromEntries, objectHasOwnProperty, objectKeys, objectMap, objectOnly, objectPropertyIsObject, objectPull, objectValues, objectWithout, objectWithoutEmpty, overridePrototypeMethod, toError, toString } from "./helpers/object_helpers.js";
|
|
35
|
+
import { asyncFirst, isPromise, silenced } from "./helpers/promise_helpers.js";
|
|
36
|
+
import { Replacements, applyReplacements } from "./helpers/replacements.js";
|
|
37
|
+
import { runtimeGlobal } from "./helpers/runtime_helpers.js";
|
|
38
|
+
import { Slug, stringCapitalize, stringExcerpt, stringMatch, stringMatchAll, stringReverse, stringSplitWords, stringToCamelCase, stringToSlug, stringToStudlyCase, stringToTitleCase, stringTrimmed } from "./helpers/string_helpers.js";
|
|
39
|
+
import { DAY_MILLISECONDS, DAY_SECONDS, HOUR_MILLISECONDS, HOUR_SECONDS, MINUTE_MILLISECONDS, MINUTE_SECONDS, MONTH_MILLISECONDS, MONTH_SECONDS, WEEK_MILLISECONDS, WEEK_SECONDS, YEAR_MILLISECONDS, YEAR_SECONDS } from "./helpers/time_constants.js";
|
|
40
|
+
import { AfterOptions, DebouncedFunction, after, afterAnimationFrame, debounce, forever, isValidDateString, seconds, sleep, throttle } from "./helpers/time_helpers.js";
|
|
41
|
+
import { UrlParts, requireUrlDirectoryName, requireUrlParentDirectory, requireUrlParse, urlClean, urlDirectoryName, urlFileName, urlParentDirectory, urlParse, urlResolve, urlResolveDirectory, urlRoot, urlRoute, validUrl } from "./helpers/url_helpers.js";
|
|
42
|
+
import FluentObjectDefinition, { FluentHelperMethods, FluentInstance, FluentPrimitiveMethods, Helper, HelperParams } from "./fluent/FluentObject.js";
|
|
43
|
+
import FluentArrayDefinition, { FluentArray, FluentArrayHelpers, FluentArrayInstance } from "./fluent/FluentArray.js";
|
|
44
|
+
import FluentStringDefinition, { FluentString, FluentStringInstance, fluentStringHelpers } from "./fluent/FluentString.js";
|
|
45
|
+
import { LazyFacade, LazyFacadeInstanceMethods, LazyFacadeMethods, isLazyFacade, lazyFacade } from "./fluent/lazyFacade.js";
|
|
46
|
+
import { Tapped, tap } from "./fluent/tap.js";
|
|
47
|
+
import { noop } from "./fluent/noop.js";
|
|
48
|
+
import { required } from "./fluent/required.js";
|
|
49
|
+
import { value } from "./fluent/value.js";
|
|
50
|
+
import { when } from "./fluent/when.js";
|
|
51
|
+
import { Invaded, invade } from "./fluent/invade.js";
|
|
52
|
+
import { arr, fluent, map, pull, str } from "./fluent/index.js";
|
|
53
|
+
export { AfterOptions, ArrayDeepItem, ArrayFrom, ArrayIncludes, ArrayItem, ArraySortCompare, ArraySortDirection, ArraySortFieldDirection, Branded, ClassInstance, Closure, ClosureArgs, ClosureResult, CollapseTupleUnion, Constructor, Cr, DAY_MILLISECONDS, DAY_SECONDS, DebouncedFunction, DeepKeyOf, DeepRequired, DeepValue, Equals, EvaluatesTo, Facade, FacadeExtension, FacadeMethods, Falsy, type FluentArray, FluentArrayDefinition, type FluentArrayHelpers, type FluentArrayInstance, type FluentHelperMethods, type FluentInstance, FluentObjectDefinition, type FluentPrimitiveMethods, type FluentString, FluentStringDefinition, type FluentStringInstance, FormatCodeBlockOptions, GetObjectKeys, GetObjectMethods, GetObjectValues, GetOptionalKeys, GetOptionalKeysWithout, GetOptionalKeysWithoutEmpty, GetRequiredKeys, GetRequiredKeysWithout, GetRequiredKeysWithoutEmpty, HOUR_MILLISECONDS, HOUR_SECONDS, type Helper, type HelperParams, InMemoryStorageService, IndexedDBMap, Invaded, Inverted, IsAny, IsPlainObject, JSError, JSErrorOptions, KeyOf, LazyFacade, LazyFacadeInstanceMethods, LazyFacadeMethods, ListenerEvents, ListenerPayload, Listeners, ListenersManager, MINUTE_MILLISECONDS, MINUTE_SECONDS, MONTH_MILLISECONDS, MONTH_SECONDS, MagicObject, MagicObjectConstructor, MagicObjectProxy, Nullable, NullableOptional, NullablePartial, Obj, ObjectKeyExtractor, ObjectValues, ObjectWithout, ObjectWithoutEmpty, ObjectsMap, OnlyKnownProperties, Override, Pretty, PromisedValue, PromisedValueRejectListener, PromisedValueResetListener, PromisedValueResolveListener, ReplaceConstructorArgs, ReplaceEmpty, ReplaceValues, Replacements, RequiredTuple, RuntimeErrorClass, Semaphore, Slug, _default as Storage, StorageService, SubPartial, type Tapped, Truthy, Tuple, TypeGuard, UrlParts, Use, ValueWithout, ValueWithoutEmpty, VoidClosure, WEEK_MILLISECONDS, WEEK_SECONDS, Writable, YEAR_MILLISECONDS, YEAR_SECONDS, _CollapseTupleUnionRecursion, _Decrement, _RequiredTupleRecursion, _TupleRecursion, __brand, after, afterAnimationFrame, applyMixins, applyReplacements, applyStrictChecks, arr, arrayChunk, arrayClear, arrayDiff, arrayEquals, arrayFilter, arrayFind, arrayFirst, arrayFlatMap, arrayFrom, arrayGroupBy, arrayIsEmpty, arrayProject, arrayPull, arrayRandomItem, arrayRandomItems, arrayRemove, arrayRemoveIndex, arrayReplace, arrayReversed, arrayShuffled, arraySorted, arraySwap, arrayUnique, arrayWhere, arrayWithItemAt, arrayWithout, arrayWithoutIndex, arrayWithoutIndexes, arrayZip, assert, asyncFirst, asyncMemo, catchError, clamp, compare, debounce, deepAssign, deepEquals, deepGet, deepSet, deleteLocationQueryParameters, downloadFile, escapeHtmlEntities, escapeRegexText, evaluate, extendFacadeMethods, facade, fail, fluent, fluentStringHelpers, forceEnv, forever, formatCodeBlock, getAsyncMemo, getClassMethods, getEnv, getFacadeInstance, getLocationQueryParameter, getLocationQueryParameters, getMemo, getWeakMemo, hasItems, hasLocationQueryParameter, invade, invert, isArray, isConstructor, isDevelopment, isEmpty, isFacade, isInstanceOf, isIterable, isLazyFacade, isNullable, isObject, isPlainObject, isProduction, isPromise, isPromiseLike, isString, isSubclassOf, isSuccessfulResponse, isTesting, isTruthy, isValidDateString, lazyFacade, map, md5, memo, mixed, mixedWithoutTypes, monkeyPatch, noop, objectDeepClone, objectEntries, objectFromEntries, objectHasOwnProperty, objectKeys, objectMap, objectOnly, objectPropertyIsObject, objectPull, objectValues, objectWithout, objectWithoutEmpty, once, overridePrototypeMethod, parseBoolean, parseDate, pull, randomInt, range, reduceBy, requireUrlDirectoryName, requireUrlParentDirectory, requireUrlParse, required, resetAsyncMemo, resetMemo, resetWeakMemo, round, runtimeGlobal, seconds, setAsyncMemo, setMemo, setWeakMemo, shortId, shuffle, silenced, sleep, str, stringCapitalize, stringExcerpt, stringMatch, stringMatchAll, stringReverse, stringSplitWords, stringToCamelCase, stringToSlug, stringToStudlyCase, stringToTitleCase, stringTrimmed, tap, throttle, toError, toString, updateLocationQueryParameters, urlClean, urlDirectoryName, urlFileName, urlParentDirectory, urlParse, urlResolve, urlResolveDirectory, urlRoot, urlRoute, usesMixin, uuid, validUrl, value, weakMemo, when };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { evaluate, isTruthy } from "./helpers/value_helpers.js";
|
|
2
|
+
import { assert, catchError, fail } from "./helpers/error_helpers.js";
|
|
3
|
+
import IndexedDBMap from "./helpers/IndexedDBMap.js";
|
|
4
|
+
import { extendFacadeMethods, facade, getFacadeInstance, isFacade } from "./fluent/facade.js";
|
|
5
|
+
import Storage_default, { StorageService } from "./helpers/Storage.js";
|
|
6
|
+
import InMemoryStorageService from "./helpers/InMemoryStorageService.js";
|
|
7
|
+
import { runtimeGlobal } from "./helpers/runtime_helpers.js";
|
|
8
|
+
import JSError, { RuntimeErrorClass } from "./helpers/JSError.js";
|
|
9
|
+
import { compare } from "./helpers/logical_helpers.js";
|
|
10
|
+
import { deepAssign, deepEquals, deepGet, deepSet, getClassMethods, invert, isArray, isConstructor, isEmpty, isInstanceOf, isIterable, isNullable, isObject, isPlainObject, isPromiseLike, isString, isSubclassOf, monkeyPatch, objectDeepClone, objectEntries, objectFromEntries, objectHasOwnProperty, objectKeys, objectMap, objectOnly, objectPropertyIsObject, objectPull, objectValues, objectWithout, objectWithoutEmpty, overridePrototypeMethod, toError, toString } from "./helpers/object_helpers.js";
|
|
11
|
+
import { arrayChunk, arrayClear, arrayDiff, arrayEquals, arrayFilter, arrayFind, arrayFirst, arrayFlatMap, arrayFrom, arrayGroupBy, arrayIsEmpty, arrayProject, arrayPull, arrayRandomItem, arrayRandomItems, arrayRemove, arrayRemoveIndex, arrayReplace, arrayReversed, arrayShuffled, arraySorted, arraySwap, arrayUnique, arrayWhere, arrayWithItemAt, arrayWithout, arrayWithoutIndex, arrayWithoutIndexes, arrayZip, hasItems, range, reduceBy, shuffle } from "./helpers/array_helpers.js";
|
|
12
|
+
import ListenersManager from "./helpers/ListenersManager.js";
|
|
13
|
+
import MagicObject from "./helpers/MagicObject.js";
|
|
14
|
+
import ObjectsMap from "./helpers/ObjectsMap.js";
|
|
15
|
+
import PromisedValue from "./helpers/PromisedValue.js";
|
|
16
|
+
import Semaphore from "./helpers/Semaphore.js";
|
|
17
|
+
import { parseBoolean } from "./helpers/boolean_helpers.js";
|
|
18
|
+
import { asyncMemo, getAsyncMemo, getMemo, getWeakMemo, memo, once, resetAsyncMemo, resetMemo, resetWeakMemo, setAsyncMemo, setMemo, setWeakMemo, weakMemo } from "./helpers/caching_helpers.js";
|
|
19
|
+
import { randomInt } from "./helpers/chaos_helpers.js";
|
|
20
|
+
import { parseDate } from "./helpers/date_helpers.js";
|
|
21
|
+
import { applyStrictChecks, forceEnv, getEnv, isDevelopment, isProduction, isTesting } from "./helpers/env.js";
|
|
22
|
+
import { escapeHtmlEntities, escapeRegexText } from "./helpers/escape_helpers.js";
|
|
23
|
+
import { downloadFile } from "./helpers/file_helpers.js";
|
|
24
|
+
import { formatCodeBlock } from "./helpers/format_helpers.js";
|
|
25
|
+
import { md5 } from "./helpers/hash_helpers.js";
|
|
26
|
+
import { shortId, uuid } from "./helpers/identity_helpers.js";
|
|
27
|
+
import { after, afterAnimationFrame, debounce, forever, isValidDateString, seconds, sleep, throttle } from "./helpers/time_helpers.js";
|
|
28
|
+
import { deleteLocationQueryParameters, getLocationQueryParameter, getLocationQueryParameters, hasLocationQueryParameter, updateLocationQueryParameters } from "./helpers/location_helpers.js";
|
|
29
|
+
import { clamp, round } from "./helpers/math_helpers.js";
|
|
30
|
+
import { applyMixins, mixed, mixedWithoutTypes, usesMixin } from "./helpers/mixin_helpers.js";
|
|
31
|
+
import { isSuccessfulResponse } from "./helpers/network_helpers.js";
|
|
32
|
+
import { asyncFirst, isPromise, silenced } from "./helpers/promise_helpers.js";
|
|
33
|
+
import { stringCapitalize, stringExcerpt, stringMatch, stringMatchAll, stringReverse, stringSplitWords, stringToCamelCase, stringToSlug, stringToStudlyCase, stringToTitleCase, stringTrimmed } from "./helpers/string_helpers.js";
|
|
34
|
+
import { applyReplacements } from "./helpers/replacements.js";
|
|
35
|
+
import { DAY_MILLISECONDS, DAY_SECONDS, HOUR_MILLISECONDS, HOUR_SECONDS, MINUTE_MILLISECONDS, MINUTE_SECONDS, MONTH_MILLISECONDS, MONTH_SECONDS, WEEK_MILLISECONDS, WEEK_SECONDS, YEAR_MILLISECONDS, YEAR_SECONDS } from "./helpers/time_constants.js";
|
|
36
|
+
import { requireUrlDirectoryName, requireUrlParentDirectory, requireUrlParse, urlClean, urlDirectoryName, urlFileName, urlParentDirectory, urlParse, urlResolve, urlResolveDirectory, urlRoot, urlRoute, validUrl } from "./helpers/url_helpers.js";
|
|
37
|
+
import FluentObjectDefinition from "./fluent/FluentObject.js";
|
|
38
|
+
import FluentArrayDefinition from "./fluent/FluentArray.js";
|
|
39
|
+
import FluentStringDefinition, { fluentStringHelpers } from "./fluent/FluentString.js";
|
|
40
|
+
import { isLazyFacade, lazyFacade } from "./fluent/lazyFacade.js";
|
|
41
|
+
import { tap } from "./fluent/tap.js";
|
|
42
|
+
import { noop } from "./fluent/noop.js";
|
|
43
|
+
import { required } from "./fluent/required.js";
|
|
44
|
+
import { value } from "./fluent/value.js";
|
|
45
|
+
import { when } from "./fluent/when.js";
|
|
46
|
+
import { invade } from "./fluent/invade.js";
|
|
47
|
+
import { arr, fluent, map, pull, str } from "./fluent/index.js";
|
|
48
|
+
import { __brand } from "./types/helpers.js";
|
|
49
|
+
export { DAY_MILLISECONDS, DAY_SECONDS, FluentArrayDefinition, FluentObjectDefinition, FluentStringDefinition, HOUR_MILLISECONDS, HOUR_SECONDS, InMemoryStorageService, IndexedDBMap, JSError, ListenersManager, MINUTE_MILLISECONDS, MINUTE_SECONDS, MONTH_MILLISECONDS, MONTH_SECONDS, MagicObject, ObjectsMap, PromisedValue, RuntimeErrorClass, Semaphore, Storage_default as Storage, StorageService, WEEK_MILLISECONDS, WEEK_SECONDS, YEAR_MILLISECONDS, YEAR_SECONDS, __brand, after, afterAnimationFrame, applyMixins, applyReplacements, applyStrictChecks, arr, arrayChunk, arrayClear, arrayDiff, arrayEquals, arrayFilter, arrayFind, arrayFirst, arrayFlatMap, arrayFrom, arrayGroupBy, arrayIsEmpty, arrayProject, arrayPull, arrayRandomItem, arrayRandomItems, arrayRemove, arrayRemoveIndex, arrayReplace, arrayReversed, arrayShuffled, arraySorted, arraySwap, arrayUnique, arrayWhere, arrayWithItemAt, arrayWithout, arrayWithoutIndex, arrayWithoutIndexes, arrayZip, assert, asyncFirst, asyncMemo, catchError, clamp, compare, debounce, deepAssign, deepEquals, deepGet, deepSet, deleteLocationQueryParameters, downloadFile, escapeHtmlEntities, escapeRegexText, evaluate, extendFacadeMethods, facade, fail, fluent, fluentStringHelpers, forceEnv, forever, formatCodeBlock, getAsyncMemo, getClassMethods, getEnv, getFacadeInstance, getLocationQueryParameter, getLocationQueryParameters, getMemo, getWeakMemo, hasItems, hasLocationQueryParameter, invade, invert, isArray, isConstructor, isDevelopment, isEmpty, isFacade, isInstanceOf, isIterable, isLazyFacade, isNullable, isObject, isPlainObject, isProduction, isPromise, isPromiseLike, isString, isSubclassOf, isSuccessfulResponse, isTesting, isTruthy, isValidDateString, lazyFacade, map, md5, memo, mixed, mixedWithoutTypes, monkeyPatch, noop, objectDeepClone, objectEntries, objectFromEntries, objectHasOwnProperty, objectKeys, objectMap, objectOnly, objectPropertyIsObject, objectPull, objectValues, objectWithout, objectWithoutEmpty, once, overridePrototypeMethod, parseBoolean, parseDate, pull, randomInt, range, reduceBy, requireUrlDirectoryName, requireUrlParentDirectory, requireUrlParse, required, resetAsyncMemo, resetMemo, resetWeakMemo, round, runtimeGlobal, seconds, setAsyncMemo, setMemo, setWeakMemo, shortId, shuffle, silenced, sleep, str, stringCapitalize, stringExcerpt, stringMatch, stringMatchAll, stringReverse, stringSplitWords, stringToCamelCase, stringToSlug, stringToStudlyCase, stringToTitleCase, stringTrimmed, tap, throttle, toError, toString, updateLocationQueryParameters, urlClean, urlDirectoryName, urlFileName, urlParentDirectory, urlParse, urlResolve, urlResolveDirectory, urlRoot, urlRoute, usesMixin, uuid, validUrl, value, weakMemo, when };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/types/arrays.d.ts
|
|
2
|
+
export type CollapseTupleUnion<Tuple extends unknown[]> = _CollapseTupleUnionRecursion<Tuple, []>;
|
|
3
|
+
export type _CollapseTupleUnionRecursion<Tuple extends unknown[], Rest extends unknown[]> = Rest['length'] extends Tuple['length'] ? Rest : _CollapseTupleUnionRecursion<Tuple, [Tuple[Rest['length']], ...Rest]>;
|
|
4
|
+
export type RequiredTuple<Item, Length extends number> = Length extends Length ? number extends Length ? Item[] : _RequiredTupleRecursion<Item, Length, []> : never;
|
|
5
|
+
export type _RequiredTupleRecursion<Item, Length extends number, Rest extends unknown[]> = Rest['length'] extends Length ? Rest : _RequiredTupleRecursion<Item, Length, [Item, ...Rest]>;
|
|
6
|
+
export type _TupleRecursion<Tuple extends unknown[], Optional extends number, Rest extends unknown[]> = Tuple['length'] extends Rest['length'] ? Rest : Optional extends Rest['length'] ? _TupleRecursion<Tuple, Optional, [Tuple[Rest['length']] | undefined, ...Rest]> : _TupleRecursion<Tuple, Optional, [Tuple[Rest['length']], ...Rest]>;
|
|
7
|
+
export type ArrayDeepItem<Array> = Array extends (infer TItem)[] ? ArrayDeepItem<TItem> : Array;
|
|
8
|
+
export type ArrayIncludes<Array extends unknown[], Item> = Item extends Array[number] ? true : false;
|
|
9
|
+
export type ArrayItem<Array> = Array extends (infer Item)[] ? Item : never;
|
|
10
|
+
export type Tuple<Item, Length extends number, Optional extends number = number> = CollapseTupleUnion<_TupleRecursion<RequiredTuple<Item, Length>, Optional, []>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=arrays.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ClosureArgs } from "./helpers.js";
|
|
2
|
+
//#region src/types/classes.d.ts
|
|
3
|
+
export interface Constructor<T = Object> {
|
|
4
|
+
new (...args: any[]): T;
|
|
5
|
+
}
|
|
6
|
+
export type ReplaceConstructorArgs<T, Args extends ClosureArgs> = T extends {
|
|
7
|
+
new (...args: ClosureArgs): infer Instance;
|
|
8
|
+
} ? Omit<T, 'new'> & {
|
|
9
|
+
new (...args: Args): Instance;
|
|
10
|
+
} : never;
|
|
11
|
+
//#endregion
|
|
12
|
+
//# sourceMappingURL=classes.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/types/helpers.d.ts
|
|
2
|
+
export declare const __brand: unique symbol;
|
|
3
|
+
export type ClassInstance<Class> = Class extends {
|
|
4
|
+
new (...args: any[]): infer T;
|
|
5
|
+
} ? T : never;
|
|
6
|
+
export type Closure<Args extends ClosureArgs = ClosureArgs, Result = unknown> = (...args: Args) => Result;
|
|
7
|
+
export type ClosureArgs = any[];
|
|
8
|
+
export type ClosureResult = any;
|
|
9
|
+
export type Branded<T, Brand> = T & {
|
|
10
|
+
[__brand]: Brand;
|
|
11
|
+
};
|
|
12
|
+
export type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
13
|
+
export type Falsy = '' | null | undefined | false | 0;
|
|
14
|
+
export type Truthy<T> = Exclude<T, Falsy>;
|
|
15
|
+
export type GetObjectMethods<T> = { [K in keyof T]: T[K] extends ((...args: ClosureArgs) => ClosureResult) ? K : never; }[keyof T];
|
|
16
|
+
export type GetOptionalKeys<T> = { [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? K : never; }[keyof T];
|
|
17
|
+
export type GetRequiredKeys<T> = { [K in keyof T]-?: T extends Record<K, T[K]> ? K : never; }[keyof T];
|
|
18
|
+
export type KeyOf<Object, Values> = { [k in keyof Object]: Object[k] extends Values ? k : never; }[keyof Object];
|
|
19
|
+
export type Nullable<T> = T | null | undefined;
|
|
20
|
+
export type NullableOptional<T> = Pretty<{ [P in GetOptionalKeys<T>]?: Nullable<T[P]>; } & { [P in GetRequiredKeys<T>]: T[P]; }>;
|
|
21
|
+
export type NullablePartial<T> = { [P in keyof T]?: Nullable<T[P]>; };
|
|
22
|
+
export type ObjectValues<T> = T[keyof T];
|
|
23
|
+
export type OnlyKnownProperties<TGeneric, TKnown> = { [K in keyof TGeneric]: K extends keyof TKnown ? TGeneric[K] : never; };
|
|
24
|
+
export type Override<T, TOverrides> = Omit<T, keyof TOverrides> & TOverrides;
|
|
25
|
+
export type Pretty<T> = T extends (infer U) ? { [K in keyof U]: U[K]; } : never;
|
|
26
|
+
export type SubPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
27
|
+
export type TypeGuard<T = unknown> = (value: unknown) => value is T;
|
|
28
|
+
export type VoidClosure<T> = T extends ((...args: infer A) => ClosureResult) ? (...args: A) => void : never;
|
|
29
|
+
export type Writable<T> = { -readonly [K in keyof T]: T[K]; };
|
|
30
|
+
export type IsAny<T> = {
|
|
31
|
+
__: 'never';
|
|
32
|
+
} extends T ? true : false;
|
|
33
|
+
export type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends any[] ? false : T extends Date ? false : T extends RegExp ? false : true : false;
|
|
34
|
+
export type Use<T> = {};
|
|
35
|
+
//#endregion
|
|
36
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","names":[],"sources":["../../src/types/helpers.ts"],"sourcesContent":["export const __brand = Symbol('__brand');\nexport type ClassInstance<Class> = Class extends { new (...args: any[]): infer T } ? T : never;\nexport type Closure<Args extends ClosureArgs = ClosureArgs, Result = unknown> = (...args: Args) => Result;\nexport type ClosureArgs = any[]; // oxlint-disable-line typescript/no-explicit-any\nexport type ClosureResult = any; // oxlint-disable-line typescript/no-explicit-any\nexport type Branded<T, Brand> = T & { [__brand]: Brand };\nexport type Equals<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;\nexport type Falsy = '' | null | undefined | false | 0;\nexport type Truthy<T> = Exclude<T, Falsy>;\nexport type GetObjectMethods<T> = {\n [K in keyof T]: T[K] extends (...args: ClosureArgs) => ClosureResult ? K : never;\n}[keyof T];\nexport type GetOptionalKeys<T> = { [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? K : never }[keyof T];\nexport type GetRequiredKeys<T> = { [K in keyof T]-?: T extends Record<K, T[K]> ? K : never }[keyof T];\nexport type KeyOf<Object, Values> = { [k in keyof Object]: Object[k] extends Values ? k : never }[keyof Object];\nexport type Nullable<T> = T | null | undefined;\nexport type NullableOptional<T> = Pretty<\n { [P in GetOptionalKeys<T>]?: Nullable<T[P]> } & { [P in GetRequiredKeys<T>]: T[P] }\n>;\nexport type NullablePartial<T> = { [P in keyof T]?: Nullable<T[P]> };\nexport type ObjectValues<T> = T[keyof T];\nexport type OnlyKnownProperties<TGeneric, TKnown> = {\n [K in keyof TGeneric]: K extends keyof TKnown ? TGeneric[K] : never;\n};\nexport type Override<T, TOverrides> = Omit<T, keyof TOverrides> & TOverrides;\nexport type Pretty<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\nexport type SubPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\nexport type TypeGuard<T = unknown> = (value: unknown) => value is T;\nexport type VoidClosure<T> = T extends (...args: infer A) => ClosureResult ? (...args: A) => void : never;\nexport type Writable<T> = { -readonly [K in keyof T]: T[K] };\nexport type IsAny<T> = { __: 'never' } extends T ? true : false;\nexport type IsPlainObject<T> = T extends object\n ? T extends Function\n ? false\n : T extends any[] // oxlint-disable-line typescript/no-explicit-any\n ? false\n : T extends Date\n ? false\n : T extends RegExp\n ? false\n : true\n : false;\n\n// Workaround for https://github.com/typescript-eslint/typescript-eslint/issues/3573\nexport type Use<T> = {}; // oxlint-disable-line typescript/no-unused-vars\n"],"mappings":";AAAA,MAAa,UAAU,OAAO,SAAS"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Equals } from "./helpers.js";
|
|
2
|
+
//#region src/types/objects.d.ts
|
|
3
|
+
export type _Decrement<N extends number> = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][N];
|
|
4
|
+
export type DeepRequired<T> = T extends object ? { [K in keyof T]-?: NonNullable<T[K]> extends Function ? NonNullable<T[K]> : NonNullable<T[K]> extends object ? DeepRequired<NonNullable<T[K]>> : NonNullable<T[K]>; } : T;
|
|
5
|
+
export type DeepKeyOf<T, TDepth extends number = 5, TRequired extends DeepRequired<T> = DeepRequired<T>> = NonNullable<TRequired extends object ? { [K in keyof TRequired]: TRequired[K] extends Function ? never : TRequired[K] extends Array<infer TItem> ? `${Exclude<K, symbol>}` | `${Exclude<K, symbol>}.${number}` | (Equals<0, TDepth> extends true ? never : `${Exclude<K, symbol>}.${number}.${DeepKeyOf<TItem, _Decrement<TDepth>, DeepRequired<TItem>>}`) : TRequired[K] extends object ? { [KK in keyof TRequired[K]]: TRequired[K][KK] extends Function ? never : TRequired[K][KK] extends Array<unknown> ? `${Exclude<K, symbol>}.${Exclude<KK, symbol>}` : TRequired[K][KK] extends object ? { [KKK in keyof TRequired[K][KK]]: TRequired[K][KK][KKK] extends Function ? never : `${Exclude<K, symbol>}.${Exclude<KK, symbol>}.${Exclude<KKK, symbol>}`; }[keyof TRequired[K][KK]] | `${Exclude<K, symbol>}.${Exclude<KK, symbol>}` : `${Exclude<K, symbol>}.${Exclude<KK, symbol>}`; }[keyof TRequired[K]] | `${Exclude<K, symbol>}` : `${Exclude<K, symbol>}`; }[keyof TRequired] : never>;
|
|
6
|
+
export type DeepValue<T extends object, K> = K extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? T[Key] extends object ? DeepValue<T[Key], Rest> : T[Key] : never : K extends keyof T ? T[K] : never;
|
|
7
|
+
//#endregion
|
|
8
|
+
//# sourceMappingURL=objects.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,53 +1,39 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"typescript": "^5.8.2",
|
|
41
|
-
"vite": "^6.2.2",
|
|
42
|
-
"vite-plugin-dts": "^4.5.3",
|
|
43
|
-
"vitest": "^3.0.9"
|
|
44
|
-
},
|
|
45
|
-
"eslintConfig": {
|
|
46
|
-
"extends": [
|
|
47
|
-
"@noeldemartin/eslint-config-typescript"
|
|
48
|
-
]
|
|
49
|
-
},
|
|
50
|
-
"prettier": {
|
|
51
|
-
"printWidth": 120
|
|
52
|
-
}
|
|
53
|
-
}
|
|
2
|
+
"name": "@noeldemartin/utils",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Noel De Martin",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/NoelDeMartin/utils.git"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"exports": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"idb": "^8.0.2"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
25
|
+
"@noeldemartin/scripts": "next",
|
|
26
|
+
"@noeldemartin/testing": "next",
|
|
27
|
+
"@noeldemartin/vite-plus-config": "next",
|
|
28
|
+
"@tsconfig/node26": "^26.0.1",
|
|
29
|
+
"@types/node": "^26.6.3",
|
|
30
|
+
"publint": "^0.3.24",
|
|
31
|
+
"typescript": "~6.0.2",
|
|
32
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@^1.0.0",
|
|
33
|
+
"vite-plus": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "vp pack",
|
|
37
|
+
"test": "vp test"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
1
|
import { tt } from '@noeldemartin/testing';
|
|
3
2
|
import type { Expect } from '@noeldemartin/testing';
|
|
4
|
-
|
|
5
3
|
import { toString } from '@noeldemartin/utils/helpers';
|
|
6
4
|
import type { Equals } from '@noeldemartin/utils/types';
|
|
5
|
+
import { describe, expect, it } from 'vite-plus/test';
|
|
7
6
|
|
|
8
7
|
import FluentArrayDefinition from './FluentArray';
|
|
9
8
|
import type { FluentArray, FluentArrayInstance } from './FluentArray';
|
|
10
9
|
|
|
11
10
|
describe('FluentArray', () => {
|
|
12
|
-
|
|
13
11
|
it('delegates to helper methods', () => {
|
|
14
12
|
const fluentArray = FluentArrayDefinition.create(['foo', 'bar']);
|
|
15
13
|
|
|
@@ -54,10 +52,9 @@ describe('FluentArray', () => {
|
|
|
54
52
|
|
|
55
53
|
it('can be subclassed', () => {
|
|
56
54
|
class SuperFluentArray<T> extends FluentArrayDefinition<T> {
|
|
57
|
-
|
|
58
55
|
// TODO avoid doing this
|
|
59
56
|
declare public static create: <TItem>(
|
|
60
|
-
value?: TItem[]
|
|
57
|
+
value?: TItem[],
|
|
61
58
|
) => FluentArrayInstance<SuperFluentArray<TItem>, TItem>;
|
|
62
59
|
|
|
63
60
|
public slice(): this {
|
|
@@ -67,7 +64,6 @@ describe('FluentArray', () => {
|
|
|
67
64
|
public sortAlphabetically(): this {
|
|
68
65
|
return this.create(this.value.slice(0).sort((a, b) => (toString(a) > toString(b) ? 1 : -1)));
|
|
69
66
|
}
|
|
70
|
-
|
|
71
67
|
}
|
|
72
68
|
const superFluentArray = SuperFluentArray.create(['foo', 'bar']);
|
|
73
69
|
|
|
@@ -88,7 +84,6 @@ describe('FluentArray', () => {
|
|
|
88
84
|
|
|
89
85
|
it.todo('can use index syntax');
|
|
90
86
|
it.todo('overrides primitive methods (use arrayFilter helper instead of primitive)');
|
|
91
|
-
|
|
92
87
|
});
|
|
93
88
|
|
|
94
89
|
type User = { name: string; age: number };
|
|
@@ -101,7 +96,6 @@ const names = fluentUsersArray.project('name');
|
|
|
101
96
|
const ages = fluentUsersArray.project('age');
|
|
102
97
|
|
|
103
98
|
describe('FluentArray types', () => {
|
|
104
|
-
|
|
105
99
|
it(
|
|
106
100
|
'has correct types',
|
|
107
101
|
tt<
|
|
@@ -116,5 +110,4 @@ describe('FluentArray types', () => {
|
|
|
116
110
|
| true
|
|
117
111
|
>(),
|
|
118
112
|
);
|
|
119
|
-
|
|
120
113
|
});
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
arrayRemove,
|
|
13
13
|
arrayRemoveIndex,
|
|
14
14
|
arrayReplace,
|
|
15
|
+
arrayShuffled,
|
|
15
16
|
arraySorted,
|
|
16
17
|
arrayUnique,
|
|
17
18
|
arrayWhere,
|
|
@@ -37,6 +38,7 @@ const fluentArrayHelpers: FluentArrayHelpers<unknown> = {
|
|
|
37
38
|
remove: arrayRemove,
|
|
38
39
|
removeIndex: arrayRemoveIndex,
|
|
39
40
|
replace: arrayReplace,
|
|
41
|
+
shuffled: arrayShuffled,
|
|
40
42
|
sorted: arraySorted,
|
|
41
43
|
unique: arrayUnique,
|
|
42
44
|
where: arrayWhere,
|
|
@@ -59,6 +61,7 @@ export type FluentArrayHelpers<T> = {
|
|
|
59
61
|
remove(items: T[], item: T): boolean;
|
|
60
62
|
removeIndex(items: T[], index: number | string): boolean;
|
|
61
63
|
replace(items: T[], original: T, replacement: T): boolean;
|
|
64
|
+
shuffled(items: T[]): T[];
|
|
62
65
|
sorted(items: T[]): T[];
|
|
63
66
|
unique(items: T[], extractKey?: (item: T) => string): T[];
|
|
64
67
|
where(items: T[], filter: string, value?: unknown): T[];
|
|
@@ -76,7 +79,6 @@ export type FluentArrayInstance<FluentClass, Item> = FluentInstance<
|
|
|
76
79
|
export type FluentArray<T> = FluentArrayInstance<FluentArrayDefinition<T>, T>;
|
|
77
80
|
|
|
78
81
|
class FluentArrayDefinition<Item> extends FluentObjectDefinition<Item[]> {
|
|
79
|
-
|
|
80
82
|
public static create<T>(value: T[] = []): FluentArrayInstance<FluentArrayDefinition<T>, T> {
|
|
81
83
|
const { prototype } = this as unknown as {
|
|
82
84
|
prototype: { create(value: T[]): FluentArrayInstance<FluentArrayDefinition<T>, T> };
|
|
@@ -90,18 +92,18 @@ class FluentArrayDefinition<Item> extends FluentObjectDefinition<Item[]> {
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
declare public flatMap: <T>(
|
|
93
|
-
callback: (item: Item, index: number) => T[]
|
|
95
|
+
callback: (item: Item, index: number) => T[],
|
|
94
96
|
) => FluentArrayInstance<FluentArrayDefinition<T>, T>;
|
|
95
97
|
|
|
96
98
|
declare public map: <T>(
|
|
97
|
-
callback: (item: Item, index: number) => T
|
|
99
|
+
callback: (item: Item, index: number) => T,
|
|
98
100
|
) => FluentArrayInstance<FluentArrayDefinition<T>, T>;
|
|
99
101
|
|
|
100
102
|
declare public project: <K extends keyof Item>(key: K) => Item[K][];
|
|
101
103
|
|
|
102
104
|
declare public where: <K extends keyof Item>(
|
|
103
105
|
key: K,
|
|
104
|
-
value?: Item[K]
|
|
106
|
+
value?: Item[K],
|
|
105
107
|
) => FluentArrayInstance<FluentArrayDefinition<Item>, Item>;
|
|
106
108
|
|
|
107
109
|
public get(index: number): Item | undefined {
|
|
@@ -115,7 +117,6 @@ class FluentArrayDefinition<Item> extends FluentObjectDefinition<Item[]> {
|
|
|
115
117
|
protected isPrimitive(value: unknown): value is Item[] {
|
|
116
118
|
return Array.isArray(value);
|
|
117
119
|
}
|
|
118
|
-
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
interface FluentArrayDefinition<Item> {
|
|
@@ -45,7 +45,7 @@ export function addHelperMethodsToPrototype(
|
|
|
45
45
|
const prototype = fluentClass.prototype as Record<string, Closure>;
|
|
46
46
|
|
|
47
47
|
for (const [name, method] of Object.entries(helpers)) {
|
|
48
|
-
prototype[name] = function(...args: any[]) {
|
|
48
|
+
prototype[name] = function (...args: any[]) {
|
|
49
49
|
const value = method(this.value, ...args);
|
|
50
50
|
|
|
51
51
|
return this.chain?.(value);
|
|
@@ -73,7 +73,7 @@ export function addPrimitiveMethodsToPrototype(
|
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
prototype[name] = function(...args: any[]) {
|
|
76
|
+
prototype[name] = function (...args: any[]) {
|
|
77
77
|
const value = descriptor.value.call(this.value, ...args);
|
|
78
78
|
|
|
79
79
|
return this.chain?.(value);
|
|
@@ -82,7 +82,6 @@ export function addPrimitiveMethodsToPrototype(
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export default abstract class FluentObjectDefinition<Primitive> {
|
|
85
|
-
|
|
86
85
|
public static isPrimitive(value: unknown): boolean {
|
|
87
86
|
return this.prototype.isPrimitive(value);
|
|
88
87
|
}
|
|
@@ -100,5 +99,4 @@ export default abstract class FluentObjectDefinition<Primitive> {
|
|
|
100
99
|
protected chain(value: unknown): unknown {
|
|
101
100
|
return this.isPrimitive(value) ? this.create(value) : value;
|
|
102
101
|
}
|
|
103
|
-
|
|
104
102
|
}
|