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

fonteditor-core

v2.4.1

Published

fonts (ttf, woff, woff2, eot, svg, otf) parse, write, transform, glyph adjust.

Downloads

67,648

Readme

fonteditor-core

FontEditor core functions

NPM version Downloads

Feature

Read and write sfnt font like ttf, woff, woff2, eot, svg, otf.

  • sfnt parse
  • read, write, transform fonts
    • ttf (read and write)
    • woff (read and write)
    • woff2 (read and write)
    • eot (read and write)
    • svg (read and write)
    • otf (only read and convert to ttf)
  • ttf glyph adjust
  • svg to glyph

Usage

// read font file
import {Font} from 'fonteditor-core';
import fs from 'fs';

const buffer = fs.readFileSync('font.ttf');
// read font data, support format:
// - for ttf, otf, woff, woff2, support ArrayBuffer, Buffer
// - for svg, support string or Document(parsed svg)
const font = Font.create(buffer, {
    // support ttf, woff, woff2, eot, otf, svg
    type: 'ttf',
    // only read `a`, `b` glyphs
    subset: [65, 66],
    // read font hinting tables, default false
    hinting: true,
    // read font kerning tables, default false
    kerning: true,
    // transform ttf compound glyph to simple
    compound2simple: true,
    // inflate function for woff
    inflate: undefined,
    // for svg path
    combinePath: false,
});
const fontObject = font.get();
console.log(Object.keys(fontObject));

/* => [ 'version',
  'numTables',
  'searchRenge',
  'entrySelector',
  'rengeShift',
  'head',
  'maxp',
  'glyf',
  'cmap',
  'name',
  'hhea',
  'post',
  'OS/2',
  'fpgm',
  'cvt',
  'prep'
]
*/

// write font file
const buffer = font.write({
    // support ttf, woff, woff2, eot, svg
    type: 'woff',
    // save font hinting tables, default false
    hinting: false,
    // save font kerning tables, default false
    kerning: false,
    // write glyf data when simple glyph has no contours, default false
    writeZeroContoursGlyfData: false,
    // deflate function for woff, eg. pako.deflate
    deflate: undefined,
    // for user to overwrite head.xMin, head.xMax, head.yMin, head.yMax, hhea etc.
    support: {head: {}, hhea: {}}
});
fs.writeFileSync('font.woff', buffer);

// to base64 str
font.toBase64({
    // support ttf, woff, woff2, eot, svg
    type: 'ttf'
});

// optimize glyphs
font.optimize()

// compound2simple
font.compound2simple()

// sort glyphs
font.sort()

// find glyphs
const result = font.find({
  unicode: [65]
});

const result = font.find({
  filter: function (glyf) {
    return glyf.name === 'icon'
  }
});

// merge another font object
font.merge(font1, {
  scale: 1
});

woff2

Notice: woff2 use wasm build of google woff2, before read and write woff2, we should first call woff2.init().

import {Font, woff2} from 'fonteditor-core';

// in nodejs
woff2.init().then(() => {
    // read woff2
    const font =  Font.create(buffer, {
      type: 'woff2'
    });
    // write woff2
    const buffer = font.write({type: 'woff2'});
});

// in browser
woff2.init('/assets/woff2.wasm').then(() => {
    // read woff2
    const font = Font.createEmpty();
    // write woff2
    const arrayBuffer = font.write({type: 'woff2'});
});

Demo

npm run dev

build

npm run build

test

npm run test

support

Node.js:>= 12.0

Browser: Chrome, Safari

Related

License

MIT © Fonteditor