@bitfiber/utils 1.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 (302) hide show
  1. package/CODE_OF_CONDUCT.md +127 -0
  2. package/CONTRIBUTING.md +87 -0
  3. package/LICENSE.txt +201 -0
  4. package/README.md +2516 -0
  5. package/arr/at/at.d.ts +7 -0
  6. package/arr/at/at.js +11 -0
  7. package/arr/at/at.js.map +1 -0
  8. package/arr/cnd/cnd.d.ts +55 -0
  9. package/arr/cnd/cnd.js +136 -0
  10. package/arr/cnd/cnd.js.map +1 -0
  11. package/arr/diff-arr/diff-arr.d.ts +10 -0
  12. package/arr/diff-arr/diff-arr.js +37 -0
  13. package/arr/diff-arr/diff-arr.js.map +1 -0
  14. package/arr/fill/fill.d.ts +8 -0
  15. package/arr/fill/fill.js +11 -0
  16. package/arr/fill/fill.js.map +1 -0
  17. package/arr/for-each-arr/for-each-arr.d.ts +9 -0
  18. package/arr/for-each-arr/for-each-arr.js +25 -0
  19. package/arr/for-each-arr/for-each-arr.js.map +1 -0
  20. package/arr/index-by/index-by.d.ts +9 -0
  21. package/arr/index-by/index-by.js +19 -0
  22. package/arr/index-by/index-by.js.map +1 -0
  23. package/arr/index.d.ts +9 -0
  24. package/arr/index.js +10 -0
  25. package/arr/index.js.map +1 -0
  26. package/arr/pluck/pluck.d.ts +7 -0
  27. package/arr/pluck/pluck.js +13 -0
  28. package/arr/pluck/pluck.js.map +1 -0
  29. package/arr/types.d.ts +84 -0
  30. package/arr/types.js +2 -0
  31. package/arr/types.js.map +1 -0
  32. package/arr/within/within.d.ts +9 -0
  33. package/arr/within/within.js +14 -0
  34. package/arr/within/within.js.map +1 -0
  35. package/common/copy/copy.d.ts +6 -0
  36. package/common/copy/copy.js +86 -0
  37. package/common/copy/copy.js.map +1 -0
  38. package/common/equals/equals.d.ts +12 -0
  39. package/common/equals/equals.js +127 -0
  40. package/common/equals/equals.js.map +1 -0
  41. package/common/error.d.ts +19 -0
  42. package/common/error.js +16 -0
  43. package/common/error.js.map +1 -0
  44. package/common/for-each/for-each.d.ts +9 -0
  45. package/common/for-each/for-each.js +40 -0
  46. package/common/for-each/for-each.js.map +1 -0
  47. package/common/get-unique-num-id/get-unique-num-id.d.ts +4 -0
  48. package/common/get-unique-num-id/get-unique-num-id.js +8 -0
  49. package/common/get-unique-num-id/get-unique-num-id.js.map +1 -0
  50. package/common/get-unique-str-id/get-unique-str-id.d.ts +4 -0
  51. package/common/get-unique-str-id/get-unique-str-id.js +16 -0
  52. package/common/get-unique-str-id/get-unique-str-id.js.map +1 -0
  53. package/common/has-iterator/has-iterator.d.ts +5 -0
  54. package/common/has-iterator/has-iterator.js +8 -0
  55. package/common/has-iterator/has-iterator.js.map +1 -0
  56. package/common/index.d.ts +16 -0
  57. package/common/index.js +17 -0
  58. package/common/index.js.map +1 -0
  59. package/common/is/is.d.ts +136 -0
  60. package/common/is/is.js +214 -0
  61. package/common/is/is.js.map +1 -0
  62. package/common/is-empty/is-empty.d.ts +6 -0
  63. package/common/is-empty/is-empty.js +30 -0
  64. package/common/is-empty/is-empty.js.map +1 -0
  65. package/common/random/random.d.ts +5 -0
  66. package/common/random/random.js +9 -0
  67. package/common/random/random.js.map +1 -0
  68. package/common/same/same.d.ts +6 -0
  69. package/common/same/same.js +9 -0
  70. package/common/same/same.js.map +1 -0
  71. package/common/stub/stub.d.ts +4 -0
  72. package/common/stub/stub.js +8 -0
  73. package/common/stub/stub.js.map +1 -0
  74. package/common/to-float/to-float.d.ts +6 -0
  75. package/common/to-float/to-float.js +10 -0
  76. package/common/to-float/to-float.js.map +1 -0
  77. package/common/to-int/to-int.d.ts +6 -0
  78. package/common/to-int/to-int.js +10 -0
  79. package/common/to-int/to-int.js.map +1 -0
  80. package/common/to-sorted-string/to-sorted-string.d.ts +7 -0
  81. package/common/to-sorted-string/to-sorted-string.js +53 -0
  82. package/common/to-sorted-string/to-sorted-string.js.map +1 -0
  83. package/common/types.d.ts +63 -0
  84. package/common/types.js +5 -0
  85. package/common/types.js.map +1 -0
  86. package/dom/closest/closest.d.ts +6 -0
  87. package/dom/closest/closest.js +26 -0
  88. package/dom/closest/closest.js.map +1 -0
  89. package/dom/document/document.d.ts +12 -0
  90. package/dom/document/document.js +24 -0
  91. package/dom/document/document.js.map +1 -0
  92. package/dom/download-file/download-file.d.ts +6 -0
  93. package/dom/download-file/download-file.js +32 -0
  94. package/dom/download-file/download-file.js.map +1 -0
  95. package/dom/for-each-elements/for-each-elements.d.ts +8 -0
  96. package/dom/for-each-elements/for-each-elements.js +16 -0
  97. package/dom/for-each-elements/for-each-elements.js.map +1 -0
  98. package/dom/for-each-nodes/for-each-nodes.d.ts +7 -0
  99. package/dom/for-each-nodes/for-each-nodes.js +15 -0
  100. package/dom/for-each-nodes/for-each-nodes.js.map +1 -0
  101. package/dom/get-all-styles/get-all-styles.d.ts +5 -0
  102. package/dom/get-all-styles/get-all-styles.js +10 -0
  103. package/dom/get-all-styles/get-all-styles.js.map +1 -0
  104. package/dom/get-body/get-body.d.ts +4 -0
  105. package/dom/get-body/get-body.js +9 -0
  106. package/dom/get-body/get-body.js.map +1 -0
  107. package/dom/get-html/get-html.d.ts +4 -0
  108. package/dom/get-html/get-html.js +9 -0
  109. package/dom/get-html/get-html.js.map +1 -0
  110. package/dom/get-non-static-parent/get-non-static-parent.d.ts +5 -0
  111. package/dom/get-non-static-parent/get-non-static-parent.js +9 -0
  112. package/dom/get-non-static-parent/get-non-static-parent.js.map +1 -0
  113. package/dom/get-offset-from-doc/get-offset-from-doc.d.ts +6 -0
  114. package/dom/get-offset-from-doc/get-offset-from-doc.js +18 -0
  115. package/dom/get-offset-from-doc/get-offset-from-doc.js.map +1 -0
  116. package/dom/get-offset-from-parent/get-offset-from-parent.d.ts +7 -0
  117. package/dom/get-offset-from-parent/get-offset-from-parent.js +45 -0
  118. package/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -0
  119. package/dom/get-offset-from-win/get-offset-from-win.d.ts +6 -0
  120. package/dom/get-offset-from-win/get-offset-from-win.js +8 -0
  121. package/dom/get-offset-from-win/get-offset-from-win.js.map +1 -0
  122. package/dom/get-scroll-width/get-scroll-width.d.ts +8 -0
  123. package/dom/get-scroll-width/get-scroll-width.js +28 -0
  124. package/dom/get-scroll-width/get-scroll-width.js.map +1 -0
  125. package/dom/get-style/get-style.d.ts +6 -0
  126. package/dom/get-style/get-style.js +23 -0
  127. package/dom/get-style/get-style.js.map +1 -0
  128. package/dom/get-styles/get-styles.d.ts +9 -0
  129. package/dom/get-styles/get-styles.js +12 -0
  130. package/dom/get-styles/get-styles.js.map +1 -0
  131. package/dom/get-valid-style-name/get-valid-style-name.d.ts +6 -0
  132. package/dom/get-valid-style-name/get-valid-style-name.js +41 -0
  133. package/dom/get-valid-style-name/get-valid-style-name.js.map +1 -0
  134. package/dom/get-window/get-window.d.ts +4 -0
  135. package/dom/get-window/get-window.js +17 -0
  136. package/dom/get-window/get-window.js.map +1 -0
  137. package/dom/has-name/has-name.d.ts +6 -0
  138. package/dom/has-name/has-name.js +9 -0
  139. package/dom/has-name/has-name.js.map +1 -0
  140. package/dom/index.d.ts +25 -0
  141. package/dom/index.js +26 -0
  142. package/dom/index.js.map +1 -0
  143. package/dom/is-comment/is-comment.d.ts +5 -0
  144. package/dom/is-comment/is-comment.js +8 -0
  145. package/dom/is-comment/is-comment.js.map +1 -0
  146. package/dom/is-element/is-element.d.ts +5 -0
  147. package/dom/is-element/is-element.js +8 -0
  148. package/dom/is-element/is-element.js.map +1 -0
  149. package/dom/is-text/is-text.d.ts +5 -0
  150. package/dom/is-text/is-text.js +8 -0
  151. package/dom/is-text/is-text.js.map +1 -0
  152. package/dom/set-offset-from-parent/set-offset-from-parent.d.ts +8 -0
  153. package/dom/set-offset-from-parent/set-offset-from-parent.js +42 -0
  154. package/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -0
  155. package/dom/set-style/set-style.d.ts +8 -0
  156. package/dom/set-style/set-style.js +14 -0
  157. package/dom/set-style/set-style.js.map +1 -0
  158. package/dom/set-styles/set-styles.d.ts +8 -0
  159. package/dom/set-styles/set-styles.js +16 -0
  160. package/dom/set-styles/set-styles.js.map +1 -0
  161. package/dom/types.d.ts +19 -0
  162. package/dom/types.js +2 -0
  163. package/dom/types.js.map +1 -0
  164. package/env/get-browser/get-browser.d.ts +10 -0
  165. package/env/get-browser/get-browser.js +33 -0
  166. package/env/get-browser/get-browser.js.map +1 -0
  167. package/env/get-engine/get-engine.d.ts +7 -0
  168. package/env/get-engine/get-engine.js +22 -0
  169. package/env/get-engine/get-engine.js.map +1 -0
  170. package/env/get-os/get-os.d.ts +8 -0
  171. package/env/get-os/get-os.js +26 -0
  172. package/env/get-os/get-os.js.map +1 -0
  173. package/env/get-platform/get-platform.d.ts +7 -0
  174. package/env/get-platform/get-platform.js +30 -0
  175. package/env/get-platform/get-platform.js.map +1 -0
  176. package/env/index.d.ts +21 -0
  177. package/env/index.js +22 -0
  178. package/env/index.js.map +1 -0
  179. package/env/is-browser/is-browser.d.ts +11 -0
  180. package/env/is-browser/is-browser.js +15 -0
  181. package/env/is-browser/is-browser.js.map +1 -0
  182. package/env/is-chrome-like/is-chrome-like.d.ts +4 -0
  183. package/env/is-chrome-like/is-chrome-like.js +9 -0
  184. package/env/is-chrome-like/is-chrome-like.js.map +1 -0
  185. package/env/is-desktop/is-desktop.d.ts +4 -0
  186. package/env/is-desktop/is-desktop.js +9 -0
  187. package/env/is-desktop/is-desktop.js.map +1 -0
  188. package/env/is-engine/is-engine.d.ts +8 -0
  189. package/env/is-engine/is-engine.js +12 -0
  190. package/env/is-engine/is-engine.js.map +1 -0
  191. package/env/is-firefox-like/is-firefox-like.d.ts +4 -0
  192. package/env/is-firefox-like/is-firefox-like.js +9 -0
  193. package/env/is-firefox-like/is-firefox-like.js.map +1 -0
  194. package/env/is-mobile/is-mobile.d.ts +4 -0
  195. package/env/is-mobile/is-mobile.js +9 -0
  196. package/env/is-mobile/is-mobile.js.map +1 -0
  197. package/env/is-os/is-os.d.ts +9 -0
  198. package/env/is-os/is-os.js +13 -0
  199. package/env/is-os/is-os.js.map +1 -0
  200. package/env/is-portable/is-portable.d.ts +4 -0
  201. package/env/is-portable/is-portable.js +8 -0
  202. package/env/is-portable/is-portable.js.map +1 -0
  203. package/env/is-safari-like/is-safari-like.d.ts +4 -0
  204. package/env/is-safari-like/is-safari-like.js +9 -0
  205. package/env/is-safari-like/is-safari-like.js.map +1 -0
  206. package/env/is-stationary/is-stationary.d.ts +4 -0
  207. package/env/is-stationary/is-stationary.js +8 -0
  208. package/env/is-stationary/is-stationary.js.map +1 -0
  209. package/env/is-tablet/is-tablet.d.ts +4 -0
  210. package/env/is-tablet/is-tablet.js +9 -0
  211. package/env/is-tablet/is-tablet.js.map +1 -0
  212. package/env/is-tv/is-tv.d.ts +4 -0
  213. package/env/is-tv/is-tv.js +9 -0
  214. package/env/is-tv/is-tv.js.map +1 -0
  215. package/env/matches/matches.d.ts +34 -0
  216. package/env/matches/matches.js +52 -0
  217. package/env/matches/matches.js.map +1 -0
  218. package/env/matches-with-browsers/matches-with-browsers.d.ts +23 -0
  219. package/env/matches-with-browsers/matches-with-browsers.js +53 -0
  220. package/env/matches-with-browsers/matches-with-browsers.js.map +1 -0
  221. package/env/matches-with-version/matches-with-version.d.ts +6 -0
  222. package/env/matches-with-version/matches-with-version.js +41 -0
  223. package/env/matches-with-version/matches-with-version.js.map +1 -0
  224. package/env/private/private.d.ts +4 -0
  225. package/env/private/private.js +67 -0
  226. package/env/private/private.js.map +1 -0
  227. package/env/types.d.ts +106 -0
  228. package/env/types.js +2 -0
  229. package/env/types.js.map +1 -0
  230. package/env/user-agent/user-agent.d.ts +9 -0
  231. package/env/user-agent/user-agent.js +24 -0
  232. package/env/user-agent/user-agent.js.map +1 -0
  233. package/index.d.ts +1 -0
  234. package/index.js +2 -0
  235. package/index.js.map +1 -0
  236. package/num/in-range/in-range.d.ts +8 -0
  237. package/num/in-range/in-range.js +23 -0
  238. package/num/in-range/in-range.js.map +1 -0
  239. package/num/index.d.ts +3 -0
  240. package/num/index.js +4 -0
  241. package/num/index.js.map +1 -0
  242. package/num/round/round.d.ts +7 -0
  243. package/num/round/round.js +11 -0
  244. package/num/round/round.js.map +1 -0
  245. package/num/types.d.ts +24 -0
  246. package/num/types.js +2 -0
  247. package/num/types.js.map +1 -0
  248. package/obj/constant/constant.d.ts +6 -0
  249. package/obj/constant/constant.js +8 -0
  250. package/obj/constant/constant.js.map +1 -0
  251. package/obj/deep-constant/deep-constant.d.ts +6 -0
  252. package/obj/deep-constant/deep-constant.js +18 -0
  253. package/obj/deep-constant/deep-constant.js.map +1 -0
  254. package/obj/diff-obj/diff-obj.d.ts +9 -0
  255. package/obj/diff-obj/diff-obj.js +48 -0
  256. package/obj/diff-obj/diff-obj.js.map +1 -0
  257. package/obj/exclude/exclude.d.ts +7 -0
  258. package/obj/exclude/exclude.js +18 -0
  259. package/obj/exclude/exclude.js.map +1 -0
  260. package/obj/extend/extend.d.ts +16 -0
  261. package/obj/extend/extend.js +49 -0
  262. package/obj/extend/extend.js.map +1 -0
  263. package/obj/for-each-obj/for-each-obj.d.ts +8 -0
  264. package/obj/for-each-obj/for-each-obj.js +16 -0
  265. package/obj/for-each-obj/for-each-obj.js.map +1 -0
  266. package/obj/has-own/has-own.d.ts +8 -0
  267. package/obj/has-own/has-own.js +11 -0
  268. package/obj/has-own/has-own.js.map +1 -0
  269. package/obj/include/include.d.ts +7 -0
  270. package/obj/include/include.js +17 -0
  271. package/obj/include/include.js.map +1 -0
  272. package/obj/index.d.ts +13 -0
  273. package/obj/index.js +14 -0
  274. package/obj/index.js.map +1 -0
  275. package/obj/keys/keys.d.ts +6 -0
  276. package/obj/keys/keys.js +8 -0
  277. package/obj/keys/keys.js.map +1 -0
  278. package/obj/map-obj/map-obj.d.ts +7 -0
  279. package/obj/map-obj/map-obj.js +12 -0
  280. package/obj/map-obj/map-obj.js.map +1 -0
  281. package/obj/map-obj-to-arr/map-obj-to-arr.d.ts +7 -0
  282. package/obj/map-obj-to-arr/map-obj-to-arr.js +12 -0
  283. package/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -0
  284. package/obj/types.d.ts +30 -0
  285. package/obj/types.js +2 -0
  286. package/obj/types.js.map +1 -0
  287. package/obj/values/values.d.ts +6 -0
  288. package/obj/values/values.js +11 -0
  289. package/obj/values/values.js.map +1 -0
  290. package/package.json +73 -0
  291. package/str/index.d.ts +3 -0
  292. package/str/index.js +4 -0
  293. package/str/index.js.map +1 -0
  294. package/str/to-camel-case/to-camel-case.d.ts +10 -0
  295. package/str/to-camel-case/to-camel-case.js +18 -0
  296. package/str/to-camel-case/to-camel-case.js.map +1 -0
  297. package/str/to-hash/to-hash.d.ts +7 -0
  298. package/str/to-hash/to-hash.js +21 -0
  299. package/str/to-hash/to-hash.js.map +1 -0
  300. package/str/with-capital/with-capital.d.ts +6 -0
  301. package/str/with-capital/with-capital.js +9 -0
  302. package/str/with-capital/with-capital.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,2516 @@
