@react-fabric/utilities 1.0.0-beta.8 → 1.0.1

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 (168) hide show
  1. package/dist/cjs/css/boundingBox.js +72 -0
  2. package/dist/cjs/css/cn.js +39 -0
  3. package/dist/cjs/css/imageColorset.js +96 -0
  4. package/dist/cjs/data/countries.js +98 -0
  5. package/dist/cjs/{_fileType.js → data/fileType.js} +37 -19
  6. package/dist/cjs/data/format.js +136 -0
  7. package/dist/cjs/helpers/debounce.js +63 -0
  8. package/dist/cjs/{useLogger.js → helpers/getLogger.js} +96 -96
  9. package/dist/cjs/helpers/lonlat.js +99 -0
  10. package/dist/cjs/index.js +99 -76
  11. package/dist/cjs/lists/dedupe.js +54 -0
  12. package/dist/cjs/lists/flatten.js +66 -0
  13. package/dist/cjs/{_getByPath.js → lists/getByPath.js} +58 -37
  14. package/dist/cjs/lists/groupBy.js +49 -0
  15. package/dist/cjs/matchers/compare.js +70 -0
  16. package/dist/cjs/matchers/isEmpty.js +34 -0
  17. package/dist/cjs/matchers/isEqual.js +82 -0
  18. package/dist/cjs/matchers/nullChecks.js +61 -0
  19. package/dist/cjs/matchers/typeChecks.js +127 -0
  20. package/dist/cjs/strings/ascii.js +105 -0
  21. package/dist/cjs/strings/hash.js +75 -0
  22. package/dist/cjs/strings/interpolate.js +47 -0
  23. package/dist/cjs/strings/matchString.js +54 -0
  24. package/dist/cjs/strings/template.js +48 -0
  25. package/dist/cjs/strings/tokenize.js +83 -0
  26. package/dist/cjs/utils/mergeRefs.js +56 -0
  27. package/dist/esm/css/boundingBox.js +71 -0
  28. package/dist/esm/css/cn.js +39 -0
  29. package/dist/esm/css/imageColorset.js +96 -0
  30. package/dist/esm/data/countries.js +98 -0
  31. package/dist/esm/{_fileType.js → data/fileType.js} +37 -19
  32. package/dist/esm/data/format.js +138 -0
  33. package/dist/esm/helpers/debounce.js +63 -0
  34. package/dist/esm/{useLogger.js → helpers/getLogger.js} +96 -96
  35. package/dist/esm/helpers/lonlat.js +97 -0
  36. package/dist/esm/index.js +54 -36
  37. package/dist/esm/lists/dedupe.js +54 -0
  38. package/dist/esm/lists/flatten.js +65 -0
  39. package/dist/esm/{_getByPath.js → lists/getByPath.js} +50 -29
  40. package/dist/esm/lists/groupBy.js +49 -0
  41. package/dist/esm/matchers/compare.js +70 -0
  42. package/dist/esm/matchers/isEmpty.js +34 -0
  43. package/dist/esm/matchers/isEqual.js +82 -0
  44. package/dist/esm/matchers/nullChecks.js +58 -0
  45. package/dist/esm/matchers/typeChecks.js +119 -0
  46. package/dist/esm/strings/ascii.js +105 -0
  47. package/dist/esm/strings/hash.js +73 -0
  48. package/dist/esm/strings/interpolate.js +47 -0
  49. package/dist/esm/strings/matchString.js +54 -0
  50. package/dist/esm/strings/template.js +48 -0
  51. package/dist/esm/strings/tokenize.js +82 -0
  52. package/dist/esm/utils/mergeRefs.js +56 -0
  53. package/dist/types/css/boundingBox.d.ts +46 -0
  54. package/dist/types/css/cn.d.ts +26 -0
  55. package/dist/types/css/imageColorset.d.ts +37 -0
  56. package/dist/types/data/countries.d.ts +136 -0
  57. package/dist/types/{_fileType.d.ts → data/fileType.d.ts} +41 -1
  58. package/dist/types/data/format.d.ts +122 -0
  59. package/dist/types/helpers/debounce.d.ts +38 -0
  60. package/dist/types/helpers/getLogger.d.ts +49 -0
  61. package/dist/types/helpers/lonlat.d.ts +48 -0
  62. package/dist/types/index.d.ts +54 -20
  63. package/dist/types/lists/dedupe.d.ts +36 -0
  64. package/dist/types/lists/flatten.d.ts +47 -0
  65. package/dist/types/lists/getByPath.d.ts +45 -0
  66. package/dist/types/lists/groupBy.d.ts +36 -0
  67. package/dist/types/matchers/compare.d.ts +38 -0
  68. package/dist/types/matchers/isEmpty.d.ts +38 -0
  69. package/dist/types/matchers/isEqual.d.ts +39 -0
  70. package/dist/types/matchers/nullChecks.d.ts +43 -0
  71. package/dist/types/matchers/typeChecks.d.ts +107 -0
  72. package/dist/types/strings/ascii.d.ts +34 -0
  73. package/dist/types/strings/hash.d.ts +46 -0
  74. package/dist/types/strings/interpolate.d.ts +34 -0
  75. package/dist/types/strings/matchString.d.ts +41 -0
  76. package/dist/types/strings/template.d.ts +35 -0
  77. package/dist/types/strings/tokenize.d.ts +44 -0
  78. package/dist/types/utils/mergeRefs.d.ts +36 -0
  79. package/package.json +13 -11
  80. package/src/css/boundingBox.ts +80 -0
  81. package/src/css/cn.ts +32 -0
  82. package/src/css/imageColorset.ts +97 -0
  83. package/src/data/countries.ts +126 -0
  84. package/src/{_fileType.ts → data/fileType.ts} +72 -89
  85. package/src/data/format.ts +192 -0
  86. package/src/helpers/debounce.ts +49 -0
  87. package/src/{useLogger.ts → helpers/getLogger.ts} +52 -101
  88. package/src/helpers/lonlat.ts +124 -0
  89. package/src/index.ts +57 -37
  90. package/src/lists/dedupe.ts +46 -0
  91. package/src/lists/flatten.ts +56 -0
  92. package/src/lists/getByPath.ts +122 -0
  93. package/src/lists/groupBy.ts +47 -0
  94. package/src/matchers/compare.ts +64 -0
  95. package/src/matchers/isEmpty.ts +54 -0
  96. package/src/matchers/isEqual.ts +71 -0
  97. package/src/matchers/nullChecks.ts +55 -0
  98. package/src/matchers/typeChecks.ts +146 -0
  99. package/src/strings/ascii.ts +100 -0
  100. package/src/strings/hash.ts +68 -0
  101. package/src/strings/interpolate.ts +42 -0
  102. package/src/strings/matchString.ts +49 -0
  103. package/src/strings/template.ts +43 -0
  104. package/src/strings/tokenize.ts +77 -0
  105. package/src/utils/mergeRefs.ts +47 -0
  106. package/src/{yup.ts → utils/yup.ts} +3 -3
  107. package/dist/cjs/_ascii.js +0 -76
  108. package/dist/cjs/_boundingBox.js +0 -59
  109. package/dist/cjs/_countries.js +0 -2805
  110. package/dist/cjs/_debounce.js +0 -53
  111. package/dist/cjs/_dedupe.js +0 -63
  112. package/dist/cjs/_fetch.js +0 -128
  113. package/dist/cjs/_format.js +0 -118
  114. package/dist/cjs/_hash.js +0 -67
  115. package/dist/cjs/_interpolate.js +0 -47
  116. package/dist/cjs/_isEqual.js +0 -108
  117. package/dist/cjs/_isType.js +0 -98
  118. package/dist/cjs/_mergeRefs.js +0 -40
  119. package/dist/cjs/_tokenize.js +0 -67
  120. package/dist/cjs/getImageColorset.js +0 -70
  121. package/dist/esm/_ascii.js +0 -76
  122. package/dist/esm/_boundingBox.js +0 -58
  123. package/dist/esm/_countries.js +0 -2805
  124. package/dist/esm/_debounce.js +0 -53
  125. package/dist/esm/_dedupe.js +0 -60
  126. package/dist/esm/_fetch.js +0 -128
  127. package/dist/esm/_format.js +0 -120
  128. package/dist/esm/_hash.js +0 -65
  129. package/dist/esm/_interpolate.js +0 -46
  130. package/dist/esm/_isEqual.js +0 -106
  131. package/dist/esm/_isType.js +0 -85
  132. package/dist/esm/_mergeRefs.js +0 -40
  133. package/dist/esm/_tokenize.js +0 -66
  134. package/dist/esm/getImageColorset.js +0 -70
  135. package/dist/types/_ascii.d.ts +0 -5
  136. package/dist/types/_boundingBox.d.ts +0 -10
  137. package/dist/types/_countries.d.ts +0 -85
  138. package/dist/types/_debounce.d.ts +0 -8
  139. package/dist/types/_dedupe.d.ts +0 -4
  140. package/dist/types/_fetch.d.ts +0 -23
  141. package/dist/types/_format.d.ts +0 -27
  142. package/dist/types/_getByPath.d.ts +0 -10
  143. package/dist/types/_hash.d.ts +0 -16
  144. package/dist/types/_interpolate.d.ts +0 -6
  145. package/dist/types/_isEqual.d.ts +0 -15
  146. package/dist/types/_isType.d.ts +0 -14
  147. package/dist/types/_mergeRefs.d.ts +0 -1
  148. package/dist/types/_tokenize.d.ts +0 -8
  149. package/dist/types/getImageColorset.d.ts +0 -1
  150. package/dist/types/useLogger.d.ts +0 -25
  151. package/src/_ascii.ts +0 -93
  152. package/src/_boundingBox.ts +0 -72
  153. package/src/_countries.ts +0 -3046
  154. package/src/_debounce.ts +0 -42
  155. package/src/_dedupe.ts +0 -56
  156. package/src/_fetch.ts +0 -109
  157. package/src/_format.ts +0 -141
  158. package/src/_getByPath.ts +0 -108
  159. package/src/_hash.ts +0 -62
  160. package/src/_interpolate.ts +0 -42
  161. package/src/_isEqual.ts +0 -102
  162. package/src/_isType.ts +0 -105
  163. package/src/_mergeRefs.ts +0 -33
  164. package/src/_tokenize.ts +0 -69
  165. package/src/getImageColorset.ts +0 -81
  166. /package/dist/cjs/{yup.js → utils/yup.js} +0 -0
  167. /package/dist/esm/{yup.js → utils/yup.js} +0 -0
  168. /package/dist/types/{yup.d.ts → utils/yup.d.ts} +0 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Check if a value is undefined.
