@clipboard-health/phone-number 0.1.0

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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @clipboard-health/phone-number <!-- omit from toc -->
2
+
3
+ Phone number utility functions.
4
+
5
+ ## Table of contents <!-- omit from toc -->
6
+
7
+ - [Install](#install)
8
+ - [Usage](#usage)
9
+ - [Local development commands](#local-development-commands)
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @clipboard-health/phone-number
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ## Local development commands
20
+
21
+ See [`package.json`](./package.json) `scripts` for a list of commands.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@clipboard-health/phone-number",
3
+ "description": "Phone number utility functions.",
4
+ "version": "0.1.0",
5
+ "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
6
+ "dependencies": {
7
+ "@clipboard-health/util-ts": "3.11.0",
8
+ "tslib": "2.8.1"
9
+ },
10
+ "devDependencies": {
11
+ "@clipboard-health/testing-core": "0.20.0",
12
+ "libphonenumber-js": "1.12.15"
13
+ },
14
+ "keywords": [],
15
+ "license": "MIT",
16
+ "main": "./src/index.js",
17
+ "peerDependencies": {
18
+ "libphonenumber-js": "^1.12"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "repository": {
24
+ "directory": "packages/phone-number",
25
+ "type": "git",
26
+ "url": "git+https://github.com/ClipboardHealth/core-utils.git"
27
+ },
28
+ "type": "commonjs",
29
+ "typings": "./src/index.d.ts",
30
+ "types": "./src/index.d.ts"
31
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/formatPhoneNumber";
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/formatPhoneNumber"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/phone-number/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
@@ -0,0 +1,5 @@
1
+ import { type ServiceResult } from "@clipboard-health/util-ts";
2
+ export declare function formatPhoneNumber(params: {
3
+ phoneNumber: string;
4
+ format: "E.164" | "humanReadable";
5
+ }): ServiceResult<string>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatPhoneNumber = formatPhoneNumber;
4
+ const util_ts_1 = require("@clipboard-health/util-ts");
5
+ const libphonenumber_js_1 = require("libphonenumber-js");
6
+ function formatPhoneNumber(params) {
7
+ const { phoneNumber, format } = params;
8
+ try {
9
+ const parsedPhoneNumber = (0, libphonenumber_js_1.parsePhoneNumberWithError)(phoneNumber.trim(), {
10
+ defaultCountry: "US",
11
+ });
12
+ return (0, util_ts_1.success)(parsedPhoneNumber.format(format === "E.164" ? "E.164" : "NATIONAL"));
13
+ }
14
+ catch {
15
+ return (0, util_ts_1.failure)({ issues: [{ message: "Invalid phone number", code: "INVALID_PHONE_NUMBER" }] });
16
+ }
17
+ }
18
+ //# sourceMappingURL=formatPhoneNumber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatPhoneNumber.js","sourceRoot":"","sources":["../../../../../packages/phone-number/src/lib/formatPhoneNumber.ts"],"names":[],"mappings":";;AAGA,8CAcC;AAjBD,uDAAiF;AACjF,yDAA8D;AAE9D,SAAgB,iBAAiB,CAAC,MAGjC;IACC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEvC,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,IAAA,6CAAyB,EAAC,WAAW,CAAC,IAAI,EAAE,EAAE;YACtE,cAAc,EAAE,IAAI;SACrB,CAAC,CAAC;QACH,OAAO,IAAA,iBAAO,EAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;IACtF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAA,iBAAO,EAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,EAAE,CAAC,CAAC;IAClG,CAAC;AACH,CAAC"}