inferred-types 0.50.18 → 0.50.20

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.
@@ -8,6 +8,7 @@ import { Email } from "src/types/index";
8
8
  * 1. that leads with alphabetic char
9
9
  * 2. has a `@` character
10
10
  * 3. has at least one `.` char after the `@`
11
+ * 4. top-level domain has at least 2 characters
11
12
  */
12
13
  export declare const isEmail: (val: unknown) => val is Email;
13
14
  //# sourceMappingURL=isEmail.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"isEmail.d.ts","sourceRoot":"","sources":["../../../src/runtime/type-guards/isEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAGvC;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,QAAS,OAAO,KAAG,GAAG,IAAI,KAa7C,CAAA"}
1
+ {"version":3,"file":"isEmail.d.ts","sourceRoot":"","sources":["../../../src/runtime/type-guards/isEmail.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAIvC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,QAAS,OAAO,KAAG,GAAG,IAAI,KAe7C,CAAA"}
@@ -1,4 +1,5 @@
1
1
  import { isString } from "src/runtime/index";
2
+ import { LOWER_ALPHA_CHARS } from "src/constants/Alpha";
2
3
  /**
3
4
  * **isEmail**`(val)`
4
5
  *
@@ -8,15 +9,18 @@ import { isString } from "src/runtime/index";
8
9
  * 1. that leads with alphabetic char
9
10
  * 2. has a `@` character
10
11
  * 3. has at least one `.` char after the `@`
12
+ * 4. top-level domain has at least 2 characters
11
13
  */
12
14
  export const isEmail = (val) => {
13
15
  if (!isString(val)) {
14
16
  return false;
15
17
  }
16
- const parts = val.split("@");
17
- const domain = parts[1].split(".");
18
- const tld = domain.pop();
19
- return isString(val) && (parts.length === 2 &&
18
+ const parts = val?.split("@");
19
+ const domain = parts[1]?.split(".");
20
+ const tld = domain ? domain.pop() : "";
21
+ const firstChar = val[0].toLowerCase();
22
+ return isString(val) && (LOWER_ALPHA_CHARS.includes(firstChar) &&
23
+ parts.length === 2 &&
20
24
  domain.length >= 1 &&
21
25
  tld.length >= 2);
22
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.50.18",
3
+ "version": "0.50.20",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",