Skip to content

Punctuate is a robust library that can be used to replace punctuation. It has no dependencies, only 2kb, easy to use and supports custom symbols. Punctuate 是一个健壮的库,可用于替换标点符号。 它没有依赖,只有 2kb,简单易用,并支持自定义符号。

License

liliangrong777/punctuate

Repository files navigation

Punctuate

Punctuate is a robust library that can be used to replace punctuation. It has no dependencies, only 2kb, easy to use and supports custom symbols.

Usage

You will need Node.js installed on your system.

npm i punctuate -S  
const { replacePunctuateByMap } = require('punctuate')

const text = 'mom said "Knowledge makes humble, ignorance makes proud。"'
const replaceMap = {
  ',': ',',
  '。': '.'
}
const newText = replacePunctuateByMap(text, replaceMap)
console.log(newText); // mom said "Knowledge makes humble, ignorance makes proud."

Or manually download and link punctuate.js in your HTML, It can also be downloaded via UNPKG:

<script src="https://unpkg.com/punctuate/dist/punctuate.js"></script>
<script>
  const { replacePunctuateByMap } = PunctuateReplace
  const text = 'mom said "Knowledge makes humble, ignorance makes proud。"'
  const replaceMap = {
    ',': ',',
    '。': '.'
  }
  const newText = replacePunctuateByMap(text, replaceMap)
  console.log(newText); // mom said "Knowledge makes humble, ignorance makes proud."
</script>

Predefine

If you feel that it is too cumbersome to fill in the mapping, punctuate has built-in mapping table for Chinese and English exchange. You just need to use replacePunctuate to pass the replacement keyword in the second parameter.for example:

const { replacePunctuate, DEFAULT_CHARACTER } = require('punctuate');
const text = 'mom said "Knowledge makes humble, ignorance makes proud。"'
const newText = replacePunctuate(text, 'ZH2EN')
console.log(newText); // mom said "Knowledge makes humble, ignorance makes proud."
console.log(DEFAULT_CHARACTER) // log predefined map

If you want to know which replacement punctuation is predefined, try printing DEFAULT_CHARACTER.

About

Punctuate is a robust library that can be used to replace punctuation. It has no dependencies, only 2kb, easy to use and supports custom symbols. Punctuate 是一个健壮的库,可用于替换标点符号。 它没有依赖,只有 2kb,简单易用,并支持自定义符号。

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published