1
+ # @bitfiber/utils
2
+
3
+ [![Release Notes](https://img.shields.io/github/release/bitfiber/utils)](https://github.com/bitfiber/utils/releases)
4
+ [![GitHub star chart](https://img.shields.io/github/stars/bitfiber/utils?style=social)](https://star-history.com/#bitfiber/utils)
5
+ [![GitHub fork](https://img.shields.io/github/forks/bitfiber/utils?style=social)](https://github.com/bitfiber/utils/fork)
6
+
7
+ The "@bitfiber/utils" library is a collection of versatile utility functions designed to streamline common tasks and
8
+ enhance the development experience in JavaScript. With a focus on simplicity and reusability, this library provides a
9
+ range of functions that cover various aspects of programming, making it a valuable resource for developers across
10
+ different projects and domains.
11
+
12
+ ---
13
+
14
+ ## Key Features
15
+
16
+ 1. **Strict Typing:** The library leverages TypeScript to enforce strict typing, ensuring robust type checking at
17
+ compile time. This reduces the likelihood of runtime errors and enhances code reliability. TypeScript's type
18
+ inference capabilities also aid in writing cleaner and more maintainable code.
19
+
20
+ 2. **Tree Shaking:** The library's modular design enables tree shaking, allowing developers to optimize bundle sizes by
21
+ selectively importing only the necessary functionalities. This eliminates unused code, resulting in smaller and more
22
+ efficient applications.
23
+
24
+ 3. **Common Use Cases:**
25
+ * Common Functions: Additional general-purpose utilities for tasks such as type checking, and more.
26
+ * String Manipulation: Functions for capitalizing strings, converting case, and more.
27
+ * Working with Numbers: Functions for numerical operations, such as rounding, formatting, converting, and more.
28
+ * Array Operations: Helper functions for working with arrays, such as comparison, traversal, mapping, and more.
29
+ * Object Operations: Utilities for working with objects, including functions for merging objects, deep cloning,
30
+ property access, and more.
31
+ * DOM Manipulation: Utilities for interacting with the Document Object Model (DOM), including functions for style
32
+ manipulation, traversal, and more.
33
+ * Environment Handling: Functions for utilizing User Agent information for tailored content delivery and feature
34
+ adaptation.
35
+
36
+ ---
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ # NPM
42
+ npm install @bitfiber/utils
43
+
44
+ # YARN
45
+ yarn add @bitfiber/utils
46
+ ```
47
+
48
+ ---
49
+
50
+ ## Contributing
51
+
52
+ We welcome contributions from the community. Before contributing, please take the time to read
53
+ our [contributing guide](https://github.com/bitfiber/utils/blob/main/CONTRIBUTING.md) to familiarize yourself with our
54
+ contribution process.
55
+ This guide can help you understand our expectations and save you time in the long run.
56
+
57
+ ---
58
+
59
+ ## Support
60
+
61
+ Have questions, encountered problems, or want to request new features?
62
+ Feel free to start a [discussion in our community forum](https://github.com/bitfiber/utils/discussions).
63
+ Your feedback is valuable to us!
64
+
65
+ ---
66
+
67
+ ## Found an Issue or Bug?
68
+
69
+ If you've found a bug or issue, please report it using [GitHub Issues](https://github.com/bitfiber/utils/issues).
70
+ Your reports help us improve the project for everyone.
71
+
72
+ ---
73
+
74
+ ## Code of Conduct
75
+
76
+ This project adheres to the [Code of Conduct](https://github.com/bitfiber/utils/blob/main/CODE_OF_CONDUCT.md) to ensure
77
+ a welcoming and inclusive community for all participants.
78
+ By participating, you are expected to uphold this code.
79
+
80
+ ---
81
+
82
+ ## License
83
+
84
+ This project is released under the Apache 2.0 License.
85
+ You can find the full text of the license in the [LICENSE](https://github.com/bitfiber/utils/blob/main/LICENSE.txt)
86
+ file.
87
+ Copyright © 2023-2024 Zmanovskyi Oleksandr. All rights reserved.
88
+
89
+ ---
90
+
91
+ ## Table of Contents
92
+
93
+ ### Common functions
94
+
95
+ * [`copy`](#copy)
96
+ * [`equals`](#equals)
97
+ * [`forEach`](#forEach)
98
+ * [`getUniqueNumId`](#getUniqueNumId)
99
+ * [`getUniqueStrId`](#getUniqueStrId)
100
+ * [`hasIterator`](#hasIterator)
101
+ * [`isNull`](#isNull)
102
+ * [`isUndefined`](#isUndefined)
103
+ * [`isDefined`](#isDefined)
104
+ * [`isNullish`](#isNullish)
105
+ * [`isNaN`](#isNaN)
106
+ * [`isString`](#isString)
107
+ * [`isNumber`](#isNumber)
108
+ * [`isBigInt`](#isBigInt)
109
+ * [`isBoolean`](#isBoolean)
110
+ * [`isSymbol`](#isSymbol)
111
+ * [`isFunction`](#isFunction)
112
+ * [`isObject`](#isObject)
113
+ * [`isArray`](#isArray)
114
+ * [`isSet`](#isSet)
115
+ * [`isMap`](#isMap)
116
+ * [`isDate`](#isDate)
117
+ * [`isRegExp`](#isRegExp)
118
+ * [`isFile`](#isFile)
119
+ * [`isBlob`](#isBlob)
120
+ * [`isFormData`](#isFormData)
121
+ * [`isArrayBuffer`](#isArrayBuffer)
122
+ * [`isDocument`](#isDocument)
123
+ * [`isWindow`](#isWindow)
124
+ * [`isPromise`](#isPromise)
125
+ * [`isObservable`](#isObservable)
126
+ * [`isTypedArray`](#isTypedArray)
127
+ * [`isUsualObject`](#isUsualObject)
128
+ * [`isEmpty`](#isEmpty)
129
+ * [`random`](#random)
130
+ * [`same`](#same)
131
+ * [`stub`](#stub)
132
+ * [`toFloat`](#toFloat)
133
+ * [`toInt`](#toInt)
134
+ * [`toSortedString`](#toSortedString)
135
+
136
+ ### Functions for working with objects
137
+
138
+ * [`constant`](#constant)
139
+ * [`deepConstant`](#deepConstant)
140
+ * [`diffObj`](#diffObj)
141
+ * [`exclude`](#exclude)
142
+ * [`extend`](#extend)
143
+ * [`extendAll`](#extendAll)
144
+ * [`forEachObj`](#forEachObj)
145
+ * [`hasOwn`](#hasOwn)
146
+ * [`include`](#include)
147
+ * [`keys`](#keys)
148
+ * [`mapObj`](#mapObj)
149
+ * [`mapObjToArr`](#mapObjToArr)
150
+ * [`values`](#values)
151
+
152
+ ### Functions for working with arrays
153
+
154
+ * [`at`](#at)
155
+ * [`cnd`](#cnd)
156
+ * [`diffArr`](#diffArr)
157
+ * [`fill`](#fill)
158
+ * [`forEachArr`](#forEachArr)
159
+ * [`indexBy`](#indexBy)
160
+ * [`pluck`](#pluck)
161
+ * [`within`](#within)
162
+
163
+ ### Functions for working with strings
164
+
165
+ * [`toCamelCase`](#toCamelCase)
166
+ * [`toHash`](#toHash)
167
+ * [`withCapital`](#withCapital)
168
+
169
+ ### Functions for working with numbers
170
+
171
+ * [`inRange`](#inRange)
172
+ * [`round`](#round)
173
+
174
+ ### Functions for working with DOM
175
+
176
+ * [`closest`](#closest)
177
+ * [`getDocument`](#getDocument)
178
+ * [`setDocument`](#setDocument)
179
+ * [`downloadFile`](#downloadFile)
180
+ * [`forEachElements`](#forEachElements)
181
+ * [`forEachNodes`](#forEachNodes)
182
+ * [`getAllStyles`](#getAllStyles)
183
+ * [`getBody`](#getBody)
184
+ * [`getHtml`](#getHtml)
185
+ * [`getNonStaticParent`](#getNonStaticParent)
186
+ * [`getOffsetFromDoc`](#getOffsetFromDoc)
187
+ * [`getOffsetFromParent`](#getOffsetFromParent)
188
+ * [`getOffsetFromWin`](#getOffsetFromWin)
189
+ * [`getScrollWidth`](#getScrollWidth)
190
+ * [`getStyle`](#getStyle)
191
+ * [`getStyles`](#getStyles)
192
+ * [`getValidStyleName`](#getValidStyleName)
193
+ * [`getWindow`](#getWindow)
194
+ * [`hasName`](#hasName)
195
+ * [`isComment`](#isComment)
196
+ * [`isElement`](#isElement)
197
+ * [`isText`](#isText)
198
+ * [`setOffsetFromParent`](#setOffsetFromParent)
199
+ * [`setStyle`](#setStyle)
200
+ * [`setStyles`](#setStyles)
201
+
202
+ ### Functions for working with environment
203
+
204
+ * [`getBrowser`](#getBrowser)
205
+ * [`getEngine`](#getEngine)
206
+ * [`getOS`](#getOS)
207
+ * [`getPlatform`](#getPlatform)
208
+ * [`isBrowser`](#isBrowser)
209
+ * [`isChromeLike`](#isChromeLike)
210
+ * [`isDesktop`](#isDesktop)
211
+ * [`isEngine`](#isEngine)
212
+ * [`isFirefoxLike`](#isFirefoxLike)
213
+ * [`isMobile`](#isMobile)
214
+ * [`isOS`](#isOS)
215
+ * [`isPortable`](#isPortable)
216
+ * [`isSafariLike`](#isSafariLike)
217
+ * [`isStationary`](#isStationary)
218
+ * [`isTablet`](#isTablet)
219
+ * [`isTV`](#isTV)
220
+ * [`matches`](#matches)
221
+ * [`matchesWithBrowsers`](#matchesWithBrowsers)
222
+ * [`matchesWithVersion`](#matchesWithVersion)
223
+ * [`getUserAgent`](#getUserAgent)
224
+ * [`setUserAgent`](#setUserAgent)
225
+
226
+ ---
227
+
228
+ ## Common functions
229
+
230
+ ---
231
+
232
+ ### `copy`
233
+
234
+ Creates a deep copy of a value of any type
235
+ Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
236
+ `<T>`
237
+ `@param value: T`
238
+ `@returns T`
239
+
240
+ **Example:**
241
+
242
+ ```ts
243
+ import {copy} from '@bitfiber/utils';
244
+
245
+ copy({foo: [{bar: 'str'}]}); // result: {foo: [{bar: 'str'}]}
246
+ ```
247
+
248
+ ---
249
+
250
+ ### `equals`
251
+
252
+ Determines whether two values are equal.
253
+ The comparison is performed to the full depth of nesting.
254
+ Objects are equal if they have the same fields with equal values.
255
+ Arrays and sets are equal if they have the same length and equal values in the same order.
256
+ Maps are equal if they have the same keys with equal values.
257
+ Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
258
+ `@param value1: any`
259
+ `@param value2: any`
260
+ `@param sortFn?: (a: any, b: any) => number): boolean` - if added, arrays and sets will be sorted before comparison
261
+ `@returns boolean`
262
+
263
+ **Example:**
264
+
265
+ ```ts
266
+ import {equals} from '@bitfiber/utils';
267
+
268
+ equals({foo: [{bar: 'str1'}]}, {foo: [{bar: 'str1'}]}); // true
269
+ equals({foo: [{bar: 'str1'}]}, {foo: [{bar: 'str2'}]}); // false
270
+ ```
271
+
272
+ ---
273
+
274
+ ### `forEach`
275
+
276
+ Iterates through all the items of any iterable object and calls a handler for each item.
277
+ If the handler returns INTERRUPT, the loop will be interrupted
278
+ `@param obj: any` - any iterable object
279
+ `@param handler: handler: (value: any, key: NumStr, obj: any) => any` - function called for each item
280
+ `@param reverse?: boolean` - iterates in reverse order if true
281
+ `@returns void`
282
+
283
+ **Example:**
284
+
285
+ ```ts
286
+ import {forEach, INTERRUPT} from '@bitfiber/utils';
287
+
288
+ forEach(new Set([1, 2, 3]), (item, i) => console.log(item), true); // 3 -> 2 -> 1
289
+ forEach(new Map([[1, 1], [2, 2], [3, 3]]), (item, i) => (item === 2 ? INTERRUPT : console.log(item))); // 1
290
+ ```
291
+
292
+ ---
293
+
294
+ ### `getUniqueNumId`
295
+
296
+ Returns a unique number identifier for the current session
297
+ `@returns number`
298
+
299
+ **Example:**
300
+
301
+ ```ts
302
+ import {getUniqueNumId} from '@bitfiber/utils';
303
+
304
+ getUniqueNumId(); // 11115
305
+ getUniqueNumId(); // 11116
306
+ ```
307
+
308
+ ---
309
+
310
+ ### `getUniqueStrId`
311
+
312
+ Returns a unique string identifier for the current session
313
+ `@returns string`
314
+
315
+ **Example:**
316
+
317
+ ```ts
318
+ import {getUniqueStrId} from '@bitfiber/utils';
319
+
320
+ getUniqueStrId(); // '11115'
321
+ getUniqueStrId(); // '11116'
322
+ ```
323
+
324
+ ---
325
+
326
+ ### `hasIterator`
327
+
328
+ Returns true if the value has an iterator, otherwise false
329
+ `@param value: any`
330
+ `@returns boolean`
331
+
332
+ **Example:**
333
+
334
+ ```ts
335
+ import {hasIterator} from '@bitfiber/utils';
336
+
337
+ hasIterator([]); // true
338
+ hasIterator(true); // false
339
+ ```
340
+
341
+ ---
342
+
343
+ ### `isNull`
344
+
345
+ Returns true if the value is null, otherwise false
346
+ `@param value: any`
347
+ `@returns value is null (boolean)`
348
+
349
+ **Example:**
350
+
351
+ ```ts
352
+ import {isNull} from '@bitfiber/utils';
353
+
354
+ isNull(null); // true
355
+ isNull(7); // false
356
+ ```
357
+
358
+ ---
359
+
360
+ ### `isUndefined`
361
+
362
+ Returns true if the value is undefined, otherwise false
363
+ `@param value: any`
364
+ `@returns value is undefined (boolean)`
365
+
366
+ **Example:**
367
+
368
+ ```ts
369
+ import {isUndefined} from '@bitfiber/utils';
370
+
371
+ isUndefined(undefined); // true
372
+ isUndefined(7); // false
373
+ ```
374
+
375
+ ---
376
+
377
+ ### `isDefined`
378
+
379
+ Returns true if the value is defined, otherwise false
380
+ `@param value: any`
381
+ `@returns boolean`
382
+
383
+ **Example:**
384
+
385
+ ```ts
386
+ import {isDefined} from '@bitfiber/utils';
387
+
388
+ isDefined(null); // true
389
+ isDefined(undefined); // false
390
+ ```
391
+
392
+ ---
393
+
394
+ ### `isNullish`
395
+
396
+ Returns true if the value is undefined or null, otherwise false
397
+ `@param value: any`
398
+ `@returns value is Nullish (boolean)`
399
+
400
+ **Example:**
401
+
402
+ ```ts
403
+ import {isNullish} from '@bitfiber/utils';
404
+
405
+ isNullish(null); // true
406
+ isNullish(undefined); // true
407
+ isNullish(false); // false
408
+ ```
409
+
410
+ ---
411
+
412
+ ### `isNaN`
413
+
414
+ Returns true if the value is NaN, otherwise false
415
+ `@param value: any`
416
+ `@returns value is NaN (boolean)`
417
+
418
+ **Example:**
419
+
420
+ ```ts
421
+ import {isNaN} from '@bitfiber/utils';
422
+
423
+ isNaN(NaN); // true
424
+ isNaN(''); // false
425
+ ```
426
+
427
+ ---
428
+
429
+ ### `isString`
430
+
431
+ Returns true if the value is a string, otherwise false
432
+ `@param value: any`
433
+ `@returns value is string (boolean)`
434
+
435
+ **Example:**
436
+
437
+ ```ts
438
+ import {isString} from '@bitfiber/utils';
439
+
440
+ isString('str'); // true
441
+ isString(7); // false
442
+ ```
443
+
444
+ ---
445
+
446
+ ### `isNumber`
447
+
448
+ Returns true if the value is a number, otherwise false
449
+ `@param value: any`
450
+ `@returns value is number (boolean)`
451
+
452
+ **Example:**
453
+
454
+ ```ts
455
+ import {isNumber} from '@bitfiber/utils';
456
+
457
+ isNumber(7); // true
458
+ isNumber(true); // false
459
+ ```
460
+
461
+ ---
462
+
463
+ ### `isBigInt`
464
+
465
+ Returns true if the value is a big integer, otherwise false
466
+ `@param value: any`
467
+ `@returns value is bigint (boolean)`
468
+
469
+ **Example:**
470
+
471
+ ```ts
472
+ import {isBigInt} from '@bitfiber/utils';
473
+
474
+ isBigInt(7n); // true
475
+ isBigInt(true); // false
476
+ ```
477
+
478
+ ---
479
+
480
+ ### `isBoolean`
481
+
482
+ Returns true if the value is a boolean, otherwise false
483
+ `@param value: any`
484
+ `@returns value is boolean (boolean)`
485
+
486
+ **Example:**
487
+
488
+ ```ts
489
+ import {isBoolean} from '@bitfiber/utils';
490
+
491
+ isBoolean(false); // true
492
+ isBoolean('true'); // false
493
+ ```
494
+
495
+ ---
496
+
497
+ ### `isSymbol`
498
+
499
+ Returns true if the value is a symbol, otherwise false
500
+ `@param value: any`
501
+ `@returns value is symbol (boolean)`
502
+
503
+ **Example:**
504
+
505
+ ```ts
506
+ import {isSymbol} from '@bitfiber/utils';
507
+
508
+ isSymbol(new Symbol()); // true
509
+ isSymbol(new Date()); // false
510
+ ```
511
+
512
+ ---
513
+
514
+ ### `isFunction`
515
+
516
+ Returns true if the value is a function, otherwise false
517
+ `@param value: any`
518
+ `@returns value is Fn (boolean)`
519
+
520
+ **Example:**
521
+
522
+ ```ts
523
+ import {isFunction} from '@bitfiber/utils';
524
+
525
+ isFunction(() => {
526
+ }); // true
527
+ isFunction({}); // false
528
+ ```
529
+
530
+ ---
531
+
532
+ ### `isObject`
533
+
534
+ Returns true if the value is an object, otherwise false
535
+ `@param value: any`
536
+ `@returns value is Obj (boolean)`
537
+
538
+ **Example:**
539
+
540
+ ```ts
541
+ import {isObject} from '@bitfiber/utils';
542
+
543
+ isObject({}); // true
544
+ isObject(() => {
545
+ }); // false
546
+ ```
547
+
548
+ ---
549
+
550
+ ### `isArray`
551
+
552
+ Returns true if the value is an array, otherwise false
553
+ `@param value: any`
554
+ `@returns value is Array<any> (boolean)`
555
+
556
+ **Example:**
557
+
558
+ ```ts
559
+ import {isArray} from '@bitfiber/utils';
560
+
561
+ isArray([]); // true
562
+ isArray(7); // false
563
+ ```
564
+
565
+ ---
566
+
567
+ ### `isSet`
568
+
569
+ Returns true if the value is a set, otherwise false
570
+ `@param value: any`
571
+ `@returns value is Set<any> (boolean)`
572
+
573
+ **Example:**
574
+
575
+ ```ts
576
+ import {isSet} from '@bitfiber/utils';
577
+
578
+ isSet(new Set()); // true
579
+ isSet([]); // false
580
+ ```
581
+
582
+ ---
583
+
584
+ ### `isMap`
585
+
586
+ Returns true if the value is a map, otherwise false
587
+ `@param value: any`
588
+ `@returns value is Map<any, any> (boolean)`
589
+
590
+ **Example:**
591
+
592
+ ```ts
593
+ import {isMap} from '@bitfiber/utils';
594
+
595
+ isMap(new Map()); // true
596
+ isMap([]); // false
597
+ ```
598
+
599
+ ---
600
+
601
+ ### `isDate`
602
+
603
+ Returns true if the value is a date, otherwise false
604
+ `@param value: any`
605
+ `@returns value is Date (boolean)`
606
+
607
+ **Example:**
608
+
609
+ ```ts
610
+ import {isDate} from '@bitfiber/utils';
611
+
612
+ isDate(new Date()); // true
613
+ isDate('12.12.12'); // false
614
+ ```
615
+
616
+ ---
617
+
618
+ ### `isRegExp`
619
+
620
+ Returns true if the value is a regular expression, otherwise false
621
+ `@param value: any`
622
+ `@returns value is RegExp (boolean)`
623
+
624
+ **Example:**
625
+
626
+ ```ts
627
+ import {isRegExp} from '@bitfiber/utils';
628
+
629
+ isRegExp(/test/i); // true
630
+ isRegExp({}); // false
631
+ ```
632
+
633
+ ---
634
+
635
+ ### `isFile`
636
+
637
+ Returns true if the value is a file, otherwise false
638
+ `@param value: any`
639
+ `@returns value is File (boolean)`
640
+
641
+ **Example:**
642
+
643
+ ```ts
644
+ import {isFile} from '@bitfiber/utils';
645
+
646
+ isFile(new File()); // true
647
+ isFile({}); // false
648
+ ```
649
+
650
+ ---
651
+
652
+ ### `isBlob`
653
+
654
+ Returns true if the value is a blob, otherwise false
655
+ `@param value: any`
656
+ `@returns value is Blob (boolean)`
657
+
658
+ **Example:**
659
+
660
+ ```ts
661
+ import {isBlob} from '@bitfiber/utils';
662
+
663
+ isBlob(new Blob()); // true
664
+ isBlob(7); // false
665
+ ```
666
+
667
+ ---
668
+
669
+ ### `isFormData`
670
+
671
+ Returns true if the value is form data, otherwise false
672
+ `@param value: any`
673
+ `@returns value is FormData (boolean)`
674
+
675
+ **Example:**
676
+
677
+ ```ts
678
+ import {isFormData} from '@bitfiber/utils';
679
+
680
+ isFormData(new FormData()); // true
681
+ isFormData([]); // false
682
+ ```
683
+
684
+ ---
685
+
686
+ ### `isArrayBuffer`
687
+
688
+ Returns true if the value is an array buffer, otherwise false
689
+ `@param value: any`
690
+ `@returns value is ArrayBuffer (boolean)`
691
+
692
+ **Example:**
693
+
694
+ ```ts
695
+ import {isArrayBuffer} from '@bitfiber/utils';
696
+
697
+ isArrayBuffer(new ArrayBuffer()); // true
698
+ isArrayBuffer('str'); // false
699
+ ```
700
+
701
+ ---
702
+
703
+ ### `isDocument`
704
+
705
+ Returns true if the value is a document, otherwise false
706
+ `@param value: any`
707
+ `@returns value is Document (boolean)`
708
+
709
+ **Example:**
710
+
711
+ ```ts
712
+ import {isDocument} from '@bitfiber/utils';
713
+
714
+ isDocument(document); // true
715
+ isDocument(true); // false
716
+ ```
717
+
718
+ ---
719
+
720
+ ### `isWindow`
721
+
722
+ Returns true if the value is a window, otherwise false
723
+ `@param value: any`
724
+ `@returns value is Window (boolean)`
725
+
726
+ **Example:**
727
+
728
+ ```ts
729
+ import {isWindow} from '@bitfiber/utils';
730
+
731
+ isWindow(window); // true
732
+ isWindow(NaN); // false
733
+ ```
734
+
735
+ ---
736
+
737
+ ### `isPromise`
738
+
739
+ Returns true if the value is a promise, otherwise false
740
+ `@param value: any`
741
+ `@returns value is Promise<any> (boolean)`
742
+
743
+ **Example:**
744
+
745
+ ```ts
746
+ import {isPromise} from '@bitfiber/utils';
747
+
748
+ isPromise(new Promise()); // true
749
+ isPromise([]); // false
750
+ ```
751
+
752
+ ---
753
+
754
+ ### `isObservable`
755
+
756
+ Returns true if the value is an observable, otherwise false
757
+ `@param value: any`
758
+ `@returns boolean`
759
+
760
+ **Example:**
761
+
762
+ ```ts
763
+ import {isObservable} from '@bitfiber/utils';
764
+
765
+ isObservable(new Subject()); // true
766
+ isObservable(false); // false
767
+ ```
768
+
769
+ ---
770
+
771
+ ### `isTypedArray`
772
+
773
+ Returns true if the value is a typed array, otherwise false
774
+ `@param value: any`
775
+ `@returns value is TypedArr (boolean)`
776
+
777
+ **Example:**
778
+
779
+ ```ts
780
+ import {isTypedArray} from '@bitfiber/utils';
781
+
782
+ isTypedArray(new Int16Array()); // true
783
+ isTypedArray(new Float32Array()); // true
784
+ isTypedArray([]); // false
785
+ ```
786
+
787
+ ---
788
+
789
+ ### `isUsualObject`
790
+
791
+ Returns true if the value is a usual object, otherwise false
792
+ `@param value: any`
793
+ `@returns value is Obj (boolean)`
794
+
795
+ **Example:**
796
+
797
+ ```ts
798
+ import {isUsualObject} from '@bitfiber/utils';
799
+
800
+ isUsualObject({}); // true
801
+ isUsualObject(new Date()); // false
802
+ isUsualObject(new Map()); // false
803
+ isUsualObject([]); // false
804
+ ```
805
+
806
+ ---
807
+
808
+ ### `isEmpty`
809
+
810
+ Returns true if the value is empty (null, undefined, NaN, Infinity, '', {}, [], Int32Array(), Set(), Map()),
811
+ otherwise false
812
+ `@param value: any`
813
+ `@returns boolean`
814
+
815
+ **Example:**
816
+
817
+ ```ts
818
+ import {isEmpty} from '@bitfiber/utils';
819
+
820
+ isEmpty(undefined); // true
821
+ isEmpty(null); // true
822
+ isEmpty(''); // true
823
+ isEmpty(0); // false
824
+ isEmpty(false); // true
825
+ isEmpty({}); // true
826
+ isEmpty({field: 'value'}); // false
827
+ isEmpty([]); // true
828
+ isEmpty([1]); // false
829
+ isEmpty(new Map()); // true
830
+ isEmpty(new Map([[1, 1]])); // false
831
+ ```
832
+
833
+ ---
834
+
835
+ ### `random`
836
+
837
+ Returns a random integer between 0 and number, not exceeding a certain number of digits
838
+ `@param numberOfDigits?: number` - number of digits (default: 7, maximum: 15)
839
+ `@returns number`
840
+
841
+ **Example:**
842
+
843
+ ```ts
844
+ import {random} from '@bitfiber/utils';
845
+
846
+ random(); // 5332544
847
+ random(4); // 8465
848
+ ```
849
+
850
+ ---
851
+
852
+ ### `same`
853
+
854
+ Determines whether two values are the same value
855
+ `@param value1: any`
856
+ `@param value2: any`
857
+ `@returns boolean`
858
+
859
+ **Example:**
860
+
861
+ ```ts
862
+ import {same} from '@bitfiber/utils';
863
+
864
+ same(9, 9); // true
865
+ same({a: 1}, {a: 1}); // false
866
+ ```
867
+
868
+ ---
869
+
870
+ ### `stub`
871
+
872
+ Can replace any required function or callback, takes any arguments and returns anything
873
+
874
+ **Example:**
875
+
876
+ ```ts
877
+ import {stub} from '@bitfiber/utils';
878
+
879
+ Promise.resolve().then(stub);
880
+ ```
881
+
882
+ ---
883
+
884
+ ### `toFloat`
885
+
886
+ Converts a string to a float and replaces NaN and Infinity with 0
887
+ `@param value: NumStr`
888
+ `@returns number`
889
+
890
+ **Example:**
891
+
892
+ ```ts
893
+ import {toFloat} from '@bitfiber/utils';
894
+
895
+ toFloat(5.56); // 5.56
896
+ toFloat('5.56'); // 5.56
897
+ toFloat('str'); // 0
898
+ ```
899
+
900
+ ---
901
+
902
+ ### `toInt`
903
+
904
+ Converts a string to an integer and replaces NaN and Infinity with 0
905
+ `@param value: NumStr`
906
+ `@returns number`
907
+
908
+ **Example:**
909
+
910
+ ```ts
911
+ import {toInt} from '@bitfiber/utils';
912
+
913
+ toInt(5); // 5
914
+ toInt('5'); // 5
915
+ toInt('str'); // 0
916
+ ```
917
+
918
+ ---
919
+
920
+ ### `toSortedString`
921
+
922
+ Converts any value to a sorted string.
923
+ Sorts arrays, maps and sets by value and sorts objects by field name before adding them to a string.
924
+ Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
925
+ `@param value: any`
926
+ `@returns string`
927
+
928
+ **Example:**
929
+
930
+ ```ts
931
+ import {toSortedString} from '@bitfiber/utils';
932
+
933
+ toSortedString(5); // '5'
934
+ toSortedString('str'); // 'str'
935
+ toSortedString({
936
+ test2: [22, 11],
937
+ test1: {}
938
+ }); // '{test1:{},test2:[11,22]}'
939
+ ```
940
+
941
+ ---
942
+
943
+ ## Functions for working with objects
944
+
945
+ ---
946
+
947
+ ### `constant`
948
+
949
+ Makes an object read-only
950
+ `<T extends Obj>`
951
+ `@param obj: T` - any object
952
+ `@returns Readonly<T>`
953
+
954
+ **Example:**
955
+
956
+ ```ts
957
+ import {constant} from '@bitfiber/utils/obj';
958
+
959
+ const readOnlyObj = constant({a: 1});
960
+ ```
961
+
962
+ ---
963
+
964
+ ### `deepConstant`
965
+
966
+ Makes an object and its nested objects read-only
967
+ `<T extends Obj>`
968
+ `@param obj: T` - any object
969
+ `@returns Readonly<T>`
970
+
971
+ **Example:**
972
+
973
+ ```ts
974
+ import {deepConstant} from '@bitfiber/utils/obj';
975
+
976
+ const readOnlyObj = deepConstant({
977
+ a: 1,
978
+ b: {c: 2}
979
+ });
980
+ ```
981
+
982
+ ---
983
+
984
+ ### `diffObj`
985
+
986
+ Returns the difference between two objects
987
+ `<T1 extends Obj, T2 extends Obj>`
988
+ `@param obj1: T1` - any object 1
989
+ `@param obj2: T2` - any object 2
990
+ `@param sortFn?: (a: any, b: any) => number` - if added, arrays and sets will be sorted before comparison
991
+ `@returns ObjDiff<T1 & T2>`
992
+
993
+ **Example:**
994
+
995
+ ```ts
996
+ import {diffObj} from '@bitfiber/utils/obj';
997
+
998
+ const result = diffObj({
999
+ a: 1,
1000
+ b: 2,
1001
+ c: {d: 4},
1002
+ e: {f: 5},
1003
+ i: 7
1004
+ }, {
1005
+ a: 1,
1006
+ b: 3,
1007
+ c: {d: 4},
1008
+ e: {g: 5},
1009
+ j: 8
1010
+ });
1011
+
1012
+ /*
1013
+ result = {
1014
+ equal: {a: 1, c: {d: 4}},
1015
+ notEqual1: {b: 2, e: {f: 5}, i: 7},
1016
+ notEqual2: {b: 3, e: {g: 5}, j: 8},
1017
+ only1: {i: 7},
1018
+ only2: {j: 8},
1019
+ isEqual: false
1020
+ }
1021
+ */
1022
+ ```
1023
+
1024
+ ---
1025
+
1026
+ ### `exclude`
1027
+
1028
+ Returns a new object with the fields of the passed object, excluding the specified set of fields
1029
+ `<T extends Obj, K extends keyof T>`
1030
+ `@param obj: T` - any object
1031
+ `@param ...fields: K[]` - set of fields to be excluded
1032
+ `@returns Omit<T, K>`
1033
+
1034
+ **Example:**
1035
+
1036
+ ```ts
1037
+ import {exclude} from '@bitfiber/utils/obj';
1038
+
1039
+ const obj = exclude({
1040
+ a: 1,
1041
+ b: 2
1042
+ }, 'b'); // {a: 1}
1043
+ ```
1044
+
1045
+ ---
1046
+
1047
+ ### `extend`
1048
+
1049
+ Copies all enumerable own properties from one or more source objects to a target object.
1050
+ It returns the modified target object
1051
+ `<T extends Obj, U extends Obj[]>`
1052
+ `@param target: T` - target object
1053
+ `@param ...sources: U` - source objects
1054
+ `@returns T & ValueIntersection<typeof sources>`
1055
+
1056
+ **Example:**
1057
+
1058
+ ```ts
1059
+ import {extend} from '@bitfiber/utils/obj';
1060
+
1061
+ const obj = extend({a: 1}, {b: 2}); // {a: 1, b: 2}
1062
+ ```
1063
+
1064
+ ---
1065
+
1066
+ ### `extendAll`
1067
+
1068
+ Copies all enumerable own properties from one or more source objects to a target object
1069
+ and copies enumerable properties from nested source objects to nested target objects
1070
+ It returns the modified target object
1071
+ `<T extends Obj, U extends Obj[]>`
1072
+ `@param target: T` - target object
1073
+ `@param ...sources: U` - source objects
1074
+ `@returns T & ValueIntersection<typeof sources>`
1075
+
1076
+ **Example:**
1077
+
1078
+ ```ts
1079
+ import {extendAll} from '@bitfiber/utils/obj';
1080
+
1081
+ const obj = extendAll({a: 1}, {b: 2}); // {a: 1, b: 2}
1082
+ ```
1083
+
1084
+ ---
1085
+
1086
+ ### `forEachObj`
1087
+
1088
+ Iterates through all the fields of an object and calls a handler for each field
1089
+ If the handler returns INTERRUPT, the loop will be interrupted
1090
+ `<T extends Obj, K extends keyof T>`
1091
+ `@param obj: T` - any object
1092
+ `@param handler: (value: ValueUnion<T>, key: K, obj: T) => any` - function called for each field
1093
+ `@returns void`
1094
+
1095
+ **Example:**
1096
+
1097
+ ```ts
1098
+ import {INTERRUPT} from '@bitfiber/utils';
1099
+ import {forEachObj} from '@bitfiber/utils/obj';
1100
+
1101
+ forEachObj({
1102
+ a: 1,
1103
+ b: 2
1104
+ }, (v, k) => console.log(v), true); // 2 -> 1
1105
+ forEachObj({
1106
+ a: 1,
1107
+ b: 2
1108
+ }, (v, k) => (v === 2 ? INTERRUPT : console.log(v))); // 1
1109
+ ```
1110
+
1111
+ ---
1112
+
1113
+ ### `hasOwn`
1114
+
1115
+ Returns true if the object has the indicated property as its own property.
1116
+ If the property is inherited, or does not exist, the method returns false
1117
+ `@param obj: Obj` - any object
1118
+ `@param property: NumStrSym`
1119
+ `@returns boolean`
1120
+
1121
+ **Example:**
1122
+
1123
+ ```ts
1124
+ import {hasOwn} from '@bitfiber/utils/obj';
1125
+
1126
+ hasOwn({
1127
+ a: 1,
1128
+ b: 2
1129
+ }, 'a'); // true
1130
+ hasOwn({
1131
+ a: 1,
1132
+ b: 2
1133
+ }, 'c'); // false
1134
+ ```
1135
+
1136
+ ---
1137
+
1138
+ ### `include`
1139
+
1140
+ Returns a new object with the specified set of fields
1141
+ `<T extends Obj, K extends keyof T>`
1142
+ `@param obj: T` - any object
1143
+ `@param ...fields: K[]` - set of fields to be included
1144
+ `@returns Pick<T, K>`
1145
+
1146
+ **Example:**
1147
+
1148
+ ```ts
1149
+ import {include} from '@bitfiber/utils/obj';
1150
+
1151
+ const obj = include({
1152
+ a: 1,
1153
+ b: 2
1154
+ }, 'b'); // {b: 2}
1155
+ ```
1156
+
1157
+ ---
1158
+
1159
+ ### `keys`
1160
+
1161
+ Returns an array of the object's own enumerable property names
1162
+ `<T extends Obj>`
1163
+ `@param obj: T` - any object
1164
+ `@returns (keyof T)[]`
1165
+
1166
+ **Example:**
1167
+
1168
+ ```ts
1169
+ import {keys} from '@bitfiber/utils/obj';
1170
+
1171
+ const arr = keys({
1172
+ a: 1,
1173
+ b: 2
1174
+ }, 'b'); // ['a', 'b']
1175
+ ```
1176
+
1177
+ ---
1178
+
1179
+ ### `mapObj`
1180
+
1181
+ Returns a new object, which has the mapped values of object fields
1182
+ `<T extends Obj, K extends keyof T, R>`
1183
+ `@param obj: T` - any object
1184
+ `@param handler: (value: ValueUnion<T>, key: K, obj: T) => R` - function called for each field
1185
+ `@returns Record<K, R>`
1186
+
1187
+ **Example:**
1188
+
1189
+ ```ts
1190
+ import {mapObj} from '@bitfiber/utils/obj';
1191
+
1192
+ const obj = mapObj({
1193
+ a: 1,
1194
+ b: 2
1195
+ }, (v, k) => k); // {a: 'a', b: 'b'}
1196
+ ```
1197
+
1198
+ ---
1199
+
1200
+ ### `mapObjToArr`
1201
+
1202
+ Returns an array, which has the mapped values of object fields
1203
+ `<T extends Obj, K extends keyof T, R>`
1204
+ `@param obj: T` - any object
1205
+ `@param handler: (value: ValueUnion<T>, key: K, obj: T) => R` - function called for each field
1206
+ `@returns R[]`
1207
+
1208
+ **Example:**
1209
+
1210
+ ```ts
1211
+ import {mapObjToArr} from '@bitfiber/utils/obj';
1212
+
1213
+ const arr = mapObjToArr({
1214
+ a: 1,
1215
+ b: 2
1216
+ }, (v, k) => [k, v]); // [['a', 1], ['b', 2]]
1217
+ ```
1218
+
1219
+ ---
1220
+
1221
+ ### `values`
1222
+
1223
+ Returns an array of values for each object's own enumerable property
1224
+ `<T>`
1225
+ `@param obj: Obj<T>` - any object
1226
+ `@returns T[]`
1227
+
1228
+ **Example:**
1229
+
1230
+ ```ts
1231
+ import {values} from '@bitfiber/utils/obj';
1232
+
1233
+ const arr = values({
1234
+ a: 1,
1235
+ b: 2
1236
+ }); // [1, 2]
1237
+ ```
1238
+
1239
+ ---
1240
+
1241
+ ## Functions for working with arrays
1242
+
1243
+ ---
1244
+
1245
+ ### `at`
1246
+
1247
+ Returns the array item at index, or undefined if there is no index.
1248
+ For negative indexes, returns items from the end
1249
+ `<T>`
1250
+ `@param arr: T[]` - any array
1251
+ `@param index: number` - item index
1252
+ `@returns T | undefined`
1253
+
1254
+ **Example:**
1255
+
1256
+ ```ts
1257
+ import {at} from '@bitfiber/utils/arr';
1258
+
1259
+ at([1, 2, 3], 0); // 1
1260
+ at([1, 2, 3], -1); // 3
1261
+ ```
1262
+
1263
+ ---
1264
+
1265
+ ### `cnd`
1266
+
1267
+ Returns a function that checks if a value matches the conditions
1268
+ `@param conditions: MatchConditions`
1269
+ `@returns MatchConditionFn`
1270
+
1271
+ **Example:**
1272
+
1273
+ ```ts
1274
+ import {cnd} from '@bitfiber/utils/arr';
1275
+
1276
+ const obj1 = {name: 'Alex'};
1277
+ const obj2 = {name: 'Mary'};
1278
+ const obj3 = {name: 'Jack'};
1279
+ const arr = [obj1, obj2, obj3];
1280
+ const strArr = ['Alex', 'Mary', 'Jack'];
1281
+
1282
+ // Handler for comparison
1283
+ arr.filter(cnd(obj => obj.name === 'Alex')); // [{name: 'Alex'}]
1284
+
1285
+ // Strict value comparison
1286
+ arr.filter(cnd({is: obj1})); // [{name: 'Alex'}]
1287
+ arr.filter(cnd({is: {name: 'Alex'}})); // []
1288
+ arr.filter(cnd({or: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
1289
+ arr.filter(cnd({or: [{name: 'Alex'}, obj2]})); // [{name: 'Mary'}]
1290
+ arr.filter(cnd({not: [obj1, obj2]})); // [{name: 'Jack'}]
1291
+ arr.filter(cnd({not: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Jack'}]
1292
+
1293
+ // Value equivalence comparison
1294
+ arr.filter(cnd({equal: obj1})); // [{name: 'Alex'}]
1295
+ arr.filter(cnd({equal: {name: 'Alex'}})); // [{name: 'Alex'}]
1296
+ arr.filter(cnd({orEqual: [obj1, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
1297
+ arr.filter(cnd({orEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Alex'}, {name: 'Mary'}]
1298
+ arr.filter(cnd({notEqual: [obj1, obj2]})); // [{name: 'Jack'}]
1299
+ arr.filter(cnd({notEqual: [{name: 'Alex'}, obj2]})); // [{name: 'Jack'}]
1300
+
1301
+ // String value RegExp comparison
1302
+ strArr.filter(cnd({equal: /^Alex$/})); // ['Alex']
1303
+ strArr.filter(cnd({orEqual: [/^Alex$/, /^Mary$/]})); // ['Alex', 'Mary']
1304
+ strArr.filter(cnd({notEqual: [/^Alex$/, /^Mary$/]})); // ['Jack']
1305
+
1306
+ // Strict comparison of field value in objects
1307
+ arr.filter(cnd({name: {is: 'Alex'}})); // [{name: 'Alex'}]
1308
+ arr.filter(cnd({name: {or: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
1309
+ arr.filter(cnd({name: {not: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
1310
+
1311
+ // Comparison of field value equivalence in objects
1312
+ arr.filter(cnd({name: {equal: 'Alex'}})); // [{name: 'Alex'}]
1313
+ arr.filter(cnd({name: {orEqual: ['Alex', 'Mary']}})); // [{name: 'Alex'}, {name: 'Mary'}]
1314
+ arr.filter(cnd({name: {notEqual: ['Alex', 'Mary']}})); // [{name: 'Jack'}]
1315
+
1316
+ // Comparing string fields in objects using RegExp
1317
+ arr.filter(cnd({name: /^Alex$/})); // [{name: 'Alex'}]
1318
+ arr.filter(cnd({name: {equal: /^Alex$/}})); // [{name: 'Alex'}]
1319
+ arr.filter(cnd({name: {orEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Alex'}, {name: 'Mary'}]
1320
+ arr.filter(cnd({name: {notEqual: [/^Alex$/, /^Mary$/]}})); // [{name: 'Jack'}]
1321
+ ```
1322
+
1323
+ ---
1324
+
1325
+ ### `diffArr`
1326
+
1327
+ Returns the difference between two arrays
1328
+ Strict comparison of array items is applied
1329
+ The order doesn't matter
1330
+ `<T extends NumStr>`
1331
+ `@param arr1: T[]` - array 1
1332
+ `@param arr2: T[]` - array 2
1333
+ `@returns ArrDiff<T>`
1334
+
1335
+ **Example:**
1336
+
1337
+ ```ts
1338
+ import {diffArr} from '@bitfiber/utils/arr';
1339
+
1340
+ const result1 = diffArr([1, 2, 3], [3, 4, 1]);
1341
+ /*
1342
+ result1 = {
1343
+ only1: [2],
1344
+ only2: [4],
1345
+ equal: [1, 3],
1346
+ isEqual: false
1347
+ }
1348
+ */
1349
+
1350
+ const result2 = diffArr([1, 2, 3], [3, 2, 1]);
1351
+ /*
1352
+ result2 = {
1353
+ only1: [],
1354
+ only2: [],
1355
+ equal: [1, 2, 3],
1356
+ isEqual: true
1357
+ }
1358
+ */
1359
+ ```
1360
+
1361
+ ---
1362
+
1363
+ ### `fill`
1364
+
1365
+ Fills a new array with items that will be returned by the handler, which will be called a certain number of times
1366
+ `<T>`
1367
+ `@param quantity: number` - number of array items
1368
+ `@param handler: (offsetIndex: number, index: number) => T` - a function that should return a new array item
1369
+ `@param offset = 1` - offset for the index, which is passed to the handler
1370
+ `@returns T[]`
1371
+
1372
+ **Example:**
1373
+
1374
+ ```ts
1375
+ import {fill} from '@bitfiber/utils/arr';
1376
+
1377
+ fill(2, i => ({id: i})); // [{id: 1}, {id: 2}]
1378
+ fill(2, i => ({id: i}), 5); // [{id: 6}, {id: 6}]
1379
+ fill(5, (i, j) => j, 5); // [0, 1, 2, 3, 4]
1380
+ ```
1381
+
1382
+ ---
1383
+
1384
+ ### `forEachArr`
1385
+
1386
+ Iterates through all the items of an array and calls a handler for each item
1387
+ If the handler returns INTERRUPT, the loop will be interrupted
1388
+ `<T extends Arr, V extends ValueUnion<T>>`
1389
+ `@param arr: T` - an array or any typed array
1390
+ `@param handler: (value: V, index: number, arr: T) => any` - function called for each item
1391
+ `@param reverse?: boolean` - iterates in reverse order if true
1392
+ `@returns void`
1393
+
1394
+ **Example:**
1395
+
1396
+ ```ts
1397
+ import {forEachArr} from '@bitfiber/utils/arr';
1398
+
1399
+ forEachArr([1, 2, 3], (item, i) => console.log(item), true); // 3 -> 2 -> 1
1400
+ forEachArr(new Int32Array([1, 2, 3]), (item, i) => (item === 2 ? INTERRUPT : console.log(item))); // 1
1401
+ ```
1402
+
1403
+ ---
1404
+
1405
+ ### `indexBy`
1406
+
1407
+ Returns an object indexed by the values from a specific field of each item or from a function that is executed on each
1408
+ item
1409
+ `<T extends Obj>`
1410
+ `@param arr: T[]` - array of objects
1411
+ `@param fieldOrFn: string | ((item: T) => string)` - the name of the field from which the index value should be taken,
1412
+ or the function that should return the index value
1413
+ `@returns Index<T>`
1414
+
1415
+ **Example:**
1416
+
1417
+ ```ts
1418
+ import {indexBy} from '@bitfiber/utils/arr';
1419
+
1420
+ const arr = [
1421
+ {
1422
+ id: '1',
1423
+ name: 'Alex'
1424
+ }, {
1425
+ id: '2',
1426
+ name: 'Mary'
1427
+ }
1428
+ ];
1429
+ indexBy(arr, 'name'); // {Alex: {id: '1', name: 'Alex'}, Mary: {id: '2', name: 'Mary'}}
1430
+ ```
1431
+
1432
+ ---
1433
+
1434
+ ### `pluck`
1435
+
1436
+ Returns an array with values, each of which corresponds to the value of a certain array item field
1437
+ `<T extends Obj, F extends keyof T>`
1438
+ `@param arr: T[]` - array of objects
1439
+ `@param fieldName: F` - name of the array item field from which the value is to be taken
1440
+ `@returns (T[F])[]`
1441
+
1442
+ **Example:**
1443
+
1444
+ ```ts
1445
+ import {pluck} from '@bitfiber/utils/arr';
1446
+
1447
+ const arr = [
1448
+ {
1449
+ id: '1',
1450
+ name: 'Alex'
1451
+ }, {
1452
+ id: '2',
1453
+ name: 'Mary'
1454
+ }
1455
+ ];
1456
+ pluck(arr, 'name'); // ['Alex', 'Mary']
1457
+ ```
1458
+
1459
+ ---
1460
+
1461
+ ### `within`
1462
+
1463
+ Returns an array item by index.
1464
+ If the index is greater than the array length, then the array item will be obtained like remainder of division the index
1465
+ by the array length.
1466
+ For negative indexes, returns items from the end
1467
+ `<T>`
1468
+ `@param arr: T[]` - any array
1469
+ `@param index: number` - an array item index
1470
+ `@returns T | undefined`
1471
+
1472
+ **Example:**
1473
+
1474
+ ```ts
1475
+ import {within} from '@bitfiber/utils/arr';
1476
+
1477
+ within([1, 2, 3], 0); // 1
1478
+ within([1, 2, 3], 3); // 1
1479
+ within([1, 2, 3], -1); // 3
1480
+ within([1, 2, 3], -4); // 3
1481
+ ```
1482
+
1483
+ ---
1484
+
1485
+ ## Functions for working with strings
1486
+
1487
+ ---
1488
+
1489
+ ### `toCamelCase`
1490
+
1491
+ Converts a given string into camelCase format.
1492
+ CamelCase is a convention where a multi-word identifier is formed by joining words together, each starting with a
1493
+ capital letter except for the initial word.
1494
+ This function takes a string as input, which may be in various formats such as snake_case, kebab-case, or
1495
+ space-separated words, and transforms it into camelCase.
1496
+ `@param str: string` - the input string that needs to be converted to camelCase
1497
+ `@param separators: string[]` - an array of any separators, default '-', '_', ' '
1498
+ `@returns string`
1499
+
1500
+ **Example:**
1501
+
1502
+ ```ts
1503
+ import {toCamelCase} from '@bitfiber/utils/str';
1504
+
1505
+ toCamelCase('convert_this_string'); // 'convertThisString'
1506
+ toCamelCase('convert this string'); // 'convertThisString'
1507
+ ```
1508
+
1509
+ ---
1510
+
1511
+ ### `toHash`
1512
+
1513
+ Generates a hash value for a given input string for insecure purposes.
1514
+ Hash functions are commonly used to convert input data into a fixed-length string of characters, providing a unique
1515
+ representation of the input
1516
+ `@param str: string` - The input string to be hashed
1517
+ `@returns string`
1518
+
1519
+ **Example:**
1520
+
1521
+ ```ts
1522
+ import {toHash} from '@bitfiber/utils/str';
1523
+
1524
+ toHash('any string'); // 'ph35534354'
1525
+ ```
1526
+
1527
+ ---
1528
+
1529
+ ### `withCapital`
1530
+
1531
+ Takes a string as input and returns a new string with the initial letter in uppercase, while preserving the rest of the
1532
+ string
1533
+ `@param str: string` - The input string whose first letter needs to be capitalized
1534
+ `@returns string`
1535
+
1536
+ **Example:**
1537
+
1538
+ ```ts
1539
+ import {withCapital} from '@bitfiber/utils/str';
1540
+
1541
+ withCapital('any strinG'); // 'Any strinG'
1542
+ ```
1543
+
1544
+ ---
1545
+
1546
+ ## Functions for working with numbers
1547
+
1548
+ ---
1549
+
1550
+ ### `inRange`
1551
+
1552
+ Converts the numeric value to a new number according to the options
1553
+ `@param value: Nullish | number` - numeric value
1554
+ `@param options: InRangeOptions = {}` - options for converting the numeric value
1555
+ `@returns number | null`
1556
+
1557
+ **Example:**
1558
+
1559
+ ```ts
1560
+ import {inRange} from '@bitfiber/utils/num';
1561
+
1562
+ inRange(10, {min: 20}); // 20
1563
+ inRange(100, {max: 50}); // 50
1564
+ inRange(10.11, {precision: 0}); // 10
1565
+ inRange(10.11, {precision: 1}); // 10.1
1566
+ inRange(null, {required: true}); // 0
1567
+ inRange(null, {min: 10}); // null
1568
+ inRange(null, {
1569
+ min: 10,
1570
+ required: true
1571
+ }); // 10
1572
+ inRange(30.555, {
1573
+ min: 10,
1574
+ max: 20.3,
1575
+ precision: 1,
1576
+ required: true
1577
+ }); // 20.3
1578
+ ```
1579
+
1580
+ ---
1581
+
1582
+ ### `round`
1583
+
1584
+ Rounds a numeric value to a number with a specified number of decimal places and replaces NaN and Infinity with 0
1585
+ `@param value: number` - numeric value
1586
+ `@param precision = 0` - number of decimal places, default 0
1587
+ `@returns number`
1588
+
1589
+ **Example:**
1590
+
1591
+ ```ts
1592
+ import {round} from '@bitfiber/utils/num';
1593
+
1594
+ round(NaN, 1); // 0
1595
+ round(10.111, 1); // 10.1
1596
+ round(-10.111, 1); // -10.1
1597
+ ```
1598
+
1599
+ ---
1600
+
1601
+ ## Functions for working with DOM
1602
+
1603
+ ---
1604
+
1605
+ ### `closest`
1606
+
1607
+ Returns the same element or the closest parent element matching the selectors, otherwise null
1608
+ `@param element: HTMLElement` - any HTML element
1609
+ `@param selectors: string | HTMLElement` - target HTML element or string of valid CSS selectors
1610
+ `@returns HTMLElement | null`
1611
+
1612
+ **Example:**
1613
+
1614
+ ```ts
1615
+ import {getDocument, closest} from '@bitfiber/utils/dom';
1616
+
1617
+ const doc = getDocument();
1618
+ const element = doc.getElementById('element-id');
1619
+ closest(element, '.any-perant-class'); // div.any-perant-class | null
1620
+ ```
1621
+
1622
+ ---
1623
+
1624
+ ### `getDocument`
1625
+
1626
+ Returns the document object representing the HTML document in the current environment
1627
+ `@returns Document`
1628
+
1629
+ **Example:**
1630
+
1631
+ ```ts
1632
+ import {getDocument} from '@bitfiber/utils/dom';
1633
+
1634
+ const doc = getDocument(); // document
1635
+ ```
1636
+
1637
+ ---
1638
+
1639
+ ### `setDocument`
1640
+
1641
+ If the global object is not a window, you can use this function to set up a stub document implementation
1642
+ `@param document: Document` - The document object representing the HTML document in the current environment
1643
+ `@returns void`
1644
+
1645
+ **Example:**
1646
+
1647
+ ```ts
1648
+ import {setDocument} from '@bitfiber/utils/dom';
1649
+
1650
+ // For Angular:
1651
+ setDocument(inject(DOCUMENT));
1652
+ ```
1653
+
1654
+ ---
1655
+
1656
+ ### `downloadFile`
1657
+
1658
+ Creates an offer to download a file from URL in the browser.
1659
+ Returns a promise that returns a blob if the download is successful
1660
+ `@param url: string` - file URL
1661
+ `@returns Promise<Blob>`
1662
+
1663
+ **Example:**
1664
+
1665
+ ```ts
1666
+ import {downloadFile} from '@bitfiber/utils/dom';
1667
+
1668
+ downloadFile('https://example.com/file/name');
1669
+ ```
1670
+
1671
+ ---
1672
+
1673
+ ### `forEachElements`
1674
+
1675
+ Iterates through all child elements of the parent element to the full depth of the tree and calls a handler for each
1676
+ element.
1677
+ If the handler returns INTERRUPT, the loop will be interrupted
1678
+ `@param parent: Element` - a parent element
1679
+ `@param handler: (child: Element, index: number, parent: Element) => any` - function called for each element
1680
+ `@returns void`
1681
+
1682
+ **Example:**
1683
+
1684
+ ```ts
1685
+ import {INTERRUPT} from '@bitfiber/utils';
1686
+ import {getDocument, forEachElements} from '@bitfiber/utils/dom';
1687
+
1688
+ const doc = getDocument();
1689
+ const element = doc.getElementById('element-id');
1690
+ forEachElements(element, (child): any => {
1691
+ // Any actions with elements
1692
+ if (child.classList.contains('some-class')) {
1693
+ return INTERRUPT;
1694
+ }
1695
+ });
1696
+ ```
1697
+
1698
+ ---
1699
+
1700
+ ### `forEachNodes`
1701
+
1702
+ Iterates through all child nodes of the parent node to the full depth of the tree and calls a handler for each node.
1703
+ If the handler returns INTERRUPT, the loop will be interrupted
1704
+ `@param parent: Node` - a parent node
1705
+ `@param handler: (child: Node, index: number, parent: Node) => any` - function called for each node (Text, Comment,
1706
+ Element)
1707
+ `@returns void`
1708
+
1709
+ **Example:**
1710
+
1711
+ ```ts
1712
+ import {INTERRUPT} from '@bitfiber/utils';
1713
+ import {getDocument, forEachNodes, isElement} from '@bitfiber/utils/dom';
1714
+
1715
+ const doc = getDocument();
1716
+ const element = doc.getElementById('element-id');
1717
+ forEachNodes(element, (child): any => {
1718
+ // Any actions with nodes
1719
+ if (isElement(child) && child.classList.contains('some-class')) {
1720
+ return INTERRUPT;
1721
+ }
1722
+ });
1723
+ ```
1724
+
1725
+ ---
1726
+
1727
+ ### `getAllStyles`
1728
+
1729
+ Returns all computed styles of a given HTML element
1730
+ `@param element: HTMLElement` - any HTML element
1731
+ `@returns CSSStyleDeclaration`
1732
+
1733
+ **Example:**
1734
+
1735
+ ```ts
1736
+ import {getDocument, getAllStyles} from '@bitfiber/utils/dom';
1737
+
1738
+ const doc = getDocument();
1739
+ const element = doc.getElementById('element-id');
1740
+ const styles = getAllStyles(element);
1741
+ ```
1742
+
1743
+ ---
1744
+
1745
+ ### `getBody`
1746
+
1747
+ Returns the <body> element of the current document
1748
+ `@returns HTMLElement`
1749
+
1750
+ **Example:**
1751
+
1752
+ ```ts
1753
+ import {getBody} from '@bitfiber/utils/dom';
1754
+
1755
+ const body = getBody();
1756
+ ```
1757
+
1758
+ ---
1759
+
1760
+ ### `getHtml`
1761
+
1762
+ Returns the <html> element that is the root element of the document
1763
+ `@returns HTMLElement`
1764
+
1765
+ **Example:**
1766
+
1767
+ ```ts
1768
+ import {getHtml} from '@bitfiber/utils/dom';
1769
+
1770
+ const html = getHtml();
1771
+ ```
1772
+
1773
+ ---
1774
+
1775
+ ### `getNonStaticParent`
1776
+
1777
+ Returns the closest non-static parent HTML element
1778
+ `@param element: HTMLElement`
1779
+ `@returns HTMLElement`
1780
+
1781
+ **Example:**
1782
+
1783
+ ```ts
1784
+ import {getNonStaticParent} from '@bitfiber/utils/dom';
1785
+
1786
+ const doc = getDocument();
1787
+ const element = doc.getElementById('element-id');
1788
+ const closestNonStaticParent = getNonStaticParent(element);
1789
+ ```
1790
+
1791
+ ---
1792
+
1793
+ ### `getOffsetFromDoc`
1794
+
1795
+ Returns the offset relative to the document
1796
+ `@param element: Element` - any element
1797
+ `@returns Offset` - {top: number, bottom: number, left: number, right: number, width: number, height: number}
1798
+
1799
+ **Example:**
1800
+
1801
+ ```ts
1802
+ import {getOffsetFromDoc} from '@bitfiber/utils/dom';
1803
+
1804
+ const doc = getDocument();
1805
+ const element = doc.getElementById('element-id');
1806
+ const offset = getOffsetFromDoc(element);
1807
+ ```
1808
+
1809
+ ---
1810
+
1811
+ ### `getOffsetFromParent`
1812
+
1813
+ Returns the offset relative to the closest non-static parent element.
1814
+ For fixed elements returns the offset relative to the global window
1815
+ `@param element: HTMLElement` - any HTML element
1816
+ `@returns Offset` - {top: number, bottom: number, left: number, right: number, width: number, height: number}
1817
+
1818
+ **Example:**
1819
+
1820
+ ```ts
1821
+ import {getOffsetFromParent} from '@bitfiber/utils/dom';
1822
+
1823
+ const doc = getDocument();
1824
+ const element = doc.getElementById('element-id');
1825
+ const offset = getOffsetFromParent(element);
1826
+ ```
1827
+
1828
+ ---
1829
+
1830
+ ### `getOffsetFromWin`
1831
+
1832
+ Returns the offset relative to the global window
1833
+ `@param element: Element` - any element
1834
+ `@returns Offset` - {top: number, bottom: number, left: number, right: number, width: number, height: number}
1835
+
1836
+ **Example:**
1837
+
1838
+ ```ts
1839
+ import {getOffsetFromWin} from '@bitfiber/utils/dom';
1840
+
1841
+ const doc = getDocument();
1842
+ const element = doc.getElementById('element-id');
1843
+ const offset = getOffsetFromWin(element);
1844
+ ```
1845
+
1846
+ ---
1847
+
1848
+ ### `getScrollWidth`
1849
+
1850
+ Returns width of vertical and horizontal scrollbars
1851
+ `@param element?: HTMLElement` - any HTML element, default the document's root element <html>
1852
+ `@returns {y: number; x: number}`
1853
+
1854
+ **Example:**
1855
+
1856
+ ```ts
1857
+ import {getScrollWidth} from '@bitfiber/utils/dom';
1858
+
1859
+ const doc = getDocument();
1860
+ const element = doc.getElementById('element-id');
1861
+ const sw = getScrollWidth(element);
1862
+ ```
1863
+
1864
+ ---
1865
+
1866
+ ### `getStyle`
1867
+
1868
+ Returns certain computed style value of a given HTML element
1869
+ `@param element: HTMLElement` - any HTML element
1870
+ `@param styleName: string` - any style name
1871
+ `@returns string` - computed style value
1872
+
1873
+ **Example:**
1874
+
1875
+ ```ts
1876
+ import {getStyle} from '@bitfiber/utils/dom';
1877
+
1878
+ const doc = getDocument();
1879
+ const element = doc.getElementById('element-id');
1880
+ const width = getStyle(element, 'width'); // 100px
1881
+ ```
1882
+
1883
+ ---
1884
+
1885
+ ### `getStyles`
1886
+
1887
+ Returns an object with the specified computed styles for a given HTML element
1888
+ `<A extends string[]>`
1889
+ `@param element: HTMLElement` - any HTML element
1890
+ `@param ...styleNames: A` - list of certain style names
1891
+ `@returns {[K in ValueUnion<A>]: string}` - an object with the specified computed styles
1892
+
1893
+ **Example:**
1894
+
1895
+ ```ts
1896
+ import {getStyles} from '@bitfiber/utils/dom';
1897
+
1898
+ const doc = getDocument();
1899
+ const element = doc.getElementById('element-id');
1900
+ const styles = getStyles(element, 'width', 'height'); // {width: 100px, height: 50px}
1901
+ ```
1902
+
1903
+ ---
1904
+
1905
+ ### `getValidStyleName`
1906
+
1907
+ Attempts to convert the name to a valid style name.
1908
+ Returns a valid style name or throws an exception if a valid name is not found
1909
+ `@param string` - any name
1910
+ `@returns string`
1911
+
1912
+ **Example:**
1913
+
1914
+ ```ts
1915
+ import {getValidStyleName} from '@bitfiber/utils/dom';
1916
+
1917
+ getValidStyleName('border-radius'); // borderRadius
1918
+ getValidStyleName('float'); // cssFloat
1919
+ ```
1920
+
1921
+ ---
1922
+
1923
+ ### `getWindow`
1924
+
1925
+ Returns the global window object in the current environment
1926
+ `@returns Window & typeof globalThis`
1927
+
1928
+ **Example:**
1929
+
1930
+ ```ts
1931
+ import {getWindow} from '@bitfiber/utils/dom';
1932
+
1933
+ const win = getWindow();
1934
+ ```
1935
+
1936
+ ---
1937
+
1938
+ ### `hasName`
1939
+
1940
+ Determines if the name of the passed element matches a specific name
1941
+ `@param element: Element` - any HTML element
1942
+ `@param name: string` - any node name
1943
+ `@returns boolean`
1944
+
1945
+ **Example:**
1946
+
1947
+ ```ts
1948
+ import {hasName} from '@bitfiber/utils/dom';
1949
+
1950
+ const doc = getDocument();
1951
+ const element = doc.createElement('div');
1952
+ hasName(element, 'div'); // true
1953
+ hasName(element, 'span'); // false
1954
+ ```
1955
+
1956
+ ---
1957
+
1958
+ ### `isComment`
1959
+
1960
+ Determines if the given node represents a comment
1961
+ `@param value: any` - any value
1962
+ `@returns value is Comment (boolean)`
1963
+
1964
+ **Example:**
1965
+
1966
+ ```ts
1967
+ import {isComment} from '@bitfiber/utils/dom';
1968
+
1969
+ const doc = getDocument();
1970
+ const comment = doc.createComment('comment');
1971
+ const element = doc.createElement('div');
1972
+ isComment(comment); // true
1973
+ isComment(element); // false
1974
+ ```
1975
+
1976
+ ---
1977
+
1978
+ ### `isElement`
1979
+
1980
+ Determines if the given node represents an element
1981
+ `@param value: any` - any value
1982
+ `@returns value is Element (boolean)`
1983
+
1984
+ **Example:**
1985
+
1986
+ ```ts
1987
+ import {isElement} from '@bitfiber/utils/dom';
1988
+
1989
+ const doc = getDocument();
1990
+ const element = doc.createElement('div');
1991
+ const comment = doc.createComment('comment');
1992
+ isElement(element); // true
1993
+ isElement(comment); // false
1994
+ ```
1995
+
1996
+ ---
1997
+
1998
+ ### `isText`
1999
+
2000
+ Determines if the given node represents a text node
2001
+ `@param value: any` - any value
2002
+ `@returns value is Text (boolean)`
2003
+
2004
+ **Example:**
2005
+
2006
+ ```ts
2007
+ import {isText} from '@bitfiber/utils/dom';
2008
+
2009
+ const doc = getDocument();
2010
+ const text = doc.createTextNode('text');
2011
+ const comment = doc.createComment('comment');
2012
+ isText(text); // true
2013
+ isText(comment); // false
2014
+ ```
2015
+
2016
+ ---
2017
+
2018
+ ### `setOffsetFromParent`
2019
+
2020
+ Sets the offset relative to the closest non-static parent element.
2021
+ For fixed elements sets the offset relative to the global window
2022
+ `@param element: HTMLElement` - any HTML element
2023
+ `@param offset: Partial<TopLeft>` - top and left position relative to the parent HTML element
2024
+ `@returns void`
2025
+
2026
+ **Example:**
2027
+
2028
+ ```ts
2029
+ import {setOffsetFromParent} from '@bitfiber/utils/dom';
2030
+
2031
+ const doc = getDocument();
2032
+ const div = doc.createElement('div');
2033
+ setOffsetFromParent(div, {
2034
+ top: 30,
2035
+ left: 40
2036
+ });
2037
+ ```
2038
+
2039
+ ---
2040
+
2041
+ ### `setStyle`
2042
+
2043
+ Sets a new value for a certain style for a given HTML element
2044
+ `@param element: HTMLElement` - any HTML element
2045
+ `@param styleName: string` - any style name
2046
+ `@param value: string` - new value for style
2047
+ `@returns string` - previous value for style
2048
+
2049
+ **Example:**
2050
+
2051
+ ```ts
2052
+ import {setStyle} from '@bitfiber/utils/dom';
2053
+
2054
+ const doc = getDocument();
2055
+ const div = doc.createElement('div');
2056
+ const prevStyle = setStyle(div, 'width', '200px'); // 100px
2057
+ ```
2058
+
2059
+ ---
2060
+
2061
+ ### `setStyles`
2062
+
2063
+ Sets new styles for a given HTML element
2064
+ `<T extends Index<string>>`
2065
+ `@param element: HTMLElement` - any HTML element
2066
+ `@param styles: T` - object containing new styles
2067
+ `@returns T` - object containing previous styles
2068
+
2069
+ **Example:**
2070
+
2071
+ ```ts
2072
+ import {setStyles} from '@bitfiber/utils/dom';
2073
+
2074
+ const doc = getDocument();
2075
+ const div = doc.createElement('div');
2076
+ const prevStyles = setStyles(div, {
2077
+ width: '200px',
2078
+ height: '10px',
2079
+ }); // {width: '100px', height: '5px'}
2080
+ ```
2081
+
2082
+ ---
2083
+
2084
+ ## Functions for working with environment
2085
+
2086
+ ---
2087
+
2088
+ ### `getBrowser`
2089
+
2090
+ Returns information about the browser.
2091
+ Possible browser names: opera | operaCoast | operaTouch | samsung | mz | yandex | uc | maxthon | kmeleon
2092
+ | wechat | qqLite | qq | edge | sailfish | webOS | tizen | miui | silk | phantomjs | slimerjs | qupzilla
2093
+ | electron | whale | focus | swing | epiphany | puffin | sleipnir | vivaldi | seamonkey | playstation4
2094
+ | playstation5 | googleSearch | firefox | chrome | android | safari | unknown | BotNames
2095
+ `@returns BrowserData`
2096
+
2097
+ **Example:**
2098
+
2099
+ ```ts
2100
+ import {getBrowser} from '@bitfiber/utils/env';
2101
+
2102
+ const browser = getBrowser(); // {name: 'chrome', version: '96.0.4664.110', major: '96'}
2103
+ ```
2104
+
2105
+ ---
2106
+
2107
+ ### `getEngine`
2108
+
2109
+ Returns information about the browser engine.
2110
+ Possible engine names: blink (Chrome like) | webkit (Safari like) | gecko (Firefox like) | unknown | BotNames
2111
+ `@returns EngineData`
2112
+
2113
+ **Example:**
2114
+
2115
+ ```ts
2116
+ import {getEngine} from '@bitfiber/utils/env';
2117
+
2118
+ const engine = getEngine(); // {name: 'blink', version: '96.0.4664.110', major: '96'}
2119
+ ```
2120
+
2121
+ ---
2122
+
2123
+ ### `getOS`
2124
+
2125
+ Returns information about the OS
2126
+ Possible OS names: xbox | windows | ios | macOS | webOS | tizen | appleTV | roku | chromeOS
2127
+ | playstation4 | playstation5 | nintendoSwitch | likeAndroid | android | linux | unknown | BotNames
2128
+ `@returns OSData`
2129
+
2130
+ **Example:**
2131
+
2132
+ ```ts
2133
+ import {getOS} from '@bitfiber/utils/env';
2134
+
2135
+ const OS = getOS(); // {name: 'windows', version: '11.2', major: '11'}
2136
+ ```
2137
+
2138
+ ---
2139
+
2140
+ ### `getPlatform`
2141
+
2142
+ Returns the name of the platform
2143
+ `@returns tv | desktop | tablet | mobile | unknown | BotNames`
2144
+
2145
+ **Example:**
2146
+
2147
+ ```ts
2148
+ import {getPlatform} from '@bitfiber/utils/env';
2149
+
2150
+ const platform = getPlatform(); // desktop
2151
+ ```
2152
+
2153
+ ---
2154
+
2155
+ ### `isBrowser`
2156
+
2157
+ Returns true if the name matches the browser name and the version matches the browser version, otherwise false
2158
+ `@param name: BrowserNames` - one of the browser names:
2159
+ opera | operaCoast | operaTouch | samsung | mz | yandex | uc | maxthon | kmeleon
2160
+ | wechat | qqLite | qq | edge | sailfish | webOS | tizen | miui | silk | phantomjs | slimerjs | qupzilla
2161
+ | electron | whale | focus | swing | epiphany | puffin | sleipnir | vivaldi | seamonkey | playstation4
2162
+ | playstation5 | googleSearch | firefox | chrome | android | safari | unknown | BotNames
2163
+ `@param version?: string` - string condition in the format: x.x...x | [~ >= > <= <]x.x...x
2164
+ `@returns tv | desktop | tablet | mobile | unknown`
2165
+
2166
+ **Example:**
2167
+
2168
+ ```ts
2169
+ import {isBrowser} from '@bitfiber/utils/env';
2170
+
2171
+ isBrowser('firefox');
2172
+ isBrowser('chrome', '~90.1');
2173
+ isBrowser('opera', '<=100.5');
2174
+ ```
2175
+
2176
+ ---
2177
+
2178
+ ### `isChromeLike`
2179
+
2180
+ Returns true if the browser uses the Blink engine like Chrome, false otherwise
2181
+ `@returns boolean`
2182
+
2183
+ **Example:**
2184
+
2185
+ ```ts
2186
+ import {isChromeLike} from '@bitfiber/utils/env';
2187
+
2188
+ isChromeLike();
2189
+ ```
2190
+
2191
+ ---
2192
+
2193
+ ### `isDesktop`
2194
+
2195
+ Returns true if the platform is desktop, otherwise false
2196
+ `@returns boolean`
2197
+
2198
+ **Example:**
2199
+
2200
+ ```ts
2201
+ import {isDesktop} from '@bitfiber/utils/env';
2202
+
2203
+ isDesktop();
2204
+ ```
2205
+
2206
+ ---
2207
+
2208
+ ### `isEngine`
2209
+
2210
+ Returns true if the name matches the engine name and the version matches the engine version, otherwise false
2211
+ `@param name: EngineNames` - one of the engine names:
2212
+ blink (Chrome like) | webkit (Safari like) | gecko (Firefox like) | unknown | BotNames
2213
+ `@param version?: string` - string condition in the format: x.x...x | [~ >= > <= <]x.x...x
2214
+ `@returns boolean`
2215
+
2216
+ **Example:**
2217
+
2218
+ ```ts
2219
+ import {isEngine} from '@bitfiber/utils/env';
2220
+
2221
+ isEngine('gecko');
2222
+ isEngine('blink', '~90.1');
2223
+ isEngine('webkit', '<=100.5');
2224
+ ```
2225
+
2226
+ ---
2227
+
2228
+ ### `isFirefoxLike`
2229
+
2230
+ Returns true if the browser uses the Gecko engine like FireFox, false otherwise
2231
+ `@returns boolean`
2232
+
2233
+ **Example:**
2234
+
2235
+ ```ts
2236
+ import {isFirefoxLike} from '@bitfiber/utils/env';
2237
+
2238
+ isFirefoxLike();
2239
+ ```
2240
+
2241
+ ---
2242
+
2243
+ ### `isMobile`
2244
+
2245
+ Returns true if the platform is mobile, otherwise false
2246
+ `@returns boolean`
2247
+
2248
+ **Example:**
2249
+
2250
+ ```ts
2251
+ import {isMobile} from '@bitfiber/utils/env';
2252
+
2253
+ isMobile();
2254
+ ```
2255
+
2256
+ ---
2257
+
2258
+ ### `isOS`
2259
+
2260
+ Returns true if the name matches the OS name and the version matches the OS version, otherwise false
2261
+ `@param name: OSNames` - one of the OS names:
2262
+ xbox | windows | ios | macOS | webOS | tizen | appleTV | roku | chromeOS
2263
+ | playstation4 | playstation5 | nintendoSwitch | likeAndroid | android | linux | unknown | BotNames
2264
+ `@param version?: string` - string condition in the format: x.x...x | [~ >= > <= <]x.x...x
2265
+ `@returns boolean`
2266
+
2267
+ **Example:**
2268
+
2269
+ ```ts
2270
+ import {isOS} from '@bitfiber/utils/env';
2271
+
2272
+ isOS('windows');
2273
+ isOS('macOS', '~15.5');
2274
+ isOS('playstation4', '<=8.1');
2275
+ ```
2276
+
2277
+ ---
2278
+
2279
+ ### `isPortable`
2280
+
2281
+ Returns true if the platform is mobile or tablet, otherwise false
2282
+ `@returns boolean`
2283
+
2284
+ **Example:**
2285
+
2286
+ ```ts
2287
+ import {isPortable} from '@bitfiber/utils/env';
2288
+
2289
+ isPortable();
2290
+ ```
2291
+
2292
+ ---
2293
+
2294
+ ### `isSafariLike`
2295
+
2296
+ Returns true if the browser uses the WebKit engine like Safari, false otherwise
2297
+ `@returns boolean`
2298
+
2299
+ **Example:**
2300
+
2301
+ ```ts
2302
+ import {isSafariLike} from '@bitfiber/utils/env';
2303
+
2304
+ isSafariLike();
2305
+ ```
2306
+
2307
+ ---
2308
+
2309
+ ### `isStationary`
2310
+
2311
+ Returns true if the platform is desktop or TV, otherwise false
2312
+ `@returns boolean`
2313
+
2314
+ **Example:**
2315
+
2316
+ ```ts
2317
+ import {isStationary} from '@bitfiber/utils/env';
2318
+
2319
+ isStationary();
2320
+ ```
2321
+
2322
+ ---
2323
+
2324
+ ### `isTablet`
2325
+
2326
+ Returns true if the platform is tablet, otherwise false
2327
+ `@returns boolean`
2328
+
2329
+ **Example:**
2330
+
2331
+ ```ts
2332
+ import {isTablet} from '@bitfiber/utils/env';
2333
+
2334
+ isTablet();
2335
+ ```
2336
+
2337
+ ---
2338
+
2339
+ ### `isTV`
2340
+
2341
+ Returns true if the platform is TV, otherwise false
2342
+ `@returns boolean`
2343
+
2344
+ **Example:**
2345
+
2346
+ ```ts
2347
+ import {isTV} from '@bitfiber/utils/env';
2348
+
2349
+ isTV();
2350
+ ```
2351
+
2352
+ ---
2353
+
2354
+ ### `matches`
2355
+
2356
+ Checks if a current browser matches a specific set of conditions
2357
+ `@param condition: PlatformsCondition` - an object that has keys corresponding to platform names
2358
+ and values corresponding to objects that have keys corresponding to OS names
2359
+ and values corresponding to objects that have keys corresponding to browser names
2360
+ and values corresponding to browser versions
2361
+
2362
+ ```
2363
+ {
2364
+ [platformName | anyPlatform]: {
2365
+ [osName | anyOS]: {
2366
+ osVersion?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
2367
+ browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
2368
+ engines?: engineName | {
2369
+ engineName: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
2370
+ ...
2371
+ }
2372
+ ...
2373
+ }
2374
+ ...
2375
+ }
2376
+ ...
2377
+ }
2378
+ ```
2379
+
2380
+ `@returns boolean`
2381
+
2382
+ **Example:**
2383
+
2384
+ ```ts
2385
+ import {matches} from '@bitfiber/utils/env';
2386
+
2387
+ matches({anyPlatform: {anyOS: {chrome: ''}}});
2388
+ matches({desktop: {windows: {chrome: '96.0.4664.110'}}});
2389
+
2390
+ matches({
2391
+ desktop: {
2392
+ windows: {
2393
+ osVersion: '~10',
2394
+ engines: 'blink'
2395
+ }
2396
+ }
2397
+ });
2398
+
2399
+ matches({
2400
+ desktop: {
2401
+ anyOS: {
2402
+ engines: {
2403
+ blink: '>90.5',
2404
+ gecko: '<=100'
2405
+ }
2406
+
2407
+ }
2408
+ }
2409
+ });
2410
+
2411
+ matches({
2412
+ anyPlatform: {
2413
+ ios: {
2414
+ chrome: '~96.1',
2415
+ safari: '>80'
2416
+ }
2417
+ }
2418
+ });
2419
+ ```
2420
+
2421
+ ---
2422
+
2423
+ ### `matchesWithBrowsers`
2424
+
2425
+ Checks if a current browser matches a specific set of browsers
2426
+ `@param condition: BrowsersCondition` - an object that has keys corresponding to browser names and values corresponding
2427
+ to browser version conditions
2428
+
2429
+ ```
2430
+ {
2431
+ browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
2432
+ engines?: engineName | {
2433
+ engineNane: versionCondition(x.x...x | [~ >= > <= <]x.x...x)
2434
+ ...
2435
+ }
2436
+ ...
2437
+ }
2438
+ ```
2439
+
2440
+ `@returns boolean`
2441
+
2442
+ **Example:**
2443
+
2444
+ ```ts
2445
+ import {matchesWithBrowsers} from '@bitfiber/utils/env';
2446
+
2447
+ matchesWithBrowsers({
2448
+ firefox: '>=95.5',
2449
+ chrome: '~96.0.4664'
2450
+ });
2451
+
2452
+ matchesWithBrowsers({
2453
+ engines: 'gecko',
2454
+ firefox: '>100.1'
2455
+ });
2456
+
2457
+ matchesWithBrowsers({
2458
+ engines: {
2459
+ blink: '~96',
2460
+ gecko: '110.5.0'
2461
+ },
2462
+ firefox: '>100.1'
2463
+ });
2464
+ ```
2465
+
2466
+ ---
2467
+
2468
+ ### `matchesWithVersion`
2469
+
2470
+ Checks if a specific version matches a version condition
2471
+ `@param version: string` - any browser or OS version, for example: x.x...x
2472
+ `@param condition: string` - version condition in the format: x.x...x | [~ >= > <= <]x.x...x
2473
+ `@returns boolean`
2474
+
2475
+ **Example:**
2476
+
2477
+ ```ts
2478
+ import {matchesWithVersion} from '@bitfiber/utils/env';
2479
+
2480
+ matchesWithVersion('96.0.4664.110', '~96'); // true
2481
+ matchesWithVersion('96.0.4664.110', '>=95.5'); // true
2482
+ matchesWithVersion('96.0.4664.110', '<95.10'); // false
2483
+ ```
2484
+
2485
+ ---
2486
+
2487
+ ### `getUserAgent`
2488
+
2489
+ Returns user agent
2490
+ `@returns string`
2491
+
2492
+ **Example:**
2493
+
2494
+ ```ts
2495
+ import {getUserAgent} from '@bitfiber/utils/env';
2496
+
2497
+ const agent = getUserAgent(); // Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ...
2498
+ ```
2499
+
2500
+ ---
2501
+
2502
+ ### `setUserAgent`
2503
+
2504
+ If the global object is not a window, you can use this function to set up a stub user agent
2505
+ `@param userAgent: string` - any string with user agent data
2506
+ `@returns void`
2507
+
2508
+ **Example:**
2509
+
2510
+ ```ts
2511
+ import {setUserAgent} from '@bitfiber/utils/env';
2512
+
2513
+ setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)');
2514
+ ```
2515
+
2516
+ ---