Code Monkey home page Code Monkey logo

zhconver's Introduction

zhconver

Convert between Simplified Chinese and Traditional Chinese

  • No dependencies.
  • Support for running in browsers and node.
  • Support for modifying conversion characters.
  • Support Type Tips.
  • Small volume ( 15~20kB ).

Install

npm install zhconver --save

browsers

<!-- 15~20kB: This js file contains simplified and traditional Chinese mapping table -->
<script src="https://cdn.jsdelivr.net/npm/zhconver/dist/zhconver.js"></script>
<script>
  console.log(zhconver)
  // => { Trie, conver, s2t, t2s }
</script>
<!-- Or ES Module -->
<script type="module">
  import * as zhconver from 'https://cdn.jsdelivr.net/npm/zhconver/dist/esm/zhconver.mjs'
  console.log(zhconver)
  // => { Trie, conver, s2t, t2s }
</script>

<!-- 1kB: If you want to customize the simplified and traditional mapping tables, you can introduce js files that contain only processing functions -->
<script src="https://cdn.jsdelivr.net/npm/zhconver/dist/conver.js"></script>
<script>
  console.log(conver)
  // => { Trie, conver }
</script>
<!-- Or ES Module -->
<script type="module">
  import * as conver from 'https://cdn.jsdelivr.net/npm/zhconver/dist/esm/conver.mjs'
  console.log(conver)
  // => { Trie, conver }
</script>

CommonJS

// No Simplified and Traditional Chinese mapping table
const { Trie, conver } = require('zhconver')

// With Simplified and Traditional Chinese Mapping Table
const { Trie, conver, s2t, t2s } = require('zhconver/zhconver')

ES Modules

// No Simplified and Traditional Chinese mapping table
import { Trie, conver } from 'zhconver'

// With Simplified and Traditional Chinese Mapping Table
import { Trie, conver, s2t, t2s } from 'zhconver/zhconver'

Usage

s2t

console.log(s2t('这是一段简体字'))
// => '這是壹段簡體字'

t2s

console.log(t2s('這是壹段簡體字'))
// => '这是一段简体字'

conver + Trie

const trie = new Trie()
trie.add('香蕉', '🍌')
trie.add('草莓', '🍓')
trie.add('芒果', '🥭')
console.log(conver('我最喜欢吃的水果是香蕉和草莓', trie))
// => '我最喜欢吃的水果是🍌和🍓'

zhconver's People

Contributors

lete114 avatar

Stargazers

 avatar  avatar

Watchers

 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.