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

xy-character

v1.0.0

Published

字符转svg,支持田字格、方格、拼音

Downloads

1

Readme

character

一个可以将字符串转换成 svg 图片的插件,支持田字格、方格、拼音+田字格、拼音+方格、拼音+汉字,解决多端兼容问题。

安装

# 使用 npm
npm install --save-dev xy-character

使用

为保证最终效果,拼音字体建议使用 dist/fonts/pinyin.ttf 下载

拼音

import { Pinyin } from 'xy-character'
const pinyin = new Pinyin()

pinyin.load(['pinyin.ttf', 'kaiti.woff']).then(() => {
    const svg = pinyin.getSVG([
        { pinyin: 'shì', chinese: '示' },
        { pinyin: 'lì', chinese: '例' },
    ])
    document.body.appendChild(svg)
})

拼音田字

import { PinyinTianzi } from 'xy-character'
const pinyinTianzi = new PinyinTianzi()

// 带汉字
pinyinTianzi.load(['pinyin.ttf', 'kaiti.woff']).then(() => {
    const svg = pinyinTianzi.getSVG([
        { pinyin: 'shì', chinese: '示' },
        { pinyin: 'lì', chinese: '例' },
    ])
    document.body.appendChild(svg)
})

// 不带汉字
pinyinTianzi.load(['pinyin.ttf', 'kaiti.woff']).then(() => {
    const svg = pinyinTianzi.getSVG([{ pinyin: 'shì' }, { pinyin: 'lì' }])
    document.body.appendChild(svg)
})

输出

拼音方格

import { PinyinTianzi } from 'xy-character'
const pinyinTianzi = new PinyinTianzi()

// 带汉字
pinyinTianzi.load(['pinyin.ttf', 'kaiti.woff']).then(() => {
    const svg = pinyinTianzi.getSVG(
        [
            { pinyin: 'shì', chinese: '示' },
            { pinyin: 'lì', chinese: '例' },
        ],
        { gridType: 2 }
    )
    document.body.appendChild(svg)
})

// 不带汉字
pinyinTianzi.load(['pinyin.ttf', 'kaiti.woff']).then(() => {
    const svg = pinyinTianzi.getSVG([{ pinyin: 'shì' }, { pinyin: 'lì' }], { gridType: 2 })
    document.body.appendChild(svg)
})

输出

田字格

import { Tianzi } from 'xy-character'
const tianzi = new Tianzi()

// 带汉字
tianzi.load('kaiti.woff').then(() => {
    const svg = tianzi.getSVG('示例')
    document.body.appendChild(svg)
})

// 不带汉字
tianzi.load(['kaiti.woff']).then(() => {
    const svg = tianzi.getSVG(2)
    document.body.appendChild(svg)
})

输出

方格

import { Tianzi } from 'xy-character'
const tianzi = new Tianzi()

// 带汉字
tianzi.load('kaiti.woff').then(() => {
    const svg = tianzi.getSVG('示例', { gridType: 2 })
    document.body.appendChild(svg)
})

// 不带汉字
tianzi.load(['kaiti.woff']).then(() => {
    const svg = tianzi.getSVG(2, { gridType: 2 })
    document.body.appendChild(svg)
})

输出

Character.Pinyin

load(url: string[], callback: (err, data?) => {}, options: object): Promise

加载字体文件。异步方法,返回 Promise,使用 getSVG 方法前调用

getSVG(text: Array<{pinyin:string, chinese?:string}>, options?: { attrs?: object }): SVGElement

获取生成的 svg 节点

Character.PinyinTianzi

load(url: string[], callback: (err, data?) => {}, options: object): Promise

加载字体文件。异步方法,返回 Promise,使用 getSVG 方法前调用

getSVG(text: Array<{pinyin:string, chinese?:string}>, options?: { attrs?: object, gridType: 1|2 }): SVGElement

获取生成的 svg 节点

Character.Tianzi

load(url: string, callback: (err, data?) => {}, options: object): Promise

加载字体文件。异步方法,返回 Promise,使用 getSVG 方法前调用

getSVG(text: Array<{pinyin:string, chinese?:string}>, options?: { attrs?: object, gridType: 1|2 }): SVGElement

获取生成的 svg 节点

依赖

学习交流

微信号:meng_xianghan

或使用微信扫以下二维码加为好友

感谢