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 CHANGED
@@ -9,3 +9,4 @@ export * from './parser';
9
9
  export * from './regex';
10
10
  export * from './secrets';
11
11
  export * from './task';
12
+ export * from './validator';
package/dist/index.js CHANGED
@@ -25,3 +25,4 @@ __exportStar(require("./parser"), exports);
25
25
  __exportStar(require("./regex"), exports);
26
26
  __exportStar(require("./secrets"), exports);
27
27
  __exportStar(require("./task"), exports);
28
+ __exportStar(require("./validator"), exports);
@@ -0,0 +1,3 @@
1
+ /** Basic email validation — good enough for most production use cases */
2
+ declare const isValidEmail: (email: string) => boolean;
3
+ export { isValidEmail };
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticedge-cloud-utils",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Common utilities for cloud functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -9,3 +9,4 @@ export * from './parser'
9
9
  export * from './regex'
10
10
  export * from './secrets'
11
11
  export * from './task'
12
+ export * from './validator'
@@ -0,0 +1,4 @@
1
+ /** Basic email validation — good enough for most production use cases */
2
+ const isValidEmail = (email: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.trim())
3
+
4
+ export { isValidEmail }
@@ -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
+ })