@luxass/utils 1.0.0 → 1.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/chunk-7RYURVAF.mjs +6 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -0
- 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/package.json +11 -1
package/dist/index.cjs
CHANGED
|
@@ -14,6 +14,11 @@ 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
24
|
if (typeof str !== "string")
|
|
@@ -52,6 +57,7 @@ function toSnakeCase(str) {
|
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
exports.capitalize = capitalize;
|
|
60
|
+
exports.clamp = clamp;
|
|
55
61
|
exports.isNotNull = isNotNull;
|
|
56
62
|
exports.isNotNullish = isNotNullish;
|
|
57
63
|
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
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxass/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "A collection of utilities for JavaScript/TypeScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -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",
|