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

@carforyou/assets

v2.1.46

Published

Assets package to build and optimize our svgs

Downloads

104

Readme

CAR FOR YOU assets

semantic-release

Usage

npm install @carforyou/assets-pkg

This package generates minified tsx components from your svg files so that you can include it as an inline svg into your React components.

build optimized assets

npx cfy-assets build
  1. Cleans the dist directory
  2. Optimizes the svg files into the dist directory
  3. Generates the tsx components into the dist directory
  4. Generates the index files for the configured files

Before

your-project
├── assets.config.json
└── assets
  └── src
    ├── your svg files
    └── some_subfolder
        └── other svg files

After

your-project
├── assets.config.json
└── assets
  └── src
  | ├── your original svg files
  | └── some_subfolder
  |     └── other original svg files
  └── dist
    ├── your minified svg files
    ├── your minified tsx components
    └── some_subfolder
        ├── other minified svg files
        ├── other minified tsx components
        └── index.js file

clean dist directory

npx cfy-assets clean

Removes all the auto-generated files.

Configuration

You can create a configuration file called assets.config.json in your root directory and specify the following things:

| Property | Type | Default | Format | | -------------- | ------- | ---------- | ------ | | rootPath | string | ./assets | Add the root path to your svg assets relative to your config file. Your svg must then be placed within that root folder in an src directory | | indexFiles | array | [] | Add the path relative to the directory you want to create an index file of. The option will create an index.js file with all the svg/tsx components in this directory | | debug | boolean | false | If you want to log details to your console or not |

Your svg have to be placed within a rootPath/src folder.

{
  "rootPath": "./assets",
  "indexFiles": [
    {
      "path": "bodyTypes",
      "extension": "tsx"
    },
    {
      "path": "badges",
      "extension": "svg"
    }
  ],
  "debug": false
}

Ignore automatically generated folders/files

You may want to ignore the folders and files the package generates automatically and only check in the original files into your git repository. For that, please add the line rootPath/dist/ (e.g. assets/dist or src/assets/dist) to:

  • .gitignore
  • .prettierignore

Configure eslint

eslint can help you to enforce defined rules in your code base. To restrict imports of original svgs so that only minified svgs are used, you can configure eslint as follows:

module.exports = {
    rules: {
        "no-restricted-imports": ["error", { patterns: ["~/assets/src"] } ],
        "no-restricted-modules": ["error", { patterns: ["~/assets/src"] } ]
    }
}

Accessibility

To make your svg accessible, assets-pkg automatically adds you a title tag and an aria-label to the svg that will be picked up by a screen reader. By default, the title tag contains of the file name and the directory where it's located. E.g.:

  • assets/src/instagram.svg -> title = instagram
  • assets/src/badges/verified.svg -> title = verified badge For better browser support, assets-pkg also adds aria-label and role=img.

If you are not happy with the auto-generated result you can pass a title and aria-label to overwrite it:

<BuyerProtectionIcon
      width="32"
      height="32"
      className="text-teal flex-shrink-0"
      title="Title that tells the viewer something meaningful as a tooltip"
      aria-label="Same as title or something else the screen reader should pickup"
/>

Development

npm run build
npm run test

to run unit and integration tests

You can link your local npm package to integrate it with any local project:

cd carforyou-assets-pkg
npm run build

cd carforyou-listings-web
npm link ../carforyou-assets-pkg

Release a new version

New versions are released on the ci using semantic-release as soon as you merge into master. Please make sure your merge commit message adheres to the corresponding conventions.