@postxl/utils 1.0.1 → 1.2.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.
Files changed (114) hide show
  1. package/dist/index.browser.d.ts +2 -0
  2. package/dist/index.browser.js +3 -0
  3. package/dist/index.d.ts +22 -25
  4. package/dist/index.js +36 -41
  5. package/dist/index.js.map +1 -1
  6. package/dist/zod-excel.decoders-CiKlp4ZC.js +1375 -0
  7. package/dist/zod-excel.decoders-CiKlp4ZC.js.map +1 -0
  8. package/dist/zod-excel.decoders-CtmUu_Yj.d.ts +775 -0
  9. package/package.json +25 -16
  10. package/dist/DefaultMap.d.ts +0 -12
  11. package/dist/DefaultMap.d.ts.map +0 -1
  12. package/dist/DefaultMap.js +0 -26
  13. package/dist/DefaultMap.js.map +0 -1
  14. package/dist/NestedMap.d.ts +0 -17
  15. package/dist/NestedMap.d.ts.map +0 -1
  16. package/dist/NestedMap.js +0 -72
  17. package/dist/NestedMap.js.map +0 -1
  18. package/dist/TypedMapping.d.ts +0 -27
  19. package/dist/TypedMapping.d.ts.map +0 -1
  20. package/dist/TypedMapping.js +0 -33
  21. package/dist/TypedMapping.js.map +0 -1
  22. package/dist/array.d.ts +0 -7
  23. package/dist/array.d.ts.map +0 -1
  24. package/dist/array.js +0 -21
  25. package/dist/array.js.map +0 -1
  26. package/dist/async.d.ts +0 -4
  27. package/dist/async.d.ts.map +0 -1
  28. package/dist/async.js +0 -41
  29. package/dist/async.js.map +0 -1
  30. package/dist/buffer.d.ts +0 -5
  31. package/dist/buffer.d.ts.map +0 -1
  32. package/dist/buffer.js +0 -16
  33. package/dist/buffer.js.map +0 -1
  34. package/dist/check-port.d.ts +0 -10
  35. package/dist/check-port.d.ts.map +0 -1
  36. package/dist/check-port.js +0 -40
  37. package/dist/check-port.js.map +0 -1
  38. package/dist/datetime.d.ts +0 -23
  39. package/dist/datetime.d.ts.map +0 -1
  40. package/dist/datetime.js +0 -37
  41. package/dist/datetime.js.map +0 -1
  42. package/dist/dictionary.d.ts +0 -9
  43. package/dist/dictionary.d.ts.map +0 -1
  44. package/dist/dictionary.js +0 -45
  45. package/dist/dictionary.js.map +0 -1
  46. package/dist/format.d.ts +0 -2
  47. package/dist/format.d.ts.map +0 -1
  48. package/dist/format.js +0 -7
  49. package/dist/format.js.map +0 -1
  50. package/dist/group-by.d.ts +0 -9
  51. package/dist/group-by.d.ts.map +0 -1
  52. package/dist/group-by.js +0 -66
  53. package/dist/group-by.js.map +0 -1
  54. package/dist/index.d.ts.map +0 -1
  55. package/dist/is-object.d.ts +0 -13
  56. package/dist/is-object.d.ts.map +0 -1
  57. package/dist/is-object.js +0 -25
  58. package/dist/is-object.js.map +0 -1
  59. package/dist/map.d.ts +0 -23
  60. package/dist/map.d.ts.map +0 -1
  61. package/dist/map.js +0 -76
  62. package/dist/map.js.map +0 -1
  63. package/dist/omit.d.ts +0 -5
  64. package/dist/omit.d.ts.map +0 -1
  65. package/dist/omit.js +0 -11
  66. package/dist/omit.js.map +0 -1
  67. package/dist/pagination.d.ts +0 -7
  68. package/dist/pagination.d.ts.map +0 -1
  69. package/dist/pagination.js +0 -14
  70. package/dist/pagination.js.map +0 -1
  71. package/dist/random.d.ts +0 -11
  72. package/dist/random.d.ts.map +0 -1
  73. package/dist/random.js +0 -56
  74. package/dist/random.js.map +0 -1
  75. package/dist/remove-secrets.d.ts +0 -12
  76. package/dist/remove-secrets.d.ts.map +0 -1
  77. package/dist/remove-secrets.js +0 -62
  78. package/dist/remove-secrets.js.map +0 -1
  79. package/dist/remove-undefined.d.ts +0 -10
  80. package/dist/remove-undefined.d.ts.map +0 -1
  81. package/dist/remove-undefined.js +0 -22
  82. package/dist/remove-undefined.js.map +0 -1
  83. package/dist/result.d.ts +0 -35
  84. package/dist/result.d.ts.map +0 -1
  85. package/dist/result.js +0 -120
  86. package/dist/result.js.map +0 -1
  87. package/dist/sort.d.ts +0 -18
  88. package/dist/sort.d.ts.map +0 -1
  89. package/dist/sort.js +0 -64
  90. package/dist/sort.js.map +0 -1
  91. package/dist/string-colors.d.ts +0 -45
  92. package/dist/string-colors.d.ts.map +0 -1
  93. package/dist/string-colors.js +0 -73
  94. package/dist/string-colors.js.map +0 -1
  95. package/dist/string.d.ts +0 -162
  96. package/dist/string.d.ts.map +0 -1
  97. package/dist/string.js +0 -434
  98. package/dist/string.js.map +0 -1
  99. package/dist/types.d.ts +0 -98
  100. package/dist/types.d.ts.map +0 -1
  101. package/dist/types.js +0 -57
  102. package/dist/types.js.map +0 -1
  103. package/dist/uniq.d.ts +0 -2
  104. package/dist/uniq.d.ts.map +0 -1
  105. package/dist/uniq.js +0 -16
  106. package/dist/uniq.js.map +0 -1
  107. package/dist/zod-excel.decoders.d.ts +0 -162
  108. package/dist/zod-excel.decoders.d.ts.map +0 -1
  109. package/dist/zod-excel.decoders.js +0 -361
  110. package/dist/zod-excel.decoders.js.map +0 -1
  111. package/dist/zod.d.ts +0 -30
  112. package/dist/zod.d.ts.map +0 -1
  113. package/dist/zod.js +0 -56
  114. package/dist/zod.js.map +0 -1
