@luxass/utils 1.0.0 → 1.2.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/chunk-7RYURVAF.mjs +6 -0
- package/dist/{chunk-JVIVQFL7.mjs → chunk-MNDVPE25.mjs} +10 -20
- package/dist/index.cjs +16 -20
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +2 -1
- package/dist/number.cjs +8 -0
- package/dist/number.d.cts +22 -0
- package/dist/number.d.ts +22 -0
- package/dist/number.mjs +1 -0
- package/dist/string.cjs +10 -20
- package/dist/string.mjs +1 -1
- package/package.json +19 -9
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
// src/string.ts
|
|
2
2
|
function capitalize(str) {
|
|
3
|
-
if (typeof str !== "string")
|
|
4
|
-
|
|
5
|
-
if (str.trim().length === 0)
|
|
6
|
-
return "";
|
|
3
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
4
|
+
if (str.trim().length === 0) return "";
|
|
7
5
|
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
8
6
|
}
|
|
9
7
|
function toCamelCase(str) {
|
|
10
|
-
if (typeof str !== "string")
|
|
11
|
-
|
|
12
|
-
if (str.trim().length === 0)
|
|
13
|
-
return "";
|
|
8
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
9
|
+
if (str.trim().length === 0) return "";
|
|
14
10
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase());
|
|
15
11
|
}
|
|
16
12
|
function toKebabCase(str) {
|
|
17
|
-
if (typeof str !== "string")
|
|
18
|
-
|
|
19
|
-
if (str.trim().length === 0)
|
|
20
|
-
return "";
|
|
13
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
14
|
+
if (str.trim().length === 0) return "";
|
|
21
15
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
22
16
|
}
|
|
23
17
|
function toPascalCase(str) {
|
|
24
|
-
if (typeof str !== "string")
|
|
25
|
-
|
|
26
|
-
if (str.trim().length === 0)
|
|
27
|
-
return "";
|
|
18
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
19
|
+
if (str.trim().length === 0) return "";
|
|
28
20
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
29
21
|
}
|
|
30
22
|
function toSnakeCase(str) {
|
|
31
|
-
if (typeof str !== "string")
|
|
32
|
-
|
|
33
|
-
if (str.trim().length === 0)
|
|
34
|
-
return "";
|
|
23
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
24
|
+
if (str.trim().length === 0) return "";
|
|
35
25
|
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
36
26
|
}
|
|
37
27
|
|
package/dist/index.cjs
CHANGED
|
@@ -14,44 +14,40 @@ function isTruthy(v) {
|
|
|
14
14
|
return Boolean(v);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// src/number.ts
|
|
18
|
+
function clamp(value, min, max) {
|
|
19
|
+
return Math.min(Math.max(value, min), max);
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
// src/string.ts
|
|
18
23
|
function capitalize(str) {
|
|
19
|
-
if (typeof str !== "string")
|
|
20
|
-
|
|
21
|
-
if (str.trim().length === 0)
|
|
22
|
-
return "";
|
|
24
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
25
|
+
if (str.trim().length === 0) return "";
|
|
23
26
|
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
24
27
|
}
|
|
25
28
|
function toCamelCase(str) {
|
|
26
|
-
if (typeof str !== "string")
|
|
27
|
-
|
|
28
|
-
if (str.trim().length === 0)
|
|
29
|
-
return "";
|
|
29
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
30
|
+
if (str.trim().length === 0) return "";
|
|
30
31
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase());
|
|
31
32
|
}
|
|
32
33
|
function toKebabCase(str) {
|
|
33
|
-
if (typeof str !== "string")
|
|
34
|
-
|
|
35
|
-
if (str.trim().length === 0)
|
|
36
|
-
return "";
|
|
34
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
35
|
+
if (str.trim().length === 0) return "";
|
|
37
36
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
38
37
|
}
|
|
39
38
|
function toPascalCase(str) {
|
|
40
|
-
if (typeof str !== "string")
|
|
41
|
-
|
|
42
|
-
if (str.trim().length === 0)
|
|
43
|
-
return "";
|
|
39
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
40
|
+
if (str.trim().length === 0) return "";
|
|
44
41
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
45
42
|
}
|
|
46
43
|
function toSnakeCase(str) {
|
|
47
|
-
if (typeof str !== "string")
|
|
48
|
-
|
|
49
|
-
if (str.trim().length === 0)
|
|
50
|
-
return "";
|
|
44
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
45
|
+
if (str.trim().length === 0) return "";
|
|
51
46
|
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
exports.capitalize = capitalize;
|
|
50
|
+
exports.clamp = clamp;
|
|
55
51
|
exports.isNotNull = isNotNull;
|
|
56
52
|
exports.isNotNullish = isNotNullish;
|
|
57
53
|
exports.isNotUndefined = isNotUndefined;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from './types.cjs';
|
|
2
2
|
export { isNotNull, isNotNullish, isNotUndefined, isTruthy } from './guards.cjs';
|
|
3
|
+
export { clamp } from './number.cjs';
|
|
3
4
|
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './string.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { Arrayable, Awaitable, ElementOf, InferArguments, Nullable, Nullish } from './types.js';
|
|
2
2
|
export { isNotNull, isNotNullish, isNotUndefined, isTruthy } from './guards.js';
|
|
3
|
+
export { clamp } from './number.js';
|
|
3
4
|
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './string.js';
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './chunk-
|
|
1
|
+
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './chunk-MNDVPE25.mjs';
|
|
2
2
|
export { isNotNull, isNotNullish, isNotUndefined, isTruthy } from './chunk-OKC7RR3A.mjs';
|
|
3
|
+
export { clamp } from './chunk-7RYURVAF.mjs';
|
package/dist/number.cjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamp a value between a min and max value.
|
|
3
|
+
* @param {number} value
|
|
4
|
+
* @param {number} min
|
|
5
|
+
* @param {number} max
|
|
6
|
+
* @returns {number} the clamped value
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* clamp(5, 0, 10)
|
|
11
|
+
* // 5
|
|
12
|
+
*
|
|
13
|
+
* clamp(5, 10, 20)
|
|
14
|
+
* // 10
|
|
15
|
+
*
|
|
16
|
+
* clamp(5, 0, 4)
|
|
17
|
+
* // 4
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
21
|
+
|
|
22
|
+
export { clamp };
|
package/dist/number.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamp a value between a min and max value.
|
|
3
|
+
* @param {number} value
|
|
4
|
+
* @param {number} min
|
|
5
|
+
* @param {number} max
|
|
6
|
+
* @returns {number} the clamped value
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* clamp(5, 0, 10)
|
|
11
|
+
* // 5
|
|
12
|
+
*
|
|
13
|
+
* clamp(5, 10, 20)
|
|
14
|
+
* // 10
|
|
15
|
+
*
|
|
16
|
+
* clamp(5, 0, 4)
|
|
17
|
+
* // 4
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function clamp(value: number, min: number, max: number): number;
|
|
21
|
+
|
|
22
|
+
export { clamp };
|
package/dist/number.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { clamp } from './chunk-7RYURVAF.mjs';
|
package/dist/string.cjs
CHANGED
|
@@ -2,38 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
// src/string.ts
|
|
4
4
|
function capitalize(str) {
|
|
5
|
-
if (typeof str !== "string")
|
|
6
|
-
|
|
7
|
-
if (str.trim().length === 0)
|
|
8
|
-
return "";
|
|
5
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
6
|
+
if (str.trim().length === 0) return "";
|
|
9
7
|
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
10
8
|
}
|
|
11
9
|
function toCamelCase(str) {
|
|
12
|
-
if (typeof str !== "string")
|
|
13
|
-
|
|
14
|
-
if (str.trim().length === 0)
|
|
15
|
-
return "";
|
|
10
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
11
|
+
if (str.trim().length === 0) return "";
|
|
16
12
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase());
|
|
17
13
|
}
|
|
18
14
|
function toKebabCase(str) {
|
|
19
|
-
if (typeof str !== "string")
|
|
20
|
-
|
|
21
|
-
if (str.trim().length === 0)
|
|
22
|
-
return "";
|
|
15
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
16
|
+
if (str.trim().length === 0) return "";
|
|
23
17
|
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
24
18
|
}
|
|
25
19
|
function toPascalCase(str) {
|
|
26
|
-
if (typeof str !== "string")
|
|
27
|
-
|
|
28
|
-
if (str.trim().length === 0)
|
|
29
|
-
return "";
|
|
20
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
21
|
+
if (str.trim().length === 0) return "";
|
|
30
22
|
return str.toLowerCase().replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
31
23
|
}
|
|
32
24
|
function toSnakeCase(str) {
|
|
33
|
-
if (typeof str !== "string")
|
|
34
|
-
|
|
35
|
-
if (str.trim().length === 0)
|
|
36
|
-
return "";
|
|
25
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
26
|
+
if (str.trim().length === 0) return "";
|
|
37
27
|
return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
38
28
|
}
|
|
39
29
|
|
package/dist/string.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './chunk-
|
|
1
|
+
export { capitalize, toCamelCase, toKebabCase, toPascalCase, toSnakeCase } from './chunk-MNDVPE25.mjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A collection of utilities for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"email": "lucasnrgaard@gmail.com",
|
|
9
9
|
"url": "https://luxass.dev"
|
|
10
10
|
},
|
|
11
|
-
"packageManager": "pnpm@
|
|
11
|
+
"packageManager": "pnpm@9.4.0",
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"homepage": "https://github.com/luxass/utils",
|
|
14
14
|
"repository": {
|
|
@@ -43,6 +43,16 @@
|
|
|
43
43
|
"default": "./dist/guards.cjs"
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
+
"./number": {
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./dist/number.d.ts",
|
|
49
|
+
"default": "./dist/number.mjs"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./dist/number.d.cts",
|
|
53
|
+
"default": "./dist/number.cjs"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
46
56
|
"./types": {
|
|
47
57
|
"import": {
|
|
48
58
|
"types": "./dist/types.d.ts",
|
|
@@ -73,12 +83,12 @@
|
|
|
73
83
|
"typecheck": "tsc --noEmit"
|
|
74
84
|
},
|
|
75
85
|
"devDependencies": {
|
|
76
|
-
"@luxass/eslint-config": "^4.
|
|
77
|
-
"@types/node": "^20.
|
|
78
|
-
"eslint": "^
|
|
79
|
-
"eslint-plugin-format": "^0.1.
|
|
80
|
-
"tsup": "^8.0
|
|
81
|
-
"typescript": "^5.
|
|
82
|
-
"vitest": "^1.0
|
|
86
|
+
"@luxass/eslint-config": "^4.7.0",
|
|
87
|
+
"@types/node": "^20.14.9",
|
|
88
|
+
"eslint": "^9.6.0",
|
|
89
|
+
"eslint-plugin-format": "^0.1.2",
|
|
90
|
+
"tsup": "^8.1.0",
|
|
91
|
+
"typescript": "^5.5.2",
|
|
92
|
+
"vitest": "^1.6.0"
|
|
83
93
|
}
|
|
84
94
|
}
|