@rogolev/value 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. package/.prettierignore +4 -4
  2. package/CHANGELOG.md +68 -56
  3. package/LICENSE +41 -41
  4. package/README.md +100 -91
  5. package/babel.config.json +20 -20
  6. package/docs/classes/Convert/toArray.md +100 -0
  7. package/docs/classes/Convert/toAssoc.md +90 -0
  8. package/docs/classes/Convert/toBool.md +72 -0
  9. package/docs/classes/Convert/toBoolean.md +72 -0
  10. package/docs/classes/Convert/toFloat.md +69 -0
  11. package/docs/classes/Convert/toInt.md +86 -0
  12. package/docs/classes/Convert/toInteger.md +86 -0
  13. package/docs/classes/Convert/toList.md +73 -0
  14. package/docs/classes/Convert/toObject.md +76 -0
  15. package/docs/classes/Convert/toString.md +125 -0
  16. package/docs/classes/Convert.md +44 -0
  17. package/docs/classes/Type/isArray.md +106 -0
  18. package/docs/classes/Type/isAssoc.md +57 -0
  19. package/docs/classes/Type/isBigInt.md +49 -0
  20. package/docs/classes/Type/isBool.md +51 -0
  21. package/docs/classes/Type/isBoolean.md +51 -0
  22. package/docs/classes/Type/isClass.md +60 -0
  23. package/docs/classes/Type/isEmpty.md +53 -0
  24. package/docs/classes/Type/isFloat.md +77 -0
  25. package/docs/classes/Type/isFunction.md +64 -0
  26. package/docs/classes/Type/isInfinity.md +59 -0
  27. package/docs/classes/Type/isInt.md +77 -0
  28. package/docs/classes/Type/isInteger.md +77 -0
  29. package/docs/classes/Type/isList.md +49 -0
  30. package/docs/classes/Type/isNaN.md +57 -0
  31. package/docs/classes/Type/isNull.md +49 -0
  32. package/docs/classes/Type/isNumber.md +60 -0
  33. package/docs/classes/Type/isNumeric.md +58 -0
  34. package/docs/classes/Type/isObject.md +53 -0
  35. package/docs/classes/Type/isScalar.md +54 -0
  36. package/docs/classes/Type/isString.md +54 -0
  37. package/docs/classes/Type/isSymbol.md +56 -0
  38. package/docs/classes/Type/isUndefined.md +52 -0
  39. package/docs/classes/Type.md +74 -0
  40. package/docs/classes.md +9 -0
  41. package/docs/helpers/array.md +80 -80
  42. package/docs/helpers/empty.md +77 -77
  43. package/docs/helpers/gettype.md +69 -69
  44. package/docs/helpers/is_array.md +105 -105
  45. package/docs/helpers/is_assoc.md +59 -59
  46. package/docs/helpers/is_bigint.md +57 -57
  47. package/docs/helpers/is_bool.md +50 -50
  48. package/docs/helpers/is_boolean.md +50 -50
  49. package/docs/helpers/is_class.md +73 -73
  50. package/docs/helpers/is_float.md +71 -71
  51. package/docs/helpers/is_function.md +62 -62
  52. package/docs/helpers/is_infinity.md +61 -61
  53. package/docs/helpers/is_int.md +81 -81
  54. package/docs/helpers/is_integer.md +82 -82
  55. package/docs/helpers/is_list.md +51 -51
  56. package/docs/helpers/is_nan.md +59 -59
  57. package/docs/helpers/is_null.md +49 -49
  58. package/docs/helpers/is_number.md +67 -67
  59. package/docs/helpers/is_numeric.md +76 -76
  60. package/docs/helpers/is_object.md +69 -69
  61. package/docs/helpers/is_scalar.md +60 -60
  62. package/docs/helpers/is_string.md +58 -58
  63. package/docs/helpers/is_symbol.md +58 -58
  64. package/docs/helpers/is_undefined.md +56 -56
  65. package/docs/helpers/print.md +187 -187
  66. package/docs/helpers/print_type.md +225 -225
  67. package/docs/helpers/settype.md +78 -78
  68. package/docs/helpers/to_array.md +106 -106
  69. package/docs/helpers/to_assoc.md +91 -91
  70. package/docs/helpers/to_bool.md +76 -76
  71. package/docs/helpers/to_boolean.md +77 -77
  72. package/docs/helpers/to_float.md +70 -70
  73. package/docs/helpers/to_int.md +87 -87
  74. package/docs/helpers/to_integer.md +87 -87
  75. package/docs/helpers/to_list.md +47 -47
  76. package/docs/helpers/to_object.md +76 -76
  77. package/docs/helpers/to_string.md +134 -134
  78. package/docs/helpers.md +51 -51
  79. package/docs/types/NaN.md +30 -30
  80. package/docs/types/array.md +252 -252
  81. package/docs/types/bigint.md +34 -34
  82. package/docs/types/boolean.md +47 -47
  83. package/docs/types/class.md +36 -36
  84. package/docs/types/float.md +35 -35
  85. package/docs/types/function.md +121 -121
  86. package/docs/types/infinity.md +32 -32
  87. package/docs/types/integer.md +35 -35
  88. package/docs/types/null.md +23 -23
  89. package/docs/types/object.md +62 -62
  90. package/docs/types/string.md +33 -33
  91. package/docs/types/symbol.md +29 -29
  92. package/docs/types/undefined.md +25 -25
  93. package/docs/types.md +44 -44
  94. package/eslint.config.mjs +1664 -1664
  95. package/index.mjs +40 -37
  96. package/jest.config.mjs +31 -31
  97. package/package.json +48 -47
  98. package/prettier.config.mjs +224 -224
  99. package/src/classes/Convert.mjs +819 -0
  100. package/src/classes/Type.mjs +1285 -0
  101. package/src/helpers/array.mjs +107 -107
  102. package/src/helpers/empty.mjs +70 -70
  103. package/src/helpers/gettype.mjs +133 -133
  104. package/src/helpers/is_array.mjs +128 -128
  105. package/src/helpers/is_assoc.mjs +51 -51
  106. package/src/helpers/is_bigint.mjs +47 -47
  107. package/src/helpers/is_bool.mjs +43 -43
  108. package/src/helpers/is_boolean.mjs +43 -43
  109. package/src/helpers/is_class.mjs +87 -87
  110. package/src/helpers/is_float.mjs +67 -67
  111. package/src/helpers/is_function.mjs +74 -74
  112. package/src/helpers/is_infinity.mjs +52 -52
  113. package/src/helpers/is_int.mjs +57 -57
  114. package/src/helpers/is_integer.mjs +74 -74
  115. package/src/helpers/is_list.mjs +43 -43
  116. package/src/helpers/is_nan.mjs +51 -51
  117. package/src/helpers/is_null.mjs +37 -37
  118. package/src/helpers/is_number.mjs +49 -49
  119. package/src/helpers/is_numeric.mjs +64 -64
  120. package/src/helpers/is_object.mjs +72 -72
  121. package/src/helpers/is_scalar.mjs +45 -45
  122. package/src/helpers/is_string.mjs +46 -46
  123. package/src/helpers/is_symbol.mjs +46 -46
  124. package/src/helpers/is_undefined.mjs +44 -44
  125. package/src/helpers/print.mjs +245 -245
  126. package/src/helpers/print_type.mjs +261 -261
  127. package/src/helpers/settype.mjs +101 -101
  128. package/src/helpers/to_array.mjs +118 -118
  129. package/src/helpers/to_assoc.mjs +98 -98
  130. package/src/helpers/to_bool.mjs +68 -68
  131. package/src/helpers/to_boolean.mjs +64 -64
  132. package/src/helpers/to_float.mjs +72 -72
  133. package/src/helpers/to_int.mjs +93 -93
  134. package/src/helpers/to_integer.mjs +81 -81
  135. package/src/helpers/to_list.mjs +56 -56
  136. package/src/helpers/to_object.mjs +94 -94
  137. package/src/helpers/to_string.mjs +157 -157
  138. package/tests/classes/Convert.test.mjs +399 -0
  139. package/tests/classes/Type.test.mjs +1263 -0
  140. package/tests/helpers/array.test.mjs +58 -58
  141. package/tests/helpers/empty.test.mjs +22 -22
  142. package/tests/helpers/gettype.test.mjs +74 -74
  143. package/tests/helpers/is_array.test.mjs +404 -404
  144. package/tests/helpers/is_assoc.test.mjs +42 -42
  145. package/tests/helpers/is_bigint.test.mjs +51 -51
  146. package/tests/helpers/is_bool.test.mjs +43 -43
  147. package/tests/helpers/is_boolean.test.mjs +43 -43
  148. package/tests/helpers/is_class.test.mjs +84 -84
  149. package/tests/helpers/is_float.test.mjs +87 -87
  150. package/tests/helpers/is_function.test.mjs +83 -83
  151. package/tests/helpers/is_infinity.test.mjs +46 -46
  152. package/tests/helpers/is_int.test.mjs +45 -45
  153. package/tests/helpers/is_integer.test.mjs +64 -64
  154. package/tests/helpers/is_list.test.mjs +42 -42
  155. package/tests/helpers/is_nan.test.mjs +43 -43
  156. package/tests/helpers/is_null.test.mjs +17 -17
  157. package/tests/helpers/is_number.test.mjs +25 -25
  158. package/tests/helpers/is_numeric.test.mjs +30 -30
  159. package/tests/helpers/is_object.test.mjs +52 -52
  160. package/tests/helpers/is_scalar.test.mjs +21 -21
  161. package/tests/helpers/is_string.test.mjs +20 -20
  162. package/tests/helpers/is_symbol.test.mjs +20 -20
  163. package/tests/helpers/is_undefined.test.mjs +18 -18
  164. package/tests/helpers/print.test.mjs +62 -62
  165. package/tests/helpers/print_type.test.mjs +62 -62
  166. package/tests/helpers/settype.test.mjs +34 -34
  167. package/tests/helpers/to_array.test.mjs +38 -38
  168. package/tests/helpers/to_assoc.test.mjs +33 -33
  169. package/tests/helpers/to_bool.test.mjs +51 -51
  170. package/tests/helpers/to_boolean.test.mjs +51 -51
  171. package/tests/helpers/to_float.test.mjs +26 -26
  172. package/tests/helpers/to_int.test.mjs +48 -48
  173. package/tests/helpers/to_integer.test.mjs +48 -48
  174. package/tests/helpers/to_list.test.mjs +32 -32
  175. package/tests/helpers/to_object.test.mjs +36 -36
  176. package/tests/helpers/to_string.test.mjs +71 -71
