@luxass/utils 1.6.1 → 2.1.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,5 +1,24 @@
1
1
  import { isNotNull$1 as isNotNull, isNotNullish$1 as isNotNullish, isNotUndefined$1 as isNotUndefined, isTruthy$1 as isTruthy } from "./guards.d-n1BzCANy.js";
2
2
  import { clamp$1 as clamp } from "./number.d-C2Xuq3Is.js";
3
- import { capitalize$1 as capitalize, dedent$1 as dedent, dedentRaw$1 as dedentRaw, sanitizeIdentifier$1 as sanitizeIdentifier, toCamelCase$1 as toCamelCase, toKebabCase$1 as toKebabCase, toPascalCase$1 as toPascalCase, toSnakeCase$1 as toSnakeCase } from "./string.d-BSY3kSBV.js";
3
+ import { capitalize$1 as capitalize, dedent$1 as dedent, dedentRaw$1 as dedentRaw, formatStr$1 as formatStr, sanitizeIdentifier$1 as sanitizeIdentifier, toCamelCase$1 as toCamelCase, toKebabCase$1 as toKebabCase, toPascalCase$1 as toPascalCase, toSnakeCase$1 as toSnakeCase } from "./string.d-B2ppMtlR.js";
4
4
  import { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from "./types.d-BcKIY6l3.js";
5
- export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish, capitalize, clamp, dedent, dedentRaw, isNotNull, isNotNullish, isNotUndefined, isTruthy, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
5
+
6
+ //#region src/common.d.ts
7
+ declare class InvariantError extends Error {
8
+ readonly message: string;
9
+ constructor(message: string, ...positionals: any[]);
10
+ }
11
+
12
+ /**
13
+ * Asserts that a condition is truthy. If the condition is falsy, throws an InvariantError.
14
+ * This function is useful for ensuring invariants and preconditions in code.
15
+ *
16
+ * @param {unknown} predicate - The condition to check
17
+ * @param {string} message - Error message to display if the condition fails
18
+ * @param {unknown[]} positionals - Values to substitute into the error message using formatStr
19
+ * @throws {InvariantError} Throws when the predicate is falsy
20
+ */
21
+ declare function invariant(predicate: unknown, message: string, ...positionals: unknown[]): asserts predicate;
22
+
23
+ //#endregion
24
+ export { Arrayable, Awaitable, ElementOf, InferArguments, InvariantError, Nullable, Nullish, capitalize, clamp, dedent, dedentRaw, formatStr, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/index.js CHANGED
@@ -1,5 +1,27 @@
1
1
  import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards-O1HGJraI.js";
2
- import { clamp } from "./number-Bfr1z0Nr.js";
3
- import { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-bY1lSRQs.js";
2
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-pQApOGKP.js";
3
+ import { clamp } from "./number-BS9T5WGO.js";
4
4
 
5
- export { capitalize, clamp, dedent, dedentRaw, isNotNull, isNotNullish, isNotUndefined, isTruthy, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
5
+ //#region src/common.ts
6
+ var InvariantError = class extends Error {
7
+ constructor(message, ...positionals) {
8
+ super(message);
9
+ this.message = message;
10
+ this.message = formatStr(message, ...positionals);
11
+ }
12
+ };
13
+ /**
14
+ * Asserts that a condition is truthy. If the condition is falsy, throws an InvariantError.
15
+ * This function is useful for ensuring invariants and preconditions in code.
16
+ *
17
+ * @param {unknown} predicate - The condition to check
18
+ * @param {string} message - Error message to display if the condition fails
19
+ * @param {unknown[]} positionals - Values to substitute into the error message using formatStr
20
+ * @throws {InvariantError} Throws when the predicate is falsy
21
+ */
22
+ function invariant(predicate, message, ...positionals) {
23
+ if (!predicate) throw new InvariantError(message, ...positionals);
24
+ }
25
+
26
+ //#endregion
27
+ export { InvariantError, capitalize, clamp, dedent, dedentRaw, formatStr, invariant, isNotNull, isNotNullish, isNotUndefined, isTruthy, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/number.js CHANGED
@@ -1,3 +1,3 @@
1
- import { clamp } from "./number-Bfr1z0Nr.js";
1
+ import { clamp } from "./number-BS9T5WGO.js";
2
2
 
3
3
  export { clamp };
@@ -1,5 +1,3 @@
1
- "use strict";
2
-
3
1
  //#region src/string.ts
4
2
  const FULL_WHITESPACE_RE = /^\s*$/;
5
3
  /**
@@ -138,53 +136,51 @@ function sanitizeIdentifier(str) {
138
136
  const cleaned = str.replace(/[^\w$]/g, "");
139
137
  return /^[A-Z_$]/i.test(cleaned) ? cleaned : `_${cleaned}`;
140
138
  }
139
+ const POSITION_REGEX = /(%?)(%([sdijo]))/g;
140
+ /** @internal */
141
+ function serializePositional(positional, flag) {
142
+ if (flag === "s") return positional;
143
+ if (flag === "d" || flag === "i") return Number(positional);
144
+ if (flag === "j") return JSON.stringify(positional);
145
+ if (flag === "o") {
146
+ if (typeof positional === "string") return positional;
147
+ const json = JSON.stringify(positional);
148
+ if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) return positional;
149
+ return json;
150
+ }
151
+ }
152
+ /**
153
+ * Formats a string by replacing placeholders with positional values
154
+ * @param {string} message - The string containing placeholders to be replaced
155
+ * @param {...any} positionals - The values to insert into the placeholders
156
+ * @returns {string} The formatted string
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * formatStr("Hello %s", "world") // "Hello world"
161
+ * formatStr("Count: %d", 5) // "Count: 5"
162
+ * formatStr("Data: %j", { name: "test" }) // "Data: {"name":"test"}"
163
+ * formatStr("Object: %o", { id: 1 }) // "Object: {"id":1}"
164
+ * formatStr("Escaped %%s", "value") // "Escaped %s"
165
+ * formatStr("Extra args", 1, 2) // "Extra args 1 2"
166
+ * ```
167
+ */
168
+ function formatStr(message, ...positionals) {
169
+ if (!positionals.length) return message;
170
+ let positionalIndex = 0;
171
+ let formattedMessage = message.replace(POSITION_REGEX, (match, isEscaped, _, flag) => {
172
+ const positional = positionals[positionalIndex];
173
+ const value = serializePositional(positional, flag);
174
+ if (!isEscaped) {
175
+ positionalIndex++;
176
+ return value;
177
+ }
178
+ return match;
179
+ });
180
+ if (positionalIndex < positionals.length) formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
181
+ formattedMessage = formattedMessage.replace(/%{2}/g, "%");
182
+ return formattedMessage;
183
+ }
141
184
 
142
185
  //#endregion
143
- Object.defineProperty(exports, 'capitalize', {
144
- enumerable: true,
145
- get: function () {
146
- return capitalize;
147
- }
148
- });
149
- Object.defineProperty(exports, 'dedent', {
150
- enumerable: true,
151
- get: function () {
152
- return dedent;
153
- }
154
- });
155
- Object.defineProperty(exports, 'dedentRaw', {
156
- enumerable: true,
157
- get: function () {
158
- return dedentRaw;
159
- }
160
- });
161
- Object.defineProperty(exports, 'sanitizeIdentifier', {
162
- enumerable: true,
163
- get: function () {
164
- return sanitizeIdentifier;
165
- }
166
- });
167
- Object.defineProperty(exports, 'toCamelCase', {
168
- enumerable: true,
169
- get: function () {
170
- return toCamelCase;
171
- }
172
- });
173
- Object.defineProperty(exports, 'toKebabCase', {
174
- enumerable: true,
175
- get: function () {
176
- return toKebabCase;
177
- }
178
- });
179
- Object.defineProperty(exports, 'toPascalCase', {
180
- enumerable: true,
181
- get: function () {
182
- return toPascalCase;
183
- }
184
- });
185
- Object.defineProperty(exports, 'toSnakeCase', {
186
- enumerable: true,
187
- get: function () {
188
- return toSnakeCase;
189
- }
190
- });
186
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
@@ -114,6 +114,23 @@ declare function dedentRaw(strings: TemplateStringsArray, ...values: unknown[]):
114
114
  * ```
115
115
  */
116
116
 
117
- declare function sanitizeIdentifier(str: string): string;
117
+ declare function sanitizeIdentifier(str: string): string; /**
118
+ * Formats a string by replacing placeholders with positional values
119
+ * @param {string} message - The string containing placeholders to be replaced
120
+ * @param {...any} positionals - The values to insert into the placeholders
121
+ * @returns {string} The formatted string
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * formatStr("Hello %s", "world") // "Hello world"
126
+ * formatStr("Count: %d", 5) // "Count: 5"
127
+ * formatStr("Data: %j", { name: "test" }) // "Data: {"name":"test"}"
128
+ * formatStr("Object: %o", { id: 1 }) // "Object: {"id":1}"
129
+ * formatStr("Escaped %%s", "value") // "Escaped %s"
130
+ * formatStr("Extra args", 1, 2) // "Extra args 1 2"
131
+ * ```
132
+ */
133
+
134
+ declare function formatStr(message: string, ...positionals: unknown[]): string;
118
135
  //#endregion
119
- export { capitalize as capitalize$1, dedent as dedent$1, dedentRaw as dedentRaw$1, sanitizeIdentifier as sanitizeIdentifier$1, toCamelCase as toCamelCase$1, toKebabCase as toKebabCase$1, toPascalCase as toPascalCase$1, toSnakeCase as toSnakeCase$1 };
136
+ export { capitalize as capitalize$1, dedent as dedent$1, dedentRaw as dedentRaw$1, formatStr as formatStr$1, sanitizeIdentifier as sanitizeIdentifier$1, toCamelCase as toCamelCase$1, toKebabCase as toKebabCase$1, toPascalCase as toPascalCase$1, toSnakeCase as toSnakeCase$1 };
package/dist/string.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { capitalize$1 as capitalize, dedent$1 as dedent, dedentRaw$1 as dedentRaw, sanitizeIdentifier$1 as sanitizeIdentifier, toCamelCase$1 as toCamelCase, toKebabCase$1 as toKebabCase, toPascalCase$1 as toPascalCase, toSnakeCase$1 as toSnakeCase } from "./string.d-BSY3kSBV.js";
2
- export { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
1
+ import { capitalize$1 as capitalize, dedent$1 as dedent, dedentRaw$1 as dedentRaw, formatStr$1 as formatStr, sanitizeIdentifier$1 as sanitizeIdentifier, toCamelCase$1 as toCamelCase, toKebabCase$1 as toKebabCase, toPascalCase$1 as toPascalCase, toSnakeCase$1 as toSnakeCase } from "./string.d-B2ppMtlR.js";
2
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/string.js CHANGED
@@ -1,3 +1,3 @@
1
- import { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-bY1lSRQs.js";
1
+ import { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string-pQApOGKP.js";
2
2
 
3
- export { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
3
+ export { capitalize, dedent, dedentRaw, formatStr, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxass/utils",
3
- "version": "1.6.1",
3
+ "version": "2.1.0",
4
4
  "description": "A collection of utilities for JavaScript/TypeScript",
5
5
  "type": "module",
6
6
  "author": {
@@ -22,49 +22,14 @@
22
22
  ],
23
23
  "sideEffects": false,
24
24
  "exports": {
25
- ".": {
26
- "import": {
27
- "types": "./dist/index.d.ts",
28
- "default": "./dist/index.js"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
34
- },
35
- "./guards": {
36
- "import": {
37
- "types": "./dist/guards.d.ts",
38
- "default": "./dist/guards.js"
39
- },
40
- "require": {
41
- "types": "./dist/guards.d.cts",
42
- "default": "./dist/guards.cjs"
43
- }
44
- },
45
- "./number": {
46
- "import": {
47
- "types": "./dist/number.d.ts",
48
- "default": "./dist/number.js"
49
- },
50
- "require": {
51
- "types": "./dist/number.d.cts",
52
- "default": "./dist/number.cjs"
53
- }
54
- },
55
- "./types": {
56
- "import": {
57
- "types": "./dist/types.d.ts",
58
- "default": "./dist/types.js"
59
- },
60
- "require": {
61
- "types": "./dist/types.d.cts",
62
- "default": "./dist/types.cjs"
63
- }
64
- },
25
+ ".": "./dist/index.js",
26
+ "./string": "./dist/string.js",
27
+ "./guards": "./dist/guards.js",
28
+ "./number": "./dist/number.js",
29
+ "./types": "./dist/types.js",
65
30
  "./package.json": "./package.json"
66
31
  },
67
- "main": "./dist/index.cjs",
32
+ "main": "./dist/index.js",
68
33
  "module": "./dist/index.js",
69
34
  "types": "./dist/index.d.ts",
70
35
  "files": [
@@ -82,7 +47,8 @@
82
47
  "publint": "^0.3.12",
83
48
  "tsdown": "^0.9.9",
84
49
  "typescript": "^5.8.3",
85
- "vitest": "^3.1.2"
50
+ "vitest": "^3.1.2",
51
+ "vitest-package-exports": "^0.1.1"
86
52
  },
87
53
  "scripts": {
88
54
  "build": "tsdown",
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- //#region src/guards.ts
4
- /**
5
- * Checks if a value is not null or undefined.
6
- *
7
- * @template T - The type of the input value.
8
- * @param {T | null | undefined} v - The value to check for not being null or undefined.
9
- * @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
10
- *
11
- * @example
12
- * ```ts
13
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
14
- * // [true, false, 0, 1, "", "hello"]
15
- * ```
16
- */
17
- function isNotNullish(v) {
18
- return v != null;
19
- }
20
- /**
21
- * Checks if a value is not null.
22
- *
23
- * @template T - The type of the input value.
24
- * @param {T | null} v - The value to check for not being null.
25
- * @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
26
- *
27
- * @example
28
- * ```ts
29
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
30
- * // [true, false, 0, 1, "", "hello", undefined]
31
- * ```
32
- */
33
- function isNotNull(v) {
34
- return v !== null;
35
- }
36
- /**
37
- * Checks if a value is defined.
38
- *
39
- * @template T - The type of the input value.
40
- * @param {T} v - The value to check for being defined.
41
- * @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
42
- *
43
- * @example
44
- * ```ts
45
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
46
- * // [true, false, 0, 1, "", "hello", null]
47
- * ```
48
- */
49
- function isNotUndefined(v) {
50
- return v !== void 0;
51
- }
52
- /**
53
- * Checks if a value is truthy, excluding null and undefined.
54
- *
55
- * @template T - The type of the input value.
56
- * @param {T} v - The value to check for truthiness.
57
- * @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
58
- *
59
- * @example
60
- * ```ts
61
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
62
- * // [true, 1, "hello"]
63
- * ```
64
- */
65
- function isTruthy(v) {
66
- return Boolean(v);
67
- }
68
-
69
- //#endregion
70
- Object.defineProperty(exports, 'isNotNull', {
71
- enumerable: true,
72
- get: function () {
73
- return isNotNull;
74
- }
75
- });
76
- Object.defineProperty(exports, 'isNotNullish', {
77
- enumerable: true,
78
- get: function () {
79
- return isNotNullish;
80
- }
81
- });
82
- Object.defineProperty(exports, 'isNotUndefined', {
83
- enumerable: true,
84
- get: function () {
85
- return isNotUndefined;
86
- }
87
- });
88
- Object.defineProperty(exports, 'isTruthy', {
89
- enumerable: true,
90
- get: function () {
91
- return isTruthy;
92
- }
93
- });
package/dist/guards.cjs DELETED
@@ -1,6 +0,0 @@
1
- const require_guards = require('./guards-DE5pQVvl.cjs');
2
-
3
- exports.isNotNull = require_guards.isNotNull
4
- exports.isNotNullish = require_guards.isNotNullish
5
- exports.isNotUndefined = require_guards.isNotUndefined
6
- exports.isTruthy = require_guards.isTruthy
@@ -1,62 +0,0 @@
1
- //#region src/guards.d.ts
2
- /**
3
- * Checks if a value is not null or undefined.
4
- *
5
- * @template T - The type of the input value.
6
- * @param {T | null | undefined} v - The value to check for not being null or undefined.
7
- * @returns {v is NonNullable<T>} - True if the value is not null or undefined, false otherwise.
8
- *
9
- * @example
10
- * ```ts
11
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNullish)
12
- * // [true, false, 0, 1, "", "hello"]
13
- * ```
14
- */declare function isNotNullish<T>(v: T | null | undefined): v is NonNullable<T>;
15
-
16
- /**
17
- * Checks if a value is not null.
18
- *
19
- * @template T - The type of the input value.
20
- * @param {T | null} v - The value to check for not being null.
21
- * @returns {v is Exclude<T, null>} True if the value is not null, false otherwise.
22
- *
23
- * @example
24
- * ```ts
25
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isNotNull)
26
- * // [true, false, 0, 1, "", "hello", undefined]
27
- * ```
28
- */
29
- declare function isNotNull<T>(v: T | null): v is Exclude<T, null>;
30
-
31
- /**
32
- * Checks if a value is defined.
33
- *
34
- * @template T - The type of the input value.
35
- * @param {T} v - The value to check for being defined.
36
- * @returns {v is Exclude<T, undefined>} True if the value is defined, false otherwise.
37
- *
38
- * @example
39
- * ```ts
40
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isDefined)
41
- * // [true, false, 0, 1, "", "hello", null]
42
- * ```
43
- */
44
- declare function isNotUndefined<T>(v: T): v is Exclude<T, undefined>;
45
-
46
- /**
47
- * Checks if a value is truthy, excluding null and undefined.
48
- *
49
- * @template T - The type of the input value.
50
- * @param {T} v - The value to check for truthiness.
51
- * @returns {v is NonNullable<T>} True if the value is truthy, false otherwise.
52
- *
53
- * @example
54
- * ```ts
55
- * [true, false, 0, 1, "", "hello", null, undefined].filter(isTruthy)
56
- * // [true, 1, "hello"]
57
- * ```
58
- */
59
- declare function isTruthy<T>(v: T): v is NonNullable<T>;
60
-
61
- //#endregion
62
- export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
package/dist/guards.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards.d-DXUlpL_S.cjs";
2
- export { isNotNull, isNotNullish, isNotUndefined, isTruthy };
package/dist/index.cjs DELETED
@@ -1,17 +0,0 @@
1
- const require_guards = require('./guards-DE5pQVvl.cjs');
2
- const require_number = require('./number-DRbo8lb6.cjs');
3
- const require_string = require('./string-CxNDb3Ui.cjs');
4
-
5
- exports.capitalize = require_string.capitalize
6
- exports.clamp = require_number.clamp
7
- exports.dedent = require_string.dedent
8
- exports.dedentRaw = require_string.dedentRaw
9
- exports.isNotNull = require_guards.isNotNull
10
- exports.isNotNullish = require_guards.isNotNullish
11
- exports.isNotUndefined = require_guards.isNotUndefined
12
- exports.isTruthy = require_guards.isTruthy
13
- exports.sanitizeIdentifier = require_string.sanitizeIdentifier
14
- exports.toCamelCase = require_string.toCamelCase
15
- exports.toKebabCase = require_string.toKebabCase
16
- exports.toPascalCase = require_string.toPascalCase
17
- exports.toSnakeCase = require_string.toSnakeCase
package/dist/index.d.cts DELETED
@@ -1,5 +0,0 @@
1
- import { isNotNull, isNotNullish, isNotUndefined, isTruthy } from "./guards.d-DXUlpL_S.cjs";
2
- import { clamp } from "./number.d-C1FAMQlq.cjs";
3
- import { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string.d-Dm-Z_ZP2.cjs";
4
- import { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from "./types.d-fcYBBT6c.cjs";
5
- export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish, capitalize, clamp, dedent, dedentRaw, isNotNull, isNotNullish, isNotUndefined, isTruthy, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- //#region src/number.ts
4
- /**
5
- * Clamp a value between a min and max value.
6
- * @param {number} value
7
- * @param {number} min
8
- * @param {number} max
9
- * @returns {number} the clamped value
10
- *
11
- * @example
12
- * ```ts
13
- * clamp(5, 0, 10)
14
- * // 5
15
- *
16
- * clamp(5, 10, 20)
17
- * // 10
18
- *
19
- * clamp(5, 0, 4)
20
- * // 4
21
- * ```
22
- */
23
- function clamp(value, min, max) {
24
- return Math.min(Math.max(value, min), max);
25
- }
26
-
27
- //#endregion
28
- Object.defineProperty(exports, 'clamp', {
29
- enumerable: true,
30
- get: function () {
31
- return clamp;
32
- }
33
- });
package/dist/number.cjs DELETED
@@ -1,3 +0,0 @@
1
- const require_number = require('./number-DRbo8lb6.cjs');
2
-
3
- exports.clamp = require_number.clamp
@@ -1,23 +0,0 @@
1
- //#region src/number.d.ts
2
- /**
3
- * Clamp a value between a min and max value.
4
- * @param {number} value
5
- * @param {number} min
6
- * @param {number} max
7
- * @returns {number} the clamped value
8
- *
9
- * @example
10
- * ```ts
11
- * clamp(5, 0, 10)
12
- * // 5
13
- *
14
- * clamp(5, 10, 20)
15
- * // 10
16
- *
17
- * clamp(5, 0, 4)
18
- * // 4
19
- * ```
20
- */declare function clamp(value: number, min: number, max: number): number;
21
-
22
- //#endregion
23
- export { clamp };
package/dist/number.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import { clamp } from "./number.d-C1FAMQlq.cjs";
2
- export { clamp };
@@ -1,141 +0,0 @@
1
- //#region src/string.ts
2
- const FULL_WHITESPACE_RE = /^\s*$/;
3
- /**
4
- * Capitalizes the first character of a string and converts the rest to lowercase
5
- * @param {string} str - The string to capitalize
6
- * @returns {string} The capitalized string
7
- * @example
8
- * ```ts
9
- * capitalize("hello") // "Hello"
10
- * capitalize("hELLO") // "Hello"
11
- * capitalize("") // ""
12
- * ```
13
- */
14
- function capitalize(str) {
15
- if (!str) return "";
16
- return str[0].toUpperCase() + str.slice(1).toLowerCase();
17
- }
18
- /**
19
- * Converts a string to camelCase format
20
- * @param {string} str - The string to convert to camelCase
21
- * @returns {string} The string in camelCase format
22
- * @example
23
- * ```ts
24
- * toCamelCase("hello world") // "helloWorld"
25
- * toCamelCase("hello-world") // "helloWorld"
26
- * toCamelCase("hello_world") // "helloWorld"
27
- * toCamelCase("HelloWorld") // "helloWorld"
28
- * toCamelCase("") // ""
29
- * ```
30
- */
31
- function toCamelCase(str) {
32
- if (!str) return "";
33
- str = str.trim().replace(/\s+/g, " ");
34
- const words = str.split(/[\s\-_]+/);
35
- if (words.length === 1 && words[0]?.length === 1) return words[0].toLowerCase();
36
- let result = words[0]?.toLowerCase() || "";
37
- for (let i = 1; i < words.length; i++) {
38
- const word = words[i];
39
- if (!word) continue;
40
- const hasCamelCase = word.match(/[a-z][A-Z]/g);
41
- result += hasCamelCase ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
42
- }
43
- return result;
44
- }
45
- /**
46
- * Converts a string to kebab-case format
47
- * @param {string} str - The string to convert to kebab-case
48
- * @returns {string} The string in kebab-case format
49
- * @example
50
- * ```ts
51
- * toKebabCase("hello world") // "hello-world"
52
- * toKebabCase("helloWorld") // "hello-world"
53
- * toKebabCase("hello_world") // "hello-world"
54
- * toKebabCase("HelloWorld") // "hello-world"
55
- * toKebabCase("") // ""
56
- * ```
57
- */
58
- function toKebabCase(str) {
59
- if (!str) return "";
60
- 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();
61
- }
62
- /**
63
- * Converts a string to PascalCase format
64
- * @param {string} str - The string to convert to PascalCase
65
- * @returns {string} The string in PascalCase format
66
- * @example
67
- * ```ts
68
- * toPascalCase("hello world") // "HelloWorld"
69
- * toPascalCase("hello-world") // "HelloWorld"
70
- * toPascalCase("hello_world") // "HelloWorld"
71
- * toPascalCase("helloWorld") // "HelloWorld"
72
- * toPascalCase("") // ""
73
- * ```
74
- */
75
- function toPascalCase(str) {
76
- if (!str) return "";
77
- return str.trim().replace(/[_-]+/g, " ").replace(/\s+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2").replace(/(\d+)([a-z])/gi, "$1 $2").split(" ").filter((word) => word.length > 0).map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join("");
78
- }
79
- /**
80
- * Converts a string to snake_case format
81
- * @param {string} str - The string to convert to snake_case
82
- * @returns {string} The string in snake_case format
83
- * @example
84
- * ```ts
85
- * toSnakeCase("hello world") // "hello_world"
86
- * toSnakeCase("helloWorld") // "hello_world"
87
- * toSnakeCase("hello-world") // "hello_world"
88
- * toSnakeCase("HelloWorld") // "hello_world"
89
- * toSnakeCase("") // ""
90
- * ```
91
- */
92
- function toSnakeCase(str) {
93
- if (!str) return "";
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
- }
96
- function dedent(strings, ...values) {
97
- return internal_dedent(strings, values, false);
98
- }
99
- dedent.raw = dedentRaw;
100
- function dedentRaw(strings, ...values) {
101
- return internal_dedent(strings, values, true);
102
- }
103
- /** @internal */
104
- function internal_dedent(strings, values, raw = false) {
105
- const _raw = typeof strings === "string" ? [strings] : raw ? strings.raw : strings;
106
- let result = "";
107
- for (let i = 0; i < _raw.length; i++) {
108
- const next = _raw[i];
109
- result += next;
110
- if (i < values.length) result += values[i];
111
- }
112
- const lines = result.split("\n");
113
- const whitespaceLines = lines.map((line) => FULL_WHITESPACE_RE.test(line));
114
- const commonIndent = lines.reduce((min, line, idx) => {
115
- if (whitespaceLines[idx]) return min;
116
- const indent = line.match(/^\s*/)?.[0].length;
117
- return indent === void 0 ? min : Math.min(min, indent);
118
- }, Number.POSITIVE_INFINITY);
119
- const firstNonWhitespaceLine = whitespaceLines.findIndex((isWhitespace) => !isWhitespace);
120
- const lastNonWhitespaceLine = whitespaceLines.lastIndexOf(false);
121
- return lines.slice(firstNonWhitespaceLine >= 0 ? firstNonWhitespaceLine : 0, lastNonWhitespaceLine >= 0 ? lastNonWhitespaceLine + 1 : lines.length).map((line) => line.slice(commonIndent)).join("\n");
122
- }
123
- /**
124
- * Ensures a string is a valid JavaScript identifier by prefixing with an underscore if necessary
125
- * @param {string} str - The string to sanitize
126
- * @returns {string} A valid JavaScript identifier
127
- * @example
128
- * ```ts
129
- * sanitizeIdentifier("validName") // "validName"
130
- * sanitizeIdentifier("123invalid") // "_123invalid"
131
- * sanitizeIdentifier("$valid") // "$valid"
132
- * sanitizeIdentifier("_valid") // "_valid"
133
- * ```
134
- */
135
- function sanitizeIdentifier(str) {
136
- const cleaned = str.replace(/[^\w$]/g, "");
137
- return /^[A-Z_$]/i.test(cleaned) ? cleaned : `_${cleaned}`;
138
- }
139
-
140
- //#endregion
141
- export { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/string.cjs DELETED
@@ -1,10 +0,0 @@
1
- const require_string = require('./string-CxNDb3Ui.cjs');
2
-
3
- exports.capitalize = require_string.capitalize
4
- exports.dedent = require_string.dedent
5
- exports.dedentRaw = require_string.dedentRaw
6
- exports.sanitizeIdentifier = require_string.sanitizeIdentifier
7
- exports.toCamelCase = require_string.toCamelCase
8
- exports.toKebabCase = require_string.toKebabCase
9
- exports.toPascalCase = require_string.toPascalCase
10
- exports.toSnakeCase = require_string.toSnakeCase
@@ -1,119 +0,0 @@
1
- //#region src/string.d.ts
2
- /**
3
- * Capitalizes the first character of a string and converts the rest to lowercase
4
- * @param {string} str - The string to capitalize
5
- * @returns {string} The capitalized string
6
- * @example
7
- * ```ts
8
- * capitalize("hello") // "Hello"
9
- * capitalize("hELLO") // "Hello"
10
- * capitalize("") // ""
11
- * ```
12
- */declare function capitalize(str: string): string;
13
-
14
- /**
15
- * Converts a string to camelCase format
16
- * @param {string} str - The string to convert to camelCase
17
- * @returns {string} The string in camelCase format
18
- * @example
19
- * ```ts
20
- * toCamelCase("hello world") // "helloWorld"
21
- * toCamelCase("hello-world") // "helloWorld"
22
- * toCamelCase("hello_world") // "helloWorld"
23
- * toCamelCase("HelloWorld") // "helloWorld"
24
- * toCamelCase("") // ""
25
- * ```
26
- */
27
- declare function toCamelCase(str: string): string;
28
-
29
- /**
30
- * Converts a string to kebab-case format
31
- * @param {string} str - The string to convert to kebab-case
32
- * @returns {string} The string in kebab-case format
33
- * @example
34
- * ```ts
35
- * toKebabCase("hello world") // "hello-world"
36
- * toKebabCase("helloWorld") // "hello-world"
37
- * toKebabCase("hello_world") // "hello-world"
38
- * toKebabCase("HelloWorld") // "hello-world"
39
- * toKebabCase("") // ""
40
- * ```
41
- */
42
- declare function toKebabCase(str: string): string;
43
-
44
- /**
45
- * Converts a string to PascalCase format
46
- * @param {string} str - The string to convert to PascalCase
47
- * @returns {string} The string in PascalCase format
48
- * @example
49
- * ```ts
50
- * toPascalCase("hello world") // "HelloWorld"
51
- * toPascalCase("hello-world") // "HelloWorld"
52
- * toPascalCase("hello_world") // "HelloWorld"
53
- * toPascalCase("helloWorld") // "HelloWorld"
54
- * toPascalCase("") // ""
55
- * ```
56
- */
57
- declare function toPascalCase(str: string): string;
58
-
59
- /**
60
- * Converts a string to snake_case format
61
- * @param {string} str - The string to convert to snake_case
62
- * @returns {string} The string in snake_case format
63
- * @example
64
- * ```ts
65
- * toSnakeCase("hello world") // "hello_world"
66
- * toSnakeCase("helloWorld") // "hello_world"
67
- * toSnakeCase("hello-world") // "hello_world"
68
- * toSnakeCase("HelloWorld") // "hello_world"
69
- * toSnakeCase("") // ""
70
- * ```
71
- */
72
- declare function toSnakeCase(str: string): string;
73
-
74
- /**
75
- * Removes leading and trailing whitespace from each line of a string
76
- * @param {TemplateStringsArray | string} literals - The string to dedent
77
- * @returns {string} The dedented string
78
- * @example ```ts
79
- * dedent`
80
- * This is a test.
81
- * This is another line.
82
- * `
83
- * // "This is a test.\nThis is another line."
84
- * ```
85
- */
86
- declare function dedent(literals: string): string;
87
- declare function dedent(strings: TemplateStringsArray, ...values: unknown[]): string;
88
- declare namespace dedent {
89
- var raw: typeof dedentRaw;
90
- } /**
91
- * Removes leading and trailing whitespace from each line of a string
92
- * @param {TemplateStringsArray | string} literals - The string to dedent
93
- * @returns {string} The dedented string
94
- * @example ```ts
95
- * dedent`
96
- * This is a test.
97
- * This is another line.
98
- * `
99
- * // "This is a test.\nThis is another line."
100
- * ```
101
- */
102
-
103
- declare function dedentRaw(literals: string): string;
104
- declare function dedentRaw(strings: TemplateStringsArray, ...values: unknown[]): string; /**
105
- * Ensures a string is a valid JavaScript identifier by prefixing with an underscore if necessary
106
- * @param {string} str - The string to sanitize
107
- * @returns {string} A valid JavaScript identifier
108
- * @example
109
- * ```ts
110
- * sanitizeIdentifier("validName") // "validName"
111
- * sanitizeIdentifier("123invalid") // "_123invalid"
112
- * sanitizeIdentifier("$valid") // "$valid"
113
- * sanitizeIdentifier("_valid") // "_valid"
114
- * ```
115
- */
116
-
117
- declare function sanitizeIdentifier(str: string): string;
118
- //#endregion
119
- export { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/string.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from "./string.d-Dm-Z_ZP2.cjs";
2
- export { capitalize, dedent, dedentRaw, sanitizeIdentifier, toCamelCase, toKebabCase, toPascalCase, toSnakeCase };
package/dist/types.cjs DELETED
File without changes
@@ -1,72 +0,0 @@
1
- //#region src/types.d.ts
2
- /**
3
- * Whatever type, or Promise of that type
4
- * @param T - Type
5
- * @returns T or Promise<T>
6
- *
7
- * @example
8
- * ```ts
9
- * type A = Awaitable<string>
10
- * // string | Promise<string>
11
- * ```
12
- */type Awaitable<T> = T | PromiseLike<T>;
13
-
14
- /**
15
- * Whatever type, or null
16
- * @param T - Type
17
- * @returns T or null
18
- *
19
- * @example
20
- * ```ts
21
- * type A = Nullable<string>
22
- * // string | null
23
- * ```
24
- */
25
- type Nullable<T> = T | null;
26
-
27
- /**
28
- * Whatever type, null or undefined
29
- * @param T - Type
30
- * @returns T, undefined or null
31
- *
32
- * @example
33
- * ```ts
34
- * type A = Nullish<string>
35
- * // string | null | undefined
36
- * ```
37
- */
38
- type Nullish<T> = T | null | undefined;
39
-
40
- /**
41
- * Array, or not yet
42
- */
43
- type Arrayable<T> = T | Array<T>;
44
-
45
- /**
46
- * Infers the element type of an array
47
- * @param T - Array type
48
- * @returns The inferred element type
49
- *
50
- * @example
51
- * ```ts
52
- * type A = ElementOf<string[]>
53
- * // string
54
- * ```
55
- */
56
- type ElementOf<T> = T extends (infer E)[] ? E : never;
57
-
58
- /**
59
- * Infers the arguments type of a function
60
- * @param T - Function type
61
- * @returns The inferred arguments type
62
- *
63
- * @example
64
- * ```ts
65
- * type A = InferArguments<(a: string, b: number) => void>
66
- * // [string, number]
67
- * ```
68
- */
69
- type InferArguments<T> = T extends ((...args: infer A) => any) ? A : never;
70
-
71
- //#endregion
72
- export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish };
package/dist/types.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from "./types.d-fcYBBT6c.cjs";
2
- export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish };
File without changes