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

codify-images

v3.0.1

Published

Quick and easy tool for converting a set of images into inline JavaScript

Downloads

442

Readme

Codify Images

License Version Release Coverage Node Version

Quick and easy tool for converting a set of images into inline JavaScript.

Installation

npm i -D codify-images

Usage

There are 2 uses of this package either as a library or a command line interface (CLI).

Library

An example of typical usage as a library can be found below.

import { codifyImages, codifyImagesSync } from 'codify-images';

const options = {
  svgMode: 'base64',
  ignoreUnsupportedTypes: true,
  log: (name, path) => {...}
};
let images = await codifyImages('path/to/assets', options); // asynchronous

images = codifyImagesSync('path/to/assets', options); // synchronous

The images object returned will have a member for each file, of supported type, found at the location path/to/assets formatted as camel case. Assuming path/to/assets has 3 files in that location (test.gif, test.png and test.svg) the resulting images would look like the following.

const images = {
  testGif: 'data:image/gif;base64,...',
  testPng: 'data:image/png;base64,...',
  testSvg: 'data:image/svg+xml;base64,...'
};

Options

  • svgMode: Allows you to supply the mode that will be used to generate SVG outputs. The current options are base64, uri, mini, mini-srcset. The default for this setting is base64 and is the recommended setting as it has the highest compatibility with different use cases. For more info related to the mini and mini-srcset modes please consult the Mini SVG Data package documentation.
  • ignoreUnsupportedTypes: This will allow files of unsupported types to be simply skipped instead of throwing an UnsupportedTypeError error. The default for this setting is true.
  • log: This allows you to add a custom logger that will be called after each file is processed. The callback provides the arguments name and path.

CLI

Below is the output of codify-images --help.

Usage: codify-images [options] <input path>

Arguments:
  input path                  path to where image files reside

Options:
  -V, --version               output the version number
  -d, --double-quotes         Use double quotes for output instead of single quotes (default: false)
  -o, --output <path>         path to write generated files (default: "generated")
  -e, --es <version>          version of ESM to generate (default: 6)
  -c, --indent-count <count>  number of indent elements to output (default: 1)
  -B, --no-banner             do not include banner comment at top of generated file
  -t, --indent-type <type>    type of indent to output (choices: "tab", "space", default: "tab")
  -s, --svg-mode <mode>       output mode to use for SVG images
                              (choices: "base64", "uri", "mini", "mini-srcset", default: "base64")
  -h, --help                  display help for command

Development

Development can be done on any machine that can install Node.js. Only the latest LTS version is tested against.

Install Dependencies

Install dependencies via npm.

npm i

Linting

Execute linters via npm.

# git, javascript, markdown and package.json
npm run lint

# git only
npm run lint:git

# javascript only
npm run lint:js

# markdown only
npm run lint:md

# package.json only
npm run lint:pkg

Testing

Execute tests via npm.

# lint and unit tests
npm test

# unit tests only
npm run test:unit

Fixing

Execute fixers via npm.

# javascript, markdown and package.json
npm run fix

# javascript only
npm run fix:js

# markdown only
npm run fix:md

# package.json only
npm run fix:pkg

Building

Run a build via npm.

npm run build