Quick and easy tool for converting a set of images into inline JavaScript
npm install codify-images[![License][License Badge]](LICENSE)
[![Version][Version Badge]][Version Package]
[![Release][Release Badge]][Release Workflow]
[![Coverage][Coverage Badge]][Coverage Report]
[![Node Version][Node Version Badge]](package.json#L75)
Quick and easy tool for converting a set of images into inline JavaScript.
``console`
npm i -D codify-images
There are 2 uses of this package either as a library or a command line interface
(CLI).
An example of typical usage as a library can be found below.
`js
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 supportedpath/to/assets
type, found at the location formatted as camel case. Assumingpath/to/assets has 3 files in that location (test.gif, test.png andtest.svg) the resulting images would look like the following.
`js`
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 SVGbase64
outputs. The current options are , uri, mini, mini-srcset. Thebase64
default for this setting is and is the recommended setting as it hasmini
the highest compatibility with different use cases. For more info related to
the and mini-srcset modes please consult the [Mini SVG Data] packageignoreUnsupportedTypes
documentation.
* : This will allow files of unsupported types to beUnsupportedTypeError
simply skipped instead of throwing an error. Thetrue
default for this setting is .log
* : This allows you to add a custom logger that will be called after eachname
file is processed. The callback provides the arguments and path.
Below is the output of codify-images --help.
`console
Usage: codify-images [options]
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
-e, --es
-c, --indent-count
-B, --no-banner do not include banner comment at top of generated file
-t, --indent-type
-s, --svg-mode
(choices: "base64", "uri", "mini", "mini-srcset", default: "base64")
-h, --help display help for command
`
Development can be done on any machine that can install Node.js. Only the
latest LTS version is tested against.
Install dependencies via npm.
`console`
npm i
Execute linters via npm.
`consolegit, javascript, markdown and package.json
npm run lint
$3
Execute tests via
npm.`console
lint and unit tests
npm testunit tests only
npm run test:unit
`$3
Execute fixers via
npm.`console
javascript, markdown and package.json
npm run fixjavascript only
npm run fix:jsmarkdown only
npm run fix:mdpackage.json only
npm run fix:pkg
`$3
Run a build via
npm.`console
npm run build
``
[License Badge]: https://img.shields.io/github/license/devpow112/codify-images?label=License
[Version Badge]: https://img.shields.io/npm/v/codify-images?label=Version
[Version Package]: https://www.npmjs.com/codify-images
[Node Version Badge]: https://img.shields.io/node/v/codify-images
[Release Badge]: https://github.com/devpow112/codify-images/actions/workflows/release.yml/badge.svg?branch=main
[Release Workflow]: https://github.com/devpow112/codify-images/actions/workflows/release.yml?query=branch%3Amain
[Coverage Badge]: https://img.shields.io/coveralls/github/devpow112/codify-images/main?label=Coverage
[Coverage Report]: https://coveralls.io/github/devpow112/codify-images?branch=main
[Mini SVG Data]: https://www.npmjs.com/package/mini-svg-data-uri