Git Product home page Git Product logo

webfont's Introduction

webfont

NPM version Travis Build Status Build status dependencies Status devDependencies Status

Generator of fonts from SVG icons.

Features:

  • Supported font formats: WOFF2, WOFF, EOT, TTF and SVG.
  • Support configuration Files - use a JavaScript, JSON or YAML file to specify configuration information for an entire directory and all of its subdirectories.
  • Supported browsers: IE8+.
  • Allows to use custom templates (example css, scss and etc).
  • No extra dependencies as gulp, grunt or other big tools.
  • Tested on all platforms (linux, windows and osx).
  • CLI.
  • Webpack plugin.

Install

npm install --save-dev webfont

Usage

const webfont = require("webfont").default;

webfont({
  files: "src/svg-icons/**/*.svg",
  fontName: "my-font-name"
})
  .then(result => {
    console.log(result);

    return result;
  })
  .catch(error => {
    throw error;
  });

Or

import webfont from "webfont";

webfont({
  files: "src/svg-icons/**/*.svg",
  fontName: "my-font-name"
})
  .then(result => {
    console.log(result);

    return result;
  })
  .catch(error => {
    throw error;
  });

Options

files

A file glob, or array of file globs. Ultimately passed to fast-glob to figure out what files you want to get.

node_modules and bower_components are always ignored.

configFile

A webfont configuration object.

fontName

Type: String Default: webfont

The font family name you want.

###ย formats

Type: Array Default value: ['svg', 'ttf', 'eot', 'woff', 'woff2'] Possible values: svg, ttf, eot, woff, woff2.

Font file types to generate.

template

Type: string Default: null

Possible values: css, scss (feel free to contribute). If you want to use custom template use this option. Example: template: path.resolve(__dirname, './my-template.css').

templateClassName

Type: string Default: null

Default font class name.

templateFontPath

Type: string Default: ./

Path to generated fonts in the CSS file.

templateFontName

Type: string

Default value getting from fontName options, but you can specify any value.

glyphTransformFn

Type: function Default: null

If you need transform glyph metadata (e.g. titles of CSS classes) before transferred in style template for your icons, you can use this option with glyphs metadata object.

Example:

import webfont from "webfont";

webfont({
  files: "src/svg-icons/**/*.svg",
  glyphTransformFn: obj => {
    obj.name += "_transform";

    return obj;
  }
})
  .then(result => {
    console.log(result);

    return result;
  })
  .catch(error => {
    throw error;
  });

sort

Type: bool Default: true

Default the icons are sorted by name, do not sort by setting this to false

fontId

fontStyle

fontWeight

fixedWidth

centerHorizontally

normalize

fontHeight

round

descent

ascent

startUnicode

prependUnicode

Options that are passed directly to svgicons2svgfont. Option fontName for svgicons2svgfont taken from above fontName argument.

Command Line Interface

The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.

Usage

webfont --help prints the CLI documentation.

Exit codes

The CLI can exit the process with the following exit codes:

  • 0: All ok.
  • 1: Something unknown went wrong.
  • Other: related to using packages.

Related

Roadmap

  • The ability to generate from any type to any type.
  • More tests, include CLI test.
  • Improved docs.
  • Reduce package size (maybe implement ttf2woff2 with native js library).
  • Improve performance (maybe use cache for this).

Contribution

Feel free to push your code if you agree with publishing under the MIT license.

webfont's People

Contributors

alexander-akait avatar ediblecode avatar evilebottnawi avatar greenkeeper[bot] avatar gustavobcx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.