npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svelte-iconify-svg

v2.3.4

Published

A node script to autogenerate svg markup from iconify references in your svelte project

Downloads

27

Readme

Svelte Iconify SVG (Markup Exporter)

github-package.json-version The MIT License CircleCI

Purpose

Converts iconify icon names to SVG markup. Intended for use in svelte projects to avoid dependencies on full font libraries, especially if you only need a few icons. Automatically searches your source files so you can simply call this script before your build step to auto-generate the iconify icons you are referencing.

How it works

Checks the contents of all your files in the supplied 'input' directories for any references to 'iconify' icons. i.e. any text in the format 'alphanumericordashes colon alphanumericordashes' such as fa:random or si-glyph:pin-location-2 It will then save a .js file which exports an icons object of all iconify files found in your project.

Installation

npm install svelte-iconify-svg --save-dev

Usage (of this script)

Add to your package.json, and run it as part of your dev or build step

"scripts": {
  "svelteiconifysvg": "svelte-iconify-svg -i 'input/directory1' 'input/directory2' -o 'output/filePath.js'"
}

Flags

  • -i or --input [default = "src"] Directories to search. Provide them as a space separated list of strings. FULL PATHS ONLY AT THE MOMENT

  • -o --output [default = "src/icons.js"] FilePath to save

  • -f --outputsvgfiles [default = false] Outputs as individual svg files. Default is a single JS object of all icons SVG code

  • -c --cjs [default = false] outputs the JS object as commonJs "module.exports = ", instead of the default ES6 export syntax "export const icons = "

  • -s --alwaysSave [default = false] forces the iconify API network call and re-save of the icons file, instead of the default which will skip these if the icons list has not changed

  • -r --recursive [default = false] recursively searches within each input directory, instead of the default which will only search within the first level of input directories

  • -l --logging [default = true] controls the amount of console.logs. Leave it on for to help with debugging, or reduce if it's getting too noisy for your workflow, options are "all"|true, "some", "none"|false

  • -t --transform [default = false] fix for when some of your font awesome icons are reversed. Default is false. Set to true to enabled vertical or horizontal flipping for a small subset of fa icons such as fa:chevron-right and fa:arrow-circle-down.

Or use the script indirectly, via the rollup plugin

https://github.com/Swiftaff/rollup-plugin-iconify-svg

Usage (in svelte)

It's a bit hacky, but the simplest way is to use the svelte @html feature

//example.svelte
<script>
import icons from "./src/icons.js";
</script>
{@html icons["fa:random"]}
<!-- note, so if this example.svelte file is in one of the input directories, the "fa:random" text above would have been found, and the icon auto-generated! -->

Usage (in plain JavaScript)

const svelteiconifysvg = require("svelte-iconify-svg");
const src = "src";
const dest = "src/icons.js";
const options = {
    commonJs: true,       //default false
    alwaysSave: true,     //default false
    recursive: true,      //default false
    logging: true,        //default true or "all". Other options are:
                          //"some"
                          //false or "none"
    transform: true       //default false
    regex:                //default is this /(?<=("|'))(?!(bind|on|svelte))[a-zA-Z0-9-]+:[a-zA-Z0-9-]+(?=("|'))/g
    getCodeFromIconList:  //default null, allows you to replace the main iconify function
                          //e.g. provide your own which does something different than the inbuilt use of the iconfiy API - go nuts!
                          //as long as it returns an object {
                          //  code: string to use when saving the file
                          //  count: count of icons saved
                          //}
                          //e.g. in the format of fn(iconsList, options)=>{ code, count }
};
const icons = svelteiconifysvg(src, dest, options);
console.log(icons);
/*
Do with the resulting object what you will...
icons = {
  "fa:random": "...svg markup for this icon",
  ... other icons
}
*/

License

This project is licensed under the MIT License.