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); |
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
| 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 curry(fn) { | |
| return function curried(...args) { | |
| if (fn.length === args.length) { | |
| return fn.apply(this, args); | |
| } | |
| return (...extraArgs) => { | |
| return curried.apply(this, args.concat(extraArgs)); | |
| }; | |
| }; | |
| } |
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
| abstract class CustomStorage { | |
| abstract storage: any; | |
| abstract getItem<T>(key: string): T | null; | |
| abstract setItem(key: string, value: any): void; | |
| abstract removeItem(key: string): void; | |
| abstract clear(): void; | |
| getItemAndDelete<T>(key: string): T | null { |
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
| class EventBus { | |
| constructor() { | |
| this.eventMap = {} | |
| this.onceEventMap = {} | |
| } | |
| on(eventName, listener) { | |
| if (!this.eventMap[eventName]) { | |
| this.eventMap[eventName] = [listener] | |
| } else { |
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 deepCopySimple(obj) { | |
| return JSON.parse(JSON.stringify(obj)); | |
| } | |
| function deepClone(obj) { | |
| if (typeof obj !== 'object') return obj; | |
| const newObj = obj instanceof Array ? [] : {}; | |
| for (let key of Object.keys(obj)) { | |
| if (typeof obj[key] !== 'object') { |
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 shallowClone(obj) { | |
| if (typeof obj !== 'object') return obj; | |
| const newObj = obj instanceof Array ? [] : {}; | |
| for (let key of Object.keys(obj)) { | |
| newObj[key] = obj[key]; | |
| } | |
| return newObj; | |
| } |
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
| class Node<T> { | |
| value: T | |
| next?: Node<T> | |
| constructor(value: T) { | |
| this.value = value | |
| } | |
| } | |
| class Queue<T> { | |
| private _size = 0 |
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
| import React from 'react'; | |
| const genContainer = | |
| (name: string): React.FC => | |
| ({ children }) => | |
| ( | |
| <div> | |
| <h1>I'm {name}</h1> | |
| <div style={{ paddingLeft: '10px' }}>{children}</div> | |
| </div> |
OlderNewer