domain-rank 0.1.1

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.
@@ -0,0 +1,360 @@
1
+ const express = require('express');
2
+ const Fuse = require('fuse.js');
3
+ const cors = require('cors');
4
+
5
+ // Initialize Express app
6
+ const app = express();
7
+ const PORT = process.env.PORT || 3000;
8
+
9
+ // Middleware
10
+ app.use(cors());
11
+ app.use(express.json());
12
+ app.use(express.static('public'));
13
+
14
+ // Your domain data
15
+ const domainData = {
16
+ "facebook.com": [1, "Facebook"],
17
+ "google.com": [2, "Google"],
18
+ "instagram.com": [3, "Instagram"],
19
+ "youtube.com": [4, "YouTube"],
20
+ "twitter.com": [5, "Twitter"],
21
+ "linkedin.com": [6, "Linkedin"],
22
+ "cloudflare.com": [7, "Cloudflare"],
23
+ "pinterest.com": [8, "Pinterest"],
24
+ "apple.com": [9, "Apple"],
25
+ "wikipedia.org": [10, "Wikipedia"],
26
+ "microsoft.com": [11, "Microsoft"],
27
+ "vimeo.com": [12, "Vimeo"],
28
+ "jquery.com": [13, "jQuery"],
29
+ "wordpress.com": [14, "Word Press"],
30
+ "whatsapp.com": [15, "Whatsapp"],
31
+ "amazon.com": [16, "Amazon.com"],
32
+ "tiktok.com": [17, "Tiktok"],
33
+ "europa.eu": [18, "Europa"],
34
+ "mozilla.org": [19, "Mozilla"],
35
+ "github.com": [20, "Github"],
36
+ "blogspot.com": [21, "Blog Spot"],
37
+ "bit.ly": [22, "BIT"],
38
+ "fontawesome.com": [23, "Font Awesome"],
39
+ "adobe.com": [24, "Adobe"],
40
+ "reddit.com": [25, "reddit"],
41
+ "spotify.com": [26, "Spotify"],
42
+ "shopify.com": [27, "Shopify"],
43
+ "w3.org": [28, "W3C"],
44
+ "medium.com": [29, "Medium"],
45
+ "tumblr.com": [30, "Tumblr"],
46
+ "flickr.com": [31, "Flickr"],
47
+ "vk.com": [32, "Welcome!"],
48
+ "qq.com": [33, "腾讯网"],
49
+ "paypal.com": [34, "Paypal"],
50
+ "who.int": [35, "WHO"],
51
+ "nih.gov": [36, "NIH"],
52
+ "yahoo.com": [37, "Yahoo"],
53
+ "nytimes.com": [38, "NY Times"],
54
+ "archive.org": [39, "Archive"],
55
+ "creativecommons.org": [40, "Creative Commons"],
56
+ "weebly.com": [41, "Weebly"],
57
+ "soundcloud.com": [42, "Soundcloud"],
58
+ "mit.edu": [43, "MIT"],
59
+ "forbes.com": [44, "Forbes"],
60
+ "researchgate.net": [45, "Researchgate"],
61
+ "ibm.com": [46, "IBM"],
62
+ "live.com": [47, "Outlook"],
63
+ "opera.com": [48, "Opera"],
64
+ "yandex.ru": [49, "Yandex"],
65
+ "t.co": [50, "T"],
66
+ "apache.org": [51, "Apache"],
67
+ "stripe.com": [52, "Stripe"]
68
+ };
69
+
70
+ // Transform domain data into searchable format
71
+ const domains = Object.entries(domainData).map(([domain, data]) => ({
72
+ domain: domain,
73
+ id: data[0],
74
+ name: data[1]
75
+ }));
76
+
77
+ // Initialize Fuse.js
78
+ const fuseOptions = {
79
+ keys: ['domain', 'name'], // Search in both domain and name fields
80
+ threshold: 0.3, // Fuzzy matching threshold (0 = exact match, 1 = match anything)
81
+ includeScore: true,
82
+ includeMatches: true,
83
+ minMatchCharLength: 1,
84
+ ignoreLocation: true
85
+ };
86
+
87
+ const fuse = new Fuse(domains, fuseOptions);
88
+
89
+ // API Routes
90
+
91
+ // GET /api/domains - Get all domains
92
+ app.get('/api/domains', (req, res) => {
93
+ res.json({
94
+ success: true,
95
+ data: domains,
96
+ total: domains.length
97
+ });
98
+ });
99
+
100
+ // GET /api/domains/search - Search domains with query parameter
101
+ app.get('/api/domains/search', (req, res) => {
102
+ const { q, limit = 50, threshold } = req.query;
103
+
104
+ if (!q || q.trim() === '') {
105
+ return res.json({
106
+ success: true,
107
+ data: domains.slice(0, parseInt(limit)),
108
+ total: domains.length,
109
+ query: q || ''
110
+ });
111
+ }
112
+
113
+ // Update threshold if provided
114
+ const searchOptions = { ...fuseOptions };
115
+ if (threshold) {
116
+ searchOptions.threshold = parseFloat(threshold);
117
+ }
118
+
119
+ const tempFuse = threshold ? new Fuse(domains, searchOptions) : fuse;
120
+ const results = tempFuse.search(q.trim());
121
+
122
+ const limitedResults = results.slice(0, parseInt(limit));
123
+
124
+ res.json({
125
+ success: true,
126
+ data: limitedResults.map(result => ({
127
+ ...result.item,
128
+ score: result.score,
129
+ matches: result.matches
130
+ })),
131
+ total: results.length,
132
+ query: q,
133
+ threshold: searchOptions.threshold
134
+ });
135
+ });
136
+
137
+ // POST /api/domains/search - Search domains with request body
138
+ app.post('/api/domains/search', (req, res) => {
139
+ const { query, options = {} } = req.body;
140
+
141
+ if (!query || query.trim() === '') {
142
+ return res.json({
143
+ success: true,
144
+ data: domains,
145
+ total: domains.length,
146
+ query: query || ''
147
+ });
148
+ }
149
+
150
+ // Merge custom options with defaults
151
+ const searchOptions = { ...fuseOptions, ...options };
152
+ const tempFuse = new Fuse(domains, searchOptions);
153
+ const results = tempFuse.search(query.trim());
154
+
155
+ res.json({
156
+ success: true,
157
+ data: results.map(result => ({
158
+ ...result.item,
159
+ score: result.score,
160
+ matches: result.matches
161
+ })),
162
+ total: results.length,
163
+ query: query,
164
+ options: searchOptions
165
+ });
166
+ });
167
+
168
+ // GET /api/domains/:id - Get domain by ID
169
+ app.get('/api/domains/:id', (req, res) => {
170
+ const id = parseInt(req.params.id);
171
+ const domain = domains.find(d => d.id === id);
172
+
173
+ if (!domain) {
174
+ return res.status(404).json({
175
+ success: false,
176
+ error: 'Domain not found'
177
+ });
178
+ }
179
+
180
+ res.json({
181
+ success: true,
182
+ data: domain
183
+ });
184
+ });
185
+
186
+ // GET /api/stats - Get statistics about the domain data
187
+ app.get('/api/stats', (req, res) => {
188
+ const stats = {
189
+ totalDomains: domains.length,
190
+ domainTypes: {
191
+ com: domains.filter(d => d.domain.endsWith('.com')).length,
192
+ org: domains.filter(d => d.domain.endsWith('.org')).length,
193
+ net: domains.filter(d => d.domain.endsWith('.net')).length,
194
+ edu: domains.filter(d => d.domain.endsWith('.edu')).length,
195
+ gov: domains.filter(d => d.domain.endsWith('.gov')).length,
196
+ other: domains.filter(d => !d.domain.match(/\.(com|org|net|edu|gov)$/)).length
197
+ },
198
+ searchableFields: fuseOptions.keys,
199
+ fuseConfiguration: fuseOptions
200
+ };
201
+
202
+ res.json({
203
+ success: true,
204
+ data: stats
205
+ });
206
+ });
207
+
208
+ // Demo endpoint - shows example searches
209
+ app.get('/api/demo', (req, res) => {
210
+ const demoSearches = [
211
+ { query: 'social', description: 'Find social media platforms' },
212
+ { query: 'google', description: 'Find Google-related domains' },
213
+ { query: 'music', description: 'Find music streaming services' },
214
+ { query: 'shop', description: 'Find shopping platforms' },
215
+ { query: 'news', description: 'Find news websites' }
216
+ ];
217
+
218
+ const results = demoSearches.map(demo => {
219
+ const searchResults = fuse.search(demo.query);
220
+ return {
221
+ ...demo,
222
+ results: searchResults.slice(0, 5).map(result => ({
223
+ ...result.item,
224
+ score: result.score
225
+ }))
226
+ };
227
+ });
228
+
229
+ res.json({
230
+ success: true,
231
+ data: results
232
+ });
233
+ });
234
+
235
+ // Serve a simple HTML demo page
236
+ app.get('/', (req, res) => {
237
+ res.send(`
238
+ <!DOCTYPE html>
239
+ <html lang="en">
240
+ <head>
241
+ <meta charset="UTF-8">
242
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
243
+ <title>Fuse.js Domain Search API Demo</title>
244
+ <style>
245
+ body {
246
+ font-family: Arial, sans-serif;
247
+ max-width: 800px;
248
+ margin: 0 auto;
249
+ padding: 20px;
250
+ line-height: 1.6;
251
+ }
252
+ .endpoint {
253
+ background: #f4f4f4;
254
+ padding: 10px;
255
+ margin: 10px 0;
256
+ border-radius: 5px;
257
+ font-family: monospace;
258
+ }
259
+ .result {
260
+ background: #e8f5e8;
261
+ padding: 15px;
262
+ margin: 10px 0;
263
+ border-radius: 5px;
264
+ white-space: pre-wrap;
265
+ }
266
+ input {
267
+ width: 100%;
268
+ padding: 10px;
269
+ margin: 10px 0;
270
+ border: 1px solid #ddd;
271
+ border-radius: 5px;
272
+ }
273
+ button {
274
+ background: #007bff;
275
+ color: white;
276
+ padding: 10px 20px;
277
+ border: none;
278
+ border-radius: 5px;
279
+ cursor: pointer;
280
+ }
281
+ button:hover {
282
+ background: #0056b3;
283
+ }
284
+ </style>
285
+ </head>
286
+ <body>
287
+ <h1>Fuse.js Domain Search API Demo</h1>
288
+
289
+ <h2>Available Endpoints:</h2>
290
+ <div class="endpoint">GET /api/domains - Get all domains</div>
291
+ <div class="endpoint">GET /api/domains/search?q=query - Search domains</div>
292
+ <div class="endpoint">POST /api/domains/search - Advanced search</div>
293
+ <div class="endpoint">GET /api/domains/:id - Get domain by ID</div>
294
+ <div class="endpoint">GET /api/stats - Get statistics</div>
295
+ <div class="endpoint">GET /api/demo - See demo searches</div>
296
+
297
+ <h2>Try it out:</h2>
298
+ <input type="text" id="searchInput" placeholder="Enter search query (e.g., 'social', 'google', 'music')">
299
+ <button onclick="search()">Search</button>
300
+
301
+ <div id="results"></div>
302
+
303
+ <script>
304
+ async function search() {
305
+ const query = document.getElementById('searchInput').value;
306
+ const resultsDiv = document.getElementById('results');
307
+
308
+ if (!query.trim()) {
309
+ resultsDiv.innerHTML = '<div class="result">Please enter a search query</div>';
310
+ return;
311
+ }
312
+
313
+ try {
314
+ const response = await fetch(\`/api/domains/search?q=\${encodeURIComponent(query)}\`);
315
+ const data = await response.json();
316
+
317
+ resultsDiv.innerHTML = \`<div class="result">\${JSON.stringify(data, null, 2)}</div>\`;
318
+ } catch (error) {
319
+ resultsDiv.innerHTML = \`<div class="result">Error: \${error.message}</div>\`;
320
+ }
321
+ }
322
+
323
+ // Allow search on Enter key
324
+ document.getElementById('searchInput').addEventListener('keypress', function(e) {
325
+ if (e.key === 'Enter') {
326
+ search();
327
+ }
328
+ });
329
+ </script>
330
+ </body>
331
+ </html>
332
+ `);
333
+ });
334
+
335
+ // Error handling middleware
336
+ app.use((err, req, res, next) => {
337
+ console.error(err.stack);
338
+ res.status(500).json({
339
+ success: false,
340
+ error: 'Something went wrong!'
341
+ });
342
+ });
343
+
344
+ // 404 handler
345
+ app.use((req, res) => {
346
+ res.status(404).json({
347
+ success: false,
348
+ error: 'Endpoint not found'
349
+ });
350
+ });
351
+
352
+ // Start the server
353
+ app.listen(PORT, () => {
354
+ console.log(`🚀 Fuse.js Domain Search API running on http://localhost:${PORT}`);
355
+ console.log(`📖 API Documentation available at http://localhost:${PORT}`);
356
+ console.log(`🔍 Try searching: http://localhost:${PORT}/api/domains/search?q=social`);
357
+ });
358
+
359
+ // Export for testing
360
+ module.exports = app;
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022"],
6
+ "moduleResolution": "bundler",
7
+ "allowImportingTsExtensions": true,
8
+ "resolveJsonModule": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "esModuleInterop": true,
11
+ "strict": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "noEmit": true,
15
+ "types": ["node"]
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { defineConfig } from 'vite';
2
+ import path from 'path';
3
+
4
+ export default defineConfig({
5
+ build: {
6
+ ssr: true,
7
+ outDir: 'dist',
8
+ lib: {
9
+ entry: path.resolve(__dirname, 'src/export.ts'),
10
+ fileName: 'export',
11
+ formats: ['cjs']
12
+ },
13
+ rollupOptions: {
14
+ external: ['fs', 'path', 'url']
15
+ },
16
+ target: 'node16'
17
+ }
18
+ });