@rogolev/value 0.0.3 → 0.0.5
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.
- 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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[Главная](../../../README.md) / [Помощники](../../helpers.md) / in_array
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../../src/helpers/array/in_array.mjs)
|
|
4
|
+
|
|
5
|
+
# in_array
|
|
6
|
+
|
|
7
|
+
`in_array` — Проверяет, существует ли значение в массиве.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function in_array(arr: object, value: any, strict: boolean = false): boolean;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `in_array` используется для проверки, существует ли значение в массиве. Она поддерживает как
|
|
18
|
+
обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями). Функция может
|
|
19
|
+
работать в строгом режиме, сравнивая значения с учетом типа.
|
|
20
|
+
|
|
21
|
+
## Параметры
|
|
22
|
+
|
|
23
|
+
- `arr` (object): Исходный массив.
|
|
24
|
+
- `value` (any): Значение для поиска.
|
|
25
|
+
- `strict` (boolean): Флаг строгого сравнения. По умолчанию `false`.
|
|
26
|
+
|
|
27
|
+
## Возвращаемое значение
|
|
28
|
+
|
|
29
|
+
Возвращает `true`, если значение существует в массиве, иначе `false`.
|
|
30
|
+
|
|
31
|
+
## Примеры использования
|
|
32
|
+
|
|
33
|
+
1. Проверка значения в обычном массиве:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const array = [1, 2, 3, 4, 5];
|
|
37
|
+
const result = in_array(array, 3);
|
|
38
|
+
console.log(result); // true
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Проверка значения в ассоциативном массиве:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const array = { a: 1, b: 2, c: 3 };
|
|
45
|
+
const result = in_array(array, 2);
|
|
46
|
+
console.log(result); // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. Проверка значения с использованием строгого сравнения:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const array = [1, '2', 3];
|
|
53
|
+
const result = in_array(array, 2, true);
|
|
54
|
+
console.log(result); // false
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
4. Обработка значений, не являющихся массивами:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
try {
|
|
61
|
+
const result = in_array('not an array', 1);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e.message); // Параметр "arr" должен быть массивом.
|
|
64
|
+
}
|
|
65
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[Главная](../../../README.md) / [Помощники](../../helpers.md) / natsort
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../../src/helpers/array/natsort.mjs)
|
|
4
|
+
|
|
5
|
+
# natsort
|
|
6
|
+
|
|
7
|
+
`natsort` — Сортирует массив в естественном порядке.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function natsort(arr: object, getter: function = (entry) => entry[1]): array;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `natsort` используется для сортировки массива в естественном порядке. Она поддерживает как
|
|
18
|
+
обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями). Функция принимает
|
|
19
|
+
необязательный параметр `getter`, который используется для получения значения для сравнения.
|
|
20
|
+
|
|
21
|
+
## Параметры
|
|
22
|
+
|
|
23
|
+
- `arr` (object): Исходный массив.
|
|
24
|
+
- `getter` (function): Функция для получения значения для сравнения. По умолчанию
|
|
25
|
+
`(entry) => entry[1]`.
|
|
26
|
+
|
|
27
|
+
## Возвращаемое значение
|
|
28
|
+
|
|
29
|
+
Возвращает новый массив, отсортированный в естественном порядке.
|
|
30
|
+
|
|
31
|
+
## Примеры использования
|
|
32
|
+
|
|
33
|
+
1. Сортировка обычного массива:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const array = [10, 2, 30, 4];
|
|
37
|
+
const result = natsort(array);
|
|
38
|
+
console.log(result); // [2, 4, 10, 30]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Сортировка ассоциативного массива:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
const array = { a: 10, b: 2, c: 30, d: 4 };
|
|
45
|
+
const result = natsort(array);
|
|
46
|
+
console.log(result); // [['b', 2], ['d', 4], ['a', 10], ['c', 30]]
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
3. Сортировка массива с использованием функции `getter`:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
const array = [{ value: 10 }, { value: 2 }, { value: 30 }, { value: 4 }];
|
|
53
|
+
const result = natsort(array, (entry) => entry[1].value);
|
|
54
|
+
console.log(result); // [{ value: 2 }, { value: 4 }, { value: 10 }, { value: 30 }]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Исключения
|
|
58
|
+
|
|
59
|
+
- `TypeError`: Если параметр `arr` не является массивом.
|
|
60
|
+
- `TypeError`: Если параметр `getter` не является функцией.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[Главная](../../../README.md) / [Помощники](../../helpers.md) / range
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../../src/helpers/array/range.mjs)
|
|
4
|
+
|
|
5
|
+
# range
|
|
6
|
+
|
|
7
|
+
`range` — Генерирует массив значений от start до end с шагом step.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function range(start: string | number, end: string | number, step: number = 1): Array<any>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `range` используется для генерации массива значений от начального значения до конечного с
|
|
18
|
+
заданным шагом. Она поддерживает как числовые значения, так и строки. Шаг не может быть равен нулю.
|
|
19
|
+
|
|
20
|
+
## Параметры
|
|
21
|
+
|
|
22
|
+
- `start` (string | number): Начальное значение (строка или число).
|
|
23
|
+
- `end` (string | number): Конечное значение (строка или число).
|
|
24
|
+
- `step` (number): Шаг между значениями. По умолчанию `1`.
|
|
25
|
+
|
|
26
|
+
## Возвращаемое значение
|
|
27
|
+
|
|
28
|
+
Возвращает массив значений от start до end с шагом step.
|
|
29
|
+
|
|
30
|
+
## Примеры использования
|
|
31
|
+
|
|
32
|
+
1. Генерация числового диапазона:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const result = range(1, 5);
|
|
36
|
+
console.log(result); // [1, 2, 3, 4, 5]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. Генерация диапазона с отрицательным шагом:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const result = range(5, 1, -1);
|
|
43
|
+
console.log(result); // [5, 4, 3, 2, 1]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
3. Генерация диапазона строк:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const result = range('a', 'e');
|
|
50
|
+
console.log(result); // ['a', 'b', 'c', 'd', 'e']
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
4. Обработка значений с преобразованием типов:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
const result = range('1', 5);
|
|
57
|
+
console.log(result); // [1, 2, 3, 4, 5]
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
5. Обработка пустых строк:
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
const result = range('', 3);
|
|
64
|
+
console.log(result); // [0, 1, 2, 3]
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
6. Обработка строк и чисел:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const result = range('1', '5');
|
|
71
|
+
console.log(result); // [1, 2, 3, 4, 5]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Исключения
|
|
75
|
+
|
|
76
|
+
- `TypeError`: Если параметры имеют неверный тип или значение.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[Главная](../../../README.md) / [Помощники](../../helpers.md) / shuffle
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../../src/helpers/array/shuffle.mjs)
|
|
4
|
+
|
|
5
|
+
# shuffle
|
|
6
|
+
|
|
7
|
+
`shuffle` — Перемешивает элементы массива в случайном порядке.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function shuffle(arr: object): Array<any>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `shuffle` используется для перемешивания элементов массива в случайном порядке. Она
|
|
18
|
+
поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
|
|
19
|
+
|
|
20
|
+
## Параметры
|
|
21
|
+
|
|
22
|
+
- `arr` (object): Исходный массив.
|
|
23
|
+
|
|
24
|
+
## Возвращаемое значение
|
|
25
|
+
|
|
26
|
+
Возвращает новый массив с элементами в случайном порядке.
|
|
27
|
+
|
|
28
|
+
## Примеры использования
|
|
29
|
+
|
|
30
|
+
1. Перемешивание обычного массива:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
const array = [1, 2, 3, 4, 5];
|
|
34
|
+
const result = shuffle(array);
|
|
35
|
+
console.log(result); // [3, 1, 5, 2, 4] (пример)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Перемешивание ассоциативного массива:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const array = { a: 1, b: 2, c: 3 };
|
|
42
|
+
const result = shuffle(array);
|
|
43
|
+
console.log(result); // [['b', 2], ['a', 1], ['c', 3]] (пример)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
3. Обработка пустого массива:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
const array = [];
|
|
50
|
+
const result = shuffle(array);
|
|
51
|
+
console.log(result); // []
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
4. Обработка массива с одним элементом:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
const array = [1];
|
|
58
|
+
const result = shuffle(array);
|
|
59
|
+
console.log(result); // [1]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
5. Обработка значений, не являющихся массивами:
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
try {
|
|
66
|
+
const result = shuffle('not an array');
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error(e.message); // Параметр "arr" должен быть массивом.
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Исключения
|
|
73
|
+
|
|
74
|
+
- `TypeError`: Если параметр не является массивом.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
[Главная](../../../README.md) / [Помощники](../../helpers.md) / sort
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../../src/helpers/array/sort.mjs)
|
|
4
|
+
|
|
5
|
+
# sort
|
|
6
|
+
|
|
7
|
+
`sort` — Сортирует элементы массива с использованием функции сравнения.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function sort(arr: object, compare_func: function = (a, b) => a[1] - b[1]): Array<any>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `sort` используется для сортировки элементов массива с использованием функции сравнения. Она
|
|
18
|
+
поддерживает как обычные массивы, так и ассоциативные массивы (объекты с ключами и значениями).
|
|
19
|
+
|
|
20
|
+
## Параметры
|
|
21
|
+
|
|
22
|
+
- `arr` (object): Исходный массив.
|
|
23
|
+
- `compare_func` (function): Функция сравнения, используемая для сортировки. По умолчанию
|
|
24
|
+
`(a, b) => a[1] - b[1]`.
|
|
25
|
+
|
|
26
|
+
## Возвращаемое значение
|
|
27
|
+
|
|
28
|
+
Возвращает новый массив с отсортированными элементами.
|
|
29
|
+
|
|
30
|
+
## Примеры использования
|
|
31
|
+
|
|
32
|
+
1. Сортировка обычного массива:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
const array = [5, 3, 1, 4, 2];
|
|
36
|
+
const result = sort(array);
|
|
37
|
+
console.log(result); // [1, 2, 3, 4, 5]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
2. Сортировка ассоциативного массива:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
const array = { a: 3, b: 1, c: 2 };
|
|
44
|
+
const result = sort(array);
|
|
45
|
+
console.log(result); // [['b', 1], ['c', 2], ['a', 3]]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
3. Сортировка с использованием пользовательской функции сравнения:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
const array = [5, 3, 1, 4, 2];
|
|
52
|
+
const result = sort(array, (a, b) => b[1] - a[1]);
|
|
53
|
+
console.log(result); // [5, 4, 3, 2, 1]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
4. Обработка значений, не являющихся массивами:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
try {
|
|
60
|
+
const result = sort('not an array');
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(e.message); // Параметр "arr" должен быть массивом.
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
5. Обработка значений параметра compare_func, не являющихся функцией:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
try {
|
|
70
|
+
const result = sort([1, 2, 3], 'not a function');
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.error(e.message); // Параметр "compare_func" должен быть функцией.
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Исключения
|
|
77
|
+
|
|
78
|
+
- `TypeError`: Если параметр не является массивом или если параметр compare_func не является
|
|
79
|
+
функцией.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[Главная](../../README.md) / [Помощники](../helpers.md) / expect
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../src/helpers/expect.mjs)
|
|
4
|
+
|
|
5
|
+
# expect
|
|
6
|
+
|
|
7
|
+
`expect` — Функция, создающая новый экземпляр класса `Expect` для проверки значений.
|
|
8
|
+
|
|
9
|
+
## Сигнатура функции
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
function expect(actual: any): Expect;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Описание
|
|
16
|
+
|
|
17
|
+
Функция `expect` используется для создания нового экземпляра класса `Expect`, который предоставляет
|
|
18
|
+
методы для проверки различных свойств и типов значений. Она принимает одно значение, которое будет
|
|
19
|
+
проверяться методами класса `Expect`.
|
|
20
|
+
|
|
21
|
+
## Параметры
|
|
22
|
+
|
|
23
|
+
- `actual` (any): Значение, которое будет проверяться методами класса `Expect`.
|
|
24
|
+
|
|
25
|
+
## Возвращаемое значение
|
|
26
|
+
|
|
27
|
+
Возвращает новый экземпляр класса `Expect`.
|
|
28
|
+
|
|
29
|
+
## Примеры использования
|
|
30
|
+
|
|
31
|
+
1. Создание экземпляра класса `Expect` и проверка значения:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
expect(5).toBe(5); // true
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. Проверка значения, являющегося массивом:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
expect([1, 2, 3]).toBeArray(); // true
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. Проверка значения, являющегося BigInt:
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
expect(123n).toBeBigInt(); // true
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Проверка значения, являющегося объектом:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
class stdClass {}
|
|
53
|
+
expect(new stdClass()).toBeObject(); // true
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Исключения
|
|
57
|
+
|
|
58
|
+
- `TypeError`: Если значение не соответствует ожидаемому типу или значению.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[Главная](../../README.md) / [Помощники](../helpers.md) / expect_array
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../src/helpers/expect_array.mjs)
|
|
4
|
+
|
|
5
|
+
# expect_array
|
|
6
|
+
|
|
7
|
+
`expect_array` — Проверяет, является ли значение массивом, и выбрасывает ошибку с указанным
|
|
8
|
+
сообщением, если это не так.
|
|
9
|
+
|
|
10
|
+
## Сигнатура функции
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
function expect_array(arr: any, message: string = ''): boolean;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Описание
|
|
17
|
+
|
|
18
|
+
Функция `expect_array` используется для проверки, является ли переданное значение массивом. Если
|
|
19
|
+
значение не является массивом, функция выбрасывает ошибку типа `TypeError` с указанным сообщением.
|
|
20
|
+
|
|
21
|
+
## Параметры
|
|
22
|
+
|
|
23
|
+
- `arr` (any): Значение для проверки.
|
|
24
|
+
- `message` (string): Сообщение об ошибке, если значение не является массивом. По умолчанию пустая
|
|
25
|
+
строка.
|
|
26
|
+
|
|
27
|
+
## Возвращаемое значение
|
|
28
|
+
|
|
29
|
+
Возвращает `true`, если значение является массивом.
|
|
30
|
+
|
|
31
|
+
## Примеры использования
|
|
32
|
+
|
|
33
|
+
1. Проверка значения, являющегося массивом:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const array = [1, 2, 3];
|
|
37
|
+
const result = expect_array(array);
|
|
38
|
+
console.log(result); // true
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Проверка значения, не являющегося массивом:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
try {
|
|
45
|
+
const result = expect_array('not an array', 'Значение должно быть массивом.');
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(e.message); // Значение должно быть массивом.
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
try {
|
|
55
|
+
const result = expect_array(123, 'Ожидался массив.');
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error(e.message); // Ожидался массив.
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Исключения
|
|
62
|
+
|
|
63
|
+
- `TypeError`: Если значение не является массивом или если параметр `message` не является строкой.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[Главная](../../README.md) / [Помощники](../helpers.md) / expect_assoc
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../src/helpers/expect_assoc.mjs)
|
|
4
|
+
|
|
5
|
+
# expect_assoc
|
|
6
|
+
|
|
7
|
+
`expect_assoc` — Проверяет, является ли значение ассоциативным массивом, и выбрасывает ошибку
|
|
8
|
+
с указанным сообщением, если это не так.
|
|
9
|
+
|
|
10
|
+
## Сигнатура функции
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
function expect_assoc(arr: any, message: string = ''): boolean;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Описание
|
|
17
|
+
|
|
18
|
+
Функция `expect_assoc` используется для проверки, является ли переданное значение ассоциативным
|
|
19
|
+
массивом. Если значение не является ассоциативным массивом, функция выбрасывает ошибку типа
|
|
20
|
+
`TypeError` с указанным сообщением.
|
|
21
|
+
|
|
22
|
+
## Параметры
|
|
23
|
+
|
|
24
|
+
- `arr` (any): Значение для проверки.
|
|
25
|
+
- `message` (string): Сообщение об ошибке, если значение не является ассоциативным массивом. По
|
|
26
|
+
умолчанию пустая строка.
|
|
27
|
+
|
|
28
|
+
## Возвращаемое значение
|
|
29
|
+
|
|
30
|
+
Возвращает `true`, если значение является ассоциативным массивом.
|
|
31
|
+
|
|
32
|
+
## Примеры использования
|
|
33
|
+
|
|
34
|
+
1. Проверка значения, являющегося ассоциативным массивом:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const assoc = { a: 1, b: 2, c: 3 };
|
|
38
|
+
const result = expect_assoc(assoc);
|
|
39
|
+
console.log(result); // true
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. Проверка значения, не являющегося ассоциативным массивом:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
try {
|
|
46
|
+
const result = expect_assoc([1, 2, 3], 'Значение должно быть ассоциативным массивом.');
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(e.message); // Значение должно быть ассоциативным массивом.
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
try {
|
|
56
|
+
const result = expect_assoc(123, 'Ожидался ассоциативный массив.');
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error(e.message); // Ожидался ассоциативный массив.
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Исключения
|
|
63
|
+
|
|
64
|
+
- `TypeError`: Если значение не является ассоциативным массивом или если параметр `message` не
|
|
65
|
+
является строкой.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
[Главная](../../README.md) / [Помощники](../helpers.md) / expect_bigint
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../src/helpers/expect_bigint.mjs)
|
|
4
|
+
|
|
5
|
+
# expect_bigint
|
|
6
|
+
|
|
7
|
+
`expect_bigint` — Проверяет, является ли значение BigInt, и выбрасывает ошибку с указанным
|
|
8
|
+
сообщением, если это не так.
|
|
9
|
+
|
|
10
|
+
## Сигнатура функции
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
function expect_bigint(value: any, message: string = ''): boolean;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Описание
|
|
17
|
+
|
|
18
|
+
Функция `expect_bigint` используется для проверки, является ли переданное значение BigInt. Если
|
|
19
|
+
значение не является BigInt, функция выбрасывает ошибку типа `TypeError` с указанным сообщением.
|
|
20
|
+
|
|
21
|
+
## Параметры
|
|
22
|
+
|
|
23
|
+
- `value` (any): Значение для проверки.
|
|
24
|
+
- `message` (string): Сообщение об ошибке, если значение не является BigInt. По умолчанию пустая
|
|
25
|
+
строка.
|
|
26
|
+
|
|
27
|
+
## Возвращаемое значение
|
|
28
|
+
|
|
29
|
+
Возвращает `true`, если значение является BigInt.
|
|
30
|
+
|
|
31
|
+
## Примеры использования
|
|
32
|
+
|
|
33
|
+
1. Проверка значения, являющегося BigInt:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const value = 123n;
|
|
37
|
+
const result = expect_bigint(value);
|
|
38
|
+
console.log(result); // true
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
2. Проверка значения, не являющегося BigInt:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
try {
|
|
45
|
+
const result = expect_bigint(123, 'Значение должно быть BigInt.');
|
|
46
|
+
} catch (e) {
|
|
47
|
+
console.error(e.message); // Значение должно быть BigInt.
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
try {
|
|
55
|
+
const result = expect_bigint('123', 'Ожидался BigInt.');
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error(e.message); // Ожидался BigInt.
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Исключения
|
|
62
|
+
|
|
63
|
+
- `TypeError`: Если значение не является BigInt или если параметр `message` не является строкой.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[Главная](../../README.md) / [Помощники](../helpers.md) / expect_bool
|
|
2
|
+
|
|
3
|
+
[Исходный код](../../src/helpers/expect_bool.mjs)
|
|
4
|
+
|
|
5
|
+
# expect_bool
|
|
6
|
+
|
|
7
|
+
`expect_bool` — Проверяет, является ли значение логическим типом, и выбрасывает ошибку с
|
|
8
|
+
указанным сообщением, если это не так.
|
|
9
|
+
|
|
10
|
+
## Сигнатура функции
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
function expect_bool(value: any, message: string = ''): boolean;
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Описание
|
|
17
|
+
|
|
18
|
+
Функция `expect_bool` используется для проверки, является ли переданное значение логическим типом.
|
|
19
|
+
Если значение не является логическим типом, функция выбрасывает ошибку типа `TypeError` с указанным
|
|
20
|
+
сообщением.
|
|
21
|
+
|
|
22
|
+
## Параметры
|
|
23
|
+
|
|
24
|
+
- `value` (any): Значение для проверки.
|
|
25
|
+
- `message` (string): Сообщение об ошибке, если значение не является логическим типом. По умолчанию
|
|
26
|
+
пустая строка.
|
|
27
|
+
|
|
28
|
+
## Возвращаемое значение
|
|
29
|
+
|
|
30
|
+
Возвращает `true`, если значение является логическим типом.
|
|
31
|
+
|
|
32
|
+
## Примеры использования
|
|
33
|
+
|
|
34
|
+
1. Проверка значения, являющегося логическим типом:
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
const value = true;
|
|
38
|
+
const result = expect_bool(value);
|
|
39
|
+
console.log(result); // true
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. Проверка значения, не являющегося логическим типом:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
try {
|
|
46
|
+
const result = expect_bool(123, 'Значение должно быть логическим типом.');
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(e.message); // Значение должно быть логическим типом.
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
try {
|
|
56
|
+
const result = expect_bool('true', 'Ожидался логический тип.');
|
|
57
|
+
} catch (e) {
|
|
58
|
+
console.error(e.message); // Ожидался логический тип.
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Исключения
|
|
63
|
+
|
|
64
|
+
- `TypeError`: Если значение не является логическим типом или если параметр `message` не является
|
|
65
|
+
строкой.
|