@sharpapi/sharpapi-node-detect-urls 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,267 @@
1
+ ![SharpAPI GitHub cover](https://sharpapi.com/sharpapi-github-php-bg.jpg "SharpAPI Node.js Client")
2
+
3
+ # URL Detector API for Node.js
4
+
5
+ ## 🔗 Detect and extract URLs from text — powered by SharpAPI AI.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@sharpapi/sharpapi-node-detect-urls.svg)](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-urls)
8
+ [![License](https://img.shields.io/npm/l/@sharpapi/sharpapi-node-detect-urls.svg)](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
9
+
10
+ **SharpAPI URL Detector** parses text content and extracts URLs with protocol information and validation. Perfect for link extraction, content moderation, and security analysis.
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-urls
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 { SharpApiDetectUrlsService } = require('@sharpapi/sharpapi-node-detect-urls');
50
+
51
+ const apiKey = process.env.SHARP_API_KEY; // Store your API key in environment variables
52
+ const service = new SharpApiDetectUrlsService(apiKey);
53
+
54
+ const text = `
55
+ Visit our website at https://example.com for more information.
56
+ Check out our blog: www.example.com/blog
57
+ Contact us at support page: example.com/contact
58
+ `;
59
+
60
+ async function detectUrls() {
61
+ try {
62
+ // Submit detection job
63
+ const statusUrl = await service.detectUrls(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 URLs:', result.getResultJson());
69
+ } catch (error) {
70
+ console.error('Error:', error.message);
71
+ }
72
+ }
73
+
74
+ detectUrls();
75
+ ```
76
+
77
+ ---
78
+
79
+ ## API Documentation
80
+
81
+ ### Methods
82
+
83
+ #### `detectUrls(text: string): Promise<string>`
84
+
85
+ Detects and extracts URLs from the provided text.
86
+
87
+ **Parameters:**
88
+ - `text` (string, required): The text content to scan for URLs
89
+
90
+ **Returns:**
91
+ - Promise<string>: Status URL for polling the job result
92
+
93
+ **Example:**
94
+ ```javascript
95
+ const statusUrl = await service.detectUrls(textWithUrls);
96
+ const result = await service.fetchResults(statusUrl);
97
+ ```
98
+
99
+ ### Response Format
100
+
101
+ The API returns detected URLs with parsed components:
102
+
103
+ ```json
104
+ {
105
+ "urls": [
106
+ {
107
+ "url": "https://example.com",
108
+ "protocol": "https",
109
+ "domain": "example.com",
110
+ "path": "/",
111
+ "is_valid": true,
112
+ "is_secure": true,
113
+ "parameters": {}
114
+ },
115
+ {
116
+ "url": "www.example.com/blog",
117
+ "protocol": "http",
118
+ "domain": "example.com",
119
+ "path": "/blog",
120
+ "is_valid": true,
121
+ "is_secure": false,
122
+ "parameters": {}
123
+ }
124
+ ]
125
+ }
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Examples
131
+
132
+ ### Basic URL Detection
133
+
134
+ ```javascript
135
+ const { SharpApiDetectUrlsService } = require('@sharpapi/sharpapi-node-detect-urls');
136
+
137
+ const service = new SharpApiDetectUrlsService(process.env.SHARP_API_KEY);
138
+
139
+ const socialPost = `
140
+ Check out these awesome resources:
141
+ - https://docs.example.com
142
+ - www.github.com/username/project
143
+ - example.com/api/docs
144
+ `;
145
+
146
+ service.detectUrls(socialPost)
147
+ .then(statusUrl => service.fetchResults(statusUrl))
148
+ .then(result => {
149
+ const urls = result.getResultJson();
150
+ console.log(`Found ${urls.length} URLs:`);
151
+ urls.forEach((url, index) => {
152
+ console.log(`${index + 1}. ${url.url} (${url.protocol})`);
153
+ });
154
+ })
155
+ .catch(error => console.error('Detection failed:', error));
156
+ ```
157
+
158
+ ### Security-Focused URL Analysis
159
+
160
+ ```javascript
161
+ const service = new SharpApiDetectUrlsService(process.env.SHARP_API_KEY);
162
+
163
+ const userContent = `
164
+ Click here: http://suspicious-site.com
165
+ Or visit: https://secure-site.com
166
+ `;
167
+
168
+ const statusUrl = await service.detectUrls(userContent);
169
+ const result = await service.fetchResults(statusUrl);
170
+ const urls = result.getResultJson();
171
+
172
+ const insecureUrls = urls.filter(url => !url.is_secure);
173
+
174
+ if (insecureUrls.length > 0) {
175
+ console.log('⚠️ Warning: Found insecure URLs:');
176
+ insecureUrls.forEach(url => {
177
+ console.log(` - ${url.url} (${url.protocol})`);
178
+ });
179
+ }
180
+ ```
181
+
182
+ ### Link Extraction from Documents
183
+
184
+ ```javascript
185
+ const service = new SharpApiDetectUrlsService(process.env.SHARP_API_KEY);
186
+
187
+ const document = `
188
+ API Documentation: https://api.example.com/v2/docs
189
+ Support Portal: https://support.example.com
190
+ Community Forum: https://community.example.com/discussions
191
+ `;
192
+
193
+ const statusUrl = await service.detectUrls(document);
194
+ const result = await service.fetchResults(statusUrl);
195
+ const urls = result.getResultJson();
196
+
197
+ const linkDirectory = urls.map(url => ({
198
+ domain: url.domain,
199
+ full_url: url.url,
200
+ secure: url.is_secure
201
+ }));
202
+
203
+ console.log('Extracted Links:', linkDirectory);
204
+ ```
205
+
206
+ ---
207
+
208
+ ## Use Cases
209
+
210
+ - **Content Moderation**: Detect and validate URLs in user-generated content
211
+ - **Link Extraction**: Parse URLs from documents, emails, and web pages
212
+ - **Security Analysis**: Identify insecure or suspicious links
213
+ - **SEO Audits**: Extract and analyze all links from content
214
+ - **Social Media Monitoring**: Track shared links and references
215
+ - **Spam Detection**: Identify spam URLs in comments and messages
216
+ - **Archive & Backup**: Extract links for archival purposes
217
+
218
+ ---
219
+
220
+ ## Detection Capabilities
221
+
222
+ The URL detector handles various formats:
223
+
224
+ - **Full URLs**: https://example.com/path?query=value
225
+ - **Protocol-less**: www.example.com or example.com
226
+ - **Subdomains**: subdomain.example.com
227
+ - **Paths**: example.com/path/to/resource
228
+ - **Query Parameters**: example.com?param1=value1&param2=value2
229
+ - **Fragments**: example.com/page#section
230
+ - **International Domains**: Internationalized domain names (IDN)
231
+
232
+ ---
233
+
234
+ ## API Endpoint
235
+
236
+ **POST** `/content/detect_urls`
237
+
238
+ For detailed API specifications, refer to:
239
+ - [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVe)
240
+ - [Product Page](https://sharpapi.com/en/catalog/ai/content-marketing-automation/urls-detector)
241
+
242
+ ---
243
+
244
+ ## Related Packages
245
+
246
+ - [@sharpapi/sharpapi-node-detect-emails](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-emails) - Email detection
247
+ - [@sharpapi/sharpapi-node-detect-phones](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-phones) - Phone number detection
248
+ - [@sharpapi/sharpapi-node-detect-spam](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-spam) - Spam detection
249
+ - [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
250
+
251
+ ---
252
+
253
+ ## License
254
+
255
+ This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
256
+
257
+ ---
258
+
259
+ ## Support
260
+
261
+ - **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
262
+ - **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
263
+ - **Email**: contact@sharpapi.com
264
+
265
+ ---
266
+
267
+ **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-urls",
3
+ "version": "1.0.0",
4
+ "description": "SharpAPI.com Node.js SDK for detecting URLs 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
+ "url 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-urls.git"
39
+ }
40
+ }
@@ -0,0 +1,21 @@
1
+ const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
2
+
3
+ /**
4
+ * Service for detecting URLs in text using SharpAPI.com
5
+ */
6
+ class SharpApiDetectUrlsService extends SharpApiCoreService {
7
+ /**
8
+ * Parses the provided text for any possible URLs. Might come in handy in case of processing and validating
9
+ * big chunks of data against URLs or if you want to detect URLs in places where they're not supposed to be.
10
+ *
11
+ * @param {string} text
12
+ * @returns {Promise<string>} - The status URL.
13
+ */
14
+ async detectUrls(text) {
15
+ const data = { content: text };
16
+ const response = await this.makeRequest('POST', SharpApiJobTypeEnum.CONTENT_DETECT_URLS.url, data);
17
+ return this.parseStatusUrl(response);
18
+ }
19
+ }
20
+
21
+ module.exports = { SharpApiDetectUrlsService };
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // sharpapi-node-detect-urls/src/index.js
2
+ const { SharpApiDetectUrlsService } = require('./SharpApiDetectUrlsService');
3
+
4
+ module.exports = {
5
+ SharpApiDetectUrlsService,
6
+ };