punctuate
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

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.

Package Sidebar

Install

npm i punctuate

Weekly Downloads

3

Version

1.0.5

License

MIT

Unpacked Size

21 kB

Total Files

9

Last publish

Collaborators

  • liliangrong777