@react-hive/honey-utils 4.3.0 → 5.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/README.md +24 -12
- package/dist/README.md +24 -12
- package/dist/a11y/focus/is-html-element-focusable.d.ts +8 -6
- package/dist/a11y/focus/move-focus-within-container.d.ts +1 -1
- package/dist/array/chunk.d.ts +4 -1
- package/dist/array/compose.d.ts +7 -3
- package/dist/array/get-adjacent-items.d.ts +1 -1
- package/dist/array/index.d.ts +1 -0
- package/dist/array/intersection.d.ts +2 -1
- package/dist/array/is-array.d.ts +6 -0
- package/dist/array/is-empty-array.d.ts +7 -0
- package/dist/array/pipe.d.ts +5 -2
- package/dist/array/to-map-by.d.ts +48 -0
- package/dist/async/async.d.ts +10 -1
- package/dist/async/retry.d.ts +4 -3
- package/dist/dom/data-transfer.d.ts +22 -4
- package/dist/dom/dom.d.ts +7 -5
- package/dist/dom/transform/parse-2d-matrix.d.ts +5 -0
- package/dist/encoding/decode-base64-json.d.ts +22 -1
- package/dist/encoding/decode-base64.d.ts +23 -1
- package/dist/encoding/encode-base64-json.d.ts +16 -0
- package/dist/encoding/encode-base64.d.ts +20 -0
- package/dist/env/storage/local-storage-json.d.ts +1 -1
- package/dist/env/storage/local-storage.d.ts +1 -6
- package/dist/file.d.ts +3 -2
- package/dist/function/function.d.ts +12 -0
- package/dist/geometry/apply-inertia-step.d.ts +1 -1
- package/dist/geometry/layout/calculate-center-offset.d.ts +11 -1
- package/dist/geometry/layout/clamp-offset-to-overflow.d.ts +6 -0
- package/dist/geometry/resolve-bounded-delta.d.ts +1 -1
- package/dist/guards.d.ts +24 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.dev.cjs +402 -97
- package/dist/index.dev.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/intersection/get-dom-rect-intersection-ratio.d.ts +8 -1
- package/dist/intersection/resolve-axis-delta.d.ts +7 -0
- package/dist/json/parse-json.d.ts +22 -1
- package/dist/math/hash-string.d.ts +1 -1
- package/dist/math/math.d.ts +17 -1
- package/dist/object.d.ts +7 -1
- package/dist/string/for-each-char.d.ts +1 -1
- package/dist/string/is-nil-or-empty-string.d.ts +1 -1
- package/dist/string/parse-file-name.d.ts +1 -1
- package/dist/tree/flatten-tree.d.ts +2 -2
- package/dist/tree/get-tree-children.d.ts +2 -2
- package/dist/tree/search-tree.d.ts +2 -2
- package/dist/tree/tree.types.d.ts +1 -1
- package/package.json +8 -7
- package/dist/geometry/apply-inertia-step.spec.d.ts +0 -1
- package/dist/geometry/resolve-bounded-delta.spec.d.ts +0 -1
- package/dist/id/generate-ephemeral-id.spec.d.ts +0 -1
|
@@ -7,6 +7,13 @@
|
|
|
7
7
|
* @param sourceRect - The rectangle used to measure overlap against the target.
|
|
8
8
|
* @param targetRect - The rectangle whose covered area is measured.
|
|
9
9
|
*
|
|
10
|
-
* @returns A number between `0` and `1` representing the intersection ratio
|
|
10
|
+
* @returns A number between `0` and `1` representing the intersection ratio - `0` for a target
|
|
11
|
+
* with no area, which nothing can cover.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* getDOMRectIntersectionRatio(new DOMRect(0, 0, 100, 100), new DOMRect(50, 0, 100, 100));
|
|
16
|
+
* // 0.5
|
|
17
|
+
* ```
|
|
11
18
|
*/
|
|
12
19
|
export declare const getDOMRectIntersectionRatio: (sourceRect: DOMRect, targetRect: DOMRect) => number;
|
|
@@ -54,5 +54,12 @@ export interface ResolveAxisDeltaOptions {
|
|
|
54
54
|
* @param options - Resolution behavior configuration.
|
|
55
55
|
*
|
|
56
56
|
* @returns A normalized, axis-aligned delta suitable for further scroll or movement processing.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // A vertical wheel scrolling a horizontal list
|
|
61
|
+
* resolveAxisDelta({ deltaX: 0, deltaY: 40 }, 'x');
|
|
62
|
+
* // { deltaX: -40, deltaY: 0 }
|
|
63
|
+
* ```
|
|
57
64
|
*/
|
|
58
65
|
export declare const resolveAxisDelta: (delta: AxisDelta, axis: Axis, { allowFallback, invert }?: ResolveAxisDeltaOptions) => AxisDelta;
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
import type { Nullable } from '
|
|
1
|
+
import type { Nullable } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a JSON string without throwing.
|
|
4
|
+
*
|
|
5
|
+
* The result is only cast to `Value`, not checked against it - check its shape before relying on
|
|
6
|
+
* it where the string comes from outside the program.
|
|
7
|
+
*
|
|
8
|
+
* @template Value - The type the JSON is expected to have.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The JSON string to parse.
|
|
11
|
+
*
|
|
12
|
+
* @returns The parsed value, or `null` when the string is not valid JSON.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* parseJson<{ name: string }>('{"name":"Mike"}');
|
|
17
|
+
* // ➜ { name: 'Mike' }
|
|
18
|
+
*
|
|
19
|
+
* parseJson('{name:"Mike"}');
|
|
20
|
+
* // ➜ null
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
2
23
|
export declare const parseJson: <Value>(value: string) => Nullable<Value>;
|
package/dist/math/math.d.ts
CHANGED
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* @param endY - The Y coordinate of the ending point.
|
|
8
8
|
*
|
|
9
9
|
* @returns The Euclidean distance between the two points.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* calculateEuclideanDistance(0, 0, 3, 4); // 5
|
|
14
|
+
* ```
|
|
10
15
|
*/
|
|
11
16
|
export declare const calculateEuclideanDistance: (startX: number, startY: number, endX: number, endY: number) => number;
|
|
12
17
|
/**
|
|
@@ -15,7 +20,13 @@ export declare const calculateEuclideanDistance: (startX: number, startY: number
|
|
|
15
20
|
* @param distance - The distance.
|
|
16
21
|
* @param elapsedTime - The time taken to move the distance.
|
|
17
22
|
*
|
|
18
|
-
* @returns The calculated speed, which is the absolute value of delta divided by elapsed time
|
|
23
|
+
* @returns The calculated speed, which is the absolute value of delta divided by elapsed time -
|
|
24
|
+
* `Infinity` for a distance covered in no time, and `NaN` for none covered in none.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* calculateMovingSpeed(-120, 60); // 2
|
|
29
|
+
* ```
|
|
19
30
|
*/
|
|
20
31
|
export declare const calculateMovingSpeed: (distance: number, elapsedTime: number) => number;
|
|
21
32
|
/**
|
|
@@ -25,5 +36,10 @@ export declare const calculateMovingSpeed: (distance: number, elapsedTime: numbe
|
|
|
25
36
|
* @param percentage - The percentage to calculate.
|
|
26
37
|
*
|
|
27
38
|
* @returns The calculated percentage of the value.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* calculatePercentage(200, 15); // 30
|
|
43
|
+
* ```
|
|
28
44
|
*/
|
|
29
45
|
export declare const calculatePercentage: (value: number, percentage: number) => number;
|
package/dist/object.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `T` without the keys `definedProps` drops: a key that can only be `undefined` is gone, and one
|
|
3
|
+
* that may be `undefined` becomes optional, as it is left out wherever its value is.
|
|
4
|
+
*/
|
|
1
5
|
export type DefinedProps<T extends object> = {
|
|
2
|
-
[K in keyof T as T[K] extends undefined ? never : K]:
|
|
6
|
+
[K in keyof T as T[K] extends undefined ? never : undefined extends T[K] ? never : K]: T[K];
|
|
7
|
+
} & {
|
|
8
|
+
[K in keyof T as T[K] extends undefined ? never : undefined extends T[K] ? K : never]?: Exclude<T[K], undefined>;
|
|
3
9
|
};
|
|
4
10
|
/**
|
|
5
11
|
* Create a new object by removing properties whose values are `undefined`.
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
* - index 0 is the base name
|
|
14
14
|
* - index 1 is the file extension (lowercased), or an empty string if none exists
|
|
15
15
|
*/
|
|
16
|
-
export declare const parseFileName: (fileName: string) => string
|
|
16
|
+
export declare const parseFileName: (fileName: string) => [string, string];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { KeysWithArrayValues, KeysWithNonArrayValues } from '
|
|
2
|
-
import type { HoneyTreeFlatNode } from '
|
|
1
|
+
import type { KeysWithArrayValues, KeysWithNonArrayValues } from '../types';
|
|
2
|
+
import type { HoneyTreeFlatNode } from './tree.types';
|
|
3
3
|
/**
|
|
4
4
|
* Flattens a hierarchical tree into a single preorder array.
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { KeysWithNonArrayValues } from '
|
|
2
|
-
import type { HoneyTreeFlatNode } from '
|
|
1
|
+
import type { KeysWithNonArrayValues } from '../types';
|
|
2
|
+
import type { HoneyTreeFlatNode } from './tree.types';
|
|
3
3
|
/**
|
|
4
4
|
* Returns the direct children of a given parent node from a flattened tree.
|
|
5
5
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { KeysWithNonArrayValues, KeysWithStringValues } from '
|
|
2
|
-
import type { HoneyTreeFlatNode } from '
|
|
1
|
+
import type { KeysWithNonArrayValues, KeysWithStringValues } from '../types';
|
|
2
|
+
import type { HoneyTreeFlatNode } from './tree.types';
|
|
3
3
|
/**
|
|
4
4
|
* Performs a context-aware search over a flattened tree.
|
|
5
5
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-hive/honey-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A lightweight TypeScript utility library providing a collection of helper functions for common programming tasks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"utils",
|
|
@@ -42,15 +42,16 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@eslint/js": "10.0.1",
|
|
44
44
|
"@mdx-js/loader": "3.1.1",
|
|
45
|
-
"@types/node": "
|
|
45
|
+
"@types/node": "26.6.5",
|
|
46
46
|
"copy-webpack-plugin": "14.0.0",
|
|
47
|
-
"eslint": "10.
|
|
48
|
-
"
|
|
47
|
+
"eslint": "10.13.0",
|
|
48
|
+
"jsdom": "30.1.3",
|
|
49
|
+
"prettier": "3.9.10",
|
|
49
50
|
"ts-loader": "9.6.2",
|
|
50
51
|
"typescript": "6.0.3",
|
|
51
|
-
"typescript-eslint": "8.71.
|
|
52
|
-
"vitest": "5.0.
|
|
53
|
-
"webpack": "5.
|
|
52
|
+
"typescript-eslint": "8.71.2",
|
|
53
|
+
"vitest": "5.0.5",
|
|
54
|
+
"webpack": "5.112.0",
|
|
54
55
|
"webpack-cli": "7.2.3"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|