@nemigo/helpers 0.4.3 → 0.5.0

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/dist/cases.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- export type CaseResult<V, T> = (value: V | null, mutate: boolean) => T;
1
+ export type CaseResult<V, T> = (value: V | undefined, mutate: boolean) => T;
2
2
  /**
3
3
  * Отлов строковых значений
4
4
  *
5
5
  * - `string` → `string`, `false`
6
6
  * - `number` → `string`, `true`
7
- * - `NaN` → `null`, `false`
8
- * - `ETC` → `null`, `false`
7
+ * - `NaN` → `undefined`, `false`
8
+ * - `ETC` → `undefined`, `false`
9
9
  */
10
10
  export declare const caseString: <T>(value: unknown, call: CaseResult<string, T>) => T;
11
11
  /**
@@ -13,8 +13,8 @@ export declare const caseString: <T>(value: unknown, call: CaseResult<string, T>
13
13
  *
14
14
  * - `number` → `number`, `false`
15
15
  * - `string` → `number`, `true`
16
- * - `NaN` → `null`, `false`
17
- * - `ETC` → `null`, `false`
16
+ * - `NaN` → `undefined`, `false`
17
+ * - `ETC` → `undefined`, `false`
18
18
  */
19
19
  export declare const caseNumber: <T>(value: unknown, call: CaseResult<number, T>) => T;
20
20
  /**
@@ -25,6 +25,6 @@ export declare const caseNumber: <T>(value: unknown, call: CaseResult<number, T>
25
25
  * - `"true"` -> `boolean`, `true`
26
26
  * - `0` -> `boolean`, `true`
27
27
  * - `1` -> `boolean`, `true`
28
- * - `ETC` → `null`, `false`
28
+ * - `ETC` → `undefined`, `false`
29
29
  */
30
30
  export declare const caseBoolean: <T>(value: unknown, call: CaseResult<boolean, T>) => T;
package/dist/cases.js CHANGED
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * - `string` → `string`, `false`
5
5
  * - `number` → `string`, `true`
6
- * - `NaN` → `null`, `false`
7
- * - `ETC` → `null`, `false`
6
+ * - `NaN` → `undefined`, `false`
7
+ * - `ETC` → `undefined`, `false`
8
8
  */
