@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.
- package/CHANGELOG.md +319 -1
- package/docs/classes/Expect/toBe.md +61 -0
- package/docs/classes/Expect/toBeArray.md +52 -0
- package/docs/classes/Expect/toBeAssoc.md +53 -0
- package/docs/classes/Expect/toBeBigInt.md +52 -0
- package/docs/classes/Expect/toBeBool.md +53 -0
- package/docs/classes/Expect/toBeBoolean.md +53 -0
- package/docs/classes/Expect/toBeChar.md +53 -0
- package/docs/classes/Expect/toBeClass.md +53 -0
- package/docs/classes/Expect/toBeFloat.md +53 -0
- package/docs/classes/Expect/toBeFunction.md +52 -0
- package/docs/classes/Expect/toBeInfinity.md +53 -0
- package/docs/classes/Expect/toBeInt.md +53 -0
- package/docs/classes/Expect/toBeInteger.md +53 -0
- package/docs/classes/Expect/toBeList.md +53 -0
- package/docs/classes/Expect/toBeNaN.md +53 -0
- package/docs/classes/Expect/toBeNull.md +51 -0
- package/docs/classes/Expect/toBeNumber.md +52 -0
- package/docs/classes/Expect/toBeNumeric.md +53 -0
- package/docs/classes/Expect/toBeObject.md +52 -0
- package/docs/classes/Expect/toBeScalar.md +53 -0
- package/docs/classes/Expect/toBeString.md +52 -0
- package/docs/classes/Expect/toBeSymbol.md +53 -0
- package/docs/classes/Expect/toBeUndefined.md +54 -0
- package/docs/classes/Expect/toEqual.md +69 -0
- package/docs/classes/Expect/toStrictEqual.md +70 -0
- package/docs/classes/Expect.md +87 -0
- package/docs/classes/Type/expectArray.md +63 -0
- package/docs/classes/Type/expectAssoc.md +65 -0
- package/docs/classes/Type/expectBigInt.md +63 -0
- package/docs/classes/Type/expectBool.md +65 -0
- package/docs/classes/Type/expectBoolean.md +65 -0
- package/docs/classes/Type/expectChar.md +63 -0
- package/docs/classes/Type/expectClass.md +63 -0
- package/docs/classes/Type/expectFloat.md +68 -0
- package/docs/classes/Type/expectFunction.md +63 -0
- package/docs/classes/Type/expectInfinity.md +65 -0
- package/docs/classes/Type/expectInt.md +64 -0
- package/docs/classes/Type/expectInteger.md +64 -0
- package/docs/classes/Type/expectList.md +63 -0
- package/docs/classes/Type/expectNaN.md +63 -0
- package/docs/classes/Type/expectNull.md +63 -0
- package/docs/classes/Type/expectNumber.md +63 -0
- package/docs/classes/Type/expectNumeric.md +63 -0
- package/docs/classes/Type/expectObject.md +64 -0
- package/docs/classes/Type/expectScalar.md +63 -0
- package/docs/classes/Type/expectString.md +63 -0
- package/docs/classes/Type/expectSymbol.md +63 -0
- package/docs/classes/Type/expectUndefined.md +63 -0
- package/docs/classes/Type.md +101 -2
- package/docs/classes.md +2 -1
- package/docs/helpers/array/array_chunk.md +80 -0
- package/docs/helpers/array/array_chunk_with_keys.md +81 -0
- package/docs/helpers/array/array_column.md +110 -0
- package/docs/helpers/array/array_combine.md +77 -0
- package/docs/helpers/array/array_count_values.md +71 -0
- package/docs/helpers/array/array_diff.md +97 -0
- package/docs/helpers/array/array_diff_assoc.md +81 -0
- package/docs/helpers/array/array_diff_key.md +81 -0
- package/docs/helpers/array/array_diff_uassoc.md +101 -0
- package/docs/helpers/array/array_diff_ukey.md +101 -0
- package/docs/helpers/array/array_fill.md +81 -0
- package/docs/helpers/array/array_fill_keys.md +73 -0
- package/docs/helpers/array/array_filter.md +79 -0
- package/docs/helpers/array/array_flip.md +70 -0
- package/docs/helpers/array/array_index_max.md +78 -0
- package/docs/helpers/array/array_index_min.md +78 -0
- package/docs/helpers/array/array_intersect.md +91 -0
- package/docs/helpers/array/array_intersect_assoc.md +91 -0
- package/docs/helpers/array/array_intersect_key.md +91 -0
- package/docs/helpers/array/array_intersect_uassoc.md +101 -0
- package/docs/helpers/array/array_intersect_ukey.md +101 -0
- package/docs/helpers/array/array_key_exists.md +73 -0
- package/docs/helpers/array/array_key_first.md +62 -0
- package/docs/helpers/array/array_key_last.md +62 -0
- package/docs/helpers/array/array_key_to_lower_case.md +57 -0
- package/docs/helpers/array/array_key_to_upper_case.md +57 -0
- package/docs/helpers/array/array_keys.md +62 -0
- package/docs/helpers/array/array_map.md +69 -0
- package/docs/helpers/array/array_merge.md +67 -0
- package/docs/helpers/array/array_merge_recursive.md +86 -0
- package/docs/helpers/array/array_pad.md +83 -0
- package/docs/helpers/array/array_pop.md +64 -0
- package/docs/helpers/array/array_product.md +62 -0
- package/docs/helpers/array/array_push.md +57 -0
- package/docs/helpers/array/array_rand.md +99 -0
- package/docs/helpers/array/array_reduce.md +77 -0
- package/docs/helpers/array/array_replace.md +85 -0
- package/docs/helpers/array/array_replace_recursive.md +87 -0
- package/docs/helpers/array/array_reverse.md +55 -0
- package/docs/helpers/array/array_search.md +74 -0
- package/docs/helpers/array/array_shift.md +64 -0
- package/docs/helpers/array/array_slice.md +65 -0
- package/docs/helpers/array/array_splice.md +103 -0
- package/docs/helpers/array/array_sum.md +55 -0
- package/docs/helpers/array/array_udiff.md +97 -0
- package/docs/helpers/array/array_udiff_assoc.md +101 -0
- package/docs/helpers/array/array_udiff_uassoc.md +88 -0
- package/docs/helpers/array/array_uintersect.md +101 -0
- package/docs/helpers/array/array_uintersect_assoc.md +102 -0
- package/docs/helpers/array/array_uintersect_uassoc.md +135 -0
- package/docs/helpers/array/array_unique.md +54 -0
- package/docs/helpers/array/array_unshift.md +58 -0
- package/docs/helpers/array/array_values.md +54 -0
- package/docs/helpers/array/array_walk.md +87 -0
- package/docs/helpers/array/array_walk_recursive.md +93 -0
- package/docs/helpers/array/count.md +54 -0
- package/docs/helpers/array/in_array.md +65 -0
- package/docs/helpers/array/natsort.md +60 -0
- package/docs/helpers/array/range.md +76 -0
- package/docs/helpers/array/shuffle.md +74 -0
- package/docs/helpers/array/sort.md +79 -0
- package/docs/helpers/expect.md +58 -0
- package/docs/helpers/expect_array.md +63 -0
- package/docs/helpers/expect_assoc.md +65 -0
- package/docs/helpers/expect_bigint.md +63 -0
- package/docs/helpers/expect_bool.md +65 -0
- package/docs/helpers/expect_boolean.md +65 -0
- package/docs/helpers/expect_char.md +63 -0
- package/docs/helpers/expect_class.md +63 -0
- package/docs/helpers/expect_float.md +65 -0
- package/docs/helpers/expect_function.md +63 -0
- package/docs/helpers/expect_infinity.md +65 -0
- package/docs/helpers/expect_int.md +65 -0
- package/docs/helpers/expect_integer.md +65 -0
- package/docs/helpers/expect_list.md +63 -0
- package/docs/helpers/expect_nan.md +63 -0
- package/docs/helpers/expect_null.md +63 -0
- package/docs/helpers/expect_number.md +63 -0
- package/docs/helpers/expect_numeric.md +63 -0
- package/docs/helpers/expect_object.md +64 -0
- package/docs/helpers/expect_scalar.md +63 -0
- package/docs/helpers/expect_string.md +63 -0
- package/docs/helpers/expect_symbol.md +63 -0
- package/docs/helpers/expect_undefined.md +64 -0
- package/docs/helpers/is_char.md +84 -0
- package/docs/helpers/is_equal.md +75 -0
- package/docs/helpers/string/is_digit_char.md +70 -0
- package/docs/helpers/string/is_whitespace_char.md +70 -0
- package/docs/helpers/string/natcompare.md +69 -0
- package/docs/helpers/string/natcompare_numeric.md +70 -0
- package/docs/helpers.md +172 -1
- package/index.mjs +91 -1
- package/package.json +1 -1
- package/prettier.config.mjs +2 -1
- package/src/classes/Expect.mjs +1445 -0
- package/src/classes/Type.mjs +2739 -1284
- package/src/constants.mjs +83 -14
- package/src/helpers/array/array_chunk.mjs +102 -0
- package/src/helpers/array/array_chunk_with_keys.mjs +102 -0
- package/src/helpers/array/array_column.mjs +131 -0
- package/src/helpers/array/array_combine.mjs +26 -0
- package/src/helpers/array/array_count_values.mjs +82 -0
- package/src/helpers/array/array_diff.mjs +77 -0
- package/src/helpers/array/array_diff_assoc.mjs +56 -0
- package/src/helpers/array/array_diff_key.mjs +56 -0
- package/src/helpers/array/array_diff_uassoc.mjs +76 -0
- package/src/helpers/array/array_diff_ukey.mjs +71 -0
- package/src/helpers/array/array_fill.mjs +108 -0
- package/src/helpers/array/array_fill_keys.mjs +90 -0
- package/src/helpers/array/array_filter.mjs +105 -0
- package/src/helpers/array/array_flip.mjs +58 -0
- package/src/helpers/array/array_index_max.mjs +82 -0
- package/src/helpers/array/array_index_min.mjs +82 -0
- package/src/helpers/array/array_intersect.mjs +71 -0
- package/src/helpers/array/array_intersect_assoc.mjs +67 -0
- package/src/helpers/array/array_intersect_key.mjs +67 -0
- package/src/helpers/array/array_intersect_uassoc.mjs +77 -0
- package/src/helpers/array/array_intersect_ukey.mjs +72 -0
- package/src/helpers/array/array_key_exists.mjs +83 -0
- package/src/helpers/array/array_key_first.mjs +73 -0
- package/src/helpers/array/array_key_last.mjs +74 -0
- package/src/helpers/array/array_key_to_lower_case.mjs +71 -0
- package/src/helpers/array/array_key_to_upper_case.mjs +71 -0
- package/src/helpers/array/array_keys.mjs +65 -0
- package/src/helpers/array/array_map.mjs +84 -0
- package/src/helpers/array/array_merge.mjs +95 -0
- package/src/helpers/array/array_merge_recursive.mjs +153 -0
- package/src/helpers/array/array_pad.mjs +105 -0
- package/src/helpers/array/array_pop.mjs +82 -0
- package/src/helpers/array/array_product.mjs +67 -0
- package/src/helpers/array/array_push.mjs +75 -0
- package/src/helpers/array/array_rand.mjs +129 -0
- package/src/helpers/array/array_reduce.mjs +90 -0
- package/src/helpers/array/array_replace.mjs +25 -0
- package/src/helpers/array/array_replace_recursive.mjs +109 -0
- package/src/helpers/array/array_reverse.mjs +62 -0
- package/src/helpers/array/array_search.mjs +104 -0
- package/src/helpers/array/array_shift.mjs +78 -0
- package/src/helpers/array/array_slice.mjs +99 -0
- package/src/helpers/array/array_splice.mjs +218 -0
- package/src/helpers/array/array_sum.mjs +60 -0
- package/src/helpers/array/array_udiff.mjs +91 -0
- package/src/helpers/array/array_udiff_assoc.mjs +71 -0
- package/src/helpers/array/array_udiff_uassoc.mjs +124 -0
- package/src/helpers/array/array_uintersect.mjs +72 -0
- package/src/helpers/array/array_uintersect_assoc.mjs +77 -0
- package/src/helpers/array/array_uintersect_uassoc.mjs +121 -0
- package/src/helpers/array/array_unique.mjs +77 -0
- package/src/helpers/array/array_unshift.mjs +64 -0
- package/src/helpers/array/array_values.mjs +57 -0
- package/src/helpers/array/array_walk.mjs +95 -0
- package/src/helpers/array/array_walk_recursive.mjs +104 -0
- package/src/helpers/array/count.mjs +57 -0
- package/src/helpers/array/in_array.mjs +67 -0
- package/src/helpers/array/natsort.mjs +62 -0
- package/src/helpers/array/range.mjs +121 -0
- package/src/helpers/array/shuffle.mjs +73 -0
- package/src/helpers/array/sort.mjs +69 -0
- package/src/helpers/expect.mjs +44 -0
- package/src/helpers/expect_array.mjs +66 -0
- package/src/helpers/expect_assoc.mjs +66 -0
- package/src/helpers/expect_bigint.mjs +66 -0
- package/src/helpers/expect_bool.mjs +66 -0
- package/src/helpers/expect_boolean.mjs +57 -0
- package/src/helpers/expect_char.mjs +66 -0
- package/src/helpers/expect_class.mjs +66 -0
- package/src/helpers/expect_float.mjs +66 -0
- package/src/helpers/expect_function.mjs +66 -0
- package/src/helpers/expect_infinity.mjs +66 -0
- package/src/helpers/expect_int.mjs +66 -0
- package/src/helpers/expect_integer.mjs +57 -0
- package/src/helpers/expect_list.mjs +66 -0
- package/src/helpers/expect_nan.mjs +66 -0
- package/src/helpers/expect_null.mjs +66 -0
- package/src/helpers/expect_number.mjs +66 -0
- package/src/helpers/expect_numeric.mjs +66 -0
- package/src/helpers/expect_object.mjs +67 -0
- package/src/helpers/expect_scalar.mjs +66 -0
- package/src/helpers/expect_string.mjs +65 -0
- package/src/helpers/expect_symbol.mjs +66 -0
- package/src/helpers/expect_undefined.mjs +66 -0
- package/src/helpers/is_char.mjs +54 -0
- package/src/helpers/is_equal.mjs +94 -0
- package/src/helpers/string/is_digit_char.mjs +60 -0
- package/src/helpers/string/is_whitespace_char.mjs +54 -0
- package/src/helpers/string/natcompare.mjs +107 -0
- package/src/helpers/string/natcompare_numeric.mjs +131 -0
- package/tests/classes/Expect/toBe.test.mjs +60 -0
- package/tests/classes/Expect/toBeArray.test.mjs +46 -0
- package/tests/classes/Expect/toBeAssoc.test.mjs +48 -0
- package/tests/classes/Expect/toBeBigInt.test.mjs +46 -0
- package/tests/classes/Expect/toBeBool.test.mjs +48 -0
- package/tests/classes/Expect/toBeBoolean.test.mjs +48 -0
- package/tests/classes/Expect/toBeChar.test.mjs +46 -0
- package/tests/classes/Expect/toBeClass.test.mjs +48 -0
- package/tests/classes/Expect/toBeFloat.test.mjs +48 -0
- package/tests/classes/Expect/toBeFunction.test.mjs +51 -0
- package/tests/classes/Expect/toBeInfinity.test.mjs +48 -0
- package/tests/classes/Expect/toBeInt.test.mjs +48 -0
- package/tests/classes/Expect/toBeInteger.test.mjs +48 -0
- package/tests/classes/Expect/toBeList.test.mjs +46 -0
- package/tests/classes/Expect/toBeNaN.test.mjs +46 -0
- package/tests/classes/Expect/toBeNull.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumber.test.mjs +46 -0
- package/tests/classes/Expect/toBeNumeric.test.mjs +53 -0
- package/tests/classes/Expect/toBeObject.test.mjs +47 -0
- package/tests/classes/Expect/toBeScalar.test.mjs +63 -0
- package/tests/classes/Expect/toBeString.test.mjs +46 -0
- package/tests/classes/Expect/toBeSymbol.test.mjs +46 -0
- package/tests/classes/Expect/toBeUndefined.test.mjs +50 -0
- package/tests/classes/Expect/toEqual.test.mjs +66 -0
- package/tests/classes/Expect/toStrictEqual.test.mjs +73 -0
- package/tests/classes/Type.test.mjs +1320 -1262
- package/tests/helpers/array/array_chunk.test.mjs +49 -0
- package/tests/helpers/array/array_chunk_with_keys.test.mjs +45 -0
- package/tests/helpers/array/array_column.test.mjs +87 -0
- package/tests/helpers/array/array_combine.test.mjs +41 -0
- package/tests/helpers/array/array_count_values.test.mjs +40 -0
- package/tests/helpers/array/array_diff.test.mjs +78 -0
- package/tests/helpers/array/array_diff_assoc.test.mjs +64 -0
- package/tests/helpers/array/array_diff_key.test.mjs +64 -0
- package/tests/helpers/array/array_diff_uassoc.test.mjs +73 -0
- package/tests/helpers/array/array_diff_ukey.test.mjs +77 -0
- package/tests/helpers/array/array_fill.test.mjs +47 -0
- package/tests/helpers/array/array_fill_keys.test.mjs +35 -0
- package/tests/helpers/array/array_filter.test.mjs +38 -0
- package/tests/helpers/array/array_flip.test.mjs +33 -0
- package/tests/helpers/array/array_index_max.test.mjs +41 -0
- package/tests/helpers/array/array_index_min.test.mjs +41 -0
- package/tests/helpers/array/array_intersect.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_assoc.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_key.test.mjs +65 -0
- package/tests/helpers/array/array_intersect_uassoc.test.mjs +76 -0
- package/tests/helpers/array/array_intersect_ukey.test.mjs +74 -0
- package/tests/helpers/array/array_key_exists.test.mjs +36 -0
- package/tests/helpers/array/array_key_first.test.mjs +29 -0
- package/tests/helpers/array/array_key_last.test.mjs +29 -0
- package/tests/helpers/array/array_key_to_lower_case.test.mjs +23 -0
- package/tests/helpers/array/array_key_to_upper_case.test.mjs +23 -0
- package/tests/helpers/array/array_keys.test.mjs +27 -0
- package/tests/helpers/array/array_map.test.mjs +32 -0
- package/tests/helpers/array/array_merge.test.mjs +37 -0
- package/tests/helpers/array/array_merge_recursive.test.mjs +65 -0
- package/tests/helpers/array/array_pad.test.mjs +48 -0
- package/tests/helpers/array/array_pop.test.mjs +29 -0
- package/tests/helpers/array/array_product.test.mjs +33 -0
- package/tests/helpers/array/array_push.test.mjs +31 -0
- package/tests/helpers/array/array_rand.test.mjs +59 -0
- package/tests/helpers/array/array_reduce.test.mjs +44 -0
- package/tests/helpers/array/array_replace.test.mjs +46 -0
- package/tests/helpers/array/array_replace_recursive.test.mjs +46 -0
- package/tests/helpers/array/array_reverse.test.mjs +31 -0
- package/tests/helpers/array/array_search.test.mjs +48 -0
- package/tests/helpers/array/array_shift.test.mjs +29 -0
- package/tests/helpers/array/array_slice.test.mjs +49 -0
- package/tests/helpers/array/array_splice.test.mjs +67 -0
- package/tests/helpers/array/array_sum.test.mjs +27 -0
- package/tests/helpers/array/array_udiff.test.mjs +95 -0
- package/tests/helpers/array/array_udiff_assoc.test.mjs +77 -0
- package/tests/helpers/array/array_udiff_uassoc.test.mjs +89 -0
- package/tests/helpers/array/array_uintersect.test.mjs +78 -0
- package/tests/helpers/array/array_uintersect_assoc.test.mjs +80 -0
- package/tests/helpers/array/array_uintersect_uassoc.test.mjs +122 -0
- package/tests/helpers/array/array_unique.test.mjs +27 -0
- package/tests/helpers/array/array_unshift.test.mjs +31 -0
- package/tests/helpers/array/array_values.test.mjs +27 -0
- package/tests/helpers/array/array_walk.test.mjs +48 -0
- package/tests/helpers/array/array_walk_recursive.test.mjs +53 -0
- package/tests/helpers/array/count.test.mjs +27 -0
- package/tests/helpers/array/in_array.test.mjs +52 -0
- package/tests/helpers/array/natsort.test.mjs +71 -0
- package/tests/helpers/array/range.test.mjs +51 -0
- package/tests/helpers/array/shuffle.test.mjs +42 -0
- package/tests/helpers/array/sort.test.mjs +60 -0
- package/tests/helpers/array.test.mjs +58 -58
- package/tests/helpers/expect.test.mjs +95 -0
- package/tests/helpers/expect_array.test.mjs +71 -0
- package/tests/helpers/expect_assoc.test.mjs +61 -0
- package/tests/helpers/expect_bigint.test.mjs +63 -0
- package/tests/helpers/expect_bool.test.mjs +59 -0
- package/tests/helpers/expect_boolean.test.mjs +61 -0
- package/tests/helpers/expect_char.test.mjs +63 -0
- package/tests/helpers/expect_class.test.mjs +64 -0
- package/tests/helpers/expect_float.test.mjs +64 -0
- package/tests/helpers/expect_function.test.mjs +65 -0
- package/tests/helpers/expect_infinity.test.mjs +62 -0
- package/tests/helpers/expect_int.test.mjs +57 -0
- package/tests/helpers/expect_integer.test.mjs +59 -0
- package/tests/helpers/expect_list.test.mjs +73 -0
- package/tests/helpers/expect_nan.test.mjs +57 -0
- package/tests/helpers/expect_null.test.mjs +57 -0
- package/tests/helpers/expect_number.test.mjs +57 -0
- package/tests/helpers/expect_numeric.test.mjs +57 -0
- package/tests/helpers/expect_object.test.mjs +63 -0
- package/tests/helpers/expect_scalar.test.mjs +72 -0
- package/tests/helpers/expect_string.test.mjs +65 -0
- package/tests/helpers/expect_symbol.test.mjs +66 -0
- package/tests/helpers/expect_undefined.test.mjs +59 -0
- package/tests/helpers/is_char.test.mjs +40 -0
- package/tests/helpers/is_equal.test.mjs +110 -0
- package/tests/helpers/string/is_digit_char.test.mjs +32 -0
- package/tests/helpers/string/is_whitespace_char.test.mjs +32 -0
- package/tests/helpers/string/natcompare.test.mjs +100 -0
- package/tests/helpers/string/natcompare_numeric.test.mjs +110 -0
package/src/constants.mjs
CHANGED
@@ -1,14 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
export const
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
export const
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
/**
|
2
|
+
* Константа, представляющая значение null.
|
3
|
+
* @type {string}
|
4
|
+
*/
|
5
|
+
export const TYPE_NULL = 'null';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Константа, представляющая значение NaN (Not-a-Number).
|
9
|
+
* @type {string}
|
10
|
+
*/
|
11
|
+
export const TYPE_NAN = 'NaN';
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Константа, представляющая значение undefined.
|
15
|
+
* @type {string}
|
16
|
+
*/
|
17
|
+
export const TYPE_UNDEFINED = 'undefined';
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Константа, представляющая значение Infinity.
|
21
|
+
* @type {string}
|
22
|
+
*/
|
23
|
+
export const TYPE_INFINITY = 'infinity';
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Константа, представляющая тип boolean.
|
27
|
+
* @type {string}
|
28
|
+
*/
|
29
|
+
export const TYPE_BOOLEAN = 'boolean';
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Константа, представляющая тип integer (целое число).
|
33
|
+
* @type {string}
|
34
|
+
*/
|
35
|
+
export const TYPE_INTEGER = 'integer';
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Константа, представляющая тип bigint (большое целое число).
|
39
|
+
* @type {string}
|
40
|
+
*/
|
41
|
+
export const TYPE_BIGINT = 'bigint';
|
42
|
+
|
43
|
+
/**
|
44
|
+
* Константа, представляющая тип float (число с плавающей запятой).
|
45
|
+
* @type {string}
|
46
|
+
*/
|
47
|
+
export const TYPE_FLOAT = 'float';
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Константа, представляющая тип string (строка).
|
51
|
+
* @type {string}
|
52
|
+
*/
|
53
|
+
export const TYPE_STRING = 'string';
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Константа, представляющая тип symbol (символ).
|
57
|
+
* @type {string}
|
58
|
+
*/
|
59
|
+
export const TYPE_SYMBOL = 'symbol';
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Константа, представляющая тип class (класс).
|
63
|
+
* @type {string}
|
64
|
+
*/
|
65
|
+
export const TYPE_CLASS = 'class';
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Константа, представляющая тип function (функция).
|
69
|
+
* @type {string}
|
70
|
+
*/
|
71
|
+
export const TYPE_FUNCTION = 'function';
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Константа, представляющая тип array (массив).
|
75
|
+
* @type {string}
|
76
|
+
*/
|
77
|
+
export const TYPE_ARRAY = 'array';
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Константа, представляющая тип object (объект).
|
81
|
+
* @type {string}
|
82
|
+
*/
|
83
|
+
export const TYPE_OBJECT = 'object';
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import is_array from '../is_array.mjs';
|
2
|
+
import is_int from '../is_int.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Разбивает массив на части указанной длины.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `array_chunk` используется для разбивки массива на части указанной длины.
|
10
|
+
* Если переданное значение не является массивом, функция выбрасывает ошибку типа `TypeError`.
|
11
|
+
* Если длина не является целым числом или меньше 1, функция выбрасывает соответствующую ошибку.
|
12
|
+
*
|
13
|
+
* ### Параметры
|
14
|
+
*
|
15
|
+
* - `value` (array): Массив, который необходимо разбить на части.
|
16
|
+
* - `length` (number): Длина каждой части.
|
17
|
+
*
|
18
|
+
* ### Возвращаемое значение
|
19
|
+
*
|
20
|
+
* Возвращает новый массив, содержащий части исходного массива.
|
21
|
+
*
|
22
|
+
* ### Примеры использования
|
23
|
+
*
|
24
|
+
* 1. Разбивка массива на части указанной длины:
|
25
|
+
*
|
26
|
+
* ```js
|
27
|
+
* const array = [1, 2, 3, 4, 5];
|
28
|
+
* const result = array_chunk(array, 2);
|
29
|
+
* console.log(result); // [[1, 2], [3, 4], [5]]
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* 2. Обработка пустого массива:
|
33
|
+
*
|
34
|
+
* ```js
|
35
|
+
* const array = [];
|
36
|
+
* const result = array_chunk(array, 2);
|
37
|
+
* console.log(result); // []
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* 3. Обработка ассоциативного массива:
|
41
|
+
*
|
42
|
+
* ```js
|
43
|
+
* const assoc = { key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' };
|
44
|
+
* const result = array_chunk(assoc, 2);
|
45
|
+
* console.log(result); // [['value1', 'value2'], ['value3', 'value4']]
|
46
|
+
* ```
|
47
|
+
*
|
48
|
+
* 4. Обработка значения, не являющегося массивом:
|
49
|
+
*
|
50
|
+
* ```js
|
51
|
+
* try {
|
52
|
+
* const result = array_chunk('not an array', 2);
|
53
|
+
* } catch (e) {
|
54
|
+
* console.error(e.message); // Параметр "value" должен быть массивом.
|
55
|
+
* }
|
56
|
+
* ```
|
57
|
+
*
|
58
|
+
* 5. Обработка некорректной длины:
|
59
|
+
*
|
60
|
+
* ```js
|
61
|
+
* try {
|
62
|
+
* const result = array_chunk([1, 2, 3], 'not an integer');
|
63
|
+
* } catch (e) {
|
64
|
+
* console.error(e.message); // Параметр "length" должен быть целым числом.
|
65
|
+
* }
|
66
|
+
*
|
67
|
+
* try {
|
68
|
+
* const result = array_chunk([1, 2, 3], 0);
|
69
|
+
* } catch (e) {
|
70
|
+
* console.error(e.message); // Параметр "length" должен быть больше нуля.
|
71
|
+
* }
|
72
|
+
* ```
|
73
|
+
*
|
74
|
+
* @param {array} value Массив, который необходимо разбить на части.
|
75
|
+
* @param {number} length Длина каждой части.
|
76
|
+
* @returns {array} Возвращает новый массив, содержащий части исходного массива.
|
77
|
+
* @throws {TypeError} Если переданное значение не является массивом.
|
78
|
+
* @throws {TypeError} Если длина не является целым числом.
|
79
|
+
* @throws {Error} Если длина меньше 1.
|
80
|
+
*/
|
81
|
+
export default function array_chunk(value, length) {
|
82
|
+
if (!is_array(value)) {
|
83
|
+
throw new TypeError('Параметр "value" должен быть массивом.');
|
84
|
+
}
|
85
|
+
|
86
|
+
if (!is_int(length)) {
|
87
|
+
throw new TypeError('Параметр "length" должен быть целым числом.');
|
88
|
+
}
|
89
|
+
|
90
|
+
if (length < 1) {
|
91
|
+
throw new Error('Параметр "length" должен быть больше нуля.');
|
92
|
+
}
|
93
|
+
|
94
|
+
const result = [];
|
95
|
+
const values = Object.values(value);
|
96
|
+
|
97
|
+
while (values.length) {
|
98
|
+
result.push(values.splice(0, length));
|
99
|
+
}
|
100
|
+
|
101
|
+
return result;
|
102
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import is_array from '../is_array.mjs';
|
2
|
+
import is_int from '../is_int.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Разбивает массив на части указанной длины с сохранением ключей.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `array_chunk_with_keys` используется для разбивки массива на части указанной длины с сохранением ключей.
|
10
|
+
* Если переданное значение не является массивом, функция выбрасывает ошибку типа `TypeError`.
|
11
|
+
* Если длина не является целым числом или меньше 1, функция выбрасывает соответствующую ошибку.
|
12
|
+
*
|
13
|
+
* ### Параметры
|
14
|
+
*
|
15
|
+
* - `value` (array): Массив, который необходимо разбить на части.
|
16
|
+
* - `length` (number): Длина каждой части.
|
17
|
+
*
|
18
|
+
* ### Возвращаемое значение
|
19
|
+
*
|
20
|
+
* Возвращает новый массив, содержащий части исходного массива с сохранением ключей.
|
21
|
+
*
|
22
|
+
* ### Примеры использования
|
23
|
+
*
|
24
|
+
* 1. Разбивка ассоциативного массива на части указанной длины с сохранением ключей:
|
25
|
+
*
|
26
|
+
* ```js
|
27
|
+
* const assoc = { a: 1, b: 2, c: 3, d: 4, e: 5 };
|
28
|
+
* const result = array_chunk_with_keys(assoc, 2);
|
29
|
+
* console.log(result); // [{ a: 1, b: 2 }, { c: 3, d: 4 }, { e: 5 }]
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* 2. Обработка пустого ассоциативного массива:
|
33
|
+
*
|
34
|
+
* ```js
|
35
|
+
* const assoc = {};
|
36
|
+
* const result = array_chunk_with_keys(assoc, 2);
|
37
|
+
* console.log(result); // []
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* 3. Разбивка обычного массива на части указанной длины с сохранением ключей:
|
41
|
+
*
|
42
|
+
* ```js
|
43
|
+
* const array = [1, 2, 3, 4, 5];
|
44
|
+
* const result = array_chunk_with_keys(array, 2);
|
45
|
+
* console.log(result); // [{ 0: 1, 1: 2 }, { 2: 3, 3: 4 }, { 4: 5 }]
|
46
|
+
* ```
|
47
|
+
*
|
48
|
+
* 4. Обработка значения, не являющегося массивом:
|
49
|
+
*
|
50
|
+
* ```js
|
51
|
+
* try {
|
52
|
+
* const result = array_chunk_with_keys('not an array', 2);
|
53
|
+
* } catch (e) {
|
54
|
+
* console.error(e.message); // Параметр "value" должен быть массивом.
|
55
|
+
* }
|
56
|
+
* ```
|
57
|
+
*
|
58
|
+
* 5. Обработка некорректной длины:
|
59
|
+
*
|
60
|
+
* ```js
|
61
|
+
* try {
|
62
|
+
* const result = array_chunk_with_keys([1, 2, 3], 'not an integer');
|
63
|
+
* } catch (e) {
|
64
|
+
* console.error(e.message); // Параметр "length" должен быть целым числом.
|
65
|
+
* }
|
66
|
+
*
|
67
|
+
* try {
|
68
|
+
* const result = array_chunk_with_keys([1, 2, 3], 0);
|
69
|
+
* } catch (e) {
|
70
|
+
* console.error(e.message); // Параметр "length" должен быть больше нуля.
|
71
|
+
* }
|
72
|
+
* ```
|
73
|
+
*
|
74
|
+
* @param {array} value Массив, который необходимо разбить на части.
|
75
|
+
* @param {number} length Длина каждой части.
|
76
|
+
* @returns {array} Возвращает новый массив, содержащий части исходного массива с сохранением ключей.
|
77
|
+
* @throws {TypeError} Если переданное значение не является массивом.
|
78
|
+
* @throws {TypeError} Если длина не является целым числом.
|
79
|
+
* @throws {Error} Если длина меньше 1.
|
80
|
+
*/
|
81
|
+
export default function array_chunk_with_keys(value, length) {
|
82
|
+
if (!is_array(value)) {
|
83
|
+
throw new TypeError('Параметр "value" должен быть массивом.');
|
84
|
+
}
|
85
|
+
|
86
|
+
if (!is_int(length)) {
|
87
|
+
throw new TypeError('Параметр "length" должен быть целым числом.');
|
88
|
+
}
|
89
|
+
|
90
|
+
if (length < 1) {
|
91
|
+
throw new Error('Параметр "length" должен быть больше нуля.');
|
92
|
+
}
|
93
|
+
|
94
|
+
const result = [];
|
95
|
+
const entries = Object.entries(value);
|
96
|
+
|
97
|
+
while (entries.length) {
|
98
|
+
result.push(Object.fromEntries(entries.splice(0, length)));
|
99
|
+
}
|
100
|
+
|
101
|
+
return result;
|
102
|
+
}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import array from '../array.mjs';
|
2
|
+
import is_int from '../is_int.mjs';
|
3
|
+
import is_list from '../is_list.mjs';
|
4
|
+
import is_null from '../is_null.mjs';
|
5
|
+
import is_string from '../is_string.mjs';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Извлекает значения указанного столбца из массива объектов.
|
9
|
+
*
|
10
|
+
* ### Описание
|
11
|
+
*
|
12
|
+
* Функция `array_column` используется для извлечения значений указанного столбца из массива объектов.
|
13
|
+
* Если переданное значение не является списком, функция выбрасывает ошибку типа `TypeError`.
|
14
|
+
* Если ключ столбца или индексный ключ не являются строкой или целым числом, функция выбрасывает соответствующую ошибку.
|
15
|
+
*
|
16
|
+
* ### Параметры
|
17
|
+
*
|
18
|
+
* - `value` (array): Массив объектов, из которого необходимо извлечь значения.
|
19
|
+
* - `column_key` (string | number): Ключ столбца, значения которого необходимо извлечь.
|
20
|
+
* - `index_key` (string | number | null): Ключ, который будет использоваться для индексации возвращаемого массива (по умолчанию `null`).
|
21
|
+
*
|
22
|
+
* ### Возвращаемое значение
|
23
|
+
*
|
24
|
+
* Возвращает массив значений указанного столбца. Если указан индексный ключ, возвращает объект с индексированными значениями.
|
25
|
+
*
|
26
|
+
* ### Примеры использования
|
27
|
+
*
|
28
|
+
* 1. Извлечение значений указанного столбца из массива объектов:
|
29
|
+
*
|
30
|
+
* ```js
|
31
|
+
* const array = [
|
32
|
+
* { id: 1, name: 'Alice' },
|
33
|
+
* { id: 2, name: 'Bob' },
|
34
|
+
* { id: 3, name: 'Charlie' },
|
35
|
+
* ];
|
36
|
+
* const result = array_column(array, 'name');
|
37
|
+
* console.log(result); // ['Alice', 'Bob', 'Charlie']
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* 2. Извлечение значений указанного столбца с использованием индексного ключа:
|
41
|
+
*
|
42
|
+
* ```js
|
43
|
+
* const array = [
|
44
|
+
* { id: 1, name: 'Alice' },
|
45
|
+
* { id: 2, name: 'Bob' },
|
46
|
+
* { id: 3, name: 'Charlie' },
|
47
|
+
* ];
|
48
|
+
* const result = array_column(array, 'name', 'id');
|
49
|
+
* console.log(result); // { 1: 'Alice', 2: 'Bob', 3: 'Charlie' }
|
50
|
+
* ```
|
51
|
+
*
|
52
|
+
* 3. Обработка пустого массива:
|
53
|
+
*
|
54
|
+
* ```js
|
55
|
+
* const array = [];
|
56
|
+
* const result = array_column(array, 'name');
|
57
|
+
* console.log(result); // []
|
58
|
+
* ```
|
59
|
+
*
|
60
|
+
* 4. Обработка значения, не являющегося массивом:
|
61
|
+
*
|
62
|
+
* ```js
|
63
|
+
* try {
|
64
|
+
* const result = array_column('not an array', 'name');
|
65
|
+
* } catch (e) {
|
66
|
+
* console.error(e.message); // Параметр "value" должен быть списком.
|
67
|
+
* }
|
68
|
+
* ```
|
69
|
+
*
|
70
|
+
* 5. Обработка некорректного ключа столбца:
|
71
|
+
*
|
72
|
+
* ```js
|
73
|
+
* const array = [
|
74
|
+
* { id: 1, name: 'Alice' },
|
75
|
+
* { id: 2, name: 'Bob' },
|
76
|
+
* { id: 3, name: 'Charlie' },
|
77
|
+
* ];
|
78
|
+
* try {
|
79
|
+
* const result = array_column(array, {});
|
80
|
+
* } catch (e) {
|
81
|
+
* console.error(e.message); // Параметр "column_key" должен быть строкой или целым числом.
|
82
|
+
* }
|
83
|
+
* ```
|
84
|
+
*
|
85
|
+
* 6. Обработка некорректного индексного ключа:
|
86
|
+
*
|
87
|
+
* ```js
|
88
|
+
* const array = [
|
89
|
+
* { id: 1, name: 'Alice' },
|
90
|
+
* { id: 2, name: 'Bob' },
|
91
|
+
* { id: 3, name: 'Charlie' },
|
92
|
+
* ];
|
93
|
+
* try {
|
94
|
+
* const result = array_column(array, 'name', {});
|
95
|
+
* } catch (e) {
|
96
|
+
* console.error(e.message); // Параметр "index_key" должен быть строкой или целым числом.
|
97
|
+
* }
|
98
|
+
* ```
|
99
|
+
*
|
100
|
+
* @param {array} value Массив объектов, из которого необходимо извлечь значения.
|
101
|
+
* @param {string | number} column_key Ключ столбца, значения которого необходимо извлечь.
|
102
|
+
* @param {string | number | null} [index_key=null] Ключ, который будет использоваться для индексации возвращаемого массива.
|
103
|
+
* @returns {array | object} Возвращает массив значений указанного столбца. Если указан индексный ключ, возвращает объект с индексированными значениями.
|
104
|
+
* @throws {TypeError} Если переданное значение не является списком.
|
105
|
+
* @throws {TypeError} Если ключ столбца или индексный ключ не являются строкой или целым числом.
|
106
|
+
*/
|
107
|
+
export default function array_column(value, column_key, index_key = null) {
|
108
|
+
if (!is_list(value)) {
|
109
|
+
throw new TypeError('Параметр "value" должен быть списком.');
|
110
|
+
}
|
111
|
+
|
112
|
+
if (!is_string(column_key) && !is_int(column_key)) {
|
113
|
+
throw new TypeError('Параметр "column_key" должен быть строкой или целым числом.');
|
114
|
+
}
|
115
|
+
|
116
|
+
if (!is_null(index_key) && !is_string(index_key) && !is_int(index_key)) {
|
117
|
+
throw new TypeError('Параметр "index_key" должен быть строкой или целым числом.');
|
118
|
+
}
|
119
|
+
|
120
|
+
if (is_null(index_key)) {
|
121
|
+
return Object.values(value).map((model) => model[column_key]);
|
122
|
+
}
|
123
|
+
|
124
|
+
const result = array({});
|
125
|
+
|
126
|
+
for (const model of value) {
|
127
|
+
result[model[index_key]] = model[column_key];
|
128
|
+
}
|
129
|
+
|
130
|
+
return result;
|
131
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import array from '../array.mjs';
|
2
|
+
import is_list from '../is_list.mjs';
|
3
|
+
|
4
|
+
export default function array_combine(keys, values) {
|
5
|
+
if (!is_list(keys)) {
|
6
|
+
throw new TypeError('Параметр "keys" должен быть списком.');
|
7
|
+
}
|
8
|
+
|
9
|
+
if (!is_list(values)) {
|
10
|
+
throw new TypeError('Параметр "values" должен быть списком.');
|
11
|
+
}
|
12
|
+
|
13
|
+
if (keys.length !== values.length) {
|
14
|
+
throw new Error(
|
15
|
+
'Количество элементов в списке ключей должно ровняться количеству элементов в списке значений.',
|
16
|
+
);
|
17
|
+
}
|
18
|
+
|
19
|
+
const result = array({});
|
20
|
+
|
21
|
+
for (let i = 0; i < keys.length; i++) {
|
22
|
+
result[keys[i]] = values[i];
|
23
|
+
}
|
24
|
+
|
25
|
+
return result;
|
26
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import array from '../array.mjs';
|
2
|
+
import is_array from '../is_array.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Подсчитывает количество значений в массиве.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `array_count_values` используется для подсчета количества значений в массиве.
|
10
|
+
* Если переданное значение не является массивом, функция выбрасывает ошибку типа `TypeError`.
|
11
|
+
*
|
12
|
+
* ### Параметры
|
13
|
+
*
|
14
|
+
* - `value` (array): Массив значений, которые необходимо подсчитать.
|
15
|
+
*
|
16
|
+
* ### Возвращаемое значение
|
17
|
+
*
|
18
|
+
* Возвращает объект, где ключи представляют уникальные значения из массива, а значения представляют количество их вхождений.
|
19
|
+
*
|
20
|
+
* ### Примеры использования
|
21
|
+
*
|
22
|
+
* 1. Подсчет количества значений в массиве:
|
23
|
+
*
|
24
|
+
* ```js
|
25
|
+
* const array = ['a', 'b', 'a', 'c', 'b', 'a'];
|
26
|
+
* const result = array_count_values(array);
|
27
|
+
* console.log(result); // { a: 3, b: 2, c: 1 }
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* 2. Обработка пустого массива:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* const array = [];
|
34
|
+
* const result = array_count_values(array);
|
35
|
+
* console.log(result); // {}
|
36
|
+
* ```
|
37
|
+
*
|
38
|
+
* 3. Обработка значений разных типов:
|
39
|
+
*
|
40
|
+
* ```js
|
41
|
+
* const array = [1, '1', true, 'true', null, 'null', undefined, 'undefined'];
|
42
|
+
* const result = array_count_values(array);
|
43
|
+
* console.log(result); // { 1: 2, true: 2, null: 2, undefined: 2 }
|
44
|
+
* ```
|
45
|
+
*
|
46
|
+
* 4. Обработка значения, не являющегося массивом:
|
47
|
+
*
|
48
|
+
* ```js
|
49
|
+
* try {
|
50
|
+
* const result = array_count_values('not an array');
|
51
|
+
* } catch (e) {
|
52
|
+
* console.error(e.message); // Параметр "value" должен быть массивом.
|
53
|
+
* }
|
54
|
+
* ```
|
55
|
+
*
|
56
|
+
* 5. Обработка ассоциативных массивов:
|
57
|
+
*
|
58
|
+
* ```js
|
59
|
+
* const assoc = { key1: 'a', key2: 'b', key3: 'a', key4: 'c' };
|
60
|
+
* const result = array_count_values(assoc);
|
61
|
+
* console.log(result); // { a: 2, b: 1, c: 1 }
|
62
|
+
* ```
|
63
|
+
*
|
64
|
+
* @param {object} value Массив значений, которые необходимо подсчитать.
|
65
|
+
* @returns {object} Возвращает объект, где ключи представляют уникальные значения из массива, а значения представляют количество их вхождений.
|
66
|
+
* @throws {TypeError} Если переданное значение не является массивом.
|
67
|
+
*/
|
68
|
+
export default function array_count_values(value) {
|
69
|
+
if (!is_array(value)) {
|
70
|
+
throw new TypeError('Параметр "value" должен быть массивом.');
|
71
|
+
}
|
72
|
+
|
73
|
+
const result = array({});
|
74
|
+
|
75
|
+
for (const k in value) {
|
76
|
+
const v = String(value[k]);
|
77
|
+
|
78
|
+
v in result ? result[v]++ : (result[v] = 1);
|
79
|
+
}
|
80
|
+
|
81
|
+
return result;
|
82
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
import array_udiff from './array_udiff.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Вычисляет расхождение между массивами.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `array_diff` используется для вычисления расхождения между массивами. Она возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
9
|
+
*
|
10
|
+
* ### Параметры
|
11
|
+
*
|
12
|
+
* - `original_array` (object): Исходный массив.
|
13
|
+
* - `...arrays` (object): Массивы для сравнения.
|
14
|
+
*
|
15
|
+
* ### Возвращаемое значение
|
16
|
+
*
|
17
|
+
* Возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
18
|
+
*
|
19
|
+
* ### Примеры использования
|
20
|
+
*
|
21
|
+
* 1. Сравнение массивов:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* const original_array = [1, 2, 3];
|
25
|
+
* const array1 = [1, 2];
|
26
|
+
* const result = array_diff(original_array, array1);
|
27
|
+
* console.log(result); // { 2: 3 }
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* 2. Обработка пустых массивов:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* const original_array = [];
|
34
|
+
* const array1 = [];
|
35
|
+
* const result = array_diff(original_array, array1);
|
36
|
+
* console.log(result); // {}
|
37
|
+
* ```
|
38
|
+
*
|
39
|
+
* 3. Сравнение массивов с различными типами данных:
|
40
|
+
*
|
41
|
+
* ```js
|
42
|
+
* const original_array = [1, '2', true];
|
43
|
+
* const array1 = [1, 2, false];
|
44
|
+
* const result = array_diff(original_array, array1);
|
45
|
+
* console.log(result); // { 1: '2', 2: true }
|
46
|
+
* ```
|
47
|
+
*
|
48
|
+
* 4. Сравнение массивов с объектами:
|
49
|
+
*
|
50
|
+
* ```js
|
51
|
+
* const original_array = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
52
|
+
* const array1 = [{ id: 1 }, { id: 2 }];
|
53
|
+
* const result = array_diff(original_array, array1);
|
54
|
+
* console.log(result); // { 2: { id: 3 } }
|
55
|
+
* ```
|
56
|
+
*
|
57
|
+
* 5. Сравнение ассоциативных массивов:
|
58
|
+
*
|
59
|
+
* ```js
|
60
|
+
* const original_array = { a: 1, b: 2, c: 3 };
|
61
|
+
* const array1 = { a: 1, b: 2 };
|
62
|
+
* const result = array_diff(original_array, array1);
|
63
|
+
* console.log(result); // { c: 3 }
|
64
|
+
* ```
|
65
|
+
*
|
66
|
+
* @param {object} original_array Исходный массив.
|
67
|
+
* @param {...object} arrays Массивы для сравнения.
|
68
|
+
* @returns {object} Возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
69
|
+
* @throws {TypeError} Если параметры не являются массивами.
|
70
|
+
*/
|
71
|
+
export default function array_diff(original_array, ...arrays) {
|
72
|
+
return array_udiff(
|
73
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b),
|
74
|
+
original_array,
|
75
|
+
...arrays,
|
76
|
+
);
|
77
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import array_diff_uassoc from './array_diff_uassoc.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Вычисляет расхождение между массивами с использованием стандартной функции сравнения значений и ключей.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `array_diff_assoc` используется для вычисления расхождения между массивами с использованием стандартной функции сравнения значений и ключей.
|
9
|
+
* Она возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
10
|
+
*
|
11
|
+
* ### Параметры
|
12
|
+
*
|
13
|
+
* - `original_array` (object): Исходный массив.
|
14
|
+
* - `...arrays` (object): Массивы для сравнения.
|
15
|
+
*
|
16
|
+
* ### Возвращаемое значение
|
17
|
+
*
|
18
|
+
* Возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
19
|
+
*
|
20
|
+
* ### Примеры использования
|
21
|
+
*
|
22
|
+
* 1. Сравнение массивов:
|
23
|
+
*
|
24
|
+
* ```js
|
25
|
+
* const original_array = { a: 1, b: 2, c: 3 };
|
26
|
+
* const array1 = { a: 1, b: 2 };
|
27
|
+
* const result = array_diff_assoc(original_array, array1);
|
28
|
+
* console.log(result); // { c: 3 }
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* 2. Обработка пустых массивов:
|
32
|
+
*
|
33
|
+
* ```js
|
34
|
+
* const original_array = {};
|
35
|
+
* const array1 = {};
|
36
|
+
* const result = array_diff_assoc(original_array, array1);
|
37
|
+
* console.log(result); // {}
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* 3. Сравнение массивов с различными типами данных:
|
41
|
+
*
|
42
|
+
* ```js
|
43
|
+
* const original_array = { a: 1, b: '2', c: true };
|
44
|
+
* const array1 = { a: 1, b: 2, d: false };
|
45
|
+
* const result = array_diff_assoc(original_array, array1);
|
46
|
+
* console.log(result); // { b: '2', c: true }
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* @param {object} original_array Исходный массив.
|
50
|
+
* @param {...object} arrays Массивы для сравнения.
|
51
|
+
* @returns {object} Возвращает ассоциативный массив, содержащий элементы из первого массива, которые отсутствуют в других массивах.
|
52
|
+
* @throws {TypeError} Если параметры не являются массивами.
|
53
|
+
*/
|
54
|
+
export default function array_diff_assoc(original_array, ...arrays) {
|
55
|
+
return array_diff_uassoc((a, b) => a === b, original_array, ...arrays);
|
56
|
+
}
|