opticedge-cloud-utils 1.1.4 → 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
@@ -5,6 +5,8 @@ export * from './tw/utils';
5
5
  export * from './tw/wallet';
6
6
  export * from './auth';
7
7
  export * from './env';
8
+ export * from './parser';
8
9
  export * from './regex';
9
10
  export * from './secrets';
10
11
  export * from './task';
12
+ export * from './validator';
package/dist/index.js CHANGED
@@ -21,6 +21,8 @@ __exportStar(require("./tw/utils"), exports);
21
21
  __exportStar(require("./tw/wallet"), exports);
22
22
  __exportStar(require("./auth"), exports);
23
23
  __exportStar(require("./env"), exports);
24
+ __exportStar(require("./parser"), exports);
24
25
  __exportStar(require("./regex"), exports);
25
26
  __exportStar(require("./secrets"), exports);
26
27
  __exportStar(require("./task"), exports);
28
+ __exportStar(require("./validator"), exports);
@@ -0,0 +1,2 @@
1
+ declare const toNumber: (v: any) => number | null;
2
+ export { toNumber };
package/dist/parser.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNumber = void 0;
4
+ // Helper: accept number or numeric-string, return number or null
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ const toNumber = (v) => {
7
+ if (typeof v === 'number' && Number.isFinite(v))
8
+ return v;
9
+ if (typeof v === 'string' && /^\d+$/.test(v))
10
+ return Number(v);
11
+ return null;
12
+ };
13
+ exports.toNumber = toNumber;
@@ -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.4",
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
@@ -5,6 +5,8 @@ export * from './tw/utils'
5
5
  export * from './tw/wallet'
6
6
  export * from './auth'
7
7
  export * from './env'
8
+ export * from './parser'
8
9
  export * from './regex'
9
10
  export * from './secrets'
10
11
  export * from './task'
12
+ export * from './validator'
package/src/parser.ts ADDED
@@ -0,0 +1,9 @@
1
+ // Helper: accept number or numeric-string, return number or null
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ const toNumber = (v: any): number | null => {
4
+ if (typeof v === 'number' && Number.isFinite(v)) return v
5
+ if (typeof v === 'string' && /^\d+$/.test(v)) return Number(v)
6
+ return null
7
+ }
8
+
9
+ export { toNumber }
@@ -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,26 @@
1
+ import { toNumber } from '../src'
2
+
3
+ describe('toNumber', () => {
4
+ it('returns the same number when input is a finite number', () => {
5
+ expect(toNumber(123)).toBe(123)
6
+ expect(toNumber(0)).toBe(0)
7
+ })
8
+
9
+ it('returns number when input is a numeric string', () => {
10
+ expect(toNumber('456')).toBe(456)
11
+ })
12
+
13
+ it('returns null for non-numeric strings', () => {
14
+ expect(toNumber('abc')).toBeNull()
15
+ expect(toNumber('123abc')).toBeNull()
16
+ expect(toNumber('')).toBeNull()
17
+ })
18
+
19
+ it('returns null for non-numbers', () => {
20
+ expect(toNumber(NaN)).toBeNull()
21
+ expect(toNumber(Infinity)).toBeNull()
22
+ expect(toNumber(undefined)).toBeNull()
23
+ expect(toNumber(null)).toBeNull()
24
+ expect(toNumber({})).toBeNull()
25
+ })
26
+ })
@@ -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
+ })