@luxass/utils 2.4.1 → 2.5.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/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-x9QZDUSt.js";
|
|
2
2
|
import { clamp } from "./number-DzUC7V5F.js";
|
|
3
3
|
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-BT3S70pM.js";
|
|
4
|
-
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-
|
|
4
|
+
import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DDSo2EBf.js";
|
|
5
5
|
import { ElementOf, InferArguments, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature } from "./types-DCrM3M9i.js";
|
|
6
6
|
import pRetry from "p-retry";
|
|
7
7
|
|
|
@@ -21,4 +21,4 @@ declare class InvariantError extends Error {
|
|
|
21
21
|
*/
|
|
22
22
|
declare function invariant(predicate: unknown, message: string, ...positionals: unknown[]): asserts predicate;
|
|
23
23
|
//#endregion
|
|
24
|
-
export { ElementOf, InferArguments, InvariantError, MaybeArray, MaybePromise, Nullable, Nullish, Prettify, RemoveIndexSignature, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
|
|
2
|
-
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-
|
|
2
|
+
import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DCBui1sH.js";
|
|
3
3
|
import { clamp } from "./number-BS9T5WGO.js";
|
|
4
4
|
import { getChangedKeys, getOwnProperty, hasOwnProperty, omit } from "./object-CyGLe77G.js";
|
|
5
5
|
|
|
@@ -317,4 +317,4 @@ async function pRetry(input, options) {
|
|
|
317
317
|
}
|
|
318
318
|
|
|
319
319
|
//#endregion
|
|
320
|
-
export { InvariantError, capitalize, clamp, dedent, dedentRaw, formatStr, getChangedKeys, getOwnProperty, hasOwnProperty, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, omit, pRetry as promiseRetry, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
320
|
+
export { InvariantError, 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 };
|
|
@@ -181,6 +181,80 @@ 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
|
+
}
|
|
184
258
|
|
|
185
259
|
//#endregion
|
|
186
|
-
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
260
|
+
export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
|
|
@@ -128,5 +128,67 @@ 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;
|
|
131
193
|
//#endregion
|
|
132
|
-
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
194
|
+
export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
|
package/dist/string.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-
|
|
2
|
-
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
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 };
|
package/dist/string.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-
|
|
1
|
+
import { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash } from "./string-DCBui1sH.js";
|
|
2
2
|
|
|
3
|
-
export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
|
|
3
|
+
export { appendTrailingSlash, capitalize, dedent, dedentRaw, formatStr, prependLeadingSlash, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, trimLeadingSlash, trimTrailingSlash };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "A collection of utilities for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"node": ">=20"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@luxass/eslint-config": "^5.
|
|
43
|
+
"@luxass/eslint-config": "^5.1.0",
|
|
44
44
|
"@types/node": "^22.15.2",
|
|
45
45
|
"@vitest/coverage-v8": "3.2.4",
|
|
46
|
-
"eslint": "^9.30.
|
|
46
|
+
"eslint": "^9.30.1",
|
|
47
47
|
"eslint-plugin-format": "^1.0.1",
|
|
48
48
|
"p-retry": "^6.2.1",
|
|
49
49
|
"publint": "^0.3.12",
|