@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
@@ -0,0 +1,65 @@
|
|
1
|
+
import is_string from './is_string.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Проверяет, является ли значение строкой, и выбрасывает ошибку с указанным сообщением, если это не так.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `expect_string` используется для проверки, является ли переданное значение строкой.
|
9
|
+
* Если значение не является строкой, функция выбрасывает ошибку типа `TypeError` с указанным сообщением.
|
10
|
+
*
|
11
|
+
* ### Параметры
|
12
|
+
*
|
13
|
+
* - `value` (any): Значение для проверки.
|
14
|
+
* - `message` (string): Сообщение об ошибке, если значение не является строкой. По умолчанию пустая строка.
|
15
|
+
*
|
16
|
+
* ### Возвращаемое значение
|
17
|
+
*
|
18
|
+
* Возвращает `true`, если значение является строкой.
|
19
|
+
*
|
20
|
+
* ### Примеры использования
|
21
|
+
*
|
22
|
+
* 1. Проверка значения, являющегося строкой:
|
23
|
+
*
|
24
|
+
* ```js
|
25
|
+
* const value = 'Hello, world!';
|
26
|
+
* const result = expect_string(value);
|
27
|
+
* console.log(result); // true
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* 2. Проверка значения, не являющегося строкой:
|
31
|
+
*
|
32
|
+
* ```js
|
33
|
+
* try {
|
34
|
+
* const result = expect_string(123, 'Значение должно быть строкой.');
|
35
|
+
* } catch (e) {
|
36
|
+
* console.error(e.message); // Значение должно быть строкой.
|
37
|
+
* }
|
38
|
+
* ```
|
39
|
+
*
|
40
|
+
* 3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
41
|
+
*
|
42
|
+
* ```js
|
43
|
+
* try {
|
44
|
+
* const result = expect_string({}, 'Ожидалась строка.');
|
45
|
+
* } catch (e) {
|
46
|
+
* console.error(e.message); // Ожидалась строка.
|
47
|
+
* }
|
48
|
+
* ```
|
49
|
+
*
|
50
|
+
* @param {any} value Значение для проверки.
|
51
|
+
* @param {string} [message=''] Сообщение об ошибке, если значение не является строкой.
|
52
|
+
* @returns {boolean} Возвращает `true`, если значение является строкой.
|
53
|
+
* @throws {TypeError} Если значение не является строкой или если параметр `message` не является строкой.
|
54
|
+
*/
|
55
|
+
export default function expect_string(value, message = '') {
|
56
|
+
if (!is_string(message)) {
|
57
|
+
throw new TypeError('Параметр "message" должен быть строкой.');
|
58
|
+
}
|
59
|
+
|
60
|
+
if (!is_string(value)) {
|
61
|
+
throw new TypeError(message);
|
62
|
+
}
|
63
|
+
|
64
|
+
return true;
|
65
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import is_string from './is_string.mjs';
|
2
|
+
import is_symbol from './is_symbol.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Проверяет, является ли значение символом, и выбрасывает ошибку с указанным сообщением, если это не так.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `expect_symbol` используется для проверки, является ли переданное значение символом.
|
10
|
+
* Если значение не является символом, функция выбрасывает ошибку типа `TypeError` с указанным сообщением.
|
11
|
+
*
|
12
|
+
* ### Параметры
|
13
|
+
*
|
14
|
+
* - `value` (any): Значение для проверки.
|
15
|
+
* - `message` (string): Сообщение об ошибке, если значение не является символом. По умолчанию пустая строка.
|
16
|
+
*
|
17
|
+
* ### Возвращаемое значение
|
18
|
+
*
|
19
|
+
* Возвращает `true`, если значение является символом.
|
20
|
+
*
|
21
|
+
* ### Примеры использования
|
22
|
+
*
|
23
|
+
* 1. Проверка значения, являющегося символом:
|
24
|
+
*
|
25
|
+
* ```js
|
26
|
+
* const value = Symbol('example');
|
27
|
+
* const result = expect_symbol(value);
|
28
|
+
* console.log(result); // true
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* 2. Проверка значения, не являющегося символом:
|
32
|
+
*
|
33
|
+
* ```js
|
34
|
+
* try {
|
35
|
+
* const result = expect_symbol('not a symbol', 'Значение должно быть символом.');
|
36
|
+
* } catch (e) {
|
37
|
+
* console.error(e.message); // Значение должно быть символом.
|
38
|
+
* }
|
39
|
+
* ```
|
40
|
+
*
|
41
|
+
* 3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
42
|
+
*
|
43
|
+
* ```js
|
44
|
+
* try {
|
45
|
+
* const result = expect_symbol(123, 'Ожидался символ.');
|
46
|
+
* } catch (e) {
|
47
|
+
* console.error(e.message); // Ожидался символ.
|
48
|
+
* }
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* @param {any} value Значение для проверки.
|
52
|
+
* @param {string} [message=''] Сообщение об ошибке, если значение не является символом.
|
53
|
+
* @returns {boolean} Возвращает `true`, если значение является символом.
|
54
|
+
* @throws {TypeError} Если значение не является символом или если параметр `message` не является строкой.
|
55
|
+
*/
|
56
|
+
export default function expect_symbol(value, message = '') {
|
57
|
+
if (!is_string(message)) {
|
58
|
+
throw new TypeError('Параметр "message" должен быть строкой.');
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!is_symbol(value)) {
|
62
|
+
throw new TypeError(message);
|
63
|
+
}
|
64
|
+
|
65
|
+
return true;
|
66
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import is_string from './is_string.mjs';
|
2
|
+
import is_undefined from './is_undefined.mjs';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Проверяет, является ли значение undefined, и выбрасывает ошибку с указанным сообщением, если это не так.
|
6
|
+
*
|
7
|
+
* ### Описание
|
8
|
+
*
|
9
|
+
* Функция `expect_undefined` используется для проверки, является ли переданное значение undefined.
|
10
|
+
* Если значение не является undefined, функция выбрасывает ошибку типа `TypeError` с указанным сообщением.
|
11
|
+
*
|
12
|
+
* ### Параметры
|
13
|
+
*
|
14
|
+
* - `value` (any): Значение для проверки.
|
15
|
+
* - `message` (string): Сообщение об ошибке, если значение не является undefined. По умолчанию пустая строка.
|
16
|
+
*
|
17
|
+
* ### Возвращаемое значение
|
18
|
+
*
|
19
|
+
* Возвращает `true`, если значение является undefined.
|
20
|
+
*
|
21
|
+
* ### Примеры использования
|
22
|
+
*
|
23
|
+
* 1. Проверка значения, являющегося undefined:
|
24
|
+
*
|
25
|
+
* ```js
|
26
|
+
* let value;
|
27
|
+
* const result = expect_undefined(value);
|
28
|
+
* console.log(result); // true
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* 2. Проверка значения, не являющегося undefined:
|
32
|
+
*
|
33
|
+
* ```js
|
34
|
+
* try {
|
35
|
+
* const result = expect_undefined(123, 'Значение должно быть undefined.');
|
36
|
+
* } catch (e) {
|
37
|
+
* console.error(e.message); // Значение должно быть undefined.
|
38
|
+
* }
|
39
|
+
* ```
|
40
|
+
*
|
41
|
+
* 3. Проверка значения с использованием пользовательского сообщения об ошибке:
|
42
|
+
*
|
43
|
+
* ```js
|
44
|
+
* try {
|
45
|
+
* const result = expect_undefined('not undefined', 'Ожидалось значение undefined.');
|
46
|
+
* } catch (e) {
|
47
|
+
* console.error(e.message); // Ожидалось значение undefined.
|
48
|
+
* }
|
49
|
+
* ```
|
50
|
+
*
|
51
|
+
* @param {any} value Значение для проверки.
|
52
|
+
* @param {string} [message=''] Сообщение об ошибке, если значение не является undefined.
|
53
|
+
* @returns {boolean} Возвращает `true`, если значение является undefined.
|
54
|
+
* @throws {TypeError} Если значение не является undefined или если параметр `message` не является строкой.
|
55
|
+
*/
|
56
|
+
export default function expect_undefined(value, message = '') {
|
57
|
+
if (!is_string(message)) {
|
58
|
+
throw new TypeError('Параметр "message" должен быть строкой.');
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!is_undefined(value)) {
|
62
|
+
throw new TypeError(message);
|
63
|
+
}
|
64
|
+
|
65
|
+
return true;
|
66
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import is_string from './is_string.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Проверяет, является ли значение одиночным символом.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `is_char` используется для проверки, является ли переданное значение одиночным символом.
|
9
|
+
* Значение считается одиночным символом, если оно является строкой длиной в один символ.
|
10
|
+
*
|
11
|
+
* ### Параметры
|
12
|
+
*
|
13
|
+
* - `value` (string): Значение для проверки.
|
14
|
+
*
|
15
|
+
* ### Возвращаемое значение
|
16
|
+
*
|
17
|
+
* Возвращает `true`, если значение является одиночным символом, иначе `false`.
|
18
|
+
*
|
19
|
+
* ### Примеры использования
|
20
|
+
*
|
21
|
+
* 1. Проверка одиночного символа:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* const result = is_char('a');
|
25
|
+
* console.log(result); // true
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* 2. Проверка строки из нескольких символов:
|
29
|
+
*
|
30
|
+
* ```js
|
31
|
+
* const result = is_char('abc');
|
32
|
+
* console.log(result); // false
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* 3. Проверка пустой строки:
|
36
|
+
*
|
37
|
+
* ```js
|
38
|
+
* const result = is_char('');
|
39
|
+
* console.log(result); // false
|
40
|
+
* ```
|
41
|
+
*
|
42
|
+
* 4. Проверка значения, не являющегося строкой:
|
43
|
+
*
|
44
|
+
* ```js
|
45
|
+
* const result = is_char(1);
|
46
|
+
* console.log(result); // false
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* @param {string} value Значение для проверки.
|
50
|
+
* @returns {boolean} Возвращает `true`, если значение является одиночным символом, иначе `false`.
|
51
|
+
*/
|
52
|
+
export default function is_char(value) {
|
53
|
+
return is_string(value) && value.length === 1;
|
54
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/**
|
2
|
+
* Проверяет, являются ли два значения равными.
|
3
|
+
*
|
4
|
+
* ### Описание
|
5
|
+
*
|
6
|
+
* Функция `is_equal` используется для проверки равенства двух значений. Она поддерживает сравнение
|
7
|
+
* примитивных типов данных, а также объектов и массивов. Для объектов и массивов функция рекурсивно
|
8
|
+
* сравнивает их ключи и значения. Функция также поддерживает строгий режим сравнения, который учитывает типы значений.
|
9
|
+
*
|
10
|
+
* ### Параметры
|
11
|
+
*
|
12
|
+
* - `actual` (any): Первое значение для сравнения.
|
13
|
+
* - `expected` (any): Второе значение для сравнения.
|
14
|
+
* - `strict` (boolean): Флаг строгого сравнения. По умолчанию `false`.
|
15
|
+
*
|
16
|
+
* ### Возвращаемое значение
|
17
|
+
*
|
18
|
+
* Возвращает `true`, если значения равны, иначе `false`.
|
19
|
+
*
|
20
|
+
* ### Примеры использования
|
21
|
+
*
|
22
|
+
* 1. Проверка равенства чисел:
|
23
|
+
*
|
24
|
+
* ```js
|
25
|
+
* const result = is_equal(1, 1);
|
26
|
+
* console.log(result); // true
|
27
|
+
* ```
|
28
|
+
*
|
29
|
+
* 2. Проверка равенства строк:
|
30
|
+
*
|
31
|
+
* ```js
|
32
|
+
* const result = is_equal('hello', 'hello');
|
33
|
+
* console.log(result); // true
|
34
|
+
* ```
|
35
|
+
*
|
36
|
+
* 3. Проверка равенства объектов:
|
37
|
+
*
|
38
|
+
* ```js
|
39
|
+
* const obj1 = { a: 1, b: 2 };
|
40
|
+
* const obj2 = { a: 1, b: 2 };
|
41
|
+
* const result = is_equal(obj1, obj2);
|
42
|
+
* console.log(result); // true
|
43
|
+
* ```
|
44
|
+
*
|
45
|
+
* 4. Проверка равенства массивов:
|
46
|
+
*
|
47
|
+
* ```js
|
48
|
+
* const arr1 = [1, 2, 3];
|
49
|
+
* const arr2 = [1, 2, 3];
|
50
|
+
* const result = is_equal(arr1, arr2);
|
51
|
+
* console.log(result); // true
|
52
|
+
* ```
|
53
|
+
*
|
54
|
+
* 5. Проверка равенства с использованием строгого сравнения:
|
55
|
+
*
|
56
|
+
* ```js
|
57
|
+
* const result = is_equal(1, '1', true);
|
58
|
+
* console.log(result); // false
|
59
|
+
* ```
|
60
|
+
*
|
61
|
+
* @param {any} actual Первое значение для сравнения.
|
62
|
+
* @param {any} expected Второе значение для сравнения.
|
63
|
+
* @param {boolean} [strict=false] Флаг строгого сравнения.
|
64
|
+
* @returns {boolean} Возвращает `true`, если значения равны, иначе `false`.
|
65
|
+
*/
|
66
|
+
export default function is_equal(actual, expected, strict = false) {
|
67
|
+
if (
|
68
|
+
typeof actual === 'object' &&
|
69
|
+
typeof expected === 'object' &&
|
70
|
+
actual !== null &&
|
71
|
+
expected !== null
|
72
|
+
) {
|
73
|
+
const entriesA = Object.entries(actual);
|
74
|
+
const entriesB = Object.entries(expected);
|
75
|
+
|
76
|
+
if (entriesA.length !== entriesB.length) {
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
|
80
|
+
for (let i = 0; i < entriesA.length; i++) {
|
81
|
+
if (entriesA[i][0] !== entriesB[i][0] || !is_equal(entriesA[i][1], entriesB[i][1])) {
|
82
|
+
return false;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (strict) {
|
90
|
+
return Object.is(actual, expected);
|
91
|
+
}
|
92
|
+
|
93
|
+
return actual == expected;
|
94
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import is_char from '../is_char.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Проверяет, является ли символ цифрой.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `is_digit_char` используется для проверки, является ли переданный символ цифрой.
|
9
|
+
* Цифровыми символами считаются символы с кодами от 48 до 57 включительно.
|
10
|
+
*
|
11
|
+
* ### Параметры
|
12
|
+
*
|
13
|
+
* - `value` (any): Символ для проверки.
|
14
|
+
*
|
15
|
+
* ### Возвращаемое значение
|
16
|
+
*
|
17
|
+
* Возвращает `true`, если символ является цифрой, иначе `false`.
|
18
|
+
*
|
19
|
+
* ### Примеры использования
|
20
|
+
*
|
21
|
+
* 1. Проверка цифрового символа:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* const result = is_digit_char('5');
|
25
|
+
* console.log(result); // true
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* 2. Проверка непробельного символа:
|
29
|
+
*
|
30
|
+
* ```js
|
31
|
+
* const result = is_digit_char('a');
|
32
|
+
* console.log(result); // false
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* 3. Проверка пустой строки:
|
36
|
+
*
|
37
|
+
* ```js
|
38
|
+
* const result = is_digit_char('');
|
39
|
+
* console.log(result); // false
|
40
|
+
* ```
|
41
|
+
*
|
42
|
+
* 4. Проверка строки из нескольких символов:
|
43
|
+
*
|
44
|
+
* ```js
|
45
|
+
* const result = is_digit_char('123');
|
46
|
+
* console.log(result); // false
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* @param {any} value Символ для проверки.
|
50
|
+
* @returns {boolean} Возвращает `true`, если символ является цифрой, иначе `false`.
|
51
|
+
*/
|
52
|
+
export default function is_digit_char(value) {
|
53
|
+
if (!is_char(value)) {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
|
57
|
+
const char_code = value.charCodeAt(0);
|
58
|
+
|
59
|
+
return char_code >= 48 && char_code <= 57;
|
60
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import is_char from '../is_char.mjs';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Проверяет, является ли символ пробельным.
|
5
|
+
*
|
6
|
+
* ### Описание
|
7
|
+
*
|
8
|
+
* Функция `is_whitespace_char` используется для проверки, является ли переданный символ пробельным.
|
9
|
+
* Пробельными символами считаются символы с кодами от 0 до 32 включительно.
|
10
|
+
*
|
11
|
+
* ### Параметры
|
12
|
+
*
|
13
|
+
* - `value` (any): Символ для проверки.
|
14
|
+
*
|
15
|
+
* ### Возвращаемое значение
|
16
|
+
*
|
17
|
+
* Возвращает `true`, если символ является пробельным, иначе `false`.
|
18
|
+
*
|
19
|
+
* ### Примеры использования
|
20
|
+
*
|
21
|
+
* 1. Проверка пробельного символа:
|
22
|
+
*
|
23
|
+
* ```js
|
24
|
+
* const result = is_whitespace_char(' ');
|
25
|
+
* console.log(result); // true
|
26
|
+
* ```
|
27
|
+
*
|
28
|
+
* 2. Проверка непробельного символа:
|
29
|
+
*
|
30
|
+
* ```js
|
31
|
+
* const result = is_whitespace_char('a');
|
32
|
+
* console.log(result); // false
|
33
|
+
* ```
|
34
|
+
*
|
35
|
+
* 3. Проверка пустой строки:
|
36
|
+
*
|
37
|
+
* ```js
|
38
|
+
* const result = is_whitespace_char('');
|
39
|
+
* console.log(result); // false
|
40
|
+
* ```
|
41
|
+
*
|
42
|
+
* 4. Проверка строки из нескольких символов:
|
43
|
+
*
|
44
|
+
* ```js
|
45
|
+
* const result = is_whitespace_char('abc');
|
46
|
+
* console.log(result); // false
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* @param {any} value Символ для проверки.
|
50
|
+
* @returns {boolean} Возвращает `true`, если символ является пробельным, иначе `false`.
|
51
|
+
*/
|
52
|
+
export default function is_whitespace_char(value) {
|
53
|
+
return is_char(value) && value.charCodeAt(0) <= 32;
|
54
|
+
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import is_string from '../is_string.mjs';
|
2
|
+
import is_digit_char from './is_digit_char.mjs';
|
3
|
+
import is_whitespace_char from './is_whitespace_char.mjs';
|
4
|
+
import natcompare_numeric from './natcompare_numeric.mjs';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Сравнивает две строки в естественном порядке.
|
8
|
+
*
|
9
|
+
* ### Описание
|
10
|
+
*
|
11
|
+
* Функция `natcompare` используется для сравнения двух строк в естественном порядке.
|
12
|
+
* Она поддерживает строки с ведущими нулями и пробелами и игнорирует их при сравнении.
|
13
|
+
*
|
14
|
+
* ### Параметры
|
15
|
+
*
|
16
|
+
* - `a` (string): Первая строка для сравнения.
|
17
|
+
* - `b` (string): Вторая строка для сравнения.
|
18
|
+
*
|
19
|
+
* ### Возвращаемое значение
|
20
|
+
*
|
21
|
+
* Возвращает отрицательное значение, если `a` меньше `b`, ноль, если `a` равно `b`, и положительное значение, если `a` больше `b`.
|
22
|
+
*
|
23
|
+
* ### Примеры использования
|
24
|
+
*
|
25
|
+
* 1. Сравнение строк с числовыми значениями:
|
26
|
+
*
|
27
|
+
* ```js
|
28
|
+
* const result = natcompare('10', '2');
|
29
|
+
* console.log(result); // 1
|
30
|
+
* ```
|
31
|
+
*
|
32
|
+
* 2. Сравнение строк с ведущими нулями:
|
33
|
+
*
|
34
|
+
* ```js
|
35
|
+
* const result = natcompare('0010', '10');
|
36
|
+
* console.log(result); // 0
|
37
|
+
* ```
|
38
|
+
*
|
39
|
+
* @param {string} a Первая строка для сравнения.
|
40
|
+
* @param {string} b Вторая строка для сравнения.
|
41
|
+
* @returns {number} Возвращает отрицательное значение, если `a` меньше `b`, ноль, если `a` равно `b`, и положительное значение, если `a` больше `b`.
|
42
|
+
* @throws {TypeError} Если параметры не являются строками.
|
43
|
+
*/
|
44
|
+
export default function natcompare(a, b) {
|
45
|
+
if (!is_string(a)) {
|
46
|
+
throw new TypeError('Параметр "a" должен быть строкой.');
|
47
|
+
}
|
48
|
+
|
49
|
+
if (!is_string(b)) {
|
50
|
+
throw new TypeError('Параметр "b" должен быть строкой.');
|
51
|
+
}
|
52
|
+
|
53
|
+
a = a.trim();
|
54
|
+
b = b.trim();
|
55
|
+
|
56
|
+
let ia = 0;
|
57
|
+
let ib = 0;
|
58
|
+
let nza = 0;
|
59
|
+
let nzb = 0;
|
60
|
+
|
61
|
+
while (true) {
|
62
|
+
nza = 0;
|
63
|
+
nzb = 0;
|
64
|
+
|
65
|
+
let ca = a.charAt(ia);
|
66
|
+
let cb = b.charAt(ib);
|
67
|
+
|
68
|
+
while (is_whitespace_char(ca) || ca === '0') {
|
69
|
+
if (ca === '0') {
|
70
|
+
nza++;
|
71
|
+
} else {
|
72
|
+
nza = 0;
|
73
|
+
}
|
74
|
+
ca = a.charAt(++ia);
|
75
|
+
}
|
76
|
+
|
77
|
+
while (is_whitespace_char(cb) || cb === '0') {
|
78
|
+
if (cb === '0') {
|
79
|
+
nzb++;
|
80
|
+
} else {
|
81
|
+
nzb = 0;
|
82
|
+
}
|
83
|
+
cb = b.charAt(++ib);
|
84
|
+
}
|
85
|
+
|
86
|
+
if (is_digit_char(ca) && is_digit_char(cb)) {
|
87
|
+
const result = natcompare_numeric(a.slice(ia), b.slice(ib));
|
88
|
+
|
89
|
+
if (result !== 0) {
|
90
|
+
return result;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
if (ca === '' && cb === '') {
|
95
|
+
return nza - nzb;
|
96
|
+
}
|
97
|
+
|
98
|
+
if (ca < cb) {
|
99
|
+
return -1;
|
100
|
+
} else if (ca > cb) {
|
101
|
+
return 1;
|
102
|
+
}
|
103
|
+
|
104
|
+
ia++;
|
105
|
+
ib++;
|
106
|
+
}
|
107
|
+
}
|