@sharpapi/sharpapi-node-detect-phones 1.0.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,253 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Phone Number Detector API for Node.js
4
+
5
+ ## 📞 Detect and extract phone numbers from text — powered by SharpAPI AI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-detect-phones.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-phones)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-detect-phones.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Phone Number Detector** parses text content and extracts phone numbers in various international formats. Perfect for lead generation, data extraction, and contact management.
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ 1. [Requirements](#requirements)
17
+ 2. [Installation](#installation)
18
+ 3. [Usage](#usage)
19
+ 4. [API Documentation](#api-documentation)
20
+ 5. [Examples](#examples)
21
+ 6. [License](#license)
22
+
23
+ ---
24
+
25
+ ## Requirements
26
+
27
+ - Node.js >= 16.x
28
+ - npm or yarn
29
+
30
+ ---
31
+
32
+ ## Installation
33
+
34
+ ### Step 1. Install the package via npm:
35
+
36
+ ```bash
37
+ npm install @sharpapi/sharpapi-node-detect-phones
38
+ ```
39
+
40
+ ### Step 2. Get your API key
41
+
42
+ Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ ```javascript
49
+ const { SharpApiDetectPhonesService } = require('@sharpapi/sharpapi-node-detect-phones');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiDetectPhonesService(apiKey);
53
+
54
+ const text = `
55
+ For customer support, call us at +1-555-123-4567 or toll-free at 1-800-EXAMPLE.
56
+ Our international office can be reached at +44 20 1234 5678.
57
+ `;
58
+
59
+ async function detectPhones() {
60
+ try {
61
+ // Submit detection job
62
+ const statusUrl = await service.detectPhones(text);
63
+ console.log('Job submitted. Status URL:', statusUrl);
64
+
65
+ // Fetch results (polls automatically until complete)
66
+ const result = await service.fetchResults(statusUrl);
67
+ console.log('Detected phones:', result.getResultJson());
68
+ } catch (error) {
69
+ console.error('Error:', error.message);
70
+ }
71
+ }
72
+
73
+ detectPhones();
74
+ ```
75
+
76
+ ---
77
+
78
+ ## API Documentation
79
+
80
+ ### Methods
81
+
82
+ #### `detectPhones(text: string): Promise<string>`
83
+
84
+ Detects and extracts phone numbers from the provided text.
85
+
86
+ **Parameters:**
87
+ - `text` (string, required): The text content to scan for phone numbers
88
+
89
+ **Returns:**
90
+ - Promise<string>: Status URL for polling the job result
91
+
92
+ **Example:**
93
+ ```javascript
94
+ const statusUrl = await service.detectPhones(textWithPhones);
95
+ const result = await service.fetchResults(statusUrl);
96
+ ```
97
+
98
+ ### Response Format
99
+
100
+ The API returns detected phone numbers with parsed components:
101
+
102
+ ```json
103
+ {
104
+ "phone_numbers": [
105
+ {
106
+ "detected_number": "+1-555-123-4567",
107
+ "parsed_number": "+15551234567",
108
+ "country_code": "+1",
109
+ "national_number": "5551234567",
110
+ "country": "United States",
111
+ "format": "international",
112
+ "is_valid": true,
113
+ "type": "mobile"
114
+ },
115
+ {
116
+ "detected_number": "+44 20 1234 5678",
117
+ "parsed_number": "+442012345678",
118
+ "country_code": "+44",
119
+ "national_number": "2012345678",
120
+ "country": "United Kingdom",
121
+ "format": "international",
122
+ "is_valid": true,
123
+ "type": "landline"
124
+ }
125
+ ]
126
+ }
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Examples
132
+
133
+ ### Basic Phone Detection
134
+
135
+ ```javascript
136
+ const { SharpApiDetectPhonesService } = require('@sharpapi/sharpapi-node-detect-phones');
137
+
138
+ const service = new SharpApiDetectPhonesService(process.env.SHARP_API_KEY);
139
+
140
+ const businessCard = `
141
+ John Doe
142
+ Senior Manager
143
+ Mobile: (555) 123-4567
144
+ Office: +1 (555) 987-6543
145
+ `;
146
+
147
+ service.detectPhones(businessCard)
148
+ .then(statusUrl => service.fetchResults(statusUrl))
149
+ .then(result => {
150
+ const phones = result.getResultJson();
151
+ console.log(`Found ${phones.length} phone numbers:`);
152
+ phones.forEach((phone, index) => {
153
+ console.log(`${index + 1}. ${phone.detected_number} (${phone.type})`);
154
+ });
155
+ })
156
+ .catch(error => console.error('Detection failed:', error));
157
+ ```
158
+
159
+ ### International Phone Number Extraction
160
+
161
+ ```javascript
162
+ const service = new SharpApiDetectPhonesService(process.env.SHARP_API_KEY);
163
+
164
+ const globalContacts = `
165
+ US Office: +1 (212) 555-0100
166
+ UK Office: +44 20 7946 0958
167
+ Australia: +61 2 9876 5432
168
+ Germany: +49 30 1234567
169
+ `;
170
+
171
+ const statusUrl = await service.detectPhones(globalContacts);
172
+ const result = await service.fetchResults(statusUrl);
173
+ const phones = result.getResultJson();
174
+
175
+ phones.forEach(phone => {
176
+ console.log(`${phone.country}: ${phone.parsed_number}`);
177
+ });
178
+ ```
179
+
180
+ ### Custom Polling Configuration
181
+
182
+ ```javascript
183
+ const service = new SharpApiDetectPhonesService(process.env.SHARP_API_KEY);
184
+
185
+ // Customize polling behavior
186
+ service.setApiJobStatusPollingInterval(5); // Poll every 5 seconds
187
+ service.setApiJobStatusPollingWait(120); // Wait up to 2 minutes
188
+
189
+ const statusUrl = await service.detectPhones(text);
190
+ const result = await service.fetchResults(statusUrl);
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Use Cases
196
+
197
+ - **Lead Generation**: Extract phone numbers from websites, PDFs, and documents
198
+ - **Contact Management**: Build databases from unstructured data
199
+ - **Data Validation**: Verify phone number formats and validity
200
+ - **CRM Integration**: Automatically populate contact information
201
+ - **Marketing**: Extract phone numbers for outreach campaigns
202
+ - **Document Processing**: Parse phone numbers from scanned documents
203
+ - **Customer Support**: Extract callback numbers from support tickets
204
+
205
+ ---
206
+
207
+ ## Supported Formats
208
+
209
+ The detector recognizes various phone number formats:
210
+
211
+ - **International**: +1 (555) 123-4567, +44 20 1234 5678
212
+ - **National**: (555) 123-4567, 555-123-4567
213
+ - **Toll-free**: 1-800-EXAMPLE, 1-888-CALL-NOW
214
+ - **Extensions**: +1 (555) 123-4567 ext. 123
215
+ - **Mobile**: Various international mobile formats
216
+ - **Landline**: Fixed-line number formats
217
+
218
+ ---
219
+
220
+ ## API Endpoint
221
+
222
+ **POST** `/content/detect_phones`
223
+
224
+ For detailed API specifications, refer to:
225
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVd)
226
+ - [Product Page](https://sharpapi.com/en/catalog/ai/content-marketing-automation/phone-numbers-detector)
227
+
228
+ ---
229
+
230
+ ## Related Packages
231
+
232
+ - [@sharpapi/sharpapi-node-detect-emails](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-emails) - Email detection
233
+ - [@sharpapi/sharpapi-node-detect-urls](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-urls) - URL detection
234
+ - [@sharpapi/sharpapi-node-detect-address](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-address) - Address detection
235
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
236
+
237
+ ---
238
+
239
+ ## License
240
+
241
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
242
+
243
+ ---
244
+
245
+ ## Support
246
+
247
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
248
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
249
+ - **Email**: contact@sharpapi.com
250
+
251
+ ---
252
+
253
+ **Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sharpapi/sharpapi-node-detect-phones",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for detecting phone numbers in text",
5
+ "main": "src/index.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "keywords": [
10
+ "sharpapi",
11
+ "ai-powered",
12
+ "ai capabilities",
13
+ "api",
14
+ "ai api",
15
+ "api integration",
16
+ "artificial intelligence",
17
+ "natural language processing",
18
+ "restful api",
19
+ "nodejs",
20
+ "software development",
21
+ "content analysis",
22
+ "phone detection",
23
+ "text processing"
24
+ ],
25
+ "author": "Dawid Makowski <contact@sharpapi.com>",
26
+ "license": "MIT",
27
+ "dependencies": {
28
+ "@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
29
+ },
30
+ "devDependencies": {
31
+ "jest": "^29.7.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/sharpapi/sharpapi-node-detect-phones.git"
39
+ }
40
+ }
@@ -0,0 +1,22 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for detecting phone numbers in text using SharpAPI.com
5
+ */
6
+ class SharpApiDetectPhonesService extends SharpApiCoreService {
7
+ /**
8
+ * Parses the provided text for any phone numbers and returns the original detected version and its E.164 format.
9
+ * Might come in handy in the case of processing and validating big chunks of data against phone numbers
10
+ * or f.e. if you want to detect phone numbers in places where they're not supposed to be.
11
+ *
12
+ * @param {string} text
13
+ * @returns {Promise<string>} - The status URL.
14
+ */
15
+ async detectPhones(text) {
16
+ const data = { content: text };
17
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_DETECT_PHONES.url, data);
18
+ return this.parseStatusUrl(response);
19
+ }
20
+ }
21
+
22
+ module.exports = { SharpApiDetectPhonesService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-detect-phones/src/index.js
2
+ const { SharpApiDetectPhonesService } = require('./SharpApiDetectPhonesService');
3
+
4
+ module.exports = {
5
+ SharpApiDetectPhonesService,
6
+ };