@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.
Files changed (54) hide show
  1. package/README.md +24 -12
  2. package/dist/README.md +24 -12
  3. package/dist/a11y/focus/is-html-element-focusable.d.ts +8 -6
  4. package/dist/a11y/focus/move-focus-within-container.d.ts +1 -1
  5. package/dist/array/chunk.d.ts +4 -1
  6. package/dist/array/compose.d.ts +7 -3
  7. package/dist/array/get-adjacent-items.d.ts +1 -1
  8. package/dist/array/index.d.ts +1 -0
  9. package/dist/array/intersection.d.ts +2 -1
  10. package/dist/array/is-array.d.ts +6 -0
  11. package/dist/array/is-empty-array.d.ts +7 -0
  12. package/dist/array/pipe.d.ts +5 -2
  13. package/dist/array/to-map-by.d.ts +48 -0
  14. package/dist/async/async.d.ts +10 -1
  15. package/dist/async/retry.d.ts +4 -3
  16. package/dist/dom/data-transfer.d.ts +22 -4
  17. package/dist/dom/dom.d.ts +7 -5
  18. package/dist/dom/transform/parse-2d-matrix.d.ts +5 -0
  19. package/dist/encoding/decode-base64-json.d.ts +22 -1
  20. package/dist/encoding/decode-base64.d.ts +23 -1
  21. package/dist/encoding/encode-base64-json.d.ts +16 -0
  22. package/dist/encoding/encode-base64.d.ts +20 -0
  23. package/dist/env/storage/local-storage-json.d.ts +1 -1
  24. package/dist/env/storage/local-storage.d.ts +1 -6
  25. package/dist/file.d.ts +3 -2
  26. package/dist/function/function.d.ts +12 -0
  27. package/dist/geometry/apply-inertia-step.d.ts +1 -1
  28. package/dist/geometry/layout/calculate-center-offset.d.ts +11 -1
  29. package/dist/geometry/layout/clamp-offset-to-overflow.d.ts +6 -0
  30. package/dist/geometry/resolve-bounded-delta.d.ts +1 -1
  31. package/dist/guards.d.ts +24 -3
  32. package/dist/index.cjs +1 -1
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.dev.cjs +402 -97
  35. package/dist/index.dev.cjs.map +1 -1
  36. package/dist/index.mjs +1 -1
  37. package/dist/index.mjs.map +1 -1
  38. package/dist/intersection/get-dom-rect-intersection-ratio.d.ts +8 -1
  39. package/dist/intersection/resolve-axis-delta.d.ts +7 -0
  40. package/dist/json/parse-json.d.ts +22 -1
  41. package/dist/math/hash-string.d.ts +1 -1
  42. package/dist/math/math.d.ts +17 -1
  43. package/dist/object.d.ts +7 -1
  44. package/dist/string/for-each-char.d.ts +1 -1
  45. package/dist/string/is-nil-or-empty-string.d.ts +1 -1
  46. package/dist/string/parse-file-name.d.ts +1 -1
  47. package/dist/tree/flatten-tree.d.ts +2 -2
  48. package/dist/tree/get-tree-children.d.ts +2 -2
  49. package/dist/tree/search-tree.d.ts +2 -2
  50. package/dist/tree/tree.types.d.ts +1 -1
  51. package/package.json +8 -7
  52. package/dist/geometry/apply-inertia-step.spec.d.ts +0 -1
  53. package/dist/geometry/resolve-bounded-delta.spec.d.ts +0 -1
  54. 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 '~/types';
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>;
@@ -19,7 +19,7 @@
19
19
  * @example
20
20
  * ```ts
21
21
  * const className = hashString('background-color: red;');
22
- * // → 'e4k1z0x'
22
+ * // → '1s0s409'
23
23
  * ```
24
24
  */
25
25
  export declare const hashString: (input: string) => string;
@@ -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]: Exclude<T[K], undefined>;
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`.
@@ -1,4 +1,4 @@
1
- import type { Nullable } from '~/types';
1
+ import type { Nullable } from '../types';
2
2
  /**
3
3
  * Context information for the currently processed character during string iteration.
4
4
  *
@@ -10,4 +10,4 @@
10
10
  *
11
11
  * @returns `true` if the value is empty; otherwise, `false`.
12
12
  */
13
- export declare const isNilOrEmptyString: (value: unknown) => value is null | undefined;
13
+ export declare const isNilOrEmptyString: (value: unknown) => value is null | 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 '~/types';
2
- import type { HoneyTreeFlatNode } from '~/tree';
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 '~/types';
2
- import type { HoneyTreeFlatNode } from '~/tree';
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 '~/types';
2
- import type { HoneyTreeFlatNode } from '~/tree';
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
  *
@@ -1,4 +1,4 @@
1
- import type { KeysWithNonArrayValues } from '~/types';
1
+ import type { KeysWithNonArrayValues } from '../types';
2
2
  /**
3
3
  * A flattened representation of a node from a hierarchical tree structure.
4
4
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-hive/honey-utils",
3
- "version": "4.3.0",
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": "24.19.0",
45
+ "@types/node": "26.6.5",
46
46
  "copy-webpack-plugin": "14.0.0",
47
- "eslint": "10.11.0",
48
- "prettier": "3.9.9",
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.0",
52
- "vitest": "5.0.3",
53
- "webpack": "5.111.1",
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 {};