-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatHotkey.coffee
68 lines (47 loc) · 1.4 KB
/
formatHotkey.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# @ts-check
import $createList from './createList'
import $length from './length'
import $push from './push'
import $replace from './replace'
import $split from './split'
import $toLowerCase from './toLowerCase'
import $trim from './trim'
$formatKeyFormatHotkey =
###* @type import('../type/module').FormatHotkey1 ###
(key) ->
$listKey = $createList 'string'
$key = $toLowerCase key
$key = $replace $key, ' ', ''
$key = $replace $key, '-', ''
$listSplit = $split $key, '+'
if $length $listSplit then $push $listKey, $listSplit...
return $listKey
$pickPrefixFormatHotkey =
###* @type import('../type/module').FormatHotkey2 ###
(listKey) ->
if ($length listKey) == 1 then return ['', listKey]
$prefix = ''
$listNew = $createList 'string'
for $key in listKey
if $key == 'alt'
$prefix = "#{$prefix}!"
continue
if $key == 'ctrl'
$prefix = "#{$prefix}^"
continue
if $key == 'shift'
$prefix = "#{$prefix}+"
continue
if $key == 'win'
$prefix = "#{$prefix}#"
continue
$push $listNew, $key
return [$prefix, $listNew]
###* @type import('../type/module').FormatHotkey ###
export default (key) ->
$listKey = $formatKeyFormatHotkey key
[$prefix, $listKey] = $pickPrefixFormatHotkey $listKey
$result = ''
for $it in $listKey
$result = "#{$result} & #{$it}"
return $replace "#{$prefix}#{$trim $result, ' &'}", ':', ' '