1.0.0 • Published 6 years ago

material-icon-convert v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Material icon converter

npm version node dependencies build status coverage status github issues

A simple utility to quickly replace ligature format Material Design icons to their unicode characters. This allows you to develop using the legible ligature format yet deploy your code using unicode characters for support in crappy browsers Edge.

Installation

# Using npm
npm install material-icon-convert

# Using yarn
yarn add material-icon-convert

Basic usage

//Load the library and specify options
const convert = require('material-icon-convert');
const options = {
  files: 'path/to/files/**/*.html',
  className: 'material-icons',
  inverse: false, //Specify true to convert from character code to ligatures
};

Asynchronous replacement with promises

convert(options)
  .then(changes => {
    console.log('Modified files:', changes.join(', '));
  })
  .catch(error => {
    console.error('Error occurred:', error);
  });

Asynchronous replacement with callback

convert(options, (error, changes) => {
  if (error) {
    return console.error('Error occurred:', error);
  }
  console.log('Modified files:', changes.join(', '));
});

Synchronous replacement

try {
  const changes = convert.sync(options);
  console.log('Modified files:', changes.join(', '));
}
catch (error) {
  console.error('Error occurred:', error);
}

Return value

The return value of the library is an array of file names of files that were modified (e.g. had some of the contents replaced). If no replacements were made, the return array will be empty.

const changes = convert.sync({
  files: 'path/to/files/**/*.html',
  className: 'material-design',
});

console.log(changes);

// [
//   'path/to/files/file1.html',
//   'path/to/files/file3.html',
//   'path/to/files/file5.html',
// ]

Advanced usage

This library uses replace-in-file under the hood to make the replacements, so check out that package for more advanced usage options.

License

(MIT License)

Copyright 2015-2017, Adam Reis