@luxass/utils 2.5.1 → 2.6.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/guards.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-x9QZDUSt.js";
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-x9QZDUSt.js";
2
- import { clamp } from "./number-DzUC7V5F.js";
3
- import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BT3S70pM.js";
4
- import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DDSo2EBf.js";
5
- import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-DCrM3M9i.js";
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-DqJkV3NT.js";
5
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-Cwp8CD7H.js";
6
+ import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-BtiMC8Uf.js";
6
7
  import pRetry from "p-retry";
7
8
 
8
9
  //#region src/common.d.ts
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
2
- import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DCBui1sH.js";
2
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-pQApOGKP.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-BS-_BQ_d.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-DzUC7V5F.js";
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-BT3S70pM.js";
1
+ import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BtzfqVfB.js";
2
2
  export { getChangedKeys, getOwnProperty, hasOwnProperty, omit };
@@ -0,0 +1,128 @@
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 two URL paths together, handling trailing and leading slashes appropriately
78
+ * @param {string | undefined} base - The base URL path
79
+ * @param {string | undefined} path - The path to append to the base
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 (POSIX-like)
97
+ * joinURL("api//v1/", "//users///") // "api/v1/users/"
98
+ * joinURL("base///", "///path") // "base/path"
99
+ *
100
+ * // Empty and undefined handling
101
+ * joinURL("", "users") // "users"
102
+ * joinURL("api", "") // "api"
103
+ * joinURL(undefined, undefined) // "/"
104
+ * ```
105
+ */
106
+ function joinURL(base, path) {
107
+ if (!base && !path) return "/";
108
+ if (!base || base === "/") return path || "/";
109
+ if (!path || path === "/") return base;
110
+ const normalize = (s) => s.replace(/\/+/g, "/");
111
+ const joinPaths = (b, p) => {
112
+ b = normalize(b);
113
+ p = normalize(p);
114
+ if (b.endsWith("/") && b !== "/") b = b.slice(0, -1);
115
+ if (p.startsWith("/")) p = p.slice(1);
116
+ return p ? `${b}/${p}` : b;
117
+ };
118
+ try {
119
+ const url = new URL(base);
120
+ url.pathname = trimLeadingSlash(joinPaths(url.pathname, path));
121
+ return url.toString();
122
+ } catch {
123
+ return joinPaths(base, path);
124
+ }
125
+ }
126
+
127
+ //#endregion
128
+ export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
@@ -0,0 +1,96 @@
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 two URL paths together, handling trailing and leading slashes appropriately
66
+ * @param {string | undefined} base - The base URL path
67
+ * @param {string | undefined} path - The path to append to the base
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 (POSIX-like)
85
+ * joinURL("api//v1/", "//users///") // "api/v1/users/"
86
+ * joinURL("base///", "///path") // "base/path"
87
+ *
88
+ * // Empty and undefined handling
89
+ * joinURL("", "users") // "users"
90
+ * joinURL("api", "") // "api"
91
+ * joinURL(undefined, undefined) // "/"
92
+ * ```
93
+ */
94
+ declare function joinURL(base: string | undefined, path: string | undefined): string;
95
+ //#endregion
96
+ export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
package/dist/path.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash } from "./path-DqJkV3NT.js";
2
+ export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
package/dist/path.js ADDED
@@ -0,0 +1,3 @@
1
+ import { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash } from "./path-BS-_BQ_d.js";
2
+
3
+ export { appendTrailingSlash, joinURL, prependLeadingSlash, trimLeadingSlash, trimTrailingSlash };
@@ -128,67 +128,5 @@ declare function sanitizeIdentifier(str: string): string;
128
128
  * ```
129
129
  */
130
130
  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
131
  //#endregion
194
- export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
132
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
@@ -181,80 +181,6 @@ function formatStr(message, ...positionals) {
181
181
  formattedMessage = formattedMessage.replace(/%{2}/g, "%");
182
182
  return formattedMessage;
183
183
  }
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
184
 
259
185
  //#endregion
260
- export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
186
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/string.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DDSo2EBf.js";
2
- export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
1
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-Cwp8CD7H.js";
2
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/string.js CHANGED
@@ -1,3 +1,3 @@
1
- import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DCBui1sH.js";
1
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-pQApOGKP.js";
2
2
 
3
- export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
3
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-DCrM3M9i.js";
1
+ import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-BtiMC8Uf.js";
2
2
  export { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxass/utils",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
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"