Skip to content

Instantly share code, notes, and snippets.

@vv13
Last active November 22, 2021 16:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
JavaScript 中英文标点转换
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