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

react-font-svg

v1.0.1

Published

fonts to react/react-native svg icon components

Downloads

20

Readme

English | 中文

react-font-svg

You can use this tool to convert fonts to react/react-native Icon Components.

Support font formats:

  • ttf
  • woff/woff2
  • otf
  • eot

Usage

npm install -g react-font-svg
react-font-svg ./src/icons/fontawesome-webfont.ttf -d ./src/icons

It will generate Jsx component, contains svg paths(default react-native):

/**
 * @file Icon.js
 * @author 
 */

import React from "react";
import Svg, {Path} from 'react-native-svg';

// icon glyphs
const glyphs = {
    'glass':'M1699 -198 q0 -23 -18 -36.5 q-18 -13.5 -38 -17.5 q-20 -4 -43 -4 l-1408 0 q-23 0 -43 4 q-20 4 -38 17.5 q-18 13.5 -18 36.5 q0 35 43 78 l632 632 l0 768 l-320 0 q-26 0 -45 19 q-19 19 -19 45 q0 26 19 45 q19 19 45 19 l896 0 q26 0 45 -19 q19 -19 19 -45 q0 -26 -19 -45 q-19 -19 -45 -19 l-320 0 l0 -768 l632 -632 q43 -43 43 -78 Z', 
    'ok':'M1643 178 l-136 -136 q-28 -28 -68 -28 q-40 0 -68 28 l-656 657 l-294 -295 q-28 -28 -68 -28 q-40 0 -68 28 l-136 136 q-28 28 -28 68 q0 40 28 68 l362 362 l136 136 q28 28 68 28 q40 0 68 -28 l136 -136 l724 -724 q28 -28 28 -68 q0 -40 -28 -68 Z' 
};

const Icon = props => (
    <Svg width={props.width || 120} height={props.height || 120} viewBox={props.viewBox || "0 -256 1792 1792"}>
        <Path fill={props.color || '#000'} d={glyphs[props.name] || ''}></Path>
    </Svg>
);

export default Icon;

You can use it in React, ReactNative project now:

import React from 'react';
import Icon from './Icon';

export default class App extends React.Component {
    render() {
        return (
            <>
            <Icon name="glass" color="#000" width="100" height="100" viewBox="0 0 1024 1024"/>
            <Icon name="ok" color="#000"/>
            </>
        );
    }
}

Api

const reactFontSvgConverter = require('react-font-svg');

const iconTexts = reactFontSvgConverter(
    './font/iconfont.ttf',
    {
        names: ['music', 'search'],
        unicodes: [0xf001, 0xf002],
        platform: 'react-native'
    });
// output
// {Icon: ''}

Notice

  • React Native project should import react-native-svg modules.
  • Font formats like otf or woff will cause errors in some cases, you can convert to ttf font file before generate.

Options

react-font-svg -h

Usage
    $ react-font-svg <file> [<output>]

  Example
    $ react-font-svg ./src/font.ttf
    $ react-font-svg ./src/font.ttf -n 'music,search' -u '0xf00d,0xf00e' -d ./src/icons


  Options,
    -n, --names                         glyph names to output eg. -n music,search
    -u, --unicodes                      unicode code points to output eg. -u 0xe001,0xe002
    -d, --dest                          output folder
    -p, --platform                      component template: react-native|react

Relative

FontEditor

fonteditor-core