
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@handy-ones/handy-svg
Advanced tools
External SVGs that you can style
fetch
request. And caches of course.body
.npm i handy-svg
import {HandySvg} from 'handy-svg';
import iconSrc from './icon.svg';
export const Icon = () => (
<HandySvg
src={iconSrc}
width="32"
height="32"
/>
);
I assume here that you use file-loader
for bundling your svg-files and get public url to SVG file in iconSrc
, like so:
module.exports = {
module: {
rules: [
{
test: /\.(png|jpe?g|gif|svg)$/i,
loader: 'file-loader',
options: {
name: '[path][name].[ext]'
}
}
]
}
};
But in fact there is no difference for the handy-svg where you get your SVGs urls from.
You may also use handy-svg without React at all.
import {injector} from 'handy-svg/lib/injector';
const src = "https://cdn-server.net/icon.svg";
// Fetches svg content and puts it to sprite
injector.load(src);
// Gets the id of your svg in sprite
const id = injector.getId(src);
// Then you can use it at your will
const svg = `<svg><use href="#${id}" /></svg>`;
<HandySvg />
import {HandySvg} from 'handy-svg';
type HandySvgProps = {
src: string; // your icon url
loadTimeot?: number; // load timeout. 4800 by default
loadRetryCount?: number; // load retry. 2 by default
[key: string]: string | number | undefined; // any extra props will be passed to svg tag
}
<HandySvg {...props} />
injector.load()
import {injector} from 'handy-svg/lib/injector';
type LoadOptions = {
flushImmediate?: boolean; // inject icon to the body without debouncing
timeout?: number; // load timeout. 4800 by default
retryCount?: number; // load retry. 2 by default
}
injector.load(src: string, options: LoadOptions): Promise<void>;
injector.getId()
import {injector} from 'handy-svg/lib/injector';
injector.getId(src: string): string;
You should add hostnames of your icons to the connect-src directive of your Content-Security-Policy header for this to work properly.
FAQs
The most handy way to use <svg> on the web
The npm package @handy-ones/handy-svg receives a total of 4 weekly downloads. As such, @handy-ones/handy-svg popularity was classified as not popular.
We found that @handy-ones/handy-svg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.