JavaScript 中英文标点转换
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const en = ["\"", "'", ",", ".", "?", "!", "(", ")", "[", "]", "{", "}", ";"]; | |
const cn = ["“", "‘", ",", "。", "?", "!", "(", ")", "【", "】", "「", "」", ";"]; | |
const converter = (source, from, target) => { | |
const map = new Map(from.map((item, index) => [item, target[index]])); | |
return source.split('').map(item => map.get(item) || item).join('') | |
}; | |
export const cn2enSymbol = (source) => converter(source, cn, en); | |
export const en2cnSymbol = (source) => converter(source, en, cn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment