cdn-icon-fetch

1.0.2 • Public • Published

CDN Icon Fetcher

CDN Icon Fetcher is a Node.js library that allows you to fetch resources from various CDN providers. It supports fetching icons, images, content, JavaScript, and JSON files from popular CDNs like Cloudflare, Fastly, KeyCDN, Akamai, Amazon CloudFront, and Gcore.

Installation

To install the package, use npm:

npm install cdn-icon-fetcher

Usage

Fetching a CDN Resource

To fetch a resource from a specified CDN, use the fetchCdnResource function. This function requires the CDN provider, resource type, token, and base URL as parameters.

const { fetchCdnResource } = require("cdn-icon-fetcher");

fetchCdnResource(
  "cloudflare",
  "icon",
  "your-token",
  "https://your-base-url.com"
)
  .then((data) => {
    console.log("Resource data:", data);
  })
  .catch((error) => {
    console.error("Error fetching resource:", error);
  });

Fetching an Icon

To fetch an icon from the CDN, use the fetchIcon function. This function can be customized with a token, request options, and the number of retries.

const { fetchIcon } = require("cdn-icon-fetcher");

fetchIcon("your-icon-token")
  .then(() => {
    console.log("Icon fetched successfully");
  })
  .catch(() => {
    console.error("Failed to fetch icon");
  });

API

fetchCdnResource(cdnProvider, resourceType, token, baseUrl)

  • cdnProvider: The CDN provider (e.g., 'cloudflare', 'fastly', 'keycdn', 'akamai', 'amazoncloudfront', 'gcore').
  • resourceType: The type of resource to fetch (e.g., 'icon', 'image', 'content', 'js', 'json').
  • token: The token or identifier for the resource.
  • baseUrl: The base URL of the CDN.
  • Returns: A promise that resolves with the resource data.

fetchIcon(token, options, retries)

  • token: The token for the icon to fetch.
  • options: Options for the request, including the URL and headers.
  • retries: The number of retries if the request fails.
  • Returns: A promise that resolves when the icon data is fetched.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

Changelog

[1.2.0] - 2025-2-12

  • Added support for additional CDN providers.
  • Improved error handling and retry logic.
  • Updated documentation and examples.

For more information, please visit the GitHub repository.


Readme

Keywords

Package Sidebar

Install

npm i cdn-icon-fetch

Weekly Downloads

128

Version

1.0.2

License

ISC

Unpacked Size

6.11 kB

Total Files

3

Last publish

Collaborators

  • michaelborder