@email-utils/validator-syntax 1.0.0-rc.1 → 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.
- package/dist/fixtures.cjs +125 -8
- package/dist/fixtures.cjs.map +1 -1
- package/dist/fixtures.d.cts +133 -7
- package/dist/fixtures.d.mts +133 -7
- package/dist/fixtures.mjs +125 -8
- package/dist/fixtures.mjs.map +1 -1
- package/dist/index.cjs +237 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -15
- package/dist/index.d.mts +24 -15
- package/dist/index.mjs +237 -68
- package/dist/index.mjs.map +1 -1
- package/dist/{result-BZjmlevS.d.cts → result-CNbJ54oT.d.cts} +17 -1
- package/dist/{result-BZjmlevS.d.mts → result-CNbJ54oT.d.mts} +17 -1
- package/package.json +7 -3
package/dist/fixtures.cjs
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let _email_utils_validator_syntax = require("./index.cjs");
|
|
3
3
|
//#region src/fixtures/types.ts
|
|
4
|
+
/**
|
|
5
|
+
* Every preset, in the order the support matrix's columns take.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { isValidSyntax } from '@email-utils/validator-syntax';
|
|
10
|
+
* import { presets } from '@email-utils/validator-syntax/fixtures';
|
|
11
|
+
*
|
|
12
|
+
* presets.filter((preset) => isValidSyntax('ada@localhost', { preset }));
|
|
13
|
+
* // => ['html5']
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
4
16
|
const presets = [
|
|
5
17
|
"practical",
|
|
6
18
|
"rfc5321",
|
|
7
19
|
"rfc5322",
|
|
8
20
|
"html5"
|
|
9
21
|
];
|
|
10
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The support matrix's rows, in order, with each feature's label.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { syntaxFeatures } from '@email-utils/validator-syntax/fixtures';
|
|
28
|
+
*
|
|
29
|
+
* syntaxFeatures[0];
|
|
30
|
+
* // => { feature: 'dot-atom', label: 'Letters, digits, and single dots' }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
11
33
|
const syntaxFeatures = [
|
|
12
34
|
{
|
|
13
35
|
feature: "dot-atom",
|
|
@@ -136,6 +158,20 @@ function quotedLocal(rfc) {
|
|
|
136
158
|
};
|
|
137
159
|
}
|
|
138
160
|
const longLabel = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl";
|
|
161
|
+
/**
|
|
162
|
+
* Dominic Sayers' is_email tests, each tagged with its `id` in tests.xml.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { isemailFixtures } from '@email-utils/validator-syntax/fixtures';
|
|
167
|
+
*
|
|
168
|
+
* isemailFixtures.find((fixture) => fixture.isemail === 5);
|
|
169
|
+
* // => {
|
|
170
|
+
* // address: 'test@io',
|
|
171
|
+
* // expected: { practical: { ok: false, reason: 'syntax.domain.no_dot' } },
|
|
172
|
+
* // }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
139
175
|
const isemailFixtures = [
|
|
140
176
|
{
|
|
141
177
|
isemail: 1,
|
|
@@ -1306,6 +1342,21 @@ function withUppercase(fixture) {
|
|
|
1306
1342
|
description: `${fixture.description}, uppercased`
|
|
1307
1343
|
}];
|
|
1308
1344
|
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Every address the 0.0.1 test suite checked, with what 0.0.1 returned.
|
|
1347
|
+
*
|
|
1348
|
+
* @example
|
|
1349
|
+
* ```ts
|
|
1350
|
+
* import { legacyFixtures } from '@email-utils/validator-syntax/fixtures';
|
|
1351
|
+
*
|
|
1352
|
+
* // The addresses v1's default preset judges differently from 0.0.1.
|
|
1353
|
+
* const flipped = legacyFixtures.filter(
|
|
1354
|
+
* (fixture) => fixture.flipped !== undefined,
|
|
1355
|
+
* );
|
|
1356
|
+
* flipped.every((fixture) => fixture.legacy !== fixture.expected.practical.ok);
|
|
1357
|
+
* // => true
|
|
1358
|
+
* ```
|
|
1359
|
+
*/
|
|
1309
1360
|
const legacyFixtures = [
|
|
1310
1361
|
...withUppercase({
|
|
1311
1362
|
address: "simple@example.com",
|
|
@@ -1781,6 +1832,24 @@ const legacyFixtures = [
|
|
|
1781
1832
|
];
|
|
1782
1833
|
//#endregion
|
|
1783
1834
|
//#region src/fixtures/rfc3696.ts
|
|
1835
|
+
/**
|
|
1836
|
+
* RFC 3696's examples, as corrected by its erratum 246.
|
|
1837
|
+
*
|
|
1838
|
+
* @example
|
|
1839
|
+
* ```ts
|
|
1840
|
+
* import { rfc3696Fixtures } from '@email-utils/validator-syntax/fixtures';
|
|
1841
|
+
*
|
|
1842
|
+
* // Printed as valid, but a backslash escape needs a quoted string.
|
|
1843
|
+
* rfc3696Fixtures
|
|
1844
|
+
* .filter((fixture) => !fixture.expected.rfc5322.ok)
|
|
1845
|
+
* .map((fixture) => fixture.address);
|
|
1846
|
+
* // => [
|
|
1847
|
+
* // 'Abc\\@def@example.com',
|
|
1848
|
+
* // 'Fred\\ Bloggs@example.com',
|
|
1849
|
+
* // 'Joe.\\\\Blow@example.com',
|
|
1850
|
+
* // ]
|
|
1851
|
+
* ```
|
|
1852
|
+
*/
|
|
1784
1853
|
const rfc3696Fixtures = [
|
|
1785
1854
|
{
|
|
1786
1855
|
address: "Abc\\@def@example.com",
|
|
@@ -1863,6 +1932,22 @@ const rfc3696Fixtures = [
|
|
|
1863
1932
|
];
|
|
1864
1933
|
//#endregion
|
|
1865
1934
|
//#region src/fixtures/wikipedia.ts
|
|
1935
|
+
/**
|
|
1936
|
+
* The examples from Wikipedia's "Email address" article.
|
|
1937
|
+
*
|
|
1938
|
+
* @example
|
|
1939
|
+
* ```ts
|
|
1940
|
+
* import { wikipediaFixtures } from '@email-utils/validator-syntax/fixtures';
|
|
1941
|
+
*
|
|
1942
|
+
* wikipediaFixtures.find((fixture) => fixture.address === 'admin@example');
|
|
1943
|
+
* // => {
|
|
1944
|
+
* // expected: {
|
|
1945
|
+
* // practical: { ok: false, reason: 'syntax.domain.no_dot' },
|
|
1946
|
+
* // html5: { ok: true },
|
|
1947
|
+
* // },
|
|
1948
|
+
* // }
|
|
1949
|
+
* ```
|
|
1950
|
+
*/
|
|
1866
1951
|
const wikipediaFixtures = [
|
|
1867
1952
|
{
|
|
1868
1953
|
address: "FirstName.LastName@EasierReading.org",
|
|
@@ -2000,8 +2085,9 @@ const wikipediaFixtures = [
|
|
|
2000
2085
|
* string, comment, or literal left open runs to the end, taking any `@`
|
|
2001
2086
|
* with it.
|
|
2002
2087
|
*
|
|
2003
|
-
* The first failure wins, checked in this order: empty input;
|
|
2004
|
-
*
|
|
2088
|
+
* The first failure wins, checked in this order: empty input; input longer
|
|
2089
|
+
* than `maxLength` (512 by default, which no fixture reaches); the split; the
|
|
2090
|
+
* local part, left to right, then its length; the domain, left to right,
|
|
2005
2091
|
* then its length; the address length; a dotless domain; the TLD. Where a
|
|
2006
2092
|
* failure has a position, `index` points at the first offending character
|
|
2007
2093
|
* in the whole address: the `(` of a disallowed or unterminated comment,
|
|
@@ -2010,14 +2096,38 @@ const wikipediaFixtures = [
|
|
|
2010
2096
|
*
|
|
2011
2097
|
* @packageDocumentation
|
|
2012
2098
|
*/
|
|
2013
|
-
/**
|
|
2099
|
+
/**
|
|
2100
|
+
* Every fixture from every source, each address once.
|
|
2101
|
+
*
|
|
2102
|
+
* @example
|
|
2103
|
+
* ```ts
|
|
2104
|
+
* import { isValidSyntax } from '@email-utils/validator-syntax';
|
|
2105
|
+
* import { syntaxFixtures } from '@email-utils/validator-syntax/fixtures';
|
|
2106
|
+
*
|
|
2107
|
+
* syntaxFixtures.every(
|
|
2108
|
+
* ({ address, expected }) =>
|
|
2109
|
+
* isValidSyntax(address, { preset: 'rfc5321' }) === expected.rfc5321.ok,
|
|
2110
|
+
* ); // => true
|
|
2111
|
+
* ```
|
|
2112
|
+
*/
|
|
2014
2113
|
const syntaxFixtures = [
|
|
2015
2114
|
...legacyFixtures,
|
|
2016
2115
|
...isemailFixtures,
|
|
2017
2116
|
...wikipediaFixtures,
|
|
2018
2117
|
...rfc3696Fixtures
|
|
2019
2118
|
];
|
|
2020
|
-
/**
|
|
2119
|
+
/**
|
|
2120
|
+
* The docs' support matrix: one row per feature, one column per preset.
|
|
2121
|
+
*
|
|
2122
|
+
* @example
|
|
2123
|
+
* ```ts
|
|
2124
|
+
* import { supportMatrix } from '@email-utils/validator-syntax/fixtures';
|
|
2125
|
+
*
|
|
2126
|
+
* const row = supportMatrix().find(({ feature }) => feature === 'quoted-local');
|
|
2127
|
+
* row?.support;
|
|
2128
|
+
* // => { practical: 'no', rfc5321: 'yes', rfc5322: 'yes', html5: 'no' }
|
|
2129
|
+
* ```
|
|
2130
|
+
*/
|
|
2021
2131
|
function supportMatrix() {
|
|
2022
2132
|
return syntaxFeatures.map(({ feature, label }) => {
|
|
2023
2133
|
const fixtures = syntaxFixtures.filter((fixture) => fixture.feature === feature);
|
|
@@ -2050,9 +2160,16 @@ function supportMatrix() {
|
|
|
2050
2160
|
*
|
|
2051
2161
|
* @example
|
|
2052
2162
|
* ```ts
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2163
|
+
* import { previewSyntaxOptions } from '@email-utils/validator-syntax/fixtures';
|
|
2164
|
+
*
|
|
2165
|
+
* const { valid } = previewSyntaxOptions({ checkTld: false });
|
|
2166
|
+
* valid.find((entry) => entry.address === 'example@s.example');
|
|
2167
|
+
* // => { changed: true }
|
|
2168
|
+
* previewSyntaxOptions({ preset: 'html5' }, ['ada@localhost', 'ada@example..com']);
|
|
2169
|
+
* // => {
|
|
2170
|
+
* // valid: [{ address: 'ada@localhost', changed: false }],
|
|
2171
|
+
* // invalid: [{ address: 'ada@example..com', reason: 'syntax.domain.label_invalid' }],
|
|
2172
|
+
* // }
|
|
2056
2173
|
* ```
|
|
2057
2174
|
*
|
|
2058
2175
|
* @param addresses - The addresses to judge; `syntaxFixtures` by default.
|