@entry-ui/utilities 0.3.0 → 0.4.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-JW4DI4Q2.js +2 -0
- package/dist/chunk-JW4DI4Q2.js.map +1 -0
- package/dist/chunk-TAV72HQS.js +2 -0
- package/dist/chunk-TAV72HQS.js.map +1 -0
- package/dist/clamp/index.d.ts +54 -0
- package/dist/clamp/index.js +2 -0
- package/dist/clamp/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/is-valid-number/index.d.ts +23 -0
- package/dist/is-valid-number/index.js +2 -0
- package/dist/is-valid-number/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a as a$1}from'./chunk-O4WYO5SA.js';import {a}from'./chunk-TAV72HQS.js';var s=r=>{let{value:m,min:e,max:i}=r;return a(m)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'value' parameter in 'clamp' utility.",`Expected a finite number, but received: ${m}`]}),a(e)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'min' parameter in 'clamp' utility.",`Expected a finite number, but received: ${e}`]}),a(i)||a$1({prefix:"[Entry UI Utilities]",messages:["Invalid 'max' parameter in 'clamp' utility.",`Expected a finite number, but received: ${i}`]}),e>i&&a$1({prefix:"[Entry UI Utilities]",messages:["Invalid range for 'clamp' utility.",`The 'min' parameter (${e}) must be less than or equal to the 'max' parameter (${i}).`]}),Math.min(i,Math.max(e,m))};export{s as a};//# sourceMappingURL=chunk-JW4DI4Q2.js.map
|
|
2
|
+
//# sourceMappingURL=chunk-JW4DI4Q2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/clamp/clamp.ts"],"names":["clamp","params","value","min","max","isValidNumber","fail"],"mappings":"+EA2BO,IAAMA,EAASC,CAAAA,EAAwB,CAC5C,GAAM,CAAE,KAAA,CAAAC,EAAO,GAAA,CAAAC,CAAAA,CAAK,GAAA,CAAAC,CAAI,EAAIH,CAAAA,CAE5B,OAAKI,EAAcH,CAAK,CAAA,EACtBI,IAAK,CACH,MAAA,CAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,+CAAA,CAAiD,CAAA,wCAAA,EAA2CJ,CAAK,CAAA,CAAE,CAChH,CAAC,CAAA,CAGEG,CAAAA,CAAcF,CAAG,CAAA,EACpBG,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CAAC,6CAAA,CAA+C,2CAA2CH,CAAG,CAAA,CAAE,CAC5G,CAAC,EAGEE,CAAAA,CAAcD,CAAG,GACpBE,GAAAA,CAAK,CACH,OAAQ,sBAAA,CACR,QAAA,CAAU,CAAC,6CAAA,CAA+C,CAAA,wCAAA,EAA2CF,CAAG,CAAA,CAAE,CAC5G,CAAC,CAAA,CAGCD,CAAAA,CAAMC,GACRE,GAAAA,CAAK,CACH,MAAA,CAAQ,sBAAA,CACR,SAAU,CACR,oCAAA,CACA,wBAAwBH,CAAG,CAAA,qDAAA,EAAwDC,CAAG,CAAA,EAAA,CACxF,CACF,CAAC,CAAA,CAGI,IAAA,CAAK,IAAIA,CAAAA,CAAK,IAAA,CAAK,IAAID,CAAAA,CAAKD,CAAK,CAAC,CAC3C","file":"chunk-JW4DI4Q2.js","sourcesContent":["import type { ClampParams } from './clamp.types';\nimport { isValidNumber } from '../is-valid-number';\nimport { fail } from '../fail';\n\n/**\n * Clamps a number between a minimum and maximum value.\n *\n * This utility ensures that the returned value is restricted to a specified range.\n * If the input value is smaller than the minimum boundary, the minimum value is\n * returned. If it exceeds the maximum boundary, the maximum value is returned.\n *\n * This function will throw an error if:\n * - Any of the input parameters are not finite numbers.\n * - The `min` value is greater than the `max` value.\n *\n * @example\n * ```ts\n * clamp({ value: 150, min: 0, max: 100 });\n * // Returns: 100\n *\n * clamp({ value: -20, min: 0, max: 100 });\n * Returns: 0\n *\n * clamp({ value: 50, min: 0, max: 100 });\n * // Returns: 50\n * ```\n */\nexport const clamp = (params: ClampParams) => {\n const { value, min, max } = params;\n\n if (!isValidNumber(value)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'value' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${value}`],\n });\n }\n\n if (!isValidNumber(min)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'min' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${min}`],\n });\n }\n\n if (!isValidNumber(max)) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [`Invalid 'max' parameter in 'clamp' utility.`, `Expected a finite number, but received: ${max}`],\n });\n }\n\n if (min > max) {\n fail({\n prefix: '[Entry UI Utilities]',\n messages: [\n `Invalid range for 'clamp' utility.`,\n `The 'min' parameter (${min}) must be less than or equal to the 'max' parameter (${max}).`,\n ],\n });\n }\n\n return Math.min(max, Math.max(min, value));\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-valid-number/is-valid-number.ts"],"names":["isValidNumber","value"],"mappings":"AAoBO,IAAMA,EAAiBC,CAAAA,EACrB,OAAOA,GAAU,QAAA,EAAY,MAAA,CAAO,SAASA,CAAK","file":"chunk-TAV72HQS.js","sourcesContent":["/**\n * Determines whether the provided value is a valid, finite number.\n *\n * This utility serves as a type guard that goes beyond a simple `typeof` check.\n * While `typeof NaN` or `typeof Infinity` returns `\"number\"`, this function\n * ensures the value is a usable numeric value by excluding these edge cases\n * using `Number.isFinite`.\n *\n * @example\n * ```ts\n * isValidNumber(10);\n * // Returns: true\n *\n * isValidNumber(NaN);\n * // Returns: false\n *\n * isValidNumber(Infinity);\n * // Returns: false\n * ```\n */\nexport const isValidNumber = (value: number): value is number => {\n return typeof value === 'number' && Number.isFinite(value);\n};\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration object for the `clamp` utility.
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the numerical boundaries and the target value required
|
|
5
|
+
* to perform a clamping operation. It ensures that all provided properties are
|
|
6
|
+
* valid, finite numbers, maintaining strict mathematical constraints where
|
|
7
|
+
* the minimum bound must not exceed the maximum bound.
|
|
8
|
+
*/
|
|
9
|
+
interface ClampParams {
|
|
10
|
+
/**
|
|
11
|
+
* The numerical value to be restricted within the specified range.
|
|
12
|
+
* Must be a finite number.
|
|
13
|
+
*/
|
|
14
|
+
value: number;
|
|
15
|
+
/**
|
|
16
|
+
* The lower bound of the range.
|
|
17
|
+
* If `value` is less than `min`, the function returns `min`.
|
|
18
|
+
* Must be a finite number and less than or equal to `max`.
|
|
19
|
+
*/
|
|
20
|
+
min: number;
|
|
21
|
+
/**
|
|
22
|
+
* The upper bound of the range.
|
|
23
|
+
* If `value` is greater than `max`, the function returns `max`.
|
|
24
|
+
* Must be a finite number and greater than or equal to `min`.
|
|
25
|
+
*/
|
|
26
|
+
max: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Clamps a number between a minimum and maximum value.
|
|
31
|
+
*
|
|
32
|
+
* This utility ensures that the returned value is restricted to a specified range.
|
|
33
|
+
* If the input value is smaller than the minimum boundary, the minimum value is
|
|
34
|
+
* returned. If it exceeds the maximum boundary, the maximum value is returned.
|
|
35
|
+
*
|
|
36
|
+
* This function will throw an error if:
|
|
37
|
+
* - Any of the input parameters are not finite numbers.
|
|
38
|
+
* - The `min` value is greater than the `max` value.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* clamp({ value: 150, min: 0, max: 100 });
|
|
43
|
+
* // Returns: 100
|
|
44
|
+
*
|
|
45
|
+
* clamp({ value: -20, min: 0, max: 100 });
|
|
46
|
+
* Returns: 0
|
|
47
|
+
*
|
|
48
|
+
* clamp({ value: 50, min: 0, max: 100 });
|
|
49
|
+
* // Returns: 50
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare const clamp: (params: ClampParams) => number;
|
|
53
|
+
|
|
54
|
+
export { type ClampParams, clamp };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { AddEventListenerOnceParams, AllEventMaps, addEventListenerOnce } from './add-event-listener-once/index.js';
|
|
2
|
+
export { ClampParams, clamp } from './clamp/index.js';
|
|
2
3
|
export { ErrorParams, error } from './error/index.js';
|
|
3
4
|
export { FailParams, fail } from './fail/index.js';
|
|
5
|
+
export { isValidNumber } from './is-valid-number/index.js';
|
|
4
6
|
export { PossibleStyle, mergeStyles } from './merge-styles/index.js';
|
|
5
7
|
export { visuallyHiddenInputStyle } from './visually-hidden-input-style/index.js';
|
|
6
8
|
export { visuallyHiddenStyle } from './visually-hidden-style/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as warn}from'./chunk-6L6DIP5N.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as
|
|
1
|
+
export{a as visuallyHiddenStyle}from'./chunk-YRBGPPKC.js';export{a as wait}from'./chunk-OUZ54COH.js';export{a as warn}from'./chunk-6L6DIP5N.js';export{a as addEventListenerOnce}from'./chunk-GLPQ4KOF.js';export{a as clamp}from'./chunk-JW4DI4Q2.js';export{a as error}from'./chunk-GG6DRWSS.js';export{a as fail}from'./chunk-O4WYO5SA.js';export{a as isValidNumber}from'./chunk-TAV72HQS.js';export{a as mergeStyles}from'./chunk-NBN5PUZ6.js';export{a as visuallyHiddenInputStyle}from'./chunk-AYHMR4G2.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines whether the provided value is a valid, finite number.
|
|
3
|
+
*
|
|
4
|
+
* This utility serves as a type guard that goes beyond a simple `typeof` check.
|
|
5
|
+
* While `typeof NaN` or `typeof Infinity` returns `"number"`, this function
|
|
6
|
+
* ensures the value is a usable numeric value by excluding these edge cases
|
|
7
|
+
* using `Number.isFinite`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* isValidNumber(10);
|
|
12
|
+
* // Returns: true
|
|
13
|
+
*
|
|
14
|
+
* isValidNumber(NaN);
|
|
15
|
+
* // Returns: false
|
|
16
|
+
*
|
|
17
|
+
* isValidNumber(Infinity);
|
|
18
|
+
* // Returns: false
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
declare const isValidNumber: (value: number) => value is number;
|
|
22
|
+
|
|
23
|
+
export { isValidNumber };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|