react-icon-svgs
v2.15.3
Published
A lightweight React utility for fetching, validating, and managing SVG icons from CDN sources.
Downloads
1,338
Maintainers
Readme
react-icon-svgs
A lightweight, production-ready Node.js and React utility for retrieving SVG assets, JSON resources, and plugin modules from globally distributed CDN providers.
Designed for modern React applications, server-side rendering environments, build pipelines, CI/CD workflows, and Node-based asset processing systems.
Features
- Multi-CDN provider support
- SVG, JSON, and static asset retrieval
- Recursive SVG discovery
- Plugin-based processing pipelines
- Asynchronous, non-blocking operations
- Compatible with React, Node.js, SSR, and build tooling
Supported CDN Providers
- Cloudflare
- Fastly
- Akamai
- Amazon CloudFront
- KeyCDN
- Gcore
Installation
npm
npm install react-icon-svgsyarn
yarn add react-icon-svgspnpm
pnpm add react-icon-svgsRequirements
- Node.js >= 16
- npm >= 8
Quick Start
Import
const {
setDefaultModule,
getPlugin,
setPlugin
} = require("react-icon-svgs");Fetch Assets From CDN
Use setDefaultModule() to fetch SVG assets, JSON files, or remote resources.
const { setDefaultModule } = require("react-icon-svgs");
async function fetchIcons() {
try {
const data = await setDefaultModule(
"cloudflare",
"svg",
"github.svg"
);
console.log(data);
} catch (error) {
console.error(error);
}
}
fetchIcons();Scan Local SVG Files
Use getPlugin() to recursively scan directories for .svg files and apply the primary plugin workflow.
const { getPlugin } = require("react-icon-svgs");
getPlugin("./assets");Alternate Plugin Pipeline
Use setPlugin() to execute the secondary SVG plugin workflow.
const { setPlugin } = require("react-icon-svgs");
setPlugin("./assets");API Reference
setDefaultModule(provider, resourceType, token, baseUrl)
Fetches a resource from a selected CDN provider.
Parameters
| Parameter | Type | Description | |-----------|------|-------------| | provider | string | CDN provider name | | resourceType | string | Resource type | | token | string | Asset filename | | baseUrl | string | Optional URL override |
Returns
Promise<any>getPlugin(directory)
Recursively scans a directory for SVG files and executes the primary plugin pipeline.
Parameters
| Parameter | Type | Default | |-----------|------|---------| | directory | string | ./script |
Returns
voidsetPlugin(directory)
Recursively scans a directory for SVG files and executes the secondary plugin pipeline.
Parameters
| Parameter | Type | Default | |-----------|------|---------| | directory | string | ./script |
Returns
voidSupported Provider Keys
| Provider | Key | |----------|-----| | Cloudflare | cloudflare | | Fastly | fastly | | Akamai | akamai | | Amazon CloudFront | amazoncloudfront | | KeyCDN | keyIcon | | Gcore | gcore |
Example Use Cases
- Design system icon delivery
- Build-time SVG processing
- Static asset validation
- CI/CD asset pipelines
- Server-side icon rendering
- CDN asset synchronization
Error Handling
The library provides runtime error handling for:
- Unsupported providers
- Network failures
- Invalid HTTP responses
- JSON parsing failures
- Plugin loading failures
Performance
Built around:
- Asynchronous filesystem operations
- Non-blocking network requests
- Recursive directory traversal
- Runtime plugin execution
License
MIT
Contributing
Issues, feature requests, and pull requests are welcome.
Please open an issue before submitting major architectural changes.
