codify-images v3.0.3
Codify Images
Quick and easy tool for converting a set of images into inline JavaScript.
Installation
npm i -D codify-imagesUsage
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); // synchronousThe 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 themodethat will be used to generate SVG outputs. The current options arebase64,uri,mini,mini-srcset. The default for this setting isbase64and is the recommended setting as it has the highest compatibility with different use cases. For more info related to theminiandmini-srcsetmodes please consult the Mini SVG Data package documentation.ignoreUnsupportedTypes: This will allow files of unsupported types to be simply skipped instead of throwing anUnsupportedTypeErrorerror. The default for this setting istrue.log: This allows you to add a custom logger that will be called after each file is processed. The callback provides the argumentsnameandpath.
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 commandDevelopment
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 iLinting
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:pkgTesting
Execute tests via npm.
# lint and unit tests
npm test
# unit tests only
npm run test:unitFixing
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:pkgBuilding
Run a build via npm.
npm run build11 months ago
12 months ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago