@sharpapi/sharpapi-node-detect-emails 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 +208 -0
- package/package.json +40 -0
- package/src/SharpApiDetectEmailsService.js +22 -0
- package/src/index.js +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Email Detector API for Node.js
|
|
4
|
+
|
|
5
|
+
## 🎯 Detect and extract email addresses from text — powered by SharpAPI AI.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-emails)
|
|
8
|
+
[](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
|
|
9
|
+
|
|
10
|
+
**SharpAPI Email Detector** parses text content and extracts any email addresses found within. Perfect for data validation, content moderation, and lead 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-emails
|
|
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 { SharpApiDetectEmailsService } = require('@sharpapi/sharpapi-node-detect-emails');
|
|
50
|
+
|
|
51
|
+
const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
|
|
52
|
+
const service = new SharpApiDetectEmailsService(apiKey);
|
|
53
|
+
|
|
54
|
+
const text = `
|
|
55
|
+
For support inquiries, please contact support@example.com or sales@example.com.
|
|
56
|
+
You can also reach our CEO at john.doe@company.org for partnership opportunities.
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
async function detectEmails() {
|
|
60
|
+
try {
|
|
61
|
+
// Submit detection job
|
|
62
|
+
const statusUrl = await service.detectEmails(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 emails:', result.getResultJson());
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Error:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
detectEmails();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## API Documentation
|
|
79
|
+
|
|
80
|
+
### Methods
|
|
81
|
+
|
|
82
|
+
#### `detectEmails(text: string): Promise<string>`
|
|
83
|
+
|
|
84
|
+
Detects and extracts email addresses from the provided text.
|
|
85
|
+
|
|
86
|
+
**Parameters:**
|
|
87
|
+
- `text` (string, required): The text content to scan for email addresses
|
|
88
|
+
|
|
89
|
+
**Returns:**
|
|
90
|
+
- Promise<string>: Status URL for polling the job result
|
|
91
|
+
|
|
92
|
+
**Example:**
|
|
93
|
+
```javascript
|
|
94
|
+
const statusUrl = await service.detectEmails(textWithEmails);
|
|
95
|
+
const result = await service.fetchResults(statusUrl);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Response Format
|
|
99
|
+
|
|
100
|
+
The API returns detected emails in a structured format:
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"emails": [
|
|
105
|
+
{
|
|
106
|
+
"email": "support@example.com",
|
|
107
|
+
"confidence": 1.0,
|
|
108
|
+
"domain": "example.com",
|
|
109
|
+
"username": "support"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"email": "john.doe@company.org",
|
|
113
|
+
"confidence": 1.0,
|
|
114
|
+
"domain": "company.org",
|
|
115
|
+
"username": "john.doe"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Examples
|
|
124
|
+
|
|
125
|
+
### Basic Email Detection
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
const { SharpApiDetectEmailsService } = require('@sharpapi/sharpapi-node-detect-emails');
|
|
129
|
+
|
|
130
|
+
const service = new SharpApiDetectEmailsService(process.env.SHARP_API_KEY);
|
|
131
|
+
|
|
132
|
+
const sampleText = `
|
|
133
|
+
Contact our team at hello@startup.io or reach out to
|
|
134
|
+
the marketing department at marketing@startup.io.
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
service.detectEmails(sampleText)
|
|
138
|
+
.then(statusUrl => service.fetchResults(statusUrl))
|
|
139
|
+
.then(result => {
|
|
140
|
+
const emails = result.getResultJson();
|
|
141
|
+
console.log(`Found ${emails.length} email addresses:`);
|
|
142
|
+
emails.forEach((email, index) => {
|
|
143
|
+
console.log(`${index + 1}. ${email.email}`);
|
|
144
|
+
});
|
|
145
|
+
})
|
|
146
|
+
.catch(error => console.error('Detection failed:', error));
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Custom Polling Configuration
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
const service = new SharpApiDetectEmailsService(process.env.SHARP_API_KEY);
|
|
153
|
+
|
|
154
|
+
// Customize polling behavior
|
|
155
|
+
service.setApiJobStatusPollingInterval(5); // Poll every 5 seconds
|
|
156
|
+
service.setApiJobStatusPollingWait(120); // Wait up to 2 minutes
|
|
157
|
+
|
|
158
|
+
const statusUrl = await service.detectEmails(text);
|
|
159
|
+
const result = await service.fetchResults(statusUrl);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Use Cases
|
|
165
|
+
|
|
166
|
+
- **Lead Generation**: Extract email addresses from web pages, documents, or social media
|
|
167
|
+
- **Data Validation**: Verify and extract emails from user-submitted forms
|
|
168
|
+
- **Content Moderation**: Detect email addresses in user-generated content
|
|
169
|
+
- **Email Harvesting**: Collect contact information from business cards or documents
|
|
170
|
+
- **Spam Detection**: Identify suspicious email patterns in text
|
|
171
|
+
- **Contact Management**: Parse unstructured text to build contact databases
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## API Endpoint
|
|
176
|
+
|
|
177
|
+
**POST** `/content/detect_emails`
|
|
178
|
+
|
|
179
|
+
For detailed API specifications, refer to:
|
|
180
|
+
- [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVW)
|
|
181
|
+
- [Product Page](https://sharpapi.com/en/catalog/ai/content-marketing-automation/emails-detector)
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Related Packages
|
|
186
|
+
|
|
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-detect-address](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-address) - Address detection
|
|
190
|
+
- [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Support
|
|
201
|
+
|
|
202
|
+
- **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
|
|
203
|
+
- **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
|
|
204
|
+
- **Email**: contact@sharpapi.com
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
**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-emails",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SharpAPI.com Node.js SDK for detecting email 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
|
+
"email 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-emails.git"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service for detecting email addresses in text using SharpAPI.com
|
|
5
|
+
*/
|
|
6
|
+
class SharpApiDetectEmailsService extends SharpApiCoreService {
|
|
7
|
+
/**
|
|
8
|
+
* Parses the provided text for any possible emails. Might come in handy in case of processing and validating
|
|
9
|
+
* big chunks of data against email addresses or f.e. if you want to detect emails in places
|
|
10
|
+
* where they're not supposed to be.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} text
|
|
13
|
+
* @returns {Promise<string>} - The status URL.
|
|
14
|
+
*/
|
|
15
|
+
async detectEmails(text) {
|
|
16
|
+
const data = { content: text };
|
|
17
|
+
const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_DETECT_EMAILS.url, data);
|
|
18
|
+
return this.parseStatusUrl(response);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = { SharpApiDetectEmailsService };
|