-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.ts
More file actions
31 lines (27 loc) · 867 Bytes
/
examples.ts
File metadata and controls
31 lines (27 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { mailbox } from './dist'
import vm from 'node:vm'
const sandbox = { mailbox, console }
vm.createContext(sandbox)
const examples = [
`mailbox('<bob@example.com>')`,
`mailbox('Bob Hope <bob@example.com>')`,
`mailbox('"Bob Hope" <bob@example.com>')`,
`mailbox('Bruce "The Boss" Springsteen <bruce@example.com>')`,
`mailbox('bob@example')`,
`mailbox('BOB@example')`,
`mailbox('bob@EXAMPLE')`,
`mailbox('a.b.c@d.e.f.g')`,
`mailbox('"site.local.test:1111"@example.com')`,
`mailbox('"hello, world"@example.com')`,
`mailbox('foo bar baz')`,
]
for (const e of examples) {
const result = vm.runInContext(e, sandbox)
// Print the result as a commented block
const commented = JSON.stringify(result, null, 2)
.split('\n')
.map((line) => `// ${line}`)
.join('\n')
console.log(commented)
console.log(`console.log(${e})\n`)
}