@unchainedshop/utils 4.8.16 → 4.8.18

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.
@@ -0,0 +1,5 @@
1
+ export declare const normalizePhoneNumber: (value?: string | null, defaultCountry?: string | null) => string | undefined;
2
+ export declare const phoneNumberToParts: (value?: string | null, defaultCountry?: string | null) => {
3
+ cc: string;
4
+ subscriber: string;
5
+ } | undefined;
@@ -0,0 +1,17 @@
1
+ import { parsePhoneNumberFromString } from 'libphonenumber-js';
2
+ export const normalizePhoneNumber = (value, defaultCountry) => {
3
+ if (!value)
4
+ return undefined;
5
+ const parsed = parsePhoneNumberFromString(value, (defaultCountry || undefined));
6
+ if (!parsed?.isValid())
7
+ return undefined;
8
+ return parsed.number;
9
+ };
10
+ export const phoneNumberToParts = (value, defaultCountry) => {
11
+ if (!value)
12
+ return undefined;
13
+ const parsed = parsePhoneNumberFromString(value, (defaultCountry || undefined));
14
+ if (!parsed?.isValid())
15
+ return undefined;
16
+ return { cc: parsed.countryCallingCode, subscriber: parsed.nationalNumber };
17
+ };
@@ -9,6 +9,7 @@ export { default as buildObfuscatedFieldsFilter } from './build-obfuscated-field
9
9
  export { default as sha256 } from './sha256.ts';
10
10
  export { default as sha1 } from './sha1.ts';
11
11
  export { timingSafeEqual, timingSafeStringEqual } from './timing-safe-equal.ts';
12
+ export { normalizePhoneNumber, phoneNumberToParts } from './phone-number.ts';
12
13
  export declare const SortDirection: {
13
14
  readonly ASC: "ASC";
14
15
  readonly DESC: "DESC";
@@ -9,6 +9,7 @@ export { default as buildObfuscatedFieldsFilter } from "./build-obfuscated-field
9
9
  export { default as sha256 } from "./sha256.js";
10
10
  export { default as sha1 } from "./sha1.js";
11
11
  export { timingSafeEqual, timingSafeStringEqual } from "./timing-safe-equal.js";
12
+ export { normalizePhoneNumber, phoneNumberToParts } from "./phone-number.js";
12
13
  export const SortDirection = {
13
14
  ASC: 'ASC',
14
15
  DESC: 'DESC',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/utils",
3
3
  "description": "Common utility functions and base classes for the Unchained Engine",
4
- "version": "4.8.16",
4
+ "version": "4.8.18",
5
5
  "main": "lib/utils-index.js",
6
6
  "types": "lib/utils-index.d.ts",
7
7
  "type": "module",
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "@unchainedshop/logger": "^4.8.12",
33
33
  "hashids": "^2.3.0",
34
+ "libphonenumber-js": "^1.11.0",
34
35
  "resolve-accept-language": "^3.1.11"
35
36
  },
36
37
  "devDependencies": {