-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create emailregex in components-core instead of using a dedicated pac…
…kage (#895)
- Loading branch information
Showing
5 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@livekit/components-core": patch | ||
--- | ||
|
||
Create emailregex in components-core instead of using a dedicated package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { describe, test } from 'vitest'; | ||
import { createEmailRegExp } from './emailRegex'; | ||
|
||
const fixtures = [ | ||
'[email protected]', | ||
'foo@bar', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'[email protected]', | ||
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklm@livekit.io', | ||
'!#$%&`*+/=?^`{|}[email protected]', | ||
'[email protected]', | ||
'a@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghikl.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefg.hij', | ||
'[email protected]', | ||
'"\\a"@livekit.io', | ||
'""@livekit.io', | ||
'"test"@livekit.io', | ||
'"\\""@livekit.io', | ||
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghiklmn@livekit.io', | ||
'[email protected]', | ||
'a@a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v', | ||
'[email protected]', | ||
'[email protected]', | ||
'foo@[IPv6:2001:db8::2]', | ||
]; | ||
|
||
const fixturesNot = [ | ||
'@', | ||
'@io', | ||
'@livekit.io', | ||
'test..livekit.io', | ||
'[email protected]', | ||
'[email protected].', | ||
'[email protected]', | ||
'livekit@[email protected]', | ||
'mailto:[email protected]', | ||
'foo.example.com', | ||
'[email protected]', | ||
]; | ||
|
||
describe('Email regex tests', () => { | ||
test('extract', (t) => { | ||
for (const fixture of fixtures) { | ||
t.expect((createEmailRegExp().exec(`foo ${fixture} bar`) || [])[0]).toBe(fixture); | ||
} | ||
|
||
t.expect(createEmailRegExp().exec('mailto:[email protected]')?.[0]).toBe('[email protected]'); | ||
}); | ||
|
||
test('exact', (t) => { | ||
for (const fixture of fixtures) { | ||
t.expect(createEmailRegExp({ exact: true }).test(fixture)).toBeTruthy(); | ||
} | ||
}); | ||
|
||
test('failures', (t) => { | ||
for (const fixture of fixturesNot) { | ||
t.expect(createEmailRegExp({ exact: true }).test(fixture)).toBeFalsy(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import createEmailRegExp from 'email-regex'; | ||
// source code adapted from https://github.com/sindresorhus/email-regex due to ESM import incompatibilities when trying to serve a CJS version of components | ||
|
||
const regex = '[^\\.\\s@:](?:[^\\s@:]*[^\\s@:\\.])?@[^\\.\\s@]+(?:\\.[^\\.\\s@]+)*'; | ||
|
||
function createEmailRegExp({ exact }: { exact?: boolean } = {}) { | ||
return exact ? new RegExp(`^${regex}$`) : new RegExp(regex, 'g'); | ||
} | ||
export { createEmailRegExp }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.