@sharpapi/sharpapi-node-detect-address 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,207 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # Address Detector API for Node.js
4
+
5
+ ## 🎯 Detect and extract addresses from text — powered by SharpAPI AI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-detect-address.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-address)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-detect-address.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI Address Detector** parses text content and extracts any physical addresses found within. Perfect for data validation, content moderation, and location extraction from unstructured text.
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-address
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 { SharpApiDetectAddressService } = require('@sharpapi/sharpapi-node-detect-address');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiDetectAddressService(apiKey);
53
+
54
+ const text = `
55
+ Please send all correspondence to our headquarters at 123 Main Street,
56
+ Suite 400, New York, NY 10001. Our European office is located at
57
+ 456 Oxford Street, London W1C 1AP, United Kingdom.
58
+ `;
59
+
60
+ async function detectAddresses() {
61
+ try {
62
+ // Submit detection job
63
+ const statusUrl = await service.detectAddress(text);
64
+ console.log('Job submitted. Status URL:', statusUrl);
65
+
66
+ // Fetch results (polls automatically until complete)
67
+ const result = await service.fetchResults(statusUrl);
68
+ console.log('Detected addresses:', result.getResultJson());
69
+ } catch (error) {
70
+ console.error('Error:', error.message);
71
+ }
72
+ }
73
+
74
+ detectAddresses();
75
+ ```
76
+
77
+ ---
78
+
79
+ ## API Documentation
80
+
81
+ ### Methods
82
+
83
+ #### `detectAddress(text: string): Promise<string>`
84
+
85
+ Detects and extracts addresses from the provided text.
86
+
87
+ **Parameters:**
88
+ - `text` (string, required): The text content to scan for addresses
89
+
90
+ **Returns:**
91
+ - Promise<string>: Status URL for polling the job result
92
+
93
+ **Example:**
94
+ ```javascript
95
+ const statusUrl = await service.detectAddress(textWithAddresses);
96
+ const result = await service.fetchResults(statusUrl);
97
+ ```
98
+
99
+ ### Response Format
100
+
101
+ The API returns detected addresses in a structured format:
102
+
103
+ ```json
104
+ {
105
+ "addresses": [
106
+ {
107
+ "address": "123 Main Street, Suite 400, New York, NY 10001",
108
+ "confidence": 0.95,
109
+ "components": {
110
+ "street": "123 Main Street",
111
+ "suite": "Suite 400",
112
+ "city": "New York",
113
+ "state": "NY",
114
+ "postal_code": "10001",
115
+ "country": "United States"
116
+ }
117
+ }
118
+ ]
119
+ }
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Examples
125
+
126
+ ### Basic Address Detection
127
+
128
+ ```javascript
129
+ const { SharpApiDetectAddressService } = require('@sharpapi/sharpapi-node-detect-address');
130
+
131
+ const service = new SharpApiDetectAddressService(process.env.SHARP_API_KEY);
132
+
133
+ const sampleText = `
134
+ Contact us at our office: 789 Tech Boulevard, San Francisco, CA 94105.
135
+ For shipping inquiries: 321 Warehouse Lane, Austin, TX 78701.
136
+ `;
137
+
138
+ service.detectAddress(sampleText)
139
+ .then(statusUrl => service.fetchResults(statusUrl))
140
+ .then(result => {
141
+ const addresses = result.getResultJson();
142
+ console.log(`Found ${addresses.length} addresses:`);
143
+ addresses.forEach((addr, index) => {
144
+ console.log(`${index + 1}. ${addr.address}`);
145
+ });
146
+ })
147
+ .catch(error => console.error('Detection failed:', error));
148
+ ```
149
+
150
+ ### Custom Polling Configuration
151
+
152
+ ```javascript
153
+ const service = new SharpApiDetectAddressService(process.env.SHARP_API_KEY);
154
+
155
+ // Customize polling behavior
156
+ service.setApiJobStatusPollingInterval(5); // Poll every 5 seconds
157
+ service.setApiJobStatusPollingWait(120); // Wait up to 2 minutes
158
+
159
+ const statusUrl = await service.detectAddress(text);
160
+ const result = await service.fetchResults(statusUrl);
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Use Cases
166
+
167
+ - **Data Validation**: Extract and validate addresses from user-submitted forms
168
+ - **Content Moderation**: Detect addresses in user-generated content where they shouldn't be
169
+ - **Location Extraction**: Parse unstructured text to extract location information
170
+ - **Document Processing**: Extract addresses from scanned documents or PDFs (after OCR)
171
+ - **Lead Generation**: Extract business addresses from web content
172
+ - **Compliance**: Identify and remove addresses from public-facing content for privacy
173
+
174
+ ---
175
+
176
+ ## API Endpoint
177
+
178
+ **POST** `/content/detect_address`
179
+
180
+ For detailed API specifications, refer to the main [SharpAPI Documentation](https://documenter.getpostman.com/view/31106842/2s9Ye8faUp).
181
+
182
+ ---
183
+
184
+ ## Related Packages
185
+
186
+ - [@sharpapi/sharpapi-node-detect-emails](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-emails) - Email detection
187
+ - [@sharpapi/sharpapi-node-detect-phones](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-phones) - Phone number detection
188
+ - [@sharpapi/sharpapi-node-detect-urls](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-urls) - URL detection
189
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
190
+
191
+ ---
192
+
193
+ ## License
194
+
195
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
196
+
197
+ ---
198
+
199
+ ## Support
200
+
201
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
202
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
203
+ - **Email**: contact@sharpapi.com
204
+
205
+ ---
206
+
207
+ **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-address",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for detecting addresses 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
+ "address 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-address.git"
39
+ }
40
+ }
@@ -0,0 +1,22 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for detecting addresses in text using SharpAPI.com
5
+ */
6
+ class SharpApiDetectAddressService extends SharpApiCoreService {
7
+ /**
8
+ * Parses the provided text for any possible addresses. Useful for processing
9
+ * and validating chunks of data against physical addresses or detecting addresses
10
+ * in places where they're not expected.
11
+ *
12
+ * @param {string} text
13
+ * @returns {Promise<string>} - The status URL.
14
+ */
15
+ async detectAddress(text) {
16
+ const data = { content: text };
17
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_DETECT_ADDRESS.url, data);
18
+ return this.parseStatusUrl(response);
19
+ }
20
+ }
21
+
22
+ module.exports = { SharpApiDetectAddressService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-detect-address/src/index.js
2
+ const { SharpApiDetectAddressService } = require('./SharpApiDetectAddressService');
3
+
4
+ module.exports = {
5
+ SharpApiDetectAddressService,
6
+ };