opticedge-cloud-utils 1.1.5 → 1.1.6
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/validator.d.ts +3 -0
- package/dist/validator.js +6 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/validator.ts +4 -0
- package/tests/validator.ts +37 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidEmail = void 0;
|
|
4
|
+
/** Basic email validation — good enough for most production use cases */
|
|
5
|
+
const isValidEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim());
|
|
6
|
+
exports.isValidEmail = isValidEmail;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/validator.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// isValidEmail.test.ts
|
|
2
|
+
import { describe, it, expect } from '@jest/globals'
|
|
3
|
+
import { isValidEmail } from '../src'
|
|
4
|
+
|
|
5
|
+
describe('isValidEmail', () => {
|
|
6
|
+
it('returns true for simple valid emails', () => {
|
|
7
|
+
expect(isValidEmail('test@example.com')).toBe(true)
|
|
8
|
+
expect(isValidEmail('user.name@domain.co')).toBe(true)
|
|
9
|
+
expect(isValidEmail('user_name+tag@sub.domain.org')).toBe(true)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('returns false for missing parts', () => {
|
|
13
|
+
expect(isValidEmail('')).toBe(false)
|
|
14
|
+
expect(isValidEmail('plainaddress')).toBe(false)
|
|
15
|
+
expect(isValidEmail('@no-local-part.com')).toBe(false)
|
|
16
|
+
expect(isValidEmail('username@')).toBe(false)
|
|
17
|
+
expect(isValidEmail('user@domain')).toBe(false)
|
|
18
|
+
expect(isValidEmail('username@.com')).toBe(false)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('handles whitespace correctly', () => {
|
|
22
|
+
expect(isValidEmail(' test@example.com ')).toBe(true) // trims input
|
|
23
|
+
expect(isValidEmail('\nuser@domain.com\t')).toBe(true)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('rejects invalid characters or formats', () => {
|
|
27
|
+
expect(isValidEmail('user@@domain.com')).toBe(false)
|
|
28
|
+
expect(isValidEmail('user@domain,com')).toBe(false)
|
|
29
|
+
expect(isValidEmail('user@domain..com')).toBe(false)
|
|
30
|
+
expect(isValidEmail('user@.domain.com')).toBe(false)
|
|
31
|
+
expect(isValidEmail('user@domain com')).toBe(false)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('accepts minimal valid domain structures', () => {
|
|
35
|
+
expect(isValidEmail('x@y.z')).toBe(true) // still valid
|
|
36
|
+
})
|
|
37
|
+
})
|