@luxass/utils 1.6.1 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxass/utils",
3
- "version": "1.6.1",
3
+ "version": "2.0.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,190 +0,0 @@
1
- "use strict";
2
-
3
- //#region src/string.ts
4
- const FULL_WHITESPACE_RE = /^\s*$/;
5
- /**
6
- * Capitalizes the first character of a string and converts the rest to lowercase
7
- * @param {string} str - The string to capitalize
8
- * @returns {string} The capitalized string
9
- * @example
10
- * ```ts
11
- * capitalize("hello") // "Hello"
12
- * capitalize("hELLO") // "Hello"
13
- * capitalize("") // ""
14
- * ```
15
- */
16
- function capitalize(str) {
17
- if (!str) return "";
18
- return str[0].toUpperCase() + str.slice(1).toLowerCase();
19
- }
20
- /**
21
- * Converts a string to camelCase format
22
- * @param {string} str - The string to convert to camelCase
23
- * @returns {string} The string in camelCase format
24
- * @example
25
- * ```ts
26
- * toCamelCase("hello world") // "helloWorld"
27
- * toCamelCase("hello-world") // "helloWorld"
28
- * toCamelCase("hello_world") // "helloWorld"
29
- * toCamelCase("HelloWorld") // "helloWorld"
30
- * toCamelCase("") // ""
31
- * ```
32
- */
33
- function toCamelCase(str) {
34
- if (!str) return "";
35
- str = str.trim().replace(/\s+/g, " ");
36
- const words = str.split(/[\s\-_]+/);
37
- if (words.length === 1 && words[0]?.length === 1) return words[0].toLowerCase();
38
- let result = words[0]?.toLowerCase() || "";
39
- for (let i = 1; i < words.length; i++) {
40
- const word = words[i];
41
- if (!word) continue;
42
- const hasCamelCase = word.match(/[a-z][A-Z]/g);
43
- result += hasCamelCase ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
44
- }
45
- return result;
46
- }
47
- /**
48
- * Converts a string to kebab-case format
49
- * @param {string} str - The string to convert to kebab-case
50
- * @returns {string} The string in kebab-case format
51
- * @example
52
- * ```ts
53
- * toKebabCase("hello world") // "hello-world"
54
- * toKebabCase("helloWorld") // "hello-world"
55
- * toKebabCase("hello_world") // "hello-world"
56
- * toKebabCase("HelloWorld") // "hello-world"
57
- * toKebabCase("") // ""
58
- * ```
59
- */
60
- function toKebabCase(str) {
61
- if (!str) return "";
62
- 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();
63
- }
64
- /**
65
- * Converts a string to PascalCase format
66
- * @param {string} str - The string to convert to PascalCase
67
- * @returns {string} The string in PascalCase format
68
- * @example
69
- * ```ts
70
- * toPascalCase("hello world") // "HelloWorld"
71
- * toPascalCase("hello-world") // "HelloWorld"
72
- * toPascalCase("hello_world") // "HelloWorld"
73
- * toPascalCase("helloWorld") // "HelloWorld"
74
- * toPascalCase("") // ""
75
- * ```
76
- */
77
- function toPascalCase(str) {
78
- if (!str) return "";
79
- 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("");
80
- }
81
- /**
82
- * Converts a string to snake_case format
83
- * @param {string} str - The string to convert to snake_case
84
- * @returns {string} The string in snake_case format
85
- * @example
86
- * ```ts
87
- * toSnakeCase("hello world") // "hello_world"
88
- * toSnakeCase("helloWorld") // "hello_world"
89
- * toSnakeCase("hello-world") // "hello_world"
90
- * toSnakeCase("HelloWorld") // "hello_world"
91
- * toSnakeCase("") // ""
92
- * ```
93
- */
94
- function toSnakeCase(str) {
95
- if (!str) return "";
96
- 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();
97
- }
98
- function dedent(strings, ...values) {
99
- return internal_dedent(strings, values, false);
100
- }
101
- dedent.raw = dedentRaw;
102
- function dedentRaw(strings, ...values) {
103
- return internal_dedent(strings, values, true);
104
- }
105
- /** @internal */
106
- function internal_dedent(strings, values, raw = false) {
107
- const _raw = typeof strings === "string" ? [strings] : raw ? strings.raw : strings;
108
- let result = "";
109
- for (let i = 0; i < _raw.length; i++) {
110
- const next = _raw[i];
111
- result += next;
112
- if (i < values.length) result += values[i];
113
- }
114
- const lines = result.split("\n");
115
- const whitespaceLines = lines.map((line) => FULL_WHITESPACE_RE.test(line));
116
- const commonIndent = lines.reduce((min, line, idx) => {
117
- if (whitespaceLines[idx]) return min;
118
- const indent = line.match(/^\s*/)?.[0].length;
119
- return indent === void 0 ? min : Math.min(min, indent);
120
- }, Number.POSITIVE_INFINITY);
121
- const firstNonWhitespaceLine = whitespaceLines.findIndex((isWhitespace) => !isWhitespace);
122
- const lastNonWhitespaceLine = whitespaceLines.lastIndexOf(false);
123
- return lines.slice(firstNonWhitespaceLine >= 0 ? firstNonWhitespaceLine : 0, lastNonWhitespaceLine >= 0 ? lastNonWhitespaceLine + 1 : lines.length).map((line) => line.slice(commonIndent)).join("\n");
124
- }
125
- /**
126
- * Ensures a string is a valid JavaScript identifier by prefixing with an underscore if necessary
127
- * @param {string} str - The string to sanitize
128
- * @returns {string} A valid JavaScript identifier
129
- * @example
130
- * ```ts
131
- * sanitizeIdentifier("validName") // "validName"
132
- * sanitizeIdentifier("123invalid") // "_123invalid"
133
- * sanitizeIdentifier("$valid") // "$valid"
134
- * sanitizeIdentifier("_valid") // "_valid"
135
- * ```
136
- */
137
- function sanitizeIdentifier(str) {
138
- const cleaned = str.replace(/[^\w$]/g, "");
139
- return /^[A-Z_$]/i.test(cleaned) ? cleaned : `_${cleaned}`;
140
- }
141
-
142
- //#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
- });
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 };