@@ -1,162 +0,0 @@
1
- import z from 'zod';
2
- /**
3
- * A decoder that transforms Excel strings to JS strings, also handling numbers and boolean. Will not parse any other type!
4
- *
5
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
6
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
7
- * hence accepts both strings and numbers, and converts numbers to strings.
8
- *
9
- * It'll perform casting based on the following rules:
10
- * - If the value is a number, it'll be converted to a string
11
- * - If the value is a string, it'll be returned as-is
12
- * - If the value is boolean, it'll return 'true' or 'false'
13
- *
14
- * Any other type will throw an error!
15
- */
16
- export declare const excelStringStrictDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, string, string | number | boolean>;
17
- /**
18
- * A decoder that transforms Excel strings to JS strings, also handling numbers and any other potential type
19
- *
20
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
21
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
22
- * hence accepts both strings and numbers, and converts numbers to strings.
23
- *
24
- * It'll perform casting based on the following rules:
25
- * - If the value is a number, it'll be converted to a string
26
- * - If the value is a string, it'll be returned as-is
27
- * - If the value is boolean, it'll return 'true' or 'false'
28
- * - If the value is null or undefined, it'll return an empty string
29
- * - If the value is any other type, it'll return an empty string
30
- *
31
- * Null handling: Null values/blank cells will be converted to a blank string.
32
- */
33
- export declare const excelStringDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUndefined, z.ZodAny]>, string, any>;
34
- /**
35
- * A decoder that transforms Excel strings to JS strings, also handling numbers and null
36
- *
37
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
38
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
39
- * hence accepts both strings and numbers, and converts numbers to strings.
40
- *
41
- * It'll perform casting based on the following rules:
42
- * - If the value is a number, it'll be converted to a string
43
- * - If the value is a string, it'll be returned as-is - except blank strings, which will be converted to null
44
- * - If the value is boolean, it'll return 'true' or 'false'
45
- * - If the value is null or undefined, it'll return null
46
- * - If the value is any other type, it'll return null
47
- *
48
- * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
49
- * cannot return null. As a workaround, one often returns a blank string to represent null.
50
- */
51
- export declare const excelStringNullableDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUndefined, z.ZodAny]>, string | null, any>;
52
- /**
53
- * A decoder that transforms Excel numbers to JS numbers, also handling strings and boolean. Will not parse any other type!
54
- *
55
- * It'll perform casting based on the following rules:
56
- * - If the value is a number, it'll be returned as-is
57
- * - If the value is a string, it'll try to parse it to a number. Blank strings will be converted to 0. Non-numeric strings will throw an error.
58
- * - If the value is boolean, it'll return 1 or 0
59
- * - If the value is any other type, it'll throw an error
60
- *
61
- */
62
- export declare const excelNumberStrictDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, number, string | number | boolean>;
63
- /**
64
- * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
65
- *
66
- * It'll perform casting based on the following rules:
67
- * - If the value is a number, it'll be returned as-is
68
- * - If the value is a string, it'll try to parse it to a number. Blank strings and non-numerical strings will be converted to 0.
69
- * - If the value is boolean, it'll return 1 or 0
70
- * - If the value is any other type, it'll return 0
71
- *
72
- * Null handling: Null values/blank cells will be converted to blank strings.
73
- */
74
- export declare const excelNumberDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUndefined, z.ZodAny]>, number, any>;
75
- /**
76
- * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
77
-
78
- * It'll perform casting based on the following rules:
79
- * - If the value is a number, it'll be returned as-is
80
- * - If the value is a string, it'll try to parse it to a number. Non-numerical and blank strings will be converted to null
81
- * - If the value is boolean, it'll return 1 or 0
82
- * - If the value is any other type, it'll return null
83
- *
84
- * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
85
- * cannot return null. As a workaround, one often returns a blank string to represent null.
86
- */
87
- export declare const excelNumberNullableDecoder: z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNull, z.ZodNumber, z.ZodUndefined, z.ZodAny]>, number | null, any>;
88
- /**
89
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will throw an error.
90
- *
91
- * If the number is not an integer, an error will be thrown.
92
- */
93
- export declare const excelIntStrictDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, number, string | number | boolean>, number, string | number | boolean>;
94
- /**
95
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to 0.
96
- *
97
- * If the number is not an integer, an error will be thrown.
98
- */
99
- export declare const excelIntDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUndefined, z.ZodAny]>, number, any>, number, any>;
100
- /**
101
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to null.
102
- *
103
- * If the number is not an integer, an error will be thrown.
104
- */
105
- export declare const excelIntNullableDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNull, z.ZodNumber, z.ZodUndefined, z.ZodAny]>, number | null, any>, number | null, any>;
106
- /**
107
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will throw an error.
108
- *
109
- * If the number is not a (big) integer, an error will be thrown.
110
- */
111
- export declare const excelBigIntStrictDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean]>, number, string | number | boolean>, bigint, string | number | boolean>;
112
- /**
113
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to 0.
114
- *
115
- * If the number is not a (big) integer, an error will be thrown.
116
- */
117
- export declare const excelBigIntDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull, z.ZodUndefined, z.ZodAny]>, number, any>, bigint, any>;
118
- /**
119
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to null.
120
- *
121
- * If the number is not a (big) integer, an error will be thrown.
122
- */
123
- export declare const excelBigIntNullableDecoder: z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodNull, z.ZodNumber, z.ZodUndefined, z.ZodAny]>, number | null, any>, bigint | null, any>;
124
- /**
125
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
126
- *
127
- * It'll perform casting based on the following rules:
128
- * - If the value is a number, it'll return true if it's not 0
129
- * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and throw an error otherwise
130
- * - If the value is boolean, it'll return it as-is
131
- * - If the value is any other type, it'll throw an error
132
- */
133
- export declare const excelBooleanStrictDecoder: z.ZodEffects<z.ZodUnion<[z.ZodBoolean, z.ZodNumber, z.ZodString]>, boolean, string | number | boolean>;
134
- /**
135
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
136
- *
137
- * It'll perform casting based on the following rules:
138
- * - If the value is a number, it'll return true if it's not 0
139
- * - If the value is a string, it'll return true if it's 'true' or '1', false otherwise
140
- * - If the value is boolean, it'll return it as-is
141
- * - If the value is any other type, it'll return false
142
- */
143
- export declare const excelBooleanDecoder: z.ZodEffects<z.ZodUnion<[z.ZodBoolean, z.ZodNumber, z.ZodNull, z.ZodString, z.ZodUndefined, z.ZodAny]>, boolean, any>;
144
- /**
145
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
146
- *
147
- * It'll perform casting based on the following rules:
148
- * - If the value is a number, it'll return true if it's not 0
149
- * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and null otherwise
150
- * - If the value is boolean, it'll return it as-is
151
- * - If the value is any other type, it'll return null
152
- */
153
- export declare const excelBooleanNullableDecoder: z.ZodEffects<z.ZodUnion<[z.ZodBoolean, z.ZodNumber, z.ZodNull, z.ZodString, z.ZodUndefined, z.ZodAny]>, boolean | null, any>;
154
- /**
155
- * A decoder that transforms Excel dates to JS Dates
156
- */
157
- export declare const excelDateDecoder: z.ZodEffects<z.ZodUnion<[z.ZodDate, z.ZodNumber, z.ZodString]>, Date, string | number | Date>;
158
- /**
159
- * A decoder that transforms nullable Excel dates to JS Dates
160
- */
161
- export declare const excelDateNullableDecoder: z.ZodEffects<z.ZodUnion<[z.ZodDate, z.ZodString, z.ZodNumber, z.ZodNull, z.ZodUndefined, z.ZodAny]>, Date | null, any>;
162
- //# sourceMappingURL=zod-excel.decoders.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-excel.decoders.d.ts","sourceRoot":"","sources":["../src/zod-excel.decoders.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAgCnB;;;;;;;;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EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EACtF,IAAI,GAAG,IAAI,EACX,GAAG,CAGqC,CAAA"}
@@ -1,361 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.excelDateNullableDecoder = exports.excelDateDecoder = exports.excelBooleanNullableDecoder = exports.excelBooleanDecoder = exports.excelBooleanStrictDecoder = exports.excelBigIntNullableDecoder = exports.excelBigIntDecoder = exports.excelBigIntStrictDecoder = exports.excelIntNullableDecoder = exports.excelIntDecoder = exports.excelIntStrictDecoder = exports.excelNumberNullableDecoder = exports.excelNumberDecoder = exports.excelNumberStrictDecoder = exports.excelStringNullableDecoder = exports.excelStringDecoder = exports.excelStringStrictDecoder = void 0;
7
- const zod_1 = __importDefault(require("zod"));
8
- const datetime_1 = require("./datetime");
9
- /**
10
- * Transformer that verifies that the number is an integer
11
- */
12
- const intValidator = (x, ctx) => {
13
- if (x % 1 !== 0) {
14
- ctx.addIssue({
15
- code: zod_1.default.ZodIssueCode.custom,
16
- message: `Not an integer: ${x}`,
17
- });
18
- return zod_1.default.NEVER;
19
- }
20
- return x;
21
- };
22
- /**
23
- * Converts any transformer to a nullable transformer, i.e. if the input is
24
- * null or undefined, the output will be nullable. Else the original transformer
25
- * is applied
26
- */
27
- const nullableTransformer = (transformer) => (x, ctx) => {
28
- if (x === null || x === undefined || (typeof x === 'string' && x === '')) {
29
- return null;
30
- }
31
- return transformer(x, ctx);
32
- };
33
- /**
34
- * A decoder that transforms Excel strings to JS strings, also handling numbers and boolean. Will not parse any other type!
35
- *
36
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
37
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
38
- * hence accepts both strings and numbers, and converts numbers to strings.
39
- *
40
- * It'll perform casting based on the following rules:
41
- * - If the value is a number, it'll be converted to a string
42
- * - If the value is a string, it'll be returned as-is
43
- * - If the value is boolean, it'll return 'true' or 'false'
44
- *
45
- * Any other type will throw an error!
46
- */
47
- exports.excelStringStrictDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean()]).transform((x) => {
48
- if (typeof x === 'number') {
49
- return x.toString();
50
- }
51
- if (typeof x === 'boolean') {
52
- return x ? 'true' : 'false';
53
- }
54
- return x;
55
- });
56
- /**
57
- * A decoder that transforms Excel strings to JS strings, also handling numbers and any other potential type
58
- *
59
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
60
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
61
- * hence accepts both strings and numbers, and converts numbers to strings.
62
- *
63
- * It'll perform casting based on the following rules:
64
- * - If the value is a number, it'll be converted to a string
65
- * - If the value is a string, it'll be returned as-is
66
- * - If the value is boolean, it'll return 'true' or 'false'
67
- * - If the value is null or undefined, it'll return an empty string
68
- * - If the value is any other type, it'll return an empty string
69
- *
70
- * Null handling: Null values/blank cells will be converted to a blank string.
71
- */
72
- exports.excelStringDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean(), zod_1.default.null(), zod_1.default.undefined(), zod_1.default.any()]).transform((x) => {
73
- if (x === null || x === undefined) {
74
- return '';
75
- }
76
- if (typeof x === 'number') {
77
- return x.toString();
78
- }
79
- if (typeof x === 'boolean') {
80
- return x ? 'true' : 'false';
81
- }
82
- if (typeof x === 'string') {
83
- return x;
84
- }
85
- return '';
86
- });
87
- /**
88
- * A decoder that transforms Excel strings to JS strings, also handling numbers and null
89
- *
90
- * Background: In Excel, entering a number in a cell will automatically convert it to a number -
91
- * and xlPort will return it as a number. However, often we want to treat it as a string - this decoder
92
- * hence accepts both strings and numbers, and converts numbers to strings.
93
- *
94
- * It'll perform casting based on the following rules:
95
- * - If the value is a number, it'll be converted to a string
96
- * - If the value is a string, it'll be returned as-is - except blank strings, which will be converted to null
97
- * - If the value is boolean, it'll return 'true' or 'false'
98
- * - If the value is null or undefined, it'll return null
99
- * - If the value is any other type, it'll return null
100
- *
101
- * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
102
- * cannot return null. As a workaround, one often returns a blank string to represent null.
103
- */
104
- exports.excelStringNullableDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean(), zod_1.default.null(), zod_1.default.undefined(), zod_1.default.any()]).transform((x) => {
105
- if (x === null || x === undefined) {
106
- return null;
107
- }
108
- if (typeof x === 'number') {
109
- return x.toString();
110
- }
111
- if (typeof x === 'boolean') {
112
- return x ? 'true' : 'false';
113
- }
114
- if (typeof x === 'string') {
115
- if (x === '') {
116
- return null;
117
- }
118
- return x;
119
- }
120
- return null;
121
- });
122
- const excelNumberTransformer = (x) => {
123
- if (typeof x === 'string') {
124
- if (x.trim() === '') {
125
- return null;
126
- }
127
- const parsed = parseFloat(x);
128
- if (Number.isNaN(parsed)) {
129
- return null;
130
- }
131
- return parsed;
132
- }
133
- if (typeof x === 'boolean') {
134
- return x ? 1 : 0;
135
- }
136
- if (typeof x === 'number') {
137
- return x;
138
- }
139
- return null;
140
- };
141
- /**
142
- * A decoder that transforms Excel numbers to JS numbers, also handling strings and boolean. Will not parse any other type!
143
- *
144
- * It'll perform casting based on the following rules:
145
- * - If the value is a number, it'll be returned as-is
146
- * - If the value is a string, it'll try to parse it to a number. Blank strings will be converted to 0. Non-numeric strings will throw an error.
147
- * - If the value is boolean, it'll return 1 or 0
148
- * - If the value is any other type, it'll throw an error
149
- *
150
- */
151
- exports.excelNumberStrictDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean()]).transform((x, ctx) => {
152
- const result = excelNumberTransformer(x);
153
- if (result === null) {
154
- ctx.addIssue({
155
- code: zod_1.default.ZodIssueCode.custom,
156
- message: `Not a number: ${x}`,
157
- });
158
- return zod_1.default.NEVER;
159
- }
160
- return result;
161
- });
162
- /**
163
- * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
164
- *
165
- * It'll perform casting based on the following rules:
166
- * - If the value is a number, it'll be returned as-is
167
- * - If the value is a string, it'll try to parse it to a number. Blank strings and non-numerical strings will be converted to 0.
168
- * - If the value is boolean, it'll return 1 or 0
169
- * - If the value is any other type, it'll return 0
170
- *
171
- * Null handling: Null values/blank cells will be converted to blank strings.
172
- */
173
- exports.excelNumberDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.number(), zod_1.default.boolean(), zod_1.default.null(), zod_1.default.undefined(), zod_1.default.any()]).transform((x) => {
174
- const result = excelNumberTransformer(x);
175
- if (result === null) {
176
- return 0;
177
- }
178
- return result;
179
- });
180
- /**
181
- * A decoder that transforms Excel numbers to JS numbers, also handling strings, boolean and other types.
182
-
183
- * It'll perform casting based on the following rules:
184
- * - If the value is a number, it'll be returned as-is
185
- * - If the value is a string, it'll try to parse it to a number. Non-numerical and blank strings will be converted to null
186
- * - If the value is boolean, it'll return 1 or 0
187
- * - If the value is any other type, it'll return null
188
- *
189
- * Null handling: Blank strings will be converted to null. This is to reflect that in Excel a formula
190
- * cannot return null. As a workaround, one often returns a blank string to represent null.
191
- */
192
- exports.excelNumberNullableDecoder = zod_1.default.union([zod_1.default.string(), zod_1.default.null(), zod_1.default.number(), zod_1.default.undefined(), zod_1.default.any()]).transform(excelNumberTransformer);
193
- /**
194
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will throw an error.
195
- *
196
- * If the number is not an integer, an error will be thrown.
197
- */
198
- exports.excelIntStrictDecoder = exports.excelNumberStrictDecoder.transform(intValidator);
199
- /**
200
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to 0.
201
- *
202
- * If the number is not an integer, an error will be thrown.
203
- */
204
- exports.excelIntDecoder = exports.excelNumberDecoder.transform(intValidator);
205
- /**
206
- * A decoder that transforms Excel numbers to JS integers, also handling strings and boolean. Other types will be converted to null.
207
- *
208
- * If the number is not an integer, an error will be thrown.
209
- */
210
- exports.excelIntNullableDecoder = exports.excelNumberNullableDecoder.transform(nullableTransformer(intValidator));
211
- // TODO: Add BigInt tests (to be investigated, how Excel handles BigInts)
212
- const bigIntTransformer = (x, ctx) => {
213
- if (x % 1 !== 0) {
214
- ctx.addIssue({
215
- code: zod_1.default.ZodIssueCode.custom,
216
- message: `Not an integer: ${x}`,
217
- });
218
- return zod_1.default.NEVER;
219
- }
220
- return BigInt(x);
221
- };
222
- /**
223
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will throw an error.
224
- *
225
- * If the number is not a (big) integer, an error will be thrown.
226
- */
227
- exports.excelBigIntStrictDecoder = exports.excelNumberStrictDecoder.transform(bigIntTransformer);
228
- /**
229
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to 0.
230
- *
231
- * If the number is not a (big) integer, an error will be thrown.
232
- */
233
- exports.excelBigIntDecoder = exports.excelNumberDecoder.transform(bigIntTransformer);
234
- /**
235
- * A decoder that transforms Excel numbers to JS BigInts, also handling strings and boolean. Other types will be converted to null.
236
- *
237
- * If the number is not a (big) integer, an error will be thrown.
238
- */
239
- exports.excelBigIntNullableDecoder = exports.excelNumberNullableDecoder.transform(nullableTransformer(bigIntTransformer));
240
- const excelBooleanNullableTransformer = (x) => {
241
- if (typeof x === 'number') {
242
- return x !== 0;
243
- }
244
- if (typeof x === 'string') {
245
- switch (x.toLowerCase()) {
246
- case 'true':
247
- case '1':
248
- return true;
249
- case 'false':
250
- case '0':
251
- return false;
252
- default:
253
- return null;
254
- }
255
- }
256
- if (typeof x === 'boolean') {
257
- return x;
258
- }
259
- return null;
260
- };
261
- /**
262
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
263
- *
264
- * It'll perform casting based on the following rules:
265
- * - If the value is a number, it'll return true if it's not 0
266
- * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and throw an error otherwise
267
- * - If the value is boolean, it'll return it as-is
268
- * - If the value is any other type, it'll throw an error
269
- */
270
- exports.excelBooleanStrictDecoder = zod_1.default.union([zod_1.default.boolean(), zod_1.default.number(), zod_1.default.string()]).transform((x, ctx) => {
271
- const result = excelBooleanNullableTransformer(x);
272
- if (result === null) {
273
- ctx.addIssue({
274
- code: zod_1.default.ZodIssueCode.custom,
275
- message: `Not a boolean: ${x}`,
276
- });
277
- return zod_1.default.NEVER;
278
- }
279
- return result;
280
- });
281
- /**
282
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
283
- *
284
- * It'll perform casting based on the following rules:
285
- * - If the value is a number, it'll return true if it's not 0
286
- * - If the value is a string, it'll return true if it's 'true' or '1', false otherwise
287
- * - If the value is boolean, it'll return it as-is
288
- * - If the value is any other type, it'll return false
289
- */
290
- exports.excelBooleanDecoder = zod_1.default.union([zod_1.default.boolean(), zod_1.default.number(), zod_1.default.null(), zod_1.default.string(), zod_1.default.undefined(), zod_1.default.any()]).transform((x) => {
291
- const result = excelBooleanNullableTransformer(x);
292
- if (result === null) {
293
- return false;
294
- }
295
- return result;
296
- });
297
- /**
298
- * A decoder that transforms Excel booleans to JS booleans, also handling numbers and strings.
299
- *
300
- * It'll perform casting based on the following rules:
301
- * - If the value is a number, it'll return true if it's not 0
302
- * - If the value is a string, it'll return true if it's 'true' or '1', false if it's 'false' or '0', and null otherwise
303
- * - If the value is boolean, it'll return it as-is
304
- * - If the value is any other type, it'll return null
305
- */
306
- exports.excelBooleanNullableDecoder = zod_1.default
307
- .union([zod_1.default.boolean(), zod_1.default.number(), zod_1.default.null(), zod_1.default.string(), zod_1.default.undefined(), zod_1.default.any()])
308
- .transform(excelBooleanNullableTransformer);
309
- const excelDateNullableTransformer = (x, ctx) => {
310
- if (x === null || x === undefined) {
311
- return null;
312
- }
313
- if ((0, datetime_1.isDate)(x)) {
314
- return x;
315
- }
316
- if (typeof x === 'number') {
317
- // Excel number is a float with 1 representing Jan 1, 1900. Each increment is a day.
318
- // As Excel incorrectly ignores the 1900 leap year, we need to correct for that
319
- const date = new Date(Date.UTC(1900, 0, 1));
320
- date.setUTCDate(date.getDate() + x - 2);
321
- const fractionalDay = x - Math.floor(x);
322
- date.setMilliseconds(date.getMilliseconds() + fractionalDay * 24 * 60 * 60 * 1000);
323
- return date;
324
- }
325
- if (typeof x === 'string') {
326
- if (typeof x === 'string' && x.trim() === '') {
327
- return null;
328
- }
329
- const result = new Date(x);
330
- if (Number.isNaN(result.getTime())) {
331
- ctx.addIssue({
332
- code: zod_1.default.ZodIssueCode.custom,
333
- message: `Not a date: ${x}`,
334
- });
335
- return zod_1.default.NEVER;
336
- }
337
- return result;
338
- }
339
- return null;
340
- };
341
- /**
342
- * A decoder that transforms Excel dates to JS Dates
343
- */
344
- exports.excelDateDecoder = zod_1.default.union([zod_1.default.date(), zod_1.default.number(), zod_1.default.string()]).transform((x, ctx) => {
345
- const result = excelDateNullableTransformer(x, ctx);
346
- if (result === null) {
347
- ctx.addIssue({
348
- code: zod_1.default.ZodIssueCode.custom,
349
- message: `Not a date: ${x.toString()}`,
350
- });
351
- return zod_1.default.NEVER;
352
- }
353
- return result;
354
- });
355
- /**
356
- * A decoder that transforms nullable Excel dates to JS Dates
357
- */
358
- exports.excelDateNullableDecoder = zod_1.default
359
- .union([zod_1.default.date(), zod_1.default.string(), zod_1.default.number(), zod_1.default.null(), zod_1.default.undefined(), zod_1.default.any()])
360
- .transform(excelDateNullableTransformer);
361
- //# sourceMappingURL=zod-excel.decoders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod-excel.decoders.js","sourceRoot":"","sources":["../src/zod-excel.decoders.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAmB;AAEnB,yCAAmC;AAEnC;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,GAAoB,EAAU,EAAE;IAC/D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QAChB,GAAG,CAAC,QAAQ,CAAC;YAC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,EAAE,aAAC,CAAC,YAAY,CAAC,MAAM;gBAC3B,OAAO,EAAE,eAAe,CAAC,EAAE;aAC5B,CAAC,CAAA;YACF,OAAO,aAAC,CAAC,KAAK,CAAA;QAChB,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED;;GAEG;AACU,QAAA,gBAAgB,GAIzB,aAAC,CAAC,KAAK,CAAC,CAAC,aAAC,CAAC,IAAI,EAAE,EAAE,aAAC,CAAC,MAAM,EAAE,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;IACnE,MAAM,MAAM,GAAG,4BAA4B,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IACnD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,GAAG,CAAC,QAAQ,CAAC;YACX,IAAI,EAAE,aAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,EAAE;SACvC,CAAC,CAAA;QACF,OAAO,aAAC,CAAC,KAAK,CAAA;IAChB,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAC,CAAA;AAEF;;GAEG;AACU,QAAA,wBAAwB,GAIjC,aAAC;KACF,KAAK,CAAC,CAAC,aAAC,CAAC,IAAI,EAAE,EAAE,aAAC,CAAC,MAAM,EAAE,EAAE,aAAC,CAAC,MAAM,EAAE,EAAE,aAAC,CAAC,IAAI,EAAE,EAAE,aAAC,CAAC,SAAS,EAAE,EAAE,aAAC,CAAC,GAAG,EAAE,CAAC,CAAC;KAC3E,SAAS,CAAC,4BAA4B,CAAC,CAAA"}
package/dist/zod.d.ts DELETED
@@ -1,30 +0,0 @@
1
- import { z } from 'zod';
2
- export type Transformer<Input, Output> = (value: Input, ctx: z.RefinementCtx) => Output | z.ZodNever;
3
- type ReturnTypeOfLast<T extends any[]> = T extends [...any, infer L] ? L extends (...args: any) => any ? ReturnType<L> : never : never;
4
- /**
5
- * Pipes a list of Zod transformers together in a type-safe way. Returns early if any of the transformers returns `z.NEVER`.
6
- */
7
- export declare function pipeZodTransformers<Initial, Fns extends [Transformer<any, any>, ...Transformer<any, any>[]]>(initialValue: Initial, ctx: z.RefinementCtx, fns: Fns): ReturnTypeOfLast<Fns>;
8
- /**
9
- * Returns a Zod error map that returns the given message for union errors.
10
- *
11
- * This is useful for generating meaningful error messages for unions, e.g.
12
- * ```
13
- * z.union(
14
- * [z.constant('foo'), z.constant('bar')],
15
- * unionErrorMessage('Value must be either "foo" or "bar"!')
16
- * )
17
- * ```
18
- *
19
- * In addition to a static message, you can also pass a function that takes the
20
- * invalid data as input and returns a string. Example:
21
- * ```
22
- * z.union(
23
- * [z.constant('foo'), z.constant('bar')],
24
- * unionErrorMessage((data) => `Value must be either "foo" or "bar" - received ${JSON.stringify(data)} instead!`)
25
- * )
26
- * ```
27
- */
28
- export declare function unionErrorMessage(param: string | ((data: any) => string)): z.RawCreateParams;
29
- export {};
30
- //# sourceMappingURL=zod.d.ts.map
package/dist/zod.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa,KAAK,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAA;AAEpG,KAAK,gBAAgB,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,EAAE,MAAM,CAAC,CAAC,GAChE,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,GAC7B,UAAU,CAAC,CAAC,CAAC,GACb,KAAK,GACP,KAAK,CAAA;AAET;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EAC1G,YAAY,EAAE,OAAO,EACrB,GAAG,EAAE,CAAC,CAAC,aAAa,EACpB,GAAG,EAAE,GAAG,GACP,gBAAgB,CAAC,GAAG,CAAC,CASvB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,CAgB5F"}
package/dist/zod.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipeZodTransformers = pipeZodTransformers;
4
- exports.unionErrorMessage = unionErrorMessage;
5
- const zod_1 = require("zod");
6
- /**
7
- * Pipes a list of Zod transformers together in a type-safe way. Returns early if any of the transformers returns `z.NEVER`.
8
- */
9
- function pipeZodTransformers(initialValue, ctx, fns) {
10
- let result = initialValue;
11
- for (const fn of fns) {
12
- result = fn(result, ctx);
13
- if (result === zod_1.z.NEVER) {
14
- return zod_1.z.NEVER;
15
- }
16
- }
17
- return result;
18
- }
19
- /**
20
- * Returns a Zod error map that returns the given message for union errors.
21
- *
22
- * This is useful for generating meaningful error messages for unions, e.g.
23
- * ```
24
- * z.union(
25
- * [z.constant('foo'), z.constant('bar')],
26
- * unionErrorMessage('Value must be either "foo" or "bar"!')
27
- * )
28
- * ```
29
- *
30
- * In addition to a static message, you can also pass a function that takes the
31
- * invalid data as input and returns a string. Example:
32
- * ```
33
- * z.union(
34
- * [z.constant('foo'), z.constant('bar')],
35
- * unionErrorMessage((data) => `Value must be either "foo" or "bar" - received ${JSON.stringify(data)} instead!`)
36
- * )
37
- * ```
38
- */
39
- function unionErrorMessage(param) {
40
- return {
41
- errorMap: (issue, ctx) => {
42
- let message;
43
- if (typeof param === 'string') {
44
- message = param;
45
- }
46
- else {
47
- message = param(ctx.data);
48
- }
49
- if (issue.code === zod_1.z.ZodIssueCode.invalid_union) {
50
- return { message };
51
- }
52
- return { message: ctx.defaultError };
53
- },
54
- };
55
- }
56
- //# sourceMappingURL=zod.js.map
package/dist/zod.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":";;AAaA,kDAaC;AAsBD,8CAgBC;AAhED,6BAAuB;AAUvB;;GAEG;AACH,SAAgB,mBAAmB,CACjC,YAAqB,EACrB,GAAoB,EACpB,GAAQ;IAER,IAAI,MAAM,GAAQ,YAAY,CAAA;IAC9B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QACxB,IAAI,MAAM,KAAK,OAAC,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,OAAC,CAAC,KAAK,CAAA;QAChB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,iBAAiB,CAAC,KAAuC;IACvE,OAAO;QACL,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACvB,IAAI,OAAe,CAAA;YACnB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,GAAG,KAAK,CAAA;YACjB,CAAC;iBAAM,CAAC;gBACN,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC3B,CAAC;YAED,IAAI,KAAK,CAAC,IAAI,KAAK,OAAC,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;gBAChD,OAAO,EAAE,OAAO,EAAE,CAAA;YACpB,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,CAAA;QACtC,CAAC;KACF,CAAA;AACH,CAAC"}