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

svelvg

v0.12.1

Published

Convert SVG files into Svelte components with TypeScript definitions

Downloads

319

Readme

svelvg

Convert SVG files into Svelte components with TypeScript definitions.

Successor to svg-to-svelte

The minimum Svelte version required to use types generated by this library is v3.55.0.

This library transforms SVG files into Svelte components through the following:

  • convert the svg file name into a valid module name (e.g., alarm-fill --> AlarmFill)
  • forward $$restProps to the svg element while preserving attributes from the original svg
  • add a default slot as child element to svg
  • generate a TypeScript definition by extending the SvelteComponentTyped interface

Usage

CLI

The easiest way to use this library is through npx.

The glob value represents the relative path to the folder containing SVG files inside node_modules/.

For example, say you have bootstrap-icons installed as a development dependency, which contains icon SVG files in the "icons" folder.

npx svelvg glob=bootstrap-icons/icons

By default, the output directory is "lib". Customize the directory using the outDir flag:

npx svelvg glob=bootstrap-icons/icons outDir=dist

Optionally, generate an index of icons (a list of all module names) by enabling the iconIndex flag. It will default to creating a ICON_INDEX.md file in your working directory.

npx svelvg glob=bootstrap-icons/icons iconIndex

Customize the icon index file name like so:

npx svelvg glob=bootstrap-icons/icons iconIndex=ICONS.md

Node.js

Alternatively, install svelvg from NPM to use it programmatically.

# Yarn
yarn add -D svelvg

# NPM
npm i -D svelvg

# pnpm
pnpm i -D svelvg

Note that the top-level await requires Node.js v14 or greater.

const svelvg = require("svelvg");

// Emits components to the `lib` folder
svelvg.createLibrary("bootstrap-icons/icons");

// Customize the output directory to be `dist`
svelvg.createLibrary("bootstrap-icons/icons", { outDir: "dist" });

API

createLibrary

interface CreateLibraryOptions {
  /** @default "lib" */
  outDir: string;

  /** @default false */
  iconIndex: boolean | string;

  /**
   * Callback to add a list of classes to the SVG element
   * provided the original filename and module name
   * @example
   * filename: "alarm-fill"
   * moduleName: "AlarmFill"
   */
  appendClassNames: (filename: string, moduleName: string) => string[];

  /**
   * Override the default module name
   */
  toModuleName: (params: {
    path: path.ParsedPath;
    moduleName: string;
  }) => string;
}

Template

Scaffold a new project using the template:

npx degit metonym/svelvg/template <folder-name>

IconLibrary.svelte

svelvg exports an IconLibrary.svelte to make listing and searching icons easier.

See template/index.html for an example.

<script type="module">
  import IconLibrary from "svelvg/lib/IconLibrary.svelte";
  import * as icons from "./lib";
  import pkg from "./package.json";

  const app = new IconLibrary({
    target: document.getElementById("svelte"),
    props: {
      pkg,
      icons,
    },
  });
</script>

License

MIT