27
+ * @param value - The value to check.
28
+ * @returns true if the value is undefined, false otherwise.
29
+ */
30
+ export declare function isUndefined(value: AnyObject): value is undefined;
31
+ /**
32
+ * Check if a value is null.
33
+ * @param value - The value to check.
34
+ * @returns true if the value is null, false otherwise.
35
+ */
36
+ export declare function isNull(value: AnyObject): value is null;
37
+ /**
38
+ * Check if a value is either null or undefined.
39
+ * @param val - The value to check.
40
+ * @returns true if the value is null or undefined, false otherwise.
41
+ */
42
+ export declare function isNil(val: AnyObject): val is null | undefined;
43
+ export declare function isDefined(val: AnyObject): boolean;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Check if a value is an object.
27
+ * An object is considered valid if it is:
28
+ * - not null or undefined
29
+ * - not a Date instance
30
+ * - of type 'object'
31
+ * - not an array
32
+ * @param val - The value to check.
33
+ * @returns true if the value is an object, false otherwise.
34
+ */
35
+ export declare function isObject<T = KeyValue>(val: AnyObject): val is T;
36
+ /**
37
+ * Check if a value is an array.
38
+ * An array is considered valid if it is:
39
+ * - not null or undefined
40
+ * - an instance of Array
41
+ * @param val - The value to check.
42
+ * @returns true if the value is an array, false otherwise.
43
+ */
44
+ export declare function isArray<T = AnyObject>(val: AnyObject): val is T[];
45
+ /**
46
+ * Check if a value is a string.
47
+ * A string is considered valid if it is:
48
+ * - not null or undefined
49
+ * - of type 'string'
50
+ * @param value - The value to check.
51
+ * @returns true if the value is a string, false otherwise.
52
+ */
53
+ export declare function isString(value: AnyObject): value is string;
54
+ /**
55
+ * Check if a value is a number.
56
+ * A number is considered valid if it is:
57
+ * - not null or undefined
58
+ * - of type 'number'
59
+ * @param value - The value to check.
60
+ * @returns true if the value is a number, false otherwise.
61
+ */
62
+ export declare function isNumber(value: AnyObject): value is number;
63
+ /**
64
+ * Check if a value is a boolean.
65
+ * A boolean is considered valid if it is:
66
+ * - not null or undefined
67
+ * - of type 'boolean'
68
+ */
69
+ export declare function isBoolean(value: AnyObject): value is boolean;
70
+ /**
71
+ * Check if a value is a true.
72
+ * A value is considered true if it is:
73
+ * - strictly equal to true
74
+ * - equal to 1
75
+ * - a string that is "yes" or "true" (case insensitive)
76
+ */
77
+ export declare function isTrue(value?: unknown): value is true;
78
+ /**
79
+ * Check if a value is false.
80
+ * A value is considered false if it is:
81
+ * - strictly equal to false
82
+ * - equal to 0
83
+ * - a string that is "no" or "false" (case insensitive)
84
+ */
85
+ export declare function isFalse(value?: unknown): value is false;
86
+ /**
87
+ * Check if a value is a valid color.
88
+ * A color is considered valid if it:
89
+ * - starts with a '#' (hex color)
90
+ * - starts with 'rgb' (RGB color)
91
+ * - starts with 'hsl' (HSL color)
92
+ * - starts with 'lab' (Lab color)
93
+ * - is equal to 'transparent'
94
+ * @param color - The value to check.
95
+ * @returns true if the value is a valid color, false otherwise.
96
+ */
97
+ export declare function isColor(color: string): boolean;
98
+ /**
99
+ * Check if a value is a valid SVG path.
100
+ * A valid SVG path is a string that:
101
+ * - starts with 'M' or 'm' (move to command)
102
+ * - contains at least one digit or decimal point
103
+ * - ends with 'Z' or 'z' (close path command)
104
+ * @param value - The value to check.
105
+ * @returns true if the value is a valid SVG path, false otherwise.
106
+ */
107
+ export declare function isSvgPath(value: AnyObject): boolean;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Converts a string to its ASCII representation by replacing
27
+ * special characters with their ASCII equivalents.
28
+ * This function is useful for normalizing strings for search or display purposes.
29
+ * It replaces characters like "Ä" with "Ae", "ß" with "ss", etc.
30
+ *
31
+ * @param {string} str - The input string to be converted.
32
+ * @returns {string} - The ASCII representation of the input string.
33
+ */
34
+ export declare function ascii(str: string): string;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Generate a hash from a string.
27
+ * This function computes a simple hash by iterating over each character in the string,
28
+ * performing bitwise operations to produce a 32-bit integer hash.
29
+ * @param str
30
+ * @returns {number} A 32-bit integer hash of the input string.
31
+ */
32
+ export declare function hash(str: string): number;
33
+ /**
34
+ * Generate a short hash using the current timestamp and a random number.
35
+ * This function creates a unique identifier by combining the current time in milliseconds
36
+ * with a random number, and then converting it to a base-36 string.
37
+ * @returns {string} A short hash string.
38
+ */
39
+ export declare function shortHash(): string;
40
+ /**
41
+ * Generate a UUID (Universally Unique Identifier).
42
+ * This function creates a version 4 UUID by generating random numbers
43
+ * and formatting them according to the UUID standard.
44
+ * @returns {string} A UUID string in the format xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx.
45
+ */
46
+ export declare function uuid(): string;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Interpolate a string with values from a model.
27
+ * This function replaces placeholders in the format ${key} with corresponding values from the model object.
28
+ * If the value is not a string or number, it returns an empty string.
29
+ *
30
+ * @param {string} str - The string to interpolate.
31
+ * @param {KeyValue} model - The model object containing key-value pairs for interpolation.
32
+ * @returns {string} The interpolated string with placeholders replaced by values from the model.
33
+ */
34
+ export declare function interpolate(str: string, model: KeyValue): string;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Match a string against another string with options for equality.
27
+ * This function checks if the base string starts with, includes, or is equal to the match string,
28
+ * based on the specified equality condition.
29
+ * It normalizes both strings to lowercase and ASCII format before comparison.
30
+ * This is useful for case-insensitive and ASCII-only comparisons,
31
+ * such as when filtering or searching through text data.
32
+ *
33
+ * @param {string} base - The base string to match against.
34
+ * @param {string} match - The string to match with the base string.
35
+ * @param {("start" | boolean)} equality - The type of match to perform:
36
+ * - "start": checks if the base string starts with the match string.
37
+ * - true: checks for exact equality.
38
+ * - false (default): checks if the base string includes the match string.
39
+ * @returns {boolean} - Returns true if the base string matches the conditions specified by the match string and equality.
40
+ */
41
+ export declare function matchString(base: string, match: string, equality?: "start" | boolean): boolean;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Render a template string with values from a model.
27
+ * This function replaces placeholders in the format {{key}} with corresponding values from the model object.
28
+ * If the value is not a string or number, it returns an empty string.
29
+ * This is similar to the interpolate function but for handlebar templates.
30
+ *
31
+ * @param {string} str - The template string to render.
32
+ * @param {KeyValue} model - The model object containing key-value pairs for rendering the template.
33
+ * @returns {string} The rendered template string with placeholders replaced by values from the model.
34
+ */
35
+ export declare function renderTemplate(str: string, model: KeyValue): string;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Tokenize a string based on provided keywords.
27
+ * This function splits the input string into tokens, where each token is an array containing
28
+ * the substring before the keyword and the keyword itself.
29
+ * If no keywords are provided, it returns the entire string as a single token.
30
+ *
31
+ * @param {string} str - The string to tokenize.
32
+ * @param {string | string[]} keywords - A string or an array of strings to use as keywords for tokenization.
33
+ * @returns {Array<[string, string]>} An array of tokens, where each token is an array of [substring, keyword].
34
+ */
35
+ export declare function tokenize(str: string, keywords?: string | string[]): string[][];
36
+ /**
37
+ * Generate a token from a string.
38
+ * This function creates a token by taking the first letter of the first word and the first letter of the last word,
39
+ * or the first two letters of the first word if there is no last word.
40
+ *
41
+ * @param {string} str - The string to tokenize.
42
+ * @returns {string} A string token consisting of the first letters of the first and last words, or the first two letters of the first word.
43
+ */
44
+ export declare function iconToken(str: string): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ /**
26
+ * Merge multiple refs into a single ref callback.
27
+ * This function allows you to combine multiple refs (either callback refs or React refs)
28
+ * into a single ref callback that can be used in React components.
29
+ * This is particularly useful when you want to assign a single element to multiple refs,
30
+ * such as when using third-party libraries that require refs or when you want to share refs between components.
31
+ * The function iterates over the provided refs and assigns the element to each ref.
32
+ *
33
+ * @param {AnyObject[]} refs - An array of refs to merge.
34
+ * @returns {function} A function that takes an element and assigns it to all provided refs.
35
+ */
36
+ export declare function mergeRefs(...refs: unknown[]): (el: unknown) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/utilities",
3
- "version": "1.0.0-beta.8",
3
+ "version": "1.0.1",
4
4
  "description": "RUF: Utility package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -21,8 +21,6 @@
