@sprucelabs/schema 30.0.18 → 30.0.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.
@@ -26,11 +26,11 @@ function formatNumberWithCode(phoneNumberString, code = '1') {
26
26
  }
27
27
  export function isValidNumber(number) {
28
28
  var _a;
29
- const code = getCode(number);
29
+ const { code } = stripCode(number);
30
30
  const formatted = (_a = formatNumberWithCode(number, code)) === null || _a === void 0 ? void 0 : _a.replace(/[^0-9]/g, '');
31
31
  return (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 11 || (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 12;
32
32
  }
33
- function getCode(number) {
33
+ function stripCode(number) {
34
34
  let code = `1`; // Default to North American country code
35
35
  const cleaned = number.replace(/(?!^\+)[^\d]/g, '');
36
36
  // Explicitly check for '+' sign to distinguish international codes
@@ -46,11 +46,11 @@ function getCode(number) {
46
46
  else if (cleaned.startsWith('905') && cleaned.length === 10) {
47
47
  code = `1`;
48
48
  }
49
- return code;
49
+ return { code, phoneWithoutCode: cleaned.replace('+' + code, '') };
50
50
  }
51
51
  export default function formatPhoneNumber(val, shouldFailSilently = true) {
52
- const code = getCode(val);
53
- const formatted = formatNumberWithCode(val, code);
52
+ const { code, phoneWithoutCode } = stripCode(val);
53
+ const formatted = formatNumberWithCode(phoneWithoutCode, code);
54
54
  if (!formatted) {
55
55
  if (!shouldFailSilently) {
56
56
  throw new Error('INVALID_PHONE_NUMBER');
@@ -29,12 +29,12 @@ function formatNumberWithCode(phoneNumberString, code = '1') {
29
29
  }
30
30
  function isValidNumber(number) {
31
31
  var _a;
32
- const code = getCode(number);
32
+ const { code } = stripCode(number);
33
33
  const formatted = (_a = formatNumberWithCode(number, code)) === null || _a === void 0 ? void 0 : _a.replace(/[^0-9]/g, '');
34
34
  return (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 11 || (formatted === null || formatted === void 0 ? void 0 : formatted.length) === 12;
35
35
  }
36
36
  exports.isValidNumber = isValidNumber;
37
- function getCode(number) {
37
+ function stripCode(number) {
38
38
  let code = `1`; // Default to North American country code
39
39
  const cleaned = number.replace(/(?!^\+)[^\d]/g, '');
40
40
  // Explicitly check for '+' sign to distinguish international codes
@@ -50,11 +50,11 @@ function getCode(number) {
50
50
  else if (cleaned.startsWith('905') && cleaned.length === 10) {
51
51
  code = `1`;
52
52
  }
53
- return code;
53
+ return { code, phoneWithoutCode: cleaned.replace('+' + code, '') };
54
54
  }
55
55
  function formatPhoneNumber(val, shouldFailSilently = true) {
56
- const code = getCode(val);
57
- const formatted = formatNumberWithCode(val, code);
56
+ const { code, phoneWithoutCode } = stripCode(val);
57
+ const formatted = formatNumberWithCode(phoneWithoutCode, code);
58
58
  if (!formatted) {
59
59
  if (!shouldFailSilently) {
60
60
  throw new Error('INVALID_PHONE_NUMBER');
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "30.0.18",
11
+ "version": "30.0.20",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",