@rogolev/value 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (355) hide show
  1. package/CHANGELOG.md +319 -1
  2. package/docs/classes/Expect/toBe.md +61 -0
  3. package/docs/classes/Expect/toBeArray.md +52 -0
  4. package/docs/classes/Expect/toBeAssoc.md +53 -0
  5. package/docs/classes/Expect/toBeBigInt.md +52 -0
  6. package/docs/classes/Expect/toBeBool.md +53 -0
  7. package/docs/classes/Expect/toBeBoolean.md +53 -0
  8. package/docs/classes/Expect/toBeChar.md +53 -0
  9. package/docs/classes/Expect/toBeClass.md +53 -0
  10. package/docs/classes/Expect/toBeFloat.md +53 -0
  11. package/docs/classes/Expect/toBeFunction.md +52 -0
  12. package/docs/classes/Expect/toBeInfinity.md +53 -0
  13. package/docs/classes/Expect/toBeInt.md +53 -0
  14. package/docs/classes/Expect/toBeInteger.md +53 -0
  15. package/docs/classes/Expect/toBeList.md +53 -0
  16. package/docs/classes/Expect/toBeNaN.md +53 -0
  17. package/docs/classes/Expect/toBeNull.md +51 -0
  18. package/docs/classes/Expect/toBeNumber.md +52 -0
  19. package/docs/classes/Expect/toBeNumeric.md +53 -0
  20. package/docs/classes/Expect/toBeObject.md +52 -0
  21. package/docs/classes/Expect/toBeScalar.md +53 -0
  22. package/docs/classes/Expect/toBeString.md +52 -0
  23. package/docs/classes/Expect/toBeSymbol.md +53 -0
  24. package/docs/classes/Expect/toBeUndefined.md +54 -0
  25. package/docs/classes/Expect/toEqual.md +69 -0
  26. package/docs/classes/Expect/toStrictEqual.md +70 -0
  27. package/docs/classes/Expect.md +87 -0
  28. package/docs/classes/Type/expectArray.md +63 -0
  29. package/docs/classes/Type/expectAssoc.md +65 -0
  30. package/docs/classes/Type/expectBigInt.md +63 -0
  31. package/docs/classes/Type/expectBool.md +65 -0
  32. package/docs/classes/Type/expectBoolean.md +65 -0
  33. package/docs/classes/Type/expectChar.md +63 -0
  34. package/docs/classes/Type/expectClass.md +63 -0
  35. package/docs/classes/Type/expectFloat.md +68 -0
  36. package/docs/classes/Type/expectFunction.md +63 -0
  37. package/docs/classes/Type/expectInfinity.md +65 -0
  38. package/docs/classes/Type/expectInt.md +64 -0
  39. package/docs/classes/Type/expectInteger.md +64 -0
  40. package/docs/classes/Type/expectList.md +63 -0
  41. package/docs/classes/Type/expectNaN.md +63 -0
  42. package/docs/classes/Type/expectNull.md +63 -0
  43. package/docs/classes/Type/expectNumber.md +63 -0
  44. package/docs/classes/Type/expectNumeric.md +63 -0
  45. package/docs/classes/Type/expectObject.md +64 -0
  46. package/docs/classes/Type/expectScalar.md +63 -0
  47. package/docs/classes/Type/expectString.md +63 -0
  48. package/docs/classes/Type/expectSymbol.md +63 -0
  49. package/docs/classes/Type/expectUndefined.md +63 -0
  50. package/docs/classes/Type.md +101 -2
  51. package/docs/classes.md +2 -1
  52. package/docs/helpers/array/array_chunk.md +80 -0
  53. package/docs/helpers/array/array_chunk_with_keys.md +81 -0
  54. package/docs/helpers/array/array_column.md +110 -0
  55. package/docs/helpers/array/array_combine.md +77 -0
  56. package/docs/helpers/array/array_count_values.md +71 -0
  57. package/docs/helpers/array/array_diff.md +97 -0
  58. package/docs/helpers/array/array_diff_assoc.md +81 -0
  59. package/docs/helpers/array/array_diff_key.md +81 -0
  60. package/docs/helpers/array/array_diff_uassoc.md +101 -0
  61. package/docs/helpers/array/array_diff_ukey.md +101 -0
  62. package/docs/helpers/array/array_fill.md +81 -0
  63. package/docs/helpers/array/array_fill_keys.md +73 -0
  64. package/docs/helpers/array/array_filter.md +79 -0
  65. package/docs/helpers/array/array_flip.md +70 -0
  66. package/docs/helpers/array/array_index_max.md +78 -0
  67. package/docs/helpers/array/array_index_min.md +78 -0
  68. package/docs/helpers/array/array_intersect.md +91 -0
  69. package/docs/helpers/array/array_intersect_assoc.md +91 -0
  70. package/docs/helpers/array/array_intersect_key.md +91 -0
  71. package/docs/helpers/array/array_intersect_uassoc.md +101 -0
  72. package/docs/helpers/array/array_intersect_ukey.md +101 -0
  73. package/docs/helpers/array/array_key_exists.md +73 -0
  74. package/docs/helpers/array/array_key_first.md +62 -0
  75. package/docs/helpers/array/array_key_last.md +62 -0
  76. package/docs/helpers/array/array_key_to_lower_case.md +57 -0
  77. package/docs/helpers/array/array_key_to_upper_case.md +57 -0
  78. package/docs/helpers/array/array_keys.md +62 -0
  79. package/docs/helpers/array/array_map.md +69 -0
  80. package/docs/helpers/array/array_merge.md +67 -0
  81. package/docs/helpers/array/array_merge_recursive.md +86 -0
  82. package/docs/helpers/array/array_pad.md +83 -0
  83. package/docs/helpers/array/array_pop.md +64 -0
  84. package/docs/helpers/array/array_product.md +62 -0
  85. package/docs/helpers/array/array_push.md +57 -0
  86. package/docs/helpers/array/array_rand.md +99 -0
  87. package/docs/helpers/array/array_reduce.md +77 -0
  88. package/docs/helpers/array/array_replace.md +85 -0
  89. package/docs/helpers/array/array_replace_recursive.md +87 -0
  90. package/docs/helpers/array/array_reverse.md +55 -0
  91. package/docs/helpers/array/array_search.md +74 -0
  92. package/docs/helpers/array/array_shift.md +64 -0
  93. package/docs/helpers/array/array_slice.md +65 -0
  94. package/docs/helpers/array/array_splice.md +103 -0
  95. package/docs/helpers/array/array_sum.md +55 -0
  96. package/docs/helpers/array/array_udiff.md +97 -0
  97. package/docs/helpers/array/array_udiff_assoc.md +101 -0
  98. package/docs/helpers/array/array_udiff_uassoc.md +88 -0
  99. package/docs/helpers/array/array_uintersect.md +101 -0
  100. package/docs/helpers/array/array_uintersect_assoc.md +102 -0
  101. package/docs/helpers/array/array_uintersect_uassoc.md +135 -0
  102. package/docs/helpers/array/array_unique.md +54 -0
  103. package/docs/helpers/array/array_unshift.md +58 -0
  104. package/docs/helpers/array/array_values.md +54 -0
  105. package/docs/helpers/array/array_walk.md +87 -0
  106. package/docs/helpers/array/array_walk_recursive.md +93 -0
  107. package/docs/helpers/array/count.md +54 -0
  108. package/docs/helpers/array/in_array.md +65 -0
  109. package/docs/helpers/array/natsort.md +60 -0
  110. package/docs/helpers/array/range.md +76 -0
  111. package/docs/helpers/array/shuffle.md +74 -0
  112. package/docs/helpers/array/sort.md +79 -0
  113. package/docs/helpers/expect.md +58 -0
  114. package/docs/helpers/expect_array.md +63 -0
  115. package/docs/helpers/expect_assoc.md +65 -0
  116. package/docs/helpers/expect_bigint.md +63 -0
  117. package/docs/helpers/expect_bool.md +65 -0
  118. package/docs/helpers/expect_boolean.md +65 -0
  119. package/docs/helpers/expect_char.md +63 -0
  120. package/docs/helpers/expect_class.md +63 -0
  121. package/docs/helpers/expect_float.md +65 -0
  122. package/docs/helpers/expect_function.md +63 -0
  123. package/docs/helpers/expect_infinity.md +65 -0
  124. package/docs/helpers/expect_int.md +65 -0
  125. package/docs/helpers/expect_integer.md +65 -0
  126. package/docs/helpers/expect_list.md +63 -0
  127. package/docs/helpers/expect_nan.md +63 -0
  128. package/docs/helpers/expect_null.md +63 -0
  129. package/docs/helpers/expect_number.md +63 -0
  130. package/docs/helpers/expect_numeric.md +63 -0
  131. package/docs/helpers/expect_object.md +64 -0
  132. package/docs/helpers/expect_scalar.md +63 -0
  133. package/docs/helpers/expect_string.md +63 -0
  134. package/docs/helpers/expect_symbol.md +63 -0
  135. package/docs/helpers/expect_undefined.md +64 -0
  136. package/docs/helpers/is_char.md +84 -0
  137. package/docs/helpers/is_equal.md +75 -0
  138. package/docs/helpers/string/is_digit_char.md +70 -0
  139. package/docs/helpers/string/is_whitespace_char.md +70 -0
  140. package/docs/helpers/string/natcompare.md +69 -0
  141. package/docs/helpers/string/natcompare_numeric.md +70 -0
  142. package/docs/helpers.md +172 -1
  143. package/index.mjs +91 -1
  144. package/package.json +1 -1
  145. package/prettier.config.mjs +2 -1
  146. package/src/classes/Expect.mjs +1445 -0
  147. package/src/classes/Type.mjs +2739 -1284
  148. package/src/constants.mjs +83 -14
  149. package/src/helpers/array/array_chunk.mjs +102 -0
  150. package/src/helpers/array/array_chunk_with_keys.mjs +102 -0
  151. package/src/helpers/array/array_column.mjs +131 -0
  152. package/src/helpers/array/array_combine.mjs +26 -0
  153. package/src/helpers/array/array_count_values.mjs +82 -0
  154. package/src/helpers/array/array_diff.mjs +77 -0
  155. package/src/helpers/array/array_diff_assoc.mjs +56 -0
  156. package/src/helpers/array/array_diff_key.mjs +56 -0
  157. package/src/helpers/array/array_diff_uassoc.mjs +76 -0
  158. package/src/helpers/array/array_diff_ukey.mjs +71 -0
  159. package/src/helpers/array/array_fill.mjs +108 -0
  160. package/src/helpers/array/array_fill_keys.mjs +90 -0
  161. package/src/helpers/array/array_filter.mjs +105 -0
  162. package/src/helpers/array/array_flip.mjs +58 -0
  163. package/src/helpers/array/array_index_max.mjs +82 -0
  164. package/src/helpers/array/array_index_min.mjs +82 -0
  165. package/src/helpers/array/array_intersect.mjs +71 -0
  166. package/src/helpers/array/array_intersect_assoc.mjs +67 -0
  167. package/src/helpers/array/array_intersect_key.mjs +67 -0
  168. package/src/helpers/array/array_intersect_uassoc.mjs +77 -0
  169. package/src/helpers/array/array_intersect_ukey.mjs +72 -0
  170. package/src/helpers/array/array_key_exists.mjs +83 -0
  171. package/src/helpers/array/array_key_first.mjs +73 -0
  172. package/src/helpers/array/array_key_last.mjs +74 -0
  173. package/src/helpers/array/array_key_to_lower_case.mjs +71 -0
  174. package/src/helpers/array/array_key_to_upper_case.mjs +71 -0
  175. package/src/helpers/array/array_keys.mjs +65 -0
  176. package/src/helpers/array/array_map.mjs +84 -0
  177. package/src/helpers/array/array_merge.mjs +95 -0
  178. package/src/helpers/array/array_merge_recursive.mjs +153 -0
  179. package/src/helpers/array/array_pad.mjs +105 -0
  180. package/src/helpers/array/array_pop.mjs +82 -0
  181. package/src/helpers/array/array_product.mjs +67 -0
  182. package/src/helpers/array/array_push.mjs +75 -0
  183. package/src/helpers/array/array_rand.mjs +129 -0
  184. package/src/helpers/array/array_reduce.mjs +90 -0
  185. package/src/helpers/array/array_replace.mjs +25 -0
  186. package/src/helpers/array/array_replace_recursive.mjs +109 -0
  187. package/src/helpers/array/array_reverse.mjs +62 -0
  188. package/src/helpers/array/array_search.mjs +104 -0
  189. package/src/helpers/array/array_shift.mjs +78 -0
  190. package/src/helpers/array/array_slice.mjs +99 -0
  191. package/src/helpers/array/array_splice.mjs +218 -0
  192. package/src/helpers/array/array_sum.mjs +60 -0
  193. package/src/helpers/array/array_udiff.mjs +91 -0
  194. package/src/helpers/array/array_udiff_assoc.mjs +71 -0
  195. package/src/helpers/array/array_udiff_uassoc.mjs +124 -0
  196. package/src/helpers/array/array_uintersect.mjs +72 -0
  197. package/src/helpers/array/array_uintersect_assoc.mjs +77 -0
  198. package/src/helpers/array/array_uintersect_uassoc.mjs +121 -0
  199. package/src/helpers/array/array_unique.mjs +77 -0
  200. package/src/helpers/array/array_unshift.mjs +64 -0
  201. package/src/helpers/array/array_values.mjs +57 -0
  202. package/src/helpers/array/array_walk.mjs +95 -0
  203. package/src/helpers/array/array_walk_recursive.mjs +104 -0
  204. package/src/helpers/array/count.mjs +57 -0
  205. package/src/helpers/array/in_array.mjs +67 -0
  206. package/src/helpers/array/natsort.mjs +62 -0
  207. package/src/helpers/array/range.mjs +121 -0
  208. package/src/helpers/array/shuffle.mjs +73 -0
  209. package/src/helpers/array/sort.mjs +69 -0
  210. package/src/helpers/expect.mjs +44 -0
  211. package/src/helpers/expect_array.mjs +66 -0
  212. package/src/helpers/expect_assoc.mjs +66 -0
  213. package/src/helpers/expect_bigint.mjs +66 -0
  214. package/src/helpers/expect_bool.mjs +66 -0
  215. package/src/helpers/expect_boolean.mjs +57 -0
  216. package/src/helpers/expect_char.mjs +66 -0
  217. package/src/helpers/expect_class.mjs +66 -0
  218. package/src/helpers/expect_float.mjs +66 -0
  219. package/src/helpers/expect_function.mjs +66 -0
  220. package/src/helpers/expect_infinity.mjs +66 -0
  221. package/src/helpers/expect_int.mjs +66 -0
  222. package/src/helpers/expect_integer.mjs +57 -0
  223. package/src/helpers/expect_list.mjs +66 -0
  224. package/src/helpers/expect_nan.mjs +66 -0
  225. package/src/helpers/expect_null.mjs +66 -0
  226. package/src/helpers/expect_number.mjs +66 -0
  227. package/src/helpers/expect_numeric.mjs +66 -0
  228. package/src/helpers/expect_object.mjs +67 -0
  229. package/src/helpers/expect_scalar.mjs +66 -0
  230. package/src/helpers/expect_string.mjs +65 -0
  231. package/src/helpers/expect_symbol.mjs +66 -0
  232. package/src/helpers/expect_undefined.mjs +66 -0
  233. package/src/helpers/is_char.mjs +54 -0
  234. package/src/helpers/is_equal.mjs +94 -0
  235. package/src/helpers/string/is_digit_char.mjs +60 -0
  236. package/src/helpers/string/is_whitespace_char.mjs +54 -0
  237. package/src/helpers/string/natcompare.mjs +107 -0
  238. package/src/helpers/string/natcompare_numeric.mjs +131 -0
  239. package/tests/classes/Expect/toBe.test.mjs +60 -0
  240. package/tests/classes/Expect/toBeArray.test.mjs +46 -0
  241. package/tests/classes/Expect/toBeAssoc.test.mjs +48 -0
  242. package/tests/classes/Expect/toBeBigInt.test.mjs +46 -0
  243. package/tests/classes/Expect/toBeBool.test.mjs +48 -0
  244. package/tests/classes/Expect/toBeBoolean.test.mjs +48 -0
  245. package/tests/classes/Expect/toBeChar.test.mjs +46 -0
  246. package/tests/classes/Expect/toBeClass.test.mjs +48 -0
  247. package/tests/classes/Expect/toBeFloat.test.mjs +48 -0
  248. package/tests/classes/Expect/toBeFunction.test.mjs +51 -0
  249. package/tests/classes/Expect/toBeInfinity.test.mjs +48 -0
  250. package/tests/classes/Expect/toBeInt.test.mjs +48 -0
  251. package/tests/classes/Expect/toBeInteger.test.mjs +48 -0
  252. package/tests/classes/Expect/toBeList.test.mjs +46 -0
  253. package/tests/classes/Expect/toBeNaN.test.mjs +46 -0
  254. package/tests/classes/Expect/toBeNull.test.mjs +46 -0
  255. package/tests/classes/Expect/toBeNumber.test.mjs +46 -0
  256. package/tests/classes/Expect/toBeNumeric.test.mjs +53 -0
  257. package/tests/classes/Expect/toBeObject.test.mjs +47 -0
  258. package/tests/classes/Expect/toBeScalar.test.mjs +63 -0
  259. package/tests/classes/Expect/toBeString.test.mjs +46 -0
  260. package/tests/classes/Expect/toBeSymbol.test.mjs +46 -0
  261. package/tests/classes/Expect/toBeUndefined.test.mjs +50 -0
  262. package/tests/classes/Expect/toEqual.test.mjs +66 -0
  263. package/tests/classes/Expect/toStrictEqual.test.mjs +73 -0
  264. package/tests/classes/Type.test.mjs +1320 -1262
  265. package/tests/helpers/array/array_chunk.test.mjs +49 -0
  266. package/tests/helpers/array/array_chunk_with_keys.test.mjs +45 -0
  267. package/tests/helpers/array/array_column.test.mjs +87 -0
  268. package/tests/helpers/array/array_combine.test.mjs +41 -0
  269. package/tests/helpers/array/array_count_values.test.mjs +40 -0
  270. package/tests/helpers/array/array_diff.test.mjs +78 -0
  271. package/tests/helpers/array/array_diff_assoc.test.mjs +64 -0
  272. package/tests/helpers/array/array_diff_key.test.mjs +64 -0
  273. package/tests/helpers/array/array_diff_uassoc.test.mjs +73 -0
  274. package/tests/helpers/array/array_diff_ukey.test.mjs +77 -0
  275. package/tests/helpers/array/array_fill.test.mjs +47 -0
  276. package/tests/helpers/array/array_fill_keys.test.mjs +35 -0
  277. package/tests/helpers/array/array_filter.test.mjs +38 -0
  278. package/tests/helpers/array/array_flip.test.mjs +33 -0
  279. package/tests/helpers/array/array_index_max.test.mjs +41 -0
  280. package/tests/helpers/array/array_index_min.test.mjs +41 -0
  281. package/tests/helpers/array/array_intersect.test.mjs +65 -0
  282. package/tests/helpers/array/array_intersect_assoc.test.mjs +65 -0
  283. package/tests/helpers/array/array_intersect_key.test.mjs +65 -0
  284. package/tests/helpers/array/array_intersect_uassoc.test.mjs +76 -0
  285. package/tests/helpers/array/array_intersect_ukey.test.mjs +74 -0
  286. package/tests/helpers/array/array_key_exists.test.mjs +36 -0
  287. package/tests/helpers/array/array_key_first.test.mjs +29 -0
  288. package/tests/helpers/array/array_key_last.test.mjs +29 -0
  289. package/tests/helpers/array/array_key_to_lower_case.test.mjs +23 -0
  290. package/tests/helpers/array/array_key_to_upper_case.test.mjs +23 -0
  291. package/tests/helpers/array/array_keys.test.mjs +27 -0
  292. package/tests/helpers/array/array_map.test.mjs +32 -0
  293. package/tests/helpers/array/array_merge.test.mjs +37 -0
  294. package/tests/helpers/array/array_merge_recursive.test.mjs +65 -0
  295. package/tests/helpers/array/array_pad.test.mjs +48 -0
  296. package/tests/helpers/array/array_pop.test.mjs +29 -0
  297. package/tests/helpers/array/array_product.test.mjs +33 -0
  298. package/tests/helpers/array/array_push.test.mjs +31 -0
  299. package/tests/helpers/array/array_rand.test.mjs +59 -0
  300. package/tests/helpers/array/array_reduce.test.mjs +44 -0
  301. package/tests/helpers/array/array_replace.test.mjs +46 -0
  302. package/tests/helpers/array/array_replace_recursive.test.mjs +46 -0
  303. package/tests/helpers/array/array_reverse.test.mjs +31 -0
  304. package/tests/helpers/array/array_search.test.mjs +48 -0
  305. package/tests/helpers/array/array_shift.test.mjs +29 -0
  306. package/tests/helpers/array/array_slice.test.mjs +49 -0
  307. package/tests/helpers/array/array_splice.test.mjs +67 -0
  308. package/tests/helpers/array/array_sum.test.mjs +27 -0
  309. package/tests/helpers/array/array_udiff.test.mjs +95 -0
  310. package/tests/helpers/array/array_udiff_assoc.test.mjs +77 -0
  311. package/tests/helpers/array/array_udiff_uassoc.test.mjs +89 -0
  312. package/tests/helpers/array/array_uintersect.test.mjs +78 -0
  313. package/tests/helpers/array/array_uintersect_assoc.test.mjs +80 -0
  314. package/tests/helpers/array/array_uintersect_uassoc.test.mjs +122 -0
  315. package/tests/helpers/array/array_unique.test.mjs +27 -0
  316. package/tests/helpers/array/array_unshift.test.mjs +31 -0
  317. package/tests/helpers/array/array_values.test.mjs +27 -0
  318. package/tests/helpers/array/array_walk.test.mjs +48 -0
  319. package/tests/helpers/array/array_walk_recursive.test.mjs +53 -0
  320. package/tests/helpers/array/count.test.mjs +27 -0
  321. package/tests/helpers/array/in_array.test.mjs +52 -0
  322. package/tests/helpers/array/natsort.test.mjs +71 -0
  323. package/tests/helpers/array/range.test.mjs +51 -0
  324. package/tests/helpers/array/shuffle.test.mjs +42 -0
  325. package/tests/helpers/array/sort.test.mjs +60 -0
  326. package/tests/helpers/array.test.mjs +58 -58
  327. package/tests/helpers/expect.test.mjs +95 -0
  328. package/tests/helpers/expect_array.test.mjs +71 -0
  329. package/tests/helpers/expect_assoc.test.mjs +61 -0
  330. package/tests/helpers/expect_bigint.test.mjs +63 -0
  331. package/tests/helpers/expect_bool.test.mjs +59 -0
  332. package/tests/helpers/expect_boolean.test.mjs +61 -0
  333. package/tests/helpers/expect_char.test.mjs +63 -0
  334. package/tests/helpers/expect_class.test.mjs +64 -0
  335. package/tests/helpers/expect_float.test.mjs +64 -0
  336. package/tests/helpers/expect_function.test.mjs +65 -0
  337. package/tests/helpers/expect_infinity.test.mjs +62 -0
  338. package/tests/helpers/expect_int.test.mjs +57 -0
  339. package/tests/helpers/expect_integer.test.mjs +59 -0
  340. package/tests/helpers/expect_list.test.mjs +73 -0
  341. package/tests/helpers/expect_nan.test.mjs +57 -0
  342. package/tests/helpers/expect_null.test.mjs +57 -0
  343. package/tests/helpers/expect_number.test.mjs +57 -0
  344. package/tests/helpers/expect_numeric.test.mjs +57 -0
  345. package/tests/helpers/expect_object.test.mjs +63 -0
  346. package/tests/helpers/expect_scalar.test.mjs +72 -0
  347. package/tests/helpers/expect_string.test.mjs +65 -0
  348. package/tests/helpers/expect_symbol.test.mjs +66 -0
  349. package/tests/helpers/expect_undefined.test.mjs +59 -0
  350. package/tests/helpers/is_char.test.mjs +40 -0
  351. package/tests/helpers/is_equal.test.mjs +110 -0
  352. package/tests/helpers/string/is_digit_char.test.mjs +32 -0
  353. package/tests/helpers/string/is_whitespace_char.test.mjs +32 -0
  354. package/tests/helpers/string/natcompare.test.mjs +100 -0
  355. package/tests/helpers/string/natcompare_numeric.test.mjs +110 -0