21
21
  "registry": "https://registry.npmjs.org/"
22
22
  },
23
23
  "scripts": {
24
- "makelink": "yarn link",
25
- "removelink": "yarn unlink",
26
24
  "prebuild": "rm -rf ./dist",
27
25
  "build:dts": "tsc -p ./tsconfig.build.json",
28
26
  "build:rollup": "rollup -c ../../rollup.config.mjs",
@@ -32,17 +30,21 @@
32
30
  "watch": "npm-run-all -p watch:rollup watch:dts"
33
31
  },
34
32
  "dependencies": {
35
- "date-fns": "^4.0.0",
36
- "libphonenumber-js": "^1.11.8",
37
- "numeral": "^2.0.6",
38
- "yup": "^1.4.0"
33
+ "chroma-js": "~3.2.0",
34
+ "clsx": "~2.1.1",
35
+ "date-fns": "~4.4.0",
36
+ "libphonenumber-js": "~1.13.10",
37
+ "numeral": "~2.0.6",
38
+ "tailwind-merge": "~3.6.0",
39
+ "world-countries": "~5.1.0",
40
+ "yup": "~1.7.1"
39
41
  },
40
42
  "devDependencies": {
41
- "@types/numeral": "^2.0.2"
43
+ "@types/numeral": "~2.0.5"
42
44
  },
