@email-utils/validator-syntax 0.0.1-9 → 1.0.0-rc.2

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.
@@ -0,0 +1,247 @@
1
+ import { i as SyntaxOptions, t as ReasonCode } from "./result-CNbJ54oT.mjs";
2
+ //#region src/fixtures/types.d.ts
3
+ /** A preset's name: the same union as the root entry's `Preset`. */
4
+ type Preset = "practical" | "rfc5321" | "rfc5322" | "html5";
5
+ /**
6
+ * Every preset, in the order the support matrix's columns take.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { isValidSyntax } from '@email-utils/validator-syntax';
11
+ * import { presets } from '@email-utils/validator-syntax/fixtures';
12
+ *
13
+ * presets.filter((preset) => isValidSyntax('ada@localhost', { preset }));
14
+ * // => ['html5']
15
+ * ```
16
+ */
17
+ export declare const presets: readonly Preset[];
18
+ /** The `syntax.*` codes from the reason-code catalogue (meta docs/api/reason-codes.md). */
19
+ type SyntaxReasonCode = ReasonCode;
20
+ /**
21
+ * A fixture's result under one preset: the `ok`, `reason`, and `index` of
22
+ * what `parseAddress` returns, without the value or message.
23
+ */
24
+ type Expected = {
25
+ ok: true;
26
+ } | {
27
+ ok: false;
28
+ reason: SyntaxReasonCode;
29
+ index?: number;
30
+ };
31
+ /**
32
+ * The address features the support matrix has a row for. A fixture is tagged
33
+ * with one only when it's a well-formed example of that feature, so counting
34
+ * which presets accept the tagged fixtures gives the matrix.
35
+ */
36
+ type SyntaxFeature = "dot-atom" | "atext-specials" | "route-chars" | "misplaced-dots" | "long-local" | "quoted-local" | "quoted-pair" | "obs-local" | "comments" | "fws" | "obs-control" | "ipv4-literal" | "ipv6-literal" | "general-literal" | "dotless-domain" | "unknown-tld";
37
+ /**
38
+ * The support matrix's rows, in order, with each feature's label.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * import { syntaxFeatures } from '@email-utils/validator-syntax/fixtures';
43
+ *
44
+ * syntaxFeatures[0];
45
+ * // => { feature: 'dot-atom', label: 'Letters, digits, and single dots' }
46
+ * ```
47
+ */
48
+ export declare const syntaxFeatures: readonly {
49
+ feature: SyntaxFeature;
50
+ label: string;
51
+ }[];
52
+ /** An address, and what each preset makes of it. */
53
+ interface SyntaxFixture {
54
+ address: string;
55
+ description: string;
56
+ /** The result with each preset's default options. */
57
+ expected: Record<Preset, Expected>;
58
+ /** The support-matrix row this fixture is a well-formed example of. */
59
+ feature?: SyntaxFeature;
60
+ }
61
+ /** A fixture from the 0.0.1 test suite, with what 0.0.1 made of it. */
62
+ interface LegacyFixture extends SyntaxFixture {
63
+ /** What 0.0.1's `validate()` returned with its default config. */
64
+ legacy: boolean;
65
+ /**
66
+ * Why v1's default preset (`practical`) disagrees with `legacy`: the 0.0.1
67
+ * bug it was, or the v1 rule that changed. Required exactly when they
68
+ * disagree.
69
+ */
70
+ flipped?: string;
71
+ }
72
+ /** A fixture from isemail's test set. */
73
+ interface IsemailFixture extends SyntaxFixture {
74
+ /** The test's `id` in isemail's tests.xml. */
75
+ isemail: number;
76
+ }
77
+ //#endregion
78
+ //#region src/fixtures/isemail.d.ts
79
+ /**
80
+ * Dominic Sayers' is_email tests, each tagged with its `id` in tests.xml.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { isemailFixtures } from '@email-utils/validator-syntax/fixtures';
85
+ *
86
+ * isemailFixtures.find((fixture) => fixture.isemail === 5);
87
+ * // => {
88
+ * // address: 'test@io',
89
+ * // expected: { practical: { ok: false, reason: 'syntax.domain.no_dot' } },
90
+ * // }
91
+ * ```
92
+ */
93
+ export declare const isemailFixtures: readonly IsemailFixture[];
94
+ //#endregion
95
+ //#region src/fixtures/legacy.d.ts
96
+ /**
97
+ * Every address the 0.0.1 test suite checked, with what 0.0.1 returned.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import { legacyFixtures } from '@email-utils/validator-syntax/fixtures';
102
+ *
103
+ * // The addresses v1's default preset judges differently from 0.0.1.
104
+ * const flipped = legacyFixtures.filter(
105
+ * (fixture) => fixture.flipped !== undefined,
106
+ * );
107
+ * flipped.every((fixture) => fixture.legacy !== fixture.expected.practical.ok);
108
+ * // => true
109
+ * ```
110
+ */
111
+ export declare const legacyFixtures: readonly LegacyFixture[];
112
+ //#endregion
113
+ //#region src/fixtures/rfc3696.d.ts
114
+ /**
115
+ * RFC 3696's examples, as corrected by its erratum 246.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { rfc3696Fixtures } from '@email-utils/validator-syntax/fixtures';
120
+ *
121
+ * // Printed as valid, but a backslash escape needs a quoted string.
122
+ * rfc3696Fixtures
123
+ * .filter((fixture) => !fixture.expected.rfc5322.ok)
124
+ * .map((fixture) => fixture.address);
125
+ * // => [
126
+ * // 'Abc\\@def@example.com',
127
+ * // 'Fred\\ Bloggs@example.com',
128
+ * // 'Joe.\\\\Blow@example.com',
129
+ * // ]
130
+ * ```
131
+ */
132
+ export declare const rfc3696Fixtures: readonly SyntaxFixture[];
133
+ //#endregion
134
+ //#region src/fixtures/wikipedia.d.ts
135
+ /**
136
+ * The examples from Wikipedia's "Email address" article.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { wikipediaFixtures } from '@email-utils/validator-syntax/fixtures';
141
+ *
142
+ * wikipediaFixtures.find((fixture) => fixture.address === 'admin@example');
143
+ * // => {
144
+ * // expected: {
145
+ * // practical: { ok: false, reason: 'syntax.domain.no_dot' },
146
+ * // html5: { ok: true },
147
+ * // },
148
+ * // }
149
+ * ```
150
+ */
151
+ export declare const wikipediaFixtures: readonly SyntaxFixture[];
152
+ //#endregion
153
+ //#region src/fixtures/index.d.ts
154
+ /**
155
+ * Every fixture from every source, each address once.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { isValidSyntax } from '@email-utils/validator-syntax';
160
+ * import { syntaxFixtures } from '@email-utils/validator-syntax/fixtures';
161
+ *
162
+ * syntaxFixtures.every(
163
+ * ({ address, expected }) =>
164
+ * isValidSyntax(address, { preset: 'rfc5321' }) === expected.rfc5321.ok,
165
+ * ); // => true
166
+ * ```
167
+ */
168
+ export declare const syntaxFixtures: readonly SyntaxFixture[];
169
+ /** Whether a preset accepts all, some, or none of a feature's fixtures. */
170
+ export type Support = "yes" | "partial" | "no";
171
+ /** A row of {@link supportMatrix}: one feature, and each preset's support. */
172
+ export interface SupportRow {
173
+ feature: SyntaxFeature;
174
+ label: string;
175
+ /** Whether the preset accepts all, some, or none of the feature's fixtures. */
176
+ support: Record<Preset, Support>;
177
+ /** The feature's fixtures, for examples. */
178
+ fixtures: readonly SyntaxFixture[];
179
+ }
180
+ /**
181
+ * The docs' support matrix: one row per feature, one column per preset.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * import { supportMatrix } from '@email-utils/validator-syntax/fixtures';
186
+ *
187
+ * const row = supportMatrix().find(({ feature }) => feature === 'quoted-local');
188
+ * row?.support;
189
+ * // => { practical: 'no', rfc5321: 'yes', rfc5322: 'yes', html5: 'no' }
190
+ * ```
191
+ */
192
+ export declare function supportMatrix(): SupportRow[];
193
+ /** An address the configuration accepts. */
194
+ export interface ValidPreviewEntry {
195
+ address: string;
196
+ /** The fixture's description; absent for addresses you pass in. */
197
+ description?: string;
198
+ /** Whether the preset alone, without the overrides, would reject it. */
199
+ changed: boolean;
200
+ }
201
+ /** An address the configuration rejects, and the first check it fails. */
202
+ export interface InvalidPreviewEntry {
203
+ address: string;
204
+ /** The fixture's description; absent for addresses you pass in. */
205
+ description?: string;
206
+ reason: ReasonCode;
207
+ message?: string;
208
+ index?: number;
209
+ /** Whether the preset alone, without the overrides, would accept it. */
210
+ changed: boolean;
211
+ }
212
+ /** The addresses split by whether the configuration accepts them. */
213
+ export interface SyntaxPreview {
214
+ valid: ValidPreviewEntry[];
215
+ invalid: InvalidPreviewEntry[];
216
+ }
217
+ /**
218
+ * Runs `addresses` through `createSyntaxValidator(options)` and splits them
219
+ * into the ones it accepts and the ones it rejects, each list in input
220
+ * order.
221
+ *
222
+ * @remarks
223
+ * `changed` marks the addresses the overrides move: those the preset alone
224
+ * would judge the other way. With no overrides, nothing is changed.
225
+ *
226
+ * @example
227
+ * ```ts
228
+ * import { previewSyntaxOptions } from '@email-utils/validator-syntax/fixtures';
229
+ *
230
+ * const { valid } = previewSyntaxOptions({ checkTld: false });
231
+ * valid.find((entry) => entry.address === 'example@s.example');
232
+ * // => { changed: true }
233
+ * previewSyntaxOptions({ preset: 'html5' }, ['ada@localhost', 'ada@example..com']);
234
+ * // => {
235
+ * // valid: [{ address: 'ada@localhost', changed: false }],
236
+ * // invalid: [{ address: 'ada@example..com', reason: 'syntax.domain.label_invalid' }],
237
+ * // }
238
+ * ```
239
+ *
240
+ * @param addresses - The addresses to judge; `syntaxFixtures` by default.
241
+ * @throws TypeError when `options` are malformed, or `addresses` isn't an
242
+ * array of strings.
243
+ */
244
+ export declare function previewSyntaxOptions(options?: SyntaxOptions, addresses?: readonly string[]): SyntaxPreview;
245
+ //#endregion
246
+ export type { Expected, IsemailFixture, LegacyFixture, Preset, SyntaxFeature, SyntaxFixture, SyntaxReasonCode };
247
+ //# sourceMappingURL=fixtures.d.mts.map