/
githubmirror
/
hyper
Обзор
Документация
Войти
/
githubmirror
/
hyper
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
v3.2.2
app/utils/map-keys.ts
41 строка
1 KB
Labhansh Agrawal
fix prettier errors
25 мар 2020, 19:12
25 мар 2020, 19:12
41b1ac1
Код
Авторство
О чём код?
const generatePrefixedCommand = (command: string, shortcuts: string[]) => { const result: Record<string, string[]> = {}; const baseCmd = command.replace(/:prefix$/, ''); for (let i = 1; i <= 9; i++) { // 9 is a special number because it means 'last' const index = i === 9 ? 'last' : i; const prefixedShortcuts = shortcuts.map((shortcut) => `${shortcut}+${i}`); result[`${baseCmd}:${index}`] = prefixedShortcuts; } return result; }; export default (config: Record<string, string[] | string>) => { return Object.keys(config).reduce((keymap: Record<string, string[]>, command: string) => { if (!command) { return keymap; } // We can have different keys for a same command. const _shortcuts = config[command]; const shortcuts = Array.isArray(_shortcuts) ? _shortcuts : [_shortcuts]; const fixedShortcuts: string[] = []; shortcuts.forEach((shortcut) => { let newShortcut = shortcut; if (newShortcut.indexOf('cmd') !== -1) { // Mousetrap use `command` and not `cmd` console.warn('Your config use deprecated `cmd` in key combination. Please use `command` instead.'); newShortcut = newShortcut.replace('cmd', 'command'); } fixedShortcuts.push(newShortcut); }); if (command.endsWith(':prefix')) { return Object.assign(keymap, generatePrefixedCommand(command, fixedShortcuts)); } keymap[command] = fixedShortcuts; return keymap; }, {}); };