43
45
  "engines": {
44
- "node": ">=18.12.0",
45
- "npm": ">=8.19.0"
46
+ "node": ">=24.0.0",
47
+ "npm": ">=11.0.0"
46
48
  },
47
- "gitHead": "9f1ede6e9629c9e79121354332cdebabad5878c5"
49
+ "gitHead": "1419a9df05b5e3850e1d2b4e896ab63df702c7e8"
48
50
  }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { isEmpty } from "../matchers/isEmpty";
27
+
28
+ function _getBox(box: string | [number, number, number, number]): [number, number, number, number] {
29
+ let boundingBox: [number, number, number, number];
30
+ if (isEmpty(box)) return [0, 0, 0, 0];
31
+ if (typeof box === "string") {
32
+ boundingBox = box.split(",").map((b: unknown) => parseInt(b as string, 10)) as [number, number, number, number];
33
+ } else {
34
+ boundingBox = box;
35
+ }
36
+ return boundingBox;
37
+ }
38
+
39
+ /**
40
+ * Get box dimensions from a string or array.
41
+ * The box can be in the format "x,y,w,h" or [x,y,w,h].
42
+ * The box is adjusted to ensure that x and y are non-negative.
43
+ * The width and height are adjusted accordingly.
44
+ *
45
+ * @param box "x,y,w,h" | [x,y,w,h]
46
+ * @returns canvas box [x,y,w,h]
47
+ */
48
+ export function getBox(box: string | [number, number, number, number] = "0,0,0,0") {
49
+ const boundingBox = _getBox(box);
50
+
51
+ let [x, y, w, h] = boundingBox;
52
+ w = x < 0 ? w + x : w;
53
+ h = y < 0 ? h + y : h;
54
+ x = x > 0 ? x : 0;
55
+ y = y > 0 ? y : 0;
56
+ return [x, y, w, h] as [number, number, number, number];
57
+ }
58
+
59
+ /**
60
+ * Get bounding box dimensions from a string or array.
61
+ * The box can be in the format "x1,y1,x2,y2" or [x1,y1,x2,y2].
62
+ * The box is adjusted to ensure that x1 and y1 are non-negative.
63
+ * The width and height are calculated as x2 - x1 and y2 - y1 respectively.
64
+ * If x1 or y1 are negative, they are set to 0 and the width and height are adjusted accordingly.
65
+ * This is useful for ensuring that the bounding box is always within the canvas area.
66
+ *
67
+ * @param box "x1,y1,x2,y2" | [x1,y1,x2,y2]
68
+ * @returns canvas box [x,y,w,h]
69
+ */
70
+ export function getBoundingBox(box: string | [number, number, number, number] = "0,0,0,0") {
71
+ const boundingBox = _getBox(box);
72
+
73
+ // eslint-disable-next-line prefer-const
74
+ let [x1, y1, x2, y2] = boundingBox;
75
+ const w = x2 - x1;
76
+ const h = y2 - y1;
77
+ x1 = x1 > 0 ? x1 : 0;
78
+ y1 = y1 > 0 ? y1 : 0;
79
+ return [x1, y1, w, h] as [number, number, number, number];
80
+ }
package/src/css/cn.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { clsx, type ClassValue } from "clsx";
27
+ import { twMerge } from "tailwind-merge";
28
+
29
+ export const cn = (...classes: ClassValue[]): string => {
30
+ // test
31
+ return twMerge(clsx(classes));
32
+ };