@@ -1,157 +1,157 @@
1
- import is_array from './is_array.mjs';
2
- import is_class from './is_class.mjs';
3
- import is_function from './is_function.mjs';
4
- import is_object from './is_object.mjs';
5
- import is_string from './is_string.mjs';
6
-
7
- /**
8
- * Приводит значение переменной к строке.
9
- *
10
- * ### Описание
11
- *
12
- * Функция `to_string` используется для преобразования различных типов данных в строку. Она обрабатывает массивы, объекты, классы, функции, символы и другие типы данных, возвращая их строковое представление.
13
- *
14
- * ### Параметры
15
- *
16
- * - `value` (any)
17
- * Переменная, значение которой необходимо привести к строке.
18
- *
19
- * ### Возвращаемое значение
20
- *
21
- * Возвращает строку, соответствующую переданному значению.
22
- *
23
- * ### Примеры использования
24
- *
25
- * 1. Преобразование строки:
26
- *
27
- * ```js
28
- * const result = to_string('example');
29
- * // Результат: 'example'
30
- * ```
31
- *
32
- * 2. Преобразование числа:
33
- *
34
- * ```js
35
- * const result = to_string(123);
36
- * // Результат: '123'
37
- * ```
38
- *
39
- * 3. Преобразование булевых значений:
40
- *
41
- * ```js
42
- * const result1 = to_string(true);
43
- * // Результат: 'true'
44
- *
45
- * const result2 = to_string(false);
46
- * // Результат: 'false'
47
- * ```
48
- *
49
- * 4. Преобразование null и undefined:
50
- *
51
- * ```js
52
- * const result1 = to_string(null);
53
- * // Результат: 'null'
54
- *
55
- * const result2 = to_string(undefined);
56
- * // Результат: 'undefined'
57
- * ```
58
- *
59
- * 5. Преобразование массива:
60
- *
61
- * ```js
62
- * const arr = [1, 2, 3];
63
- * const result = to_string(arr);
64
- * // Результат: '[\n 1,\n 2,\n 3,\n]'
65
- * ```
66
- *
67
- * 6. Преобразование объекта:
68
- *
69
- * ```js
70
- * const obj = { key: 'value' };
71
- * const result = to_string(obj);
72
- * // Результат: '{\n key: 'value',\n}'
73
- * ```
74
- *
75
- * 7. Преобразование функции:
76
- *
77
- * ```js
78
- * const func = function() {};
79
- * const result = to_string(func);
80
- * // Результат: 'function func() {}'
81
- * ```
82
- *
83
- * 8. Преобразование символа:
84
- *
85
- * ```js
86
- * const symbol = Symbol('example');
87
- * const result = to_string(symbol);
88
- * // Результат: 'Symbol(example)'
89
- * ```
90
- *
91
- * 9. Преобразование BigInt:
92
- *
93
- * ```js
94
- * const bigInt = BigInt(123);
95
- * const result = to_string(bigInt);
96
- * // Результат: '123'
97
- * ```
98
- *
99
- * 10. Преобразование класса:
100
- *
101
- * ```js
102
- * class MyClass {
103
- * static test = 'test';
104
- * }
105
- * const result = to_string(MyClass);
106
- * // Результат: 'class MyClass {}'
107
- * ```
108
- *
109
- * 11. Преобразование экземпляра класса:
110
- *
111
- * ```js
112
- * class MyClass {}
113
- * const instance = new MyClass();
114
- * const result = to_string(instance);
115
- * // Результат: 'object MyClass'
116
- * ```
117
- *
118
- * @param {any} value Переменная, значение которой необходимо привести к строке.
119
- * @returns {string} Возвращает приведенное к строке значение переменной `value`.
120
- */
121
- export default function to_string(value) {
122
- if (Array.isArray(value)) {
123
- let string = '[';
124
-
125
- for (const v of value) {
126
- string += `\n ${is_string(v) ? "'" : ''}${to_string(v).replace(/\n/g, '\n ')}${is_string(v) ? "'" : ''},`;
127
- }
128
-
129
- return (string += string.length > 1 ? '\n]' : ']');
130
- }
131
-
132
- if (is_array(value)) {
133
- let string = '{';
134
-
135
- for (const [k, v] of Object.entries(value)) {
136
- string += `\n ${k}: ${is_string(v) ? "'" : ''}${to_string(v).replace(/\n/g, '\n ')}${is_string(v) ? "'" : ''},`;
137
- }
138
-
139
- return (string += string.length > 1 ? '\n}' : '}');
140
- }
141
-
142
- if (is_class(value)) {
143
- return `class ${value.name ? `${value.name} ` : ''}{}`;
144
- }
145
-
146
- if (is_object(value)) {
147
- return value.toString() === '[object Object]' ?
148
- `object ${Object.getPrototypeOf(value).constructor.name}`
149
- : value.toString();
150
- }
151
-
152
- if (is_function(value)) {
153
- return `function ${value.name}() {}`;
154
- }
155
-
156
- return String(value);
157
- }
1
+ import is_array from './is_array.mjs';
2
+ import is_class from './is_class.mjs';
3
+ import is_function from './is_function.mjs';
4
+ import is_object from './is_object.mjs';
5
+ import is_string from './is_string.mjs';
6
+
7
+ /**
8
+ * Приводит значение переменной к строке.
9
+ *
10
+ * ### Описание
11
+ *
12
+ * Функция `to_string` используется для преобразования различных типов данных в строку. Она обрабатывает массивы, объекты, классы, функции, символы и другие типы данных, возвращая их строковое представление.
13
+ *
14
+ * ### Параметры
15
+ *
16
+ * - `value` (any)
17
+ * Переменная, значение которой необходимо привести к строке.
18
+ *
19
+ * ### Возвращаемое значение
20
+ *
21
+ * Возвращает строку, соответствующую переданному значению.
22
+ *
23
+ * ### Примеры использования
24
+ *
25
+ * 1. Преобразование строки:
26
+ *
27
+ * ```js
28
+ * const result = to_string('example');
29
+ * // Результат: 'example'
30
+ * ```
31
+ *
32
+ * 2. Преобразование числа:
33
+ *
34
+ * ```js
35
+ * const result = to_string(123);
36
+ * // Результат: '123'
37
+ * ```
38
+ *
39
+ * 3. Преобразование булевых значений:
40
+ *
41
+ * ```js
42
+ * const result1 = to_string(true);
43
+ * // Результат: 'true'
44
+ *
45
+ * const result2 = to_string(false);
46
+ * // Результат: 'false'
47
+ * ```
48
+ *
49
+ * 4. Преобразование null и undefined:
50
+ *
51
+ * ```js
52
+ * const result1 = to_string(null);
53
+ * // Результат: 'null'
54
+ *
55
+ * const result2 = to_string(undefined);
56
+ * // Результат: 'undefined'
57
+ * ```
58
+ *
59
+ * 5. Преобразование массива:
60
+ *
61
+ * ```js
62
+ * const arr = [1, 2, 3];
63
+ * const result = to_string(arr);
64
+ * // Результат: '[\n 1,\n 2,\n 3,\n]'
65
+ * ```
66
+ *
67
+ * 6. Преобразование объекта:
68
+ *
69
+ * ```js
70
+ * const obj = { key: 'value' };
71
+ * const result = to_string(obj);
72
+ * // Результат: '{\n key: 'value',\n}'
73
+ * ```
74
+ *
75
+ * 7. Преобразование функции:
76
+ *
77
+ * ```js
78
+ * const func = function() {};
79
+ * const result = to_string(func);
80
+ * // Результат: 'function func() {}'
81
+ * ```
82
+ *
83
+ * 8. Преобразование символа:
84
+ *
85
+ * ```js
86
+ * const symbol = Symbol('example');
87
+ * const result = to_string(symbol);
88
+ * // Результат: 'Symbol(example)'
89
+ * ```
90
+ *
91
+ * 9. Преобразование BigInt:
92
+ *
93
+ * ```js
94
+ * const bigInt = BigInt(123);
95
+ * const result = to_string(bigInt);
96
+ * // Результат: '123'
97
+ * ```
98
+ *
99
+ * 10. Преобразование класса:
100
+ *
101
+ * ```js
102
+ * class MyClass {
103
+ * static test = 'test';
104
+ * }
105
+ * const result = to_string(MyClass);
106
+ * // Результат: 'class MyClass {}'
107
+ * ```
108
+ *
109
+ * 11. Преобразование экземпляра класса:
110
+ *
111
+ * ```js
112
+ * class MyClass {}
113
+ * const instance = new MyClass();
114
+ * const result = to_string(instance);
115
+ * // Результат: 'object MyClass'
116
+ * ```
117
+ *
118
+ * @param {any} value Переменная, значение которой необходимо привести к строке.
119
+ * @returns {string} Возвращает приведенное к строке значение переменной `value`.
120
+ */
121
+ export default function to_string(value) {
122
+ if (Array.isArray(value)) {
123
+ let string = '[';
124
+
125
+ for (const v of value) {
126
+ string += `\n ${is_string(v) ? "'" : ''}${to_string(v).replace(/\n/g, '\n ')}${is_string(v) ? "'" : ''},`;
127
+ }
128
+
129
+ return (string += string.length > 1 ? '\n]' : ']');
130
+ }
131
+
132
+ if (is_array(value)) {
133
+ let string = '{';
134
+
135
+ for (const [k, v] of Object.entries(value)) {
136
+ string += `\n ${k}: ${is_string(v) ? "'" : ''}${to_string(v).replace(/\n/g, '\n ')}${is_string(v) ? "'" : ''},`;
137
+ }
138
+
139
+ return (string += string.length > 1 ? '\n}' : '}');
140
+ }
141
+
142
+ if (is_class(value)) {
143
+ return `class ${value.name ? `${value.name} ` : ''}{}`;
144
+ }
145
+
146
+ if (is_object(value)) {
147
+ return value.toString() === '[object Object]' ?
148
+ `object ${Object.getPrototypeOf(value).constructor.name}`
149
+ : value.toString();
150
+ }
151
+
152
+ if (is_function(value)) {
153
+ return `function ${value.name}() {}`;
154
+ }
155
+
156
+ return String(value);
157
+ }