@@ -0,0 +1,95 @@
1
+ import is_array from '../is_array.mjs';
2
+ import is_function from '../is_function.mjs';
3
+
4
+ /**
5
+ * Применяет пользовательскую функцию к каждому элементу массива.
6
+ *
7
+ * ### Описание
8
+ *
9
+ * Функция `array_walk` используется для применения пользовательской функции к каждому элементу массива.
10
+ * Она поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
11
+ *
12
+ * ### Параметры
13
+ *
14
+ * - `arr` (object): Исходный массив.
15
+ * - `callback` (function): Функция, которая будет применена к каждому элементу массива.
16
+ * - `arg` (any): Дополнительный аргумент, который будет передан в функцию обратного вызова. По умолчанию `null`.
17
+ *
18
+ * ### Возвращаемое значение
19
+ *
20
+ * Возвращает `true` после успешного выполнения функции для всех элементов массива.
21
+ *
22
+ * ### Примеры использования
23
+ *
24
+ * 1. Применение функции к каждому элементу обычного массива:
25
+ *
26
+ * ```js
27
+ * const array = [1, 2, 3];
28
+ * array_walk(array, (value, key) => {
29
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
30
+ * });
31
+ * // Вывод:
32
+ * // Ключ: 0, Значение: 1
33
+ * // Ключ: 1, Значение: 2
34
+ * // Ключ: 2, Значение: 3
35
+ * ```
36
+ *
37
+ * 2. Применение функции к каждому элементу ассоциативного массива:
38
+ *
39
+ * ```js
40
+ * const array = { a: 1, b: 2, c: 3 };
41
+ * array_walk(array, (value, key) => {
42
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
43
+ * });
44
+ * // Вывод:
45
+ * // Ключ: a, Значение: 1
46
+ * // Ключ: b, Значение: 2
47
+ * // Ключ: c, Значение: 3
48
+ * ```
49
+ *
50
+ * 3. Применение функции с дополнительным аргументом:
51
+ *
52
+ * ```js
53
+ * const array = [1, 2, 3];
54
+ * array_walk(array, (value, key, arg) => {
55
+ * console.log(`Ключ: ${key}, Значение: ${value}, Аргумент: ${arg}`);
56
+ * }, 'дополнительный аргумент');
57
+ * // Вывод:
58
+ * // Ключ: 0, Значение: 1, Аргумент: дополнительный аргумент
59
+ * // Ключ: 1, Значение: 2, Аргумент: дополнительный аргумент
60
+ * // Ключ: 2, Значение: 3, Аргумент: дополнительный аргумент
61
+ * ```
62
+ *
63
+ * 4. Обработка значений, не являющихся массивами:
64
+ *
65
+ * ```js
66
+ * try {
67
+ * array_walk('not an array', (value, key) => {
68
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
69
+ * });
70
+ * } catch (e) {
71
+ * console.error(e.message); // Параметр "arr" должен быть массивом.
72
+ * }
73
+ * ```
74
+ *
75
+ * @param {object} arr Исходный массив.
76
+ * @param {function} callback Функция, которая будет применена к каждому элементу массива.
77
+ * @param {any} [arg=null] Дополнительный аргумент, который будет передан в функцию обратного вызова.
78
+ * @returns {boolean} Возвращает `true` после успешного выполнения функции для всех элементов массива.
79
+ * @throws {TypeError} Если параметры не являются массивом или функцией.
80
+ */
81
+ export default function array_walk(arr, callback, arg = null) {
82
+ if (!is_array(arr)) {
83
+ throw new TypeError('Параметр "arr" должен быть массивом.');
84
+ }
85
+
86
+ if (!is_function(callback)) {
87
+ throw new TypeError('Параметр "callback" должен быть функцией.');
88
+ }
89
+
90
+ for (const [k, v] of Object.entries(arr)) {
91
+ callback(v, k, arg);
92
+ }
93
+
94
+ return true;
95
+ }
@@ -0,0 +1,104 @@
1
+ import is_array from '../is_array.mjs';
2
+ import is_function from '../is_function.mjs';
3
+
4
+ /**
5
+ * Применяет пользовательскую функцию к каждому элементу массива рекурсивно.
6
+ *
7
+ * ### Описание
8
+ *
9
+ * Функция `array_walk_recursive` используется для применения пользовательской функции к каждому элементу массива рекурсивно.
10
+ * Она поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
11
+ *
12
+ * ### Параметры
13
+ *
14
+ * - `arr` (object): Исходный массив.
15
+ * - `callback` (function): Функция, которая будет применена к каждому элементу массива.
16
+ * - `arg` (any): Дополнительный аргумент, который будет передан в функцию обратного вызова. По умолчанию `null`.
17
+ *
18
+ * ### Возвращаемое значение
19
+ *
20
+ * Возвращает `true` после успешного выполнения функции для всех элементов массива.
21
+ *
22
+ * ### Примеры использования
23
+ *
24
+ * 1. Применение функции к каждому элементу обычного массива:
25
+ *
26
+ * ```js
27
+ * const array = [1, 2, [3, 4], 5];
28
+ * array_walk_recursive(array, (value, key) => {
29
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
30
+ * });
31
+ * // Вывод:
32
+ * // Ключ: 0, Значение: 1
33
+ * // Ключ: 1, Значение: 2
34
+ * // Ключ: 0, Значение: 3
35
+ * // Ключ: 1, Значение: 4
36
+ * // Ключ: 3, Значение: 5
37
+ * ```
38
+ *
39
+ * 2. Применение функции к каждому элементу ассоциативного массива:
40
+ *
41
+ * ```js
42
+ * const array = { a: 1, b: { c: 2, d: 3 }, e: 4 };
43
+ * array_walk_recursive(array, (value, key) => {
44
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
45
+ * });
46
+ * // Вывод:
47
+ * // Ключ: a, Значение: 1
48
+ * // Ключ: c, Значение: 2
49
+ * // Ключ: d, Значение: 3
50
+ * // Ключ: e, Значение: 4
51
+ * ```
52
+ *
53
+ * 3. Применение функции с дополнительным аргументом:
54
+ *
55
+ * ```js
56
+ * const array = [1, 2, [3, 4], 5];
57
+ * array_walk_recursive(array, (value, key, arg) => {
58
+ * console.log(`Ключ: ${key}, Значение: ${value}, Аргумент: ${arg}`);
59
+ * }, 'дополнительный аргумент');
60
+ * // Вывод:
61
+ * // Ключ: 0, Значение: 1, Аргумент: дополнительный аргумент
62
+ * // Ключ: 1, Значение: 2, Аргумент: дополнительный аргумент
63
+ * // Ключ: 0, Значение: 3, Аргумент: дополнительный аргумент
64
+ * // Ключ: 1, Значение: 4, Аргумент: дополнительный аргумент
65
+ * // Ключ: 3, Значение: 5, Аргумент: дополнительный аргумент
66
+ * ```
67
+ *
68
+ * 4. Обработка значений, не являющихся массивами:
69
+ *
70
+ * ```js
71
+ * try {
72
+ * array_walk_recursive('not an array', (value, key) => {
73
+ * console.log(`Ключ: ${key}, Значение: ${value}`);
74
+ * });
75
+ * } catch (e) {
76
+ * console.error(e.message); // Параметр "arr" должен быть массивом.
77
+ * }
78
+ * ```
79
+ *
80
+ * @param {object} arr Исходный массив.
81
+ * @param {function} callback Функция, которая будет применена к каждому элементу массива.
82
+ * @param {any} [arg=null] Дополнительный аргумент, который будет передан в функцию обратного вызова.
83
+ * @returns {boolean} Возвращает `true` после успешного выполнения функции для всех элементов массива.
84
+ * @throws {TypeError} Если параметры не являются массивом или функцией.
85
+ */
86
+ export default function array_walk_recursive(arr, callback, arg = null) {
87
+ if (!is_array(arr)) {
88
+ throw new TypeError('Параметр "arr" должен быть массивом.');
89
+ }
90
+
91
+ if (!is_function(callback)) {
92
+ throw new TypeError('Параметр "callback" должен быть функцией.');
93
+ }
94
+
95
+ for (const [k, v] of Object.entries(arr)) {
96
+ if (is_array(v)) {
97
+ array_walk_recursive(v, callback, arg);
98
+ } else {
99
+ callback(v, k, arg);
100
+ }
101
+ }
102
+
103
+ return true;
104
+ }
@@ -0,0 +1,57 @@
1
+ import is_array from '../is_array.mjs';
2
+
3
+ /**
4
+ * Возвращает количество элементов в массиве или ассоциативном массиве.
5
+ *
6
+ * ### Описание
7
+ *
8
+ * Функция `count` используется для подсчета количества элементов в массиве или ассоциативном массиве (объекте с ключами и значениями).
9
+ * Она поддерживает как обычные массивы, так и ассоциативные массивы.
10
+ *
11
+ * ### Параметры
12
+ *
13
+ * - `arr` (object): Исходный массив или ассоциативный массив.
14
+ *
15
+ * ### Возвращаемое значение
16
+ *
17
+ * Возвращает количество элементов в массиве или ассоциативном массиве.
18
+ *
19
+ * ### Примеры использования
20
+ *
21
+ * 1. Подсчет элементов в обычном массиве:
22
+ *
23
+ * ```js
24
+ * const array = [1, 2, 3, 4, 5];
25
+ * const result = count(array);
26
+ * console.log(result); // 5
27
+ * ```
28
+ *
29
+ * 2. Подсчет элементов в ассоциативном массиве:
30
+ *
31
+ * ```js
32
+ * const array = { a: 1, b: 2, c: 3 };
33
+ * const result = count(array);
34
+ * console.log(result); // 3
35
+ * ```
36
+ *
37
+ * 3. Обработка значений, не являющихся массивами:
38
+ *
39
+ * ```js
40
+ * try {
41
+ * const result = count('not an array');
42
+ * } catch (e) {
43
+ * console.error(e.message); // Параметр "arr" должен быть массивом.
44
+ * }
45
+ * ```
46
+ *
47
+ * @param {object} arr Исходный массив или ассоциативный массив.
48
+ * @returns {number} Возвращает количество элементов в массиве или ассоциативном массиве.
49
+ * @throws {TypeError} Если параметр не является массивом или ассоциативным массивом.
50
+ */
51
+ export default function count(arr) {
52
+ if (!is_array(arr)) {
53
+ throw new TypeError('Параметр "arr" должен быть массивом.');
54
+ }
55
+
56
+ return Object.keys(arr).length;
57
+ }
@@ -0,0 +1,67 @@
1
+ import is_null from '../is_null.mjs';
2
+ import array_search from './array_search.mjs';
3
+
4
+ /**
5
+ * Проверяет, существует ли значение в массиве.
6
+ *
7
+ * ### Описание
8
+ *
9
+ * Функция `in_array` используется для проверки, существует ли значение в массиве.
10
+ * Она поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
11
+ * Функция может работать в строгом режиме, сравнивая значения с учетом типа.
12
+ *
13
+ * ### Параметры
14
+ *
15
+ * - `arr` (object): Исходный массив.
16
+ * - `value` (any): Значение для поиска.
17
+ * - `strict` (boolean): Флаг строгого сравнения. По умолчанию `false`.
18
+ *
19
+ * ### Возвращаемое значение
20
+ *
21
+ * Возвращает `true`, если значение существует в массиве, иначе `false`.
22
+ *
23
+ * ### Примеры использования
24
+ *
25
+ * 1. Проверка значения в обычном массиве:
26
+ *
27
+ * ```js
28
+ * const array = [1, 2, 3, 4, 5];
29
+ * const result = in_array(array, 3);
30
+ * console.log(result); // true
31
+ * ```
32
+ *
33
+ * 2. Проверка значения в ассоциативном массиве:
34
+ *
35
+ * ```js
36
+ * const array = { a: 1, b: 2, c: 3 };
37
+ * const result = in_array(array, 2);
38
+ * console.log(result); // true
39
+ * ```
40
+ *
41
+ * 3. Проверка значения с использованием строгого сравнения:
42
+ *
43
+ * ```js
44
+ * const array = [1, '2', 3];
45
+ * const result = in_array(array, 2, true);
46
+ * console.log(result); // false
47
+ * ```
48
+ *
49
+ * 4. Обработка значений, не являющихся массивами:
50
+ *
51
+ * ```js
52
+ * try {
53
+ * const result = in_array('not an array', 1);
54
+ * } catch (e) {
55
+ * console.error(e.message); // Параметр "arr" должен быть массивом.
56
+ * }
57
+ * ```
58
+ *
59
+ * @param {object} arr Исходный массив.
60
+ * @param {any} value Значение для поиска.
61
+ * @param {boolean} [strict=false] Флаг строгого сравнения.
62
+ * @returns {boolean} Возвращает `true`, если значение существует в массиве, иначе `false`.
63
+ * @throws {TypeError} Если параметр не является массивом или если параметр strict не является логическим значением.
64
+ */
65
+ export default function in_array(arr, value, strict = false) {
66
+ return !is_null(array_search(arr, value, strict));
67
+ }
@@ -0,0 +1,62 @@
1
+ import is_function from '../is_function.mjs';
2
+ import natcompare from '../string/natcompare.mjs';
3
+ import to_string from '../to_string.mjs';
4
+ import sort from './sort.mjs';
5
+
6
+ /**
7
+ * Сортирует массив в естественном порядке.
8
+ *
9
+ * ### Описание
10
+ *
11
+ * Функция `natsort` используется для сортировки массива в естественном порядке.
12
+ * Она поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
13
+ * Функция принимает необязательный параметр `getter`, который используется для получения значения для сравнения.
14
+ *
15
+ * ### Параметры
16
+ *
17
+ * - `arr` (object): Исходный массив.
18
+ * - `getter` (function): Функция для получения значения для сравнения. По умолчанию `(entry) => entry[1]`.
19
+ *
20
+ * ### Возвращаемое значение
21
+ *
22
+ * Возвращает новый массив, отсортированный в естественном порядке.
23
+ *
24
+ * ### Примеры использования
25
+ *
26
+ * 1. Сортировка обычного массива:
27
+ *
28
+ * ```js
29
+ * const array = [10, 2, 30, 4];
30
+ * const result = natsort(array);
31
+ * console.log(result); // [2, 4, 10, 30]
32
+ * ```
33
+ *
34
+ * 2. Сортировка ассоциативного массива:
35
+ *
36
+ * ```js
37
+ * const array = { a: 10, b: 2, c: 30, d: 4 };
38
+ * const result = natsort(array);
39
+ * console.log(result); // [['b', 2], ['d', 4], ['a', 10], ['c', 30]]
40
+ * ```
41
+ *
42
+ * 3. Сортировка массива с использованием функции `getter`:
43
+ *
44
+ * ```js
45
+ * const array = [{ value: 10 }, { value: 2 }, { value: 30 }, { value: 4 }];
46
+ * const result = natsort(array, (entry) => entry[1].value);
47
+ * console.log(result); // [{ value: 2 }, { value: 4 }, { value: 10 }, { value: 30 }]
48
+ * ```
49
+ *
50
+ * @param {object} arr Исходный массив.
51
+ * @param {function} [getter=(entry) => entry[1]] Функция для получения значения для сравнения.
52
+ * @returns {array} Новый массив, отсортированный в естественном порядке.
53
+ * @throws {TypeError} Если параметр `arr` не является массивом.
54
+ * @throws {TypeError} Если параметр `getter` не является функцией.
55
+ */
56
+ export default function natsort(arr, getter = (entry) => entry[1]) {
57
+ if (!is_function(getter)) {
58
+ throw new TypeError('Параметр "getter" должен быть функцией.');
59
+ }
60
+
61
+ return sort(arr, (a, b) => natcompare(to_string(getter(a)), to_string(getter(b))));
62
+ }
@@ -0,0 +1,121 @@
1
+ import is_float from '../is_float.mjs';
2
+ import is_int from '../is_int.mjs';
3
+ import is_nan from '../is_nan.mjs';
4
+ import is_string from '../is_string.mjs';
5
+ import to_float from '../to_float.mjs';
6
+
7
+ /**
8
+ * Генерирует массив значений от start до end с шагом step.
9
+ *
10
+ * ### Описание
11
+ *
12
+ * Функция `range` используется для генерации массива значений от начального значения до конечного с заданным шагом.
13
+ * Поддерживает как числовые значения, так и строки. Шаг не может быть равен нулю.
14
+ *
15
+ * ### Параметры
16
+ *
17
+ * - `start` (string|number): Начальное значение (строка или число).
18
+ * - `end` (string|number): Конечное значение (строка или число).
19
+ * - `step` (number): Шаг между значениями (по умолчанию 1).
20
+ *
21
+ * ### Возвращаемое значение
22
+ *
23
+ * Возвращает массив значений от start до end с шагом step.
24
+ *
25
+ * ### Примеры использования
26
+ *
27
+ * 1. Генерация числового диапазона:
28
+ *
29
+ * ```js
30
+ * const result = range(1, 5);
31
+ * console.log(result); // [1, 2, 3, 4, 5]
32
+ * ```
33
+ *
34
+ * 2. Генерация диапазона с отрицательным шагом:
35
+ *
36
+ * ```js
37
+ * const result = range(5, 1, -1);
38
+ * console.log(result); // [5, 4, 3, 2, 1]
39
+ * ```
40
+ *
41
+ * 3. Генерация диапазона строк:
42
+ *
43
+ * ```js
44
+ * const result = range('a', 'e');
45
+ * console.log(result); // ['a', 'b', 'c', 'd', 'e']
46
+ * ```
47
+ *
48
+ * 4. Обработка значений с преобразованием типов:
49
+ *
50
+ * ```js
51
+ * const result = range('1', 5);
52
+ * console.log(result); // [1, 2, 3, 4, 5]
53
+ * ```
54
+ *
55
+ * @param {string|number} start Начальное значение (строка или число).
56
+ * @param {string|number} end Конечное значение (строка или число).
57
+ * @param {number} [step=1] Шаг между значениями.
58
+ * @returns {Array} Массив значений от start до end с шагом step.
59
+ * @throws {TypeError} Если параметры имеют неверный тип или значение.
60
+ */
61
+ export default function range(start, end, step = 1) {
62
+ if (!is_string(start) && !is_int(start) && !is_float(start)) {
63
+ throw new TypeError('Параметр "start" должен быть строкой или числом.');
64
+ }
65
+
66
+ if (!is_string(end) && !is_int(end) && !is_float(end)) {
67
+ throw new TypeError('Параметр "end" должен быть строкой или числом.');
68
+ }
69
+
70
+ if (!is_int(step) && !is_float(step)) {
71
+ throw new TypeError('Параметр "step" должен быть числом.');
72
+ }
73
+
74
+ if (step === 0) {
75
+ throw new TypeError('Параметр "step" не может быть равен нулю.');
76
+ }
77
+
78
+ if (start < end && step < 0) {
79
+ throw new TypeError('Параметр "step" должен быть больше нуля при start <= end.');
80
+ }
81
+
82
+ step = Math.abs(step);
83
+
84
+ if (start === '') {
85
+ start = 0;
86
+ }
87
+
88
+ if (end === '') {
89
+ end = 0;
90
+ }
91
+
92
+ if (is_string(start) && (is_int(end) || is_float(end))) {
93
+ start = is_nan(to_float(start)) ? 0 : to_float(start);
94
+ }
95
+
96
+ if ((is_int(start) || is_float(start)) && is_string(end)) {
97
+ end = is_nan(to_float(end)) ? 0 : to_float(end);
98
+ }
99
+
100
+ let next;
101
+
102
+ if ((is_int(start) || is_float(start)) && (is_int(end) || is_float(end))) {
103
+ next = start < end ? (value) => (value += step) : (value) => (value -= step);
104
+ } else {
105
+ next =
106
+ start < end ?
107
+ (value) => String.fromCharCode(value.charCodeAt(0) + step)
108
+ : (value) => String.fromCharCode(value.charCodeAt(0) - step);
109
+ }
110
+
111
+ const result = [];
112
+
113
+ let value = is_string(start) ? start.at(0) : start;
114
+
115
+ do {
116
+ result.push(value);
117
+ value = next(value);
118
+ } while (start < end ? value <= end : value >= end);
119
+
120
+ return result;
121
+ }
@@ -0,0 +1,73 @@
1
+ import is_array from '../is_array.mjs';
2
+ import is_list from '../is_list.mjs';
3
+ import array_rand from './array_rand.mjs';
4
+
5
+ /**
6
+ * Перемешивает элементы массива в случайном порядке.
7
+ *
8
+ * ### Описание
9
+ *
10
+ * Функция `shuffle` используется для перемешивания элементов массива в случайном порядке.
11
+ * Поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
12
+ *
13
+ * ### Параметры
14
+ *
15
+ * - `arr` (object): Исходный массив.
16
+ *
17
+ * ### Возвращаемое значение
18
+ *
19
+ * Возвращает новый массив с элементами в случайном порядке.
20
+ *
21
+ * ### Примеры использования
22
+ *
23
+ * 1. Перемешивание обычного массива:
24
+ *
25
+ * ```js
26
+ * const array = [1, 2, 3, 4, 5];
27
+ * const result = shuffle(array);
28
+ * console.log(result); // [3, 1, 5, 2, 4] (пример)
29
+ * ```
30
+ *
31
+ * 2. Перемешивание ассоциативного массива:
32
+ *
33
+ * ```js
34
+ * const array = { a: 1, b: 2, c: 3 };
35
+ * const result = shuffle(array);
36
+ * console.log(result); // [['b', 2], ['a', 1], ['c', 3]] (пример)
37
+ * ```
38
+ *
39
+ * @param {object} arr Исходный массив.
40
+ * @returns {array} Новый массив с элементами в случайном порядке.
41
+ * @throws {TypeError} Если параметр не является массивом.
42
+ */
43
+ export default function shuffle(arr) {
44
+ if (!is_array(arr)) {
45
+ throw new TypeError('Параметр "arr" должен быть массивом.');
46
+ }
47
+
48
+ const count = Object.keys(arr).length;
49
+
50
+ if (count === 0 || count === 1) {
51
+ return arr;
52
+ }
53
+
54
+ const rand_keys = array_rand(arr, count);
55
+
56
+ if (is_list(arr)) {
57
+ const rand_values = [];
58
+
59
+ for (const key of rand_keys) {
60
+ rand_values.push(arr[key]);
61
+ }
62
+
63
+ return rand_values;
64
+ }
65
+
66
+ const result = [];
67
+
68
+ for (const key of rand_keys) {
69
+ result.push([key, arr[key]]);
70
+ }
71
+
72
+ return result;
73
+ }
@@ -0,0 +1,69 @@
1
+ import is_array from '../is_array.mjs';
2
+ import is_function from '../is_function.mjs';
3
+ import is_list from '../is_list.mjs';
4
+
5
+ /**
6
+ * Сортирует элементы массива с использованием функции сравнения.
7
+ *
8
+ * ### Описание
9
+ *
10
+ * Функция `sort` используется для сортировки элементов массива с использованием функции сравнения.
11
+ * Поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
12
+ *
13
+ * ### Параметры
14
+ *
15
+ * - `arr` (object): Исходный массив.
16
+ * - `compare_func` (function): Функция сравнения, используемая для сортировки. По умолчанию `(a, b) => a[1] - b[1]`.
17
+ *
18
+ * ### Возвращаемое значение
19
+ *
20
+ * Возвращает новый массив с отсортированными элементами.
21
+ *
22
+ * ### Примеры использования
23
+ *
24
+ * 1. Сортировка обычного массива:
25
+ *
26
+ * ```js
27
+ * const array = [5, 3, 1, 4, 2];
28
+ * const result = sort(array);
29
+ * console.log(result); // [1, 2, 3, 4, 5]
30
+ * ```
31
+ *
32
+ * 2. Сортировка ассоциативного массива:
33
+ *
34
+ * ```js
35
+ * const array = { a: 3, b: 1, c: 2 };
36
+ * const result = sort(array);
37
+ * console.log(result); // [['b', 1], ['c', 2], ['a', 3]]
38
+ * ```
39
+ *
40
+ * 3. Сортировка с использованием пользовательской функции сравнения:
41
+ *
42
+ * ```js
43
+ * const array = [5, 3, 1, 4, 2];
44
+ * const result = sort(array, (a, b) => b[1] - a[1]);
45
+ * console.log(result); // [5, 4, 3, 2, 1]
46
+ * ```
47
+ *
48
+ * @param {object} arr Исходный массив.
49
+ * @param {function} [compare_func=(a, b) => a[1] - b[1]] Функция сравнения, используемая для сортировки.
50
+ * @returns {array} Новый массив с отсортированными элементами.
51
+ * @throws {TypeError} Если параметр не является массивом или если параметр compare_func не является функцией.
52
+ */
53
+ export default function sort(arr, compare_func = (a, b) => a[1] - b[1]) {
54
+ if (!is_array(arr)) {
55
+ throw new TypeError('Параметр "arr" должен быть массивом.');
56
+ }
57
+
58
+ if (!is_function(compare_func)) {
59
+ throw new TypeError('Параметр "compare_func" должен быть функцией.');
60
+ }
61
+
62
+ const result = Object.entries(arr).sort(compare_func);
63
+
64
+ if (is_list(arr)) {
65
+ return result.map(([, v]) => v);
66
+ }
67
+
68
+ return result;
69
+ }