@luxass/utils 2.5.1 → 2.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/guards.d.ts +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +2 -1
- package/dist/number.d.ts +1 -1
- package/dist/object.d.ts +1 -1
- package/dist/path-CFkUYi0a.d.ts +100 -0
- package/dist/path-a1A1qAWN.js +131 -0
- package/dist/path.d.ts +2 -0
- package/dist/path.js +3 -0
- package/dist/{string-DDSo2EBf.d.ts → string-BgrFQWVx.d.ts} +49 -75
- package/dist/{string-DCBui1sH.js → string-BlwTLoKD.js} +43 -75
- package/dist/string.d.ts +2 -2
- package/dist/string.js +2 -2
- package/dist/types-DwW0ucVr.d.ts +143 -0
- package/dist/types.d.ts +2 -2
- package/package.json +5 -4
- package/dist/types-DCrM3M9i.d.ts +0 -86
- /package/dist/{guards-x9QZDUSt.d.ts → guards-SWdmRZ5e.d.ts} +0 -0
- /package/dist/{number-DzUC7V5F.d.ts → number-Culbli-Y.d.ts} +0 -0
- /package/dist/{object-BT3S70pM.d.ts → object-BtzfqVfB.d.ts} +0 -0
package/dist/guards.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-SWdmRZ5e.js";
|
|
2
2
|
export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-
|
|
2
|
-
import { clamp } from "./number-
|
|
3
|
-
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-
|
|
4
|
-
import { appendTrailingSlash,
|
|
5
|
-
import {
|
|
1
|
+
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-SWdmRZ5e.js";
|
|
2
|
+
import { clamp } from "./number-Culbli-Y.js";
|
|
3
|
+
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BtzfqVfB.js";
|
|
4
|
+
import { appendTrailingSlash, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash } from "./path-CFkUYi0a.js";
|
|
5
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BgrFQWVx.js";
|
|
6
|
+
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, SafeOmit } from "./types-DwW0ucVr.js";
|
|
6
7
|
import pRetry from "p-retry";
|
|
7
8
|
|
|
8
9
|
//#region src/common.d.ts
|
|
@@ -21,4 +22,4 @@ declare class InvariantError extends Error {
|
|
|
21
22
|
*/
|
|
22
23
|
declare function invariant(predicate: unknown, message: string, ...positionals: unknown[]): asserts predicate;
|
|
23
24
|
//#endregion
|
|
24
|
-
export { ElementOf, InferArguments, InvariantError, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, appendTrailingSlash, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, prependLeadingSlash, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
|
|
25
|
+
export { type ElementOf, type InferArguments, InvariantError, type MaybeArray, type MaybePromise, type Nullable, type Nullish, type Prettify, type RemoveIndexSignature, type SafeOmit, appendTrailingSlash, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, prependLeadingSlash, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
|
|
2
|
-
import {
|
|
2
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BlwTLoKD.js";
|
|
3
3
|
import { clamp } from "./number-BS9T5WGO.js";
|
|
4
4
|
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-CyGLe77G.js";
|
|
5
|
+
import { appendTrailingSlash, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash } from "./path-a1A1qAWN.js";
|
|
5
6
|
import pRetry from "p-retry";
|
|
6
7
|
|
|
7
8
|
//#region src/common.ts
|
package/dist/number.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { clamp } from "./number-
|
|
1
|
+
import { clamp } from "./number-Culbli-Y.js";
|
|
2
2
|
export { clamp };
|
package/dist/object.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-
|
|
1
|
+
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BtzfqVfB.js";
|
|
2
2
|
export { getChangedKeys, getOwnProperty, hasOwnProperty, omit };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//#region src/path.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Removes trailing slashes from a string
|
|
4
|
+
* @param {string} path - The string to remove trailing slashes from
|
|
5
|
+
* @returns {string} The string with trailing slashes removed
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { trimTrailingSlash } from "@luxass/utils/path";
|
|
10
|
+
*
|
|
11
|
+
* trimTrailingSlash("path/to/file/") // "path/to/file"
|
|
12
|
+
* trimTrailingSlash("path/to/file///") // "path/to/file"
|
|
13
|
+
* trimTrailingSlash("path/to/file") // "path/to/file"
|
|
14
|
+
* trimTrailingSlash("") // ""
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare function trimTrailingSlash(path: string | undefined): string;
|
|
18
|
+
/**
|
|
19
|
+
* Removes leading slashes from a string
|
|
20
|
+
* @param {string} path - The string to remove leading slashes from
|
|
21
|
+
* @returns {string} The string with leading slashes removed
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { trimLeadingSlash } from "@luxass/utils/path";
|
|
26
|
+
*
|
|
27
|
+
* trimLeadingSlash("/path/to/file") // "path/to/file"
|
|
28
|
+
* trimLeadingSlash("///path/to/file") // "path/to/file"
|
|
29
|
+
* trimLeadingSlash("path/to/file") // "path/to/file"
|
|
30
|
+
* trimLeadingSlash("") // ""
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function trimLeadingSlash(path: string | undefined): string;
|
|
34
|
+
/**
|
|
35
|
+
* Ensures a string ends with a trailing slash
|
|
36
|
+
* @param {string} path - The string to append a trailing slash to
|
|
37
|
+
* @returns {string} The string with a trailing slash appended if not already present
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { appendTrailingSlash } from "@luxass/utils/path";
|
|
42
|
+
*
|
|
43
|
+
* appendTrailingSlash("path/to/file") // "path/to/file/"
|
|
44
|
+
* appendTrailingSlash("path/to/file/") // "path/to/file/"
|
|
45
|
+
* appendTrailingSlash("") // ""
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function appendTrailingSlash(path: string | undefined): string;
|
|
49
|
+
/**
|
|
50
|
+
* Ensures a string starts with a leading slash
|
|
51
|
+
* @param {string} path - The string to prepend a leading slash to
|
|
52
|
+
* @returns {string} The string with a leading slash prepended if not already present
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { prependLeadingSlash } from "@luxass/utils/path";
|
|
57
|
+
*
|
|
58
|
+
* prependLeadingSlash("path/to/file") // "/path/to/file"
|
|
59
|
+
* prependLeadingSlash("/path/to/file") // "/path/to/file"
|
|
60
|
+
* prependLeadingSlash("") // ""
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function prependLeadingSlash(path: string | undefined): string;
|
|
64
|
+
/**
|
|
65
|
+
* Joins URL paths together, handling trailing and leading slashes appropriately
|
|
66
|
+
* @param {string} base - The base URL path
|
|
67
|
+
* @param {...string} segments - Additional URL segments to join
|
|
68
|
+
* @returns {string} The joined URL path
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { joinURL } from "@luxass/utils/path";
|
|
73
|
+
*
|
|
74
|
+
* // Basic path joining
|
|
75
|
+
* joinURL("api", "users") // "api/users"
|
|
76
|
+
* joinURL("api/", "users") // "api/users"
|
|
77
|
+
* joinURL("api", "/users") // "api/users"
|
|
78
|
+
* joinURL("api/", "/users") // "api/users"
|
|
79
|
+
*
|
|
80
|
+
* // URL joining with protocol
|
|
81
|
+
* joinURL("https://api.example.com", "v1/users") // "https://api.example.com/v1/users"
|
|
82
|
+
* joinURL("https://api.example.com/", "/v1/users") // "https://api.example.com/v1/users"
|
|
83
|
+
*
|
|
84
|
+
* // Multiple slash normalization
|
|
85
|
+
* joinURL("api//v1/", "//users///") // "api/v1/users/"
|
|
86
|
+
* joinURL("base///", "///path") // "base/path"
|
|
87
|
+
*
|
|
88
|
+
* // Root path handling
|
|
89
|
+
* joinURL("/", "users") // "/users"
|
|
90
|
+
* joinURL("api", "/") // "api/"
|
|
91
|
+
*
|
|
92
|
+
* // Empty and undefined handling
|
|
93
|
+
* joinURL("", "users") // "users"
|
|
94
|
+
* joinURL("api", "") // "api"
|
|
95
|
+
* joinURL("", "") // "/"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare function joinURL(base: string, ...segments: string[]): string;
|
|
99
|
+
//#endregion
|
|
100
|
+
export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//#region src/path.ts
|
|
2
|
+
/**
|
|
3
|
+
* Removes trailing slashes from a string
|
|
4
|
+
* @param {string} path - The string to remove trailing slashes from
|
|
5
|
+
* @returns {string} The string with trailing slashes removed
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { trimTrailingSlash } from "@luxass/utils/path";
|
|
10
|
+
*
|
|
11
|
+
* trimTrailingSlash("path/to/file/") // "path/to/file"
|
|
12
|
+
* trimTrailingSlash("path/to/file///") // "path/to/file"
|
|
13
|
+
* trimTrailingSlash("path/to/file") // "path/to/file"
|
|
14
|
+
* trimTrailingSlash("") // ""
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
function trimTrailingSlash(path) {
|
|
18
|
+
if (!path || path === "/") return "/";
|
|
19
|
+
return path.replace(/\/+$/, "");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Removes leading slashes from a string
|
|
23
|
+
* @param {string} path - The string to remove leading slashes from
|
|
24
|
+
* @returns {string} The string with leading slashes removed
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { trimLeadingSlash } from "@luxass/utils/path";
|
|
29
|
+
*
|
|
30
|
+
* trimLeadingSlash("/path/to/file") // "path/to/file"
|
|
31
|
+
* trimLeadingSlash("///path/to/file") // "path/to/file"
|
|
32
|
+
* trimLeadingSlash("path/to/file") // "path/to/file"
|
|
33
|
+
* trimLeadingSlash("") // ""
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function trimLeadingSlash(path) {
|
|
37
|
+
if (!path || path === "/") return "/";
|
|
38
|
+
return path.replace(/^\/+/, "");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Ensures a string ends with a trailing slash
|
|
42
|
+
* @param {string} path - The string to append a trailing slash to
|
|
43
|
+
* @returns {string} The string with a trailing slash appended if not already present
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { appendTrailingSlash } from "@luxass/utils/path";
|
|
48
|
+
*
|
|
49
|
+
* appendTrailingSlash("path/to/file") // "path/to/file/"
|
|
50
|
+
* appendTrailingSlash("path/to/file/") // "path/to/file/"
|
|
51
|
+
* appendTrailingSlash("") // ""
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function appendTrailingSlash(path) {
|
|
55
|
+
if (!path || path === "/") return "/";
|
|
56
|
+
return path.endsWith("/") ? path : `${path}/`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Ensures a string starts with a leading slash
|
|
60
|
+
* @param {string} path - The string to prepend a leading slash to
|
|
61
|
+
* @returns {string} The string with a leading slash prepended if not already present
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { prependLeadingSlash } from "@luxass/utils/path";
|
|
66
|
+
*
|
|
67
|
+
* prependLeadingSlash("path/to/file") // "/path/to/file"
|
|
68
|
+
* prependLeadingSlash("/path/to/file") // "/path/to/file"
|
|
69
|
+
* prependLeadingSlash("") // ""
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function prependLeadingSlash(path) {
|
|
73
|
+
if (!path || path === "/") return "/";
|
|
74
|
+
return path[0] === "/" ? path : `/${path}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Joins URL paths together, handling trailing and leading slashes appropriately
|
|
78
|
+
* @param {string} base - The base URL path
|
|
79
|
+
* @param {...string} segments - Additional URL segments to join
|
|
80
|
+
* @returns {string} The joined URL path
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { joinURL } from "@luxass/utils/path";
|
|
85
|
+
*
|
|
86
|
+
* // Basic path joining
|
|
87
|
+
* joinURL("api", "users") // "api/users"
|
|
88
|
+
* joinURL("api/", "users") // "api/users"
|
|
89
|
+
* joinURL("api", "/users") // "api/users"
|
|
90
|
+
* joinURL("api/", "/users") // "api/users"
|
|
91
|
+
*
|
|
92
|
+
* // URL joining with protocol
|
|
93
|
+
* joinURL("https://api.example.com", "v1/users") // "https://api.example.com/v1/users"
|
|
94
|
+
* joinURL("https://api.example.com/", "/v1/users") // "https://api.example.com/v1/users"
|
|
95
|
+
*
|
|
96
|
+
* // Multiple slash normalization
|
|
97
|
+
* joinURL("api//v1/", "//users///") // "api/v1/users/"
|
|
98
|
+
* joinURL("base///", "///path") // "base/path"
|
|
99
|
+
*
|
|
100
|
+
* // Root path handling
|
|
101
|
+
* joinURL("/", "users") // "/users"
|
|
102
|
+
* joinURL("api", "/") // "api/"
|
|
103
|
+
*
|
|
104
|
+
* // Empty and undefined handling
|
|
105
|
+
* joinURL("", "users") // "users"
|
|
106
|
+
* joinURL("api", "") // "api"
|
|
107
|
+
* joinURL("", "") // "/"
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function joinURL(base, ...segments) {
|
|
111
|
+
if (!base && !segments) return "/";
|
|
112
|
+
if (!segments || segments.length === 0) return base || "/";
|
|
113
|
+
const normalize = (s) => {
|
|
114
|
+
return s.replace(/([^:])\/+/g, "$1/").replace(/^\/+/, "/");
|
|
115
|
+
};
|
|
116
|
+
let path = base;
|
|
117
|
+
for (const seg of segments) {
|
|
118
|
+
if (!seg) continue;
|
|
119
|
+
if (path.length > 0) {
|
|
120
|
+
const pathTrailing = path[path.length - 1] === "/";
|
|
121
|
+
const segLeading = seg[0] === "/";
|
|
122
|
+
const both = pathTrailing && segLeading;
|
|
123
|
+
if (both) path += seg.slice(1);
|
|
124
|
+
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
125
|
+
} else path += seg;
|
|
126
|
+
}
|
|
127
|
+
return normalize(path) || "/";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
|
package/dist/path.d.ts
ADDED
package/dist/path.js
ADDED
|
@@ -68,35 +68,71 @@ declare function toPascalCase(str: string): string;
|
|
|
68
68
|
*/
|
|
69
69
|
declare function toSnakeCase(str: string): string;
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @param {
|
|
71
|
+
* @overload
|
|
72
|
+
* @param {string} literals - The string to dedent
|
|
73
73
|
* @returns {string} The dedented string
|
|
74
|
+
*
|
|
74
75
|
* @example ```ts
|
|
75
|
-
* dedent
|
|
76
|
-
* This is a test.
|
|
76
|
+
* import { dedent } from "@luxass/utils/string";
|
|
77
|
+
* const text = dedent(` * This is a test.
|
|
77
78
|
* This is another line.
|
|
78
|
-
* `
|
|
79
|
+
* `);
|
|
79
80
|
* // "This is a test.\nThis is another line."
|
|
80
81
|
* ```
|
|
81
82
|
*/
|
|
82
83
|
declare function dedent(literals: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* @overload
|
|
86
|
+
* @param {TemplateStringsArray} strings - The string to dedent
|
|
87
|
+
* @param {unknown[]} values - The values to insert into the string
|
|
88
|
+
* @returns {string} The dedented string
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { dedent } from "@luxass/utils/string";
|
|
93
|
+
* const text = dedent`
|
|
94
|
+
* This is a test.
|
|
95
|
+
* This is another line.
|
|
96
|
+
* `;
|
|
97
|
+
* // "This is a test.\nThis is another line."
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
83
100
|
declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
84
101
|
declare namespace dedent {
|
|
85
102
|
var raw: typeof dedentRaw;
|
|
86
103
|
}
|
|
87
104
|
/**
|
|
88
|
-
*
|
|
89
|
-
* @param {
|
|
105
|
+
* @overload
|
|
106
|
+
* @param {string} literals - The string to dedent
|
|
90
107
|
* @returns {string} The dedented string
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* `
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { dedentRaw } from "@luxass/utils/string";
|
|
112
|
+
* const text = dedentRaw(`
|
|
113
|
+
* This is a test.
|
|
114
|
+
* This is another line.
|
|
115
|
+
* `);
|
|
96
116
|
* // "This is a test.\nThis is another line."
|
|
97
117
|
* ```
|
|
98
118
|
*/
|
|
99
119
|
declare function dedentRaw(literals: string): string;
|
|
120
|
+
/**
|
|
121
|
+
* @overload
|
|
122
|
+
* @param {TemplateStringsArray} strings - The string to dedent
|
|
123
|
+
* @param {unknown[]} values - The values to insert into the string
|
|
124
|
+
* @return {string} The dedented string
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { dedentRaw } from "@luxass/utils/string";
|
|
129
|
+
* const text = dedentRaw`
|
|
130
|
+
* This is a test.
|
|
131
|
+
* This is another line.
|
|
132
|
+
* `
|
|
133
|
+
* // "This is a test.\nThis is another line."
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
100
136
|
declare function dedentRaw(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
101
137
|
/**
|
|
102
138
|
* Ensures a string is a valid JavaScript identifier by prefixing with an underscore if necessary
|
|
@@ -128,67 +164,5 @@ declare function sanitizeIdentifier(str: string): string;
|
|
|
128
164
|
* ```
|
|
129
165
|
*/
|
|
130
166
|
declare function formatStr(message: string, ...positionals: unknown[]): string;
|
|
131
|
-
/**
|
|
132
|
-
* Removes trailing slashes from a string
|
|
133
|
-
* @param {string} str - The string to remove trailing slashes from
|
|
134
|
-
* @returns {string} The string with trailing slashes removed
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```ts
|
|
138
|
-
* import { trimTrailingSlash } from "@luxass/utils/string";
|
|
139
|
-
*
|
|
140
|
-
* trimTrailingSlash("path/to/file/") // "path/to/file"
|
|
141
|
-
* trimTrailingSlash("path/to/file///") // "path/to/file"
|
|
142
|
-
* trimTrailingSlash("path/to/file") // "path/to/file"
|
|
143
|
-
* trimTrailingSlash("") // ""
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
declare function trimTrailingSlash(str: string): string;
|
|
147
|
-
/**
|
|
148
|
-
* Removes leading slashes from a string
|
|
149
|
-
* @param {string} str - The string to remove leading slashes from
|
|
150
|
-
* @returns {string} The string with leading slashes removed
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* import { trimLeadingSlash } from "@luxass/utils/string";
|
|
155
|
-
*
|
|
156
|
-
* trimLeadingSlash("/path/to/file") // "path/to/file"
|
|
157
|
-
* trimLeadingSlash("///path/to/file") // "path/to/file"
|
|
158
|
-
* trimLeadingSlash("path/to/file") // "path/to/file"
|
|
159
|
-
* trimLeadingSlash("") // ""
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
declare function trimLeadingSlash(str: string): string;
|
|
163
|
-
/**
|
|
164
|
-
* Ensures a string ends with a trailing slash
|
|
165
|
-
* @param {string} str - The string to append a trailing slash to
|
|
166
|
-
* @returns {string} The string with a trailing slash appended if not already present
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```ts
|
|
170
|
-
* import { appendTrailingSlash } from "@luxass/utils/string";
|
|
171
|
-
*
|
|
172
|
-
* appendTrailingSlash("path/to/file") // "path/to/file/"
|
|
173
|
-
* appendTrailingSlash("path/to/file/") // "path/to/file/"
|
|
174
|
-
* appendTrailingSlash("") // ""
|
|
175
|
-
* ```
|
|
176
|
-
*/
|
|
177
|
-
declare function appendTrailingSlash(str: string): string;
|
|
178
|
-
/**
|
|
179
|
-
* Ensures a string starts with a leading slash
|
|
180
|
-
* @param {string} str - The string to prepend a leading slash to
|
|
181
|
-
* @returns {string} The string with a leading slash prepended if not already present
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```ts
|
|
185
|
-
* import { prependLeadingSlash } from "@luxass/utils/string";
|
|
186
|
-
*
|
|
187
|
-
* prependLeadingSlash("path/to/file") // "/path/to/file"
|
|
188
|
-
* prependLeadingSlash("/path/to/file") // "/path/to/file"
|
|
189
|
-
* prependLeadingSlash("") // ""
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
declare function prependLeadingSlash(str: string): string;
|
|
193
167
|
//#endregion
|
|
194
|
-
export {
|
|
168
|
+
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
@@ -93,10 +93,52 @@ function toSnakeCase(str) {
|
|
|
93
93
|
if (!str) return "";
|
|
94
94
|
return str.trim().replace(/-/g, "_").replace(/\s+/g, " ").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/\s+/g, "_").replace(/_+/g, "_").toLowerCase();
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Removes leading and trailing whitespace from each line of a string
|
|
98
|
+
* @param {TemplateStringsArray | string} strings - The string to dedent
|
|
99
|
+
* @param {unknown[]} values - The values to insert into the string
|
|
100
|
+
* @returns {string} The dedented string
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { dedent } from "@luxass/utils/string";
|
|
105
|
+
* const text = dedent` * This is a test.
|
|
106
|
+
* This is another line.
|
|
107
|
+
* `;
|
|
108
|
+
* // "This is a test.\nThis is another line."
|
|
109
|
+
*
|
|
110
|
+
* const text = dedent(` * This is a test.
|
|
111
|
+
* This is another line.
|
|
112
|
+
* `);
|
|
113
|
+
* // "This is a test.\nThis is another line."
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
96
116
|
function dedent(strings, ...values) {
|
|
97
117
|
return internal_dedent(strings, values, false);
|
|
98
118
|
}
|
|
99
119
|
dedent.raw = dedentRaw;
|
|
120
|
+
/**
|
|
121
|
+
* Removes leading and trailing whitespace from each line of a string
|
|
122
|
+
* @param {TemplateStringsArray | string} strings - The string to dedent
|
|
123
|
+
* @param {unknown[]} values - The values to insert into the string
|
|
124
|
+
* @returns {string} The dedented string
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { dedentRaw } from "@luxass/utils/string";
|
|
129
|
+
* const text = dedentRaw(`
|
|
130
|
+
* This is a test.
|
|
131
|
+
* This is another line.
|
|
132
|
+
* `);
|
|
133
|
+
* // "This is a test.\nThis is another line."
|
|
134
|
+
*
|
|
135
|
+
* const text = dedentRaw`
|
|
136
|
+
* This is a test.
|
|
137
|
+
* This is another line.
|
|
138
|
+
* `
|
|
139
|
+
* // "This is a test.\nThis is another line."
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
100
142
|
function dedentRaw(strings, ...values) {
|
|
101
143
|
return internal_dedent(strings, values, true);
|
|
102
144
|
}
|
|
@@ -181,80 +223,6 @@ function formatStr(message, ...positionals) {
|
|
|
181
223
|
formattedMessage = formattedMessage.replace(/%{2}/g, "%");
|
|
182
224
|
return formattedMessage;
|
|
183
225
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Removes trailing slashes from a string
|
|
186
|
-
* @param {string} str - The string to remove trailing slashes from
|
|
187
|
-
* @returns {string} The string with trailing slashes removed
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* import { trimTrailingSlash } from "@luxass/utils/string";
|
|
192
|
-
*
|
|
193
|
-
* trimTrailingSlash("path/to/file/") // "path/to/file"
|
|
194
|
-
* trimTrailingSlash("path/to/file///") // "path/to/file"
|
|
195
|
-
* trimTrailingSlash("path/to/file") // "path/to/file"
|
|
196
|
-
* trimTrailingSlash("") // ""
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
function trimTrailingSlash(str) {
|
|
200
|
-
if (!str) return str;
|
|
201
|
-
return str.replace(/\/+$/, "");
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Removes leading slashes from a string
|
|
205
|
-
* @param {string} str - The string to remove leading slashes from
|
|
206
|
-
* @returns {string} The string with leading slashes removed
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* import { trimLeadingSlash } from "@luxass/utils/string";
|
|
211
|
-
*
|
|
212
|
-
* trimLeadingSlash("/path/to/file") // "path/to/file"
|
|
213
|
-
* trimLeadingSlash("///path/to/file") // "path/to/file"
|
|
214
|
-
* trimLeadingSlash("path/to/file") // "path/to/file"
|
|
215
|
-
* trimLeadingSlash("") // ""
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
function trimLeadingSlash(str) {
|
|
219
|
-
if (!str) return str;
|
|
220
|
-
return str.replace(/^\/+/, "");
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Ensures a string ends with a trailing slash
|
|
224
|
-
* @param {string} str - The string to append a trailing slash to
|
|
225
|
-
* @returns {string} The string with a trailing slash appended if not already present
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* ```ts
|
|
229
|
-
* import { appendTrailingSlash } from "@luxass/utils/string";
|
|
230
|
-
*
|
|
231
|
-
* appendTrailingSlash("path/to/file") // "path/to/file/"
|
|
232
|
-
* appendTrailingSlash("path/to/file/") // "path/to/file/"
|
|
233
|
-
* appendTrailingSlash("") // ""
|
|
234
|
-
* ```
|
|
235
|
-
*/
|
|
236
|
-
function appendTrailingSlash(str) {
|
|
237
|
-
if (!str) return str;
|
|
238
|
-
return str.endsWith("/") ? str : `${str}/`;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Ensures a string starts with a leading slash
|
|
242
|
-
* @param {string} str - The string to prepend a leading slash to
|
|
243
|
-
* @returns {string} The string with a leading slash prepended if not already present
|
|
244
|
-
*
|
|
245
|
-
* @example
|
|
246
|
-
* ```ts
|
|
247
|
-
* import { prependLeadingSlash } from "@luxass/utils/string";
|
|
248
|
-
*
|
|
249
|
-
* prependLeadingSlash("path/to/file") // "/path/to/file"
|
|
250
|
-
* prependLeadingSlash("/path/to/file") // "/path/to/file"
|
|
251
|
-
* prependLeadingSlash("") // ""
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
function prependLeadingSlash(str) {
|
|
255
|
-
if (!str) return str;
|
|
256
|
-
return str.startsWith("/") ? str : `/${str}`;
|
|
257
|
-
}
|
|
258
226
|
|
|
259
227
|
//#endregion
|
|
260
|
-
export {
|
|
228
|
+
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/string.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BgrFQWVx.js";
|
|
2
|
+
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
package/dist/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-BlwTLoKD.js";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Whatever type, or null
|
|
4
|
+
* @template T
|
|
5
|
+
* @returns {T | null} T or null
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Nullable } from "@luxass/utils/types";
|
|
10
|
+
*
|
|
11
|
+
* type A = Nullable<string>
|
|
12
|
+
* // string | null
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
type Nullable<T> = T | null;
|
|
16
|
+
/**
|
|
17
|
+
* Whatever type, null or undefined
|
|
18
|
+
* @template T
|
|
19
|
+
* @returns {T | null | undefined} T, undefined or null
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { Nullish } from "@luxass/utils/types";
|
|
24
|
+
*
|
|
25
|
+
* type A = Nullish<string>
|
|
26
|
+
* // string | null | undefined
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
type Nullish<T> = T | null | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* A type that can be an array or a single value.
|
|
32
|
+
* @template T
|
|
33
|
+
* @returns {T | T[]} T or T[]
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { MaybeArray } from "@luxass/utils/types";
|
|
38
|
+
*
|
|
39
|
+
* type A = MaybeArray<string>
|
|
40
|
+
* // string | string[]
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
type MaybeArray<T> = T | T[];
|
|
44
|
+
/**
|
|
45
|
+
* A type that can be a value or a promise.
|
|
46
|
+
* @template T
|
|
47
|
+
* @returns {T | Promise<T>} T or Promise<T>
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { MaybePromise } from "@luxass/utils/types";
|
|
52
|
+
*
|
|
53
|
+
* type A = MaybePromise<string>
|
|
54
|
+
* // string | Promise<string>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
58
|
+
/**
|
|
59
|
+
* Infers the element type of an array
|
|
60
|
+
* @template T
|
|
61
|
+
* @returns {T extends (infer E)[] ? E : never} The inferred element type
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { ElementOf } from "@luxass/utils/types";
|
|
66
|
+
*
|
|
67
|
+
* type A = ElementOf<string[]>
|
|
68
|
+
* // string
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
72
|
+
/**
|
|
73
|
+
* Infers the arguments type of a function
|
|
74
|
+
* @template T
|
|
75
|
+
* @returns {T extends ((...args: infer A) => any) ? A : never} The inferred arguments type
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* import { InferArguments } from "@luxass/utils/types";
|
|
80
|
+
*
|
|
81
|
+
* type A = InferArguments<(a: string, b: number) => void>
|
|
82
|
+
* // [string, number]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
type InferArguments<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
86
|
+
/**
|
|
87
|
+
* Makes complex nested types more readable in editor tooltips by flattening
|
|
88
|
+
* the type to a simple object type with all properties
|
|
89
|
+
* @template T
|
|
90
|
+
* @returns {{ [K in keyof T]: T[K] } & {}} A simplified representation of the same type
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { Prettify } from "@luxass/utils/types";
|
|
95
|
+
*
|
|
96
|
+
* type Messy = { a: string } & { b: number } & { c: boolean }
|
|
97
|
+
* type Clean = Prettify<Messy>
|
|
98
|
+
* // { a: string; b: number; c: boolean }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
102
|
+
/**
|
|
103
|
+
* Removes index signatures from a type while preserving specific properties
|
|
104
|
+
* @template T
|
|
105
|
+
* @returns {{ [K in keyof T as {} extends Record<K, 1> ? never : K]: T[K] }} A new type without index signatures
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { RemoveIndexSignature } from "@luxass/utils/types";
|
|
110
|
+
*
|
|
111
|
+
* type WithIndex = { id: number; [key: string]: any }
|
|
112
|
+
* type Clean = RemoveIndexSignature<WithIndex>
|
|
113
|
+
* // { id: number }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
type RemoveIndexSignature<T> = { [K in keyof T as {} extends Record<K, 1> ? never : K]: T[K] };
|
|
117
|
+
/**
|
|
118
|
+
* A safer version of the built-in Omit utility type that ensures the keys
|
|
119
|
+
* being omitted actually exist on the source type
|
|
120
|
+
* @template T
|
|
121
|
+
* @template {keyof T} K
|
|
122
|
+
* @returns {Omit<T, K>} A new type with the specified keys omitted
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { SafeOmit } from "@luxass/utils/types";
|
|
127
|
+
*
|
|
128
|
+
* interface User {
|
|
129
|
+
* id: number;
|
|
130
|
+
* name: string;
|
|
131
|
+
* email: string;
|
|
132
|
+
* }
|
|
133
|
+
*
|
|
134
|
+
* type UserWithoutEmail = SafeOmit<User, 'email'>
|
|
135
|
+
* // { id: number; name: string }
|
|
136
|
+
*
|
|
137
|
+
* // TypeScript error - 'invalid' is not a key of User
|
|
138
|
+
* type Invalid = SafeOmit<User, 'invalid'>
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
type SafeOmit<T, K extends keyof T> = Omit<T, K>;
|
|
142
|
+
//#endregion
|
|
143
|
+
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, SafeOmit };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-
|
|
2
|
-
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature };
|
|
1
|
+
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, SafeOmit } from "./types-DwW0ucVr.js";
|
|
2
|
+
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, SafeOmit };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"description": "A collection of utilities for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"./guards": "./dist/guards.js",
|
|
27
27
|
"./number": "./dist/number.js",
|
|
28
28
|
"./object": "./dist/object.js",
|
|
29
|
+
"./path": "./dist/path.js",
|
|
29
30
|
"./string": "./dist/string.js",
|
|
30
31
|
"./types": "./dist/types.js",
|
|
31
32
|
"./package.json": "./package.json"
|
|
@@ -43,13 +44,13 @@
|
|
|
43
44
|
"p-retry": "^6.2.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
46
|
-
"@luxass/eslint-config": "^5.1.
|
|
47
|
+
"@luxass/eslint-config": "^5.1.1",
|
|
47
48
|
"@types/node": "^22.15.2",
|
|
48
49
|
"@vitest/coverage-v8": "3.2.4",
|
|
49
|
-
"eslint": "^9.
|
|
50
|
+
"eslint": "^9.32.0",
|
|
50
51
|
"eslint-plugin-format": "^1.0.1",
|
|
51
52
|
"publint": "^0.3.12",
|
|
52
|
-
"tsdown": "^0.
|
|
53
|
+
"tsdown": "^0.13.0",
|
|
53
54
|
"typescript": "^5.8.3",
|
|
54
55
|
"vitest": "^3.2.4",
|
|
55
56
|
"vitest-package-exports": "^0.1.1"
|
package/dist/types-DCrM3M9i.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
//#region src/types.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Whatever type, or null
|
|
4
|
-
* @param T - Type
|
|
5
|
-
* @returns T or null
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* type A = Nullable<string>
|
|
10
|
-
* // string | null
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
type Nullable<T> = T | null;
|
|
14
|
-
/**
|
|
15
|
-
* Whatever type, null or undefined
|
|
16
|
-
* @param T - Type
|
|
17
|
-
* @returns T, undefined or null
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* type A = Nullish<string>
|
|
22
|
-
* // string | null | undefined
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
type Nullish<T> = T | null | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* A type that can be an array or a single value.
|
|
28
|
-
*/
|
|
29
|
-
type MaybeArray<T> = T | T[];
|
|
30
|
-
/**
|
|
31
|
-
* A type that can be a value or a promise.
|
|
32
|
-
*/
|
|
33
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
34
|
-
/**
|
|
35
|
-
* Infers the element type of an array
|
|
36
|
-
* @param T - Array type
|
|
37
|
-
* @returns The inferred element type
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* type A = ElementOf<string[]>
|
|
42
|
-
* // string
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
46
|
-
/**
|
|
47
|
-
* Infers the arguments type of a function
|
|
48
|
-
* @param T - Function type
|
|
49
|
-
* @returns The inferred arguments type
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* type A = InferArguments<(a: string, b: number) => void>
|
|
54
|
-
* // [string, number]
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
type InferArguments<T> = T extends ((...args: infer A) => any) ? A : never;
|
|
58
|
-
/**
|
|
59
|
-
* Makes complex nested types more readable in editor tooltips by flattening
|
|
60
|
-
* the type to a simple object type with all properties
|
|
61
|
-
* @param T - The type to prettify
|
|
62
|
-
* @returns A simplified representation of the same type
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* type Messy = { a: string } & { b: number } & { c: boolean }
|
|
67
|
-
* type Clean = Prettify<Messy>
|
|
68
|
-
* // { a: string; b: number; c: boolean }
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
72
|
-
/**
|
|
73
|
-
* Removes index signatures from a type while preserving specific properties
|
|
74
|
-
* @param T - The type to remove index signatures from
|
|
75
|
-
* @returns A new type without index signatures
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```ts
|
|
79
|
-
* type WithIndex = { id: number; [key: string]: any }
|
|
80
|
-
* type Clean = RemoveIndexSignature<WithIndex>
|
|
81
|
-
* // { id: number }
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
type RemoveIndexSignature<T> = { [K in keyof T as {} extends Record<K, 1> ? never : K]: T[K] };
|
|
85
|
-
//#endregion
|
|
86
|
-
export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|