This file contains hidden or 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
| function debounce(fn, delay) { | |
| let timerId = null; | |
| return (...args) => { | |
| clearTimeout(timerId); | |
| timerId = setTimeout(() => { | |
| fn(args) | |
| }, delay) | |
| } | |
| } |
This file contains hidden or 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
| function throttle(fn, delay) { | |
| let lock = false; | |
| return (...args) => { | |
| if (lock) return; | |
| lock = true; | |
| setTimeout(() => { | |
| lock = false; | |
| fn(args) | |
| }, delay) |
This file contains hidden or 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); |
NewerOlder