9
9
  export const caseString = (value, call) => {
10
10
  switch (typeof value) {
@@ -14,20 +14,20 @@ export const caseString = (value, call) => {
14
14
  if (!isNaN(value))
15
15
  return call(String(value), true);
16
16
  }
17
- return call(null, false);
17
+ return call(undefined, false);
18
18
  };
19
19
  /**
20
20
  * Отлов числовых значений
21
21
  *
22
22
  * - `number` → `number`, `false`
23
23
  * - `string` → `number`, `true`
24
- * - `NaN` → `null`, `false`
25
- * - `ETC` → `null`, `false`
24
+ * - `NaN` → `undefined`, `false`
25
+ * - `ETC` → `undefined`, `false`
26
26
  */
27
27
  export const caseNumber = (value, call) => {
28
28
  switch (typeof value) {
29
29
  case "number":
30
- return call(isNaN(value) ? null : value, false);
30
+ return call(isNaN(value) ? undefined : value, false);
31
31
  case "string": {
32
32
  const trimmed = value.trim();
33
33
  const number = Number(trimmed);
@@ -35,7 +35,7 @@ export const caseNumber = (value, call) => {
35
35
  return call(number, true);
36
36
  }
37
37
  }
38
- return call(null, false);
38
+ return call(undefined, false);
39
39
  };
40
40
  /**
41
41
  * Отлов булевых значений
@@ -45,7 +45,7 @@ export const caseNumber = (value, call) => {
45
45
  * - `"true"` -> `boolean`, `true`
46
46
  * - `0` -> `boolean`, `true`
47
47
  * - `1` -> `boolean`, `true`
48
- * - `ETC` → `null`, `false`
48
+ * - `ETC` → `undefined`, `false`
49
49
  */
50
50
  export const caseBoolean = (value, call) => {
51
51
  switch (typeof value) {
@@ -65,5 +65,5 @@ export const caseBoolean = (value, call) => {
65
65
  return call(true, true);
66
66
  }
67
67
  }
68
- return call(null, false);
68
+ return call(undefined, false);
69
69
  };
@@ -29,6 +29,16 @@ export declare const abbs: string[];
29
29
  * console.log(formatted); // "09.10.2023 14:30:59"
30
30
  */
31
31
  export declare const formatDateTime: (datetime?: Date | Timestamp | string, format?: string, timezone?: number) => string;
32
+ /**
33
+ * Готовый пресет для {@link formatDateTime}
34
+ *
35
+ * `DD.DM.DY TH:TM (МСК)` с МСК-флагом
36
+ *
37
+ * @example
38
+ * const mskTime = formatMSK(Date.now());
39
+ * console.log(mskTime); // "09.10.2023 14:30 (МСК)"
40
+ */
41
+ export declare const formatMSK: (timestamp?: Timestamp, format?: string) => string;
32
42
  /**
33
43
  * Конвертирует строковые представления даты и времени в {@link Timestamp}
34
44
  *
package/dist/datetime.js CHANGED
@@ -94,6 +94,16 @@ export const formatDateTime = (datetime = Date.now(), format = "DD.DM.DY TH:TM",
94
94
  }
95
95
  return result.join("");
96
96
  };
97
+ /**
98
+ * Готовый пресет для {@link formatDateTime}
99
+ *
100
+ * `DD.DM.DY TH:TM (МСК)` с МСК-флагом
101
+ *
102
+ * @example
103
+ * const mskTime = formatMSK(Date.now());
104
+ * console.log(mskTime); // "09.10.2023 14:30 (МСК)"
105
+ */
106
+ export const formatMSK = (timestamp = Date.now(), format = "DD.DM.DY TH:TM (МСК)") => formatDateTime(timestamp, format, 3);
97
107
  //...
98
108
  /**
99
109
  * Конвертирует строковые представления даты и времени в {@link Timestamp}
package/dist/format.js CHANGED
@@ -7,7 +7,7 @@ export const FormatNumberRegExp = /\B(?=(\d{3})+(?!\d))/g;
7
7
  * @example "1 234" или "1 234,56"
8
8
  */
9
9
  export const formatNumber = (amount, { fraction = 2, fallback = "---", zero = "value", postfix } = {}) => caseNumber(amount, (v) => {
10
- if (v === null)
10
+ if (v === undefined)
11
11
  return zero === "always" ? (postfix ? "0 " + postfix : "0") : fallback;
12
12
  if (v === 0)
13
13
  return zero === "never" ? fallback : postfix ? "0 " + postfix : "0";
package/dist/xod.js CHANGED
@@ -27,7 +27,7 @@ export const nullSchema = z.union([
27
27
  }),
28
28
  ]);
29
29
  //...
30
- export const booleanSchema = z.unknown().transform((value, ctx) => caseBoolean(value, (result) => result === null
30
+ export const booleanSchema = z.unknown().transform((value, ctx) => caseBoolean(value, (result) => result === undefined
31
31
  ? invalid(value, ctx, {
32
32
  message: "It isn't a boolean",
33
33
  expected: "boolean (or string / number like boolean)",
@@ -35,7 +35,7 @@ export const booleanSchema = z.unknown().transform((value, ctx) => caseBoolean(v
35
35
  : result));
36
36
  export const booleanSchemaOptional = z.union([nullSchema, booleanSchema]);
37
37
  //...
38
- export const numberSchema = z.unknown().transform((value, ctx) => caseNumber(value, (result) => result === null
38
+ export const numberSchema = z.unknown().transform((value, ctx) => caseNumber(value, (result) => result === undefined
39
39
  ? invalid(value, ctx, {
40
40
  message: "It isn't a number",
41
41
  expected: "number (or string like number)",
@@ -44,7 +44,7 @@ export const numberSchema = z.unknown().transform((value, ctx) => caseNumber(val
44
44
  export const numberSchemaOptional = z.union([nullSchema, numberSchema]);
45
45
  //...
46
46
  export const stringSchema = z.unknown().transform((value, ctx) => caseString(value, (result) => {
47
- const trimmed = result === null ? "" : result.trim();
47
+ const trimmed = result === undefined ? "" : result.trim();
48
48
  return trimmed === ""
49
49
  ? invalid(value, ctx, {
50
50
  message: "It isn't a string or empty string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/helpers",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",