avil13-co 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ask.js +14 -2
- package/package.json +1 -1
- package/src/ask.ts +21 -5
package/dist/ask.js
CHANGED
|
@@ -18,7 +18,10 @@ const ask = async (message, choices) => {
|
|
|
18
18
|
name: 'branch',
|
|
19
19
|
message,
|
|
20
20
|
source(answersSoFar, input = '') {
|
|
21
|
-
|
|
21
|
+
let list = choices.filter(choiceItem => checkItem(choiceItem, input));
|
|
22
|
+
list = list.sort((a, b) => {
|
|
23
|
+
return sortOrder(input, a, b);
|
|
24
|
+
});
|
|
22
25
|
return Promise.resolve(list);
|
|
23
26
|
}
|
|
24
27
|
});
|
|
@@ -27,7 +30,16 @@ const ask = async (message, choices) => {
|
|
|
27
30
|
exports.ask = ask;
|
|
28
31
|
//
|
|
29
32
|
function checkItem(item, filterString) {
|
|
30
|
-
const reg =
|
|
33
|
+
const reg = getRegExp(filterString);
|
|
31
34
|
return reg.test(item);
|
|
32
35
|
}
|
|
33
36
|
exports.checkItem = checkItem;
|
|
37
|
+
function sortOrder(searchString, name1, name2) {
|
|
38
|
+
if (name2.includes(searchString)) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
function getRegExp(filterString) {
|
|
44
|
+
return new RegExp(filterString.split('').map(s => s.trim()).filter(Boolean).join('.*').replace('.*.*', '.*'), 'gi');
|
|
45
|
+
}
|
package/package.json
CHANGED
package/src/ask.ts
CHANGED
|
@@ -18,7 +18,11 @@ export const ask = async (message: string, choices: string[]) => {
|
|
|
18
18
|
name: 'branch',
|
|
19
19
|
message,
|
|
20
20
|
source(answersSoFar, input = '') {
|
|
21
|
-
|
|
21
|
+
let list = choices.filter(choiceItem => checkItem(choiceItem, input));
|
|
22
|
+
|
|
23
|
+
list = list.sort((a, b) => {
|
|
24
|
+
return sortOrder(input, a, b);
|
|
25
|
+
});
|
|
22
26
|
|
|
23
27
|
return Promise.resolve(list);
|
|
24
28
|
}
|
|
@@ -28,12 +32,24 @@ export const ask = async (message: string, choices: string[]) => {
|
|
|
28
32
|
};
|
|
29
33
|
|
|
30
34
|
//
|
|
31
|
-
|
|
32
35
|
export function checkItem(item: string, filterString: string): boolean {
|
|
33
|
-
const reg =
|
|
36
|
+
const reg = getRegExp(filterString);
|
|
37
|
+
|
|
38
|
+
return reg.test(item);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function sortOrder(searchString: string, name1: string, name2: string): number {
|
|
42
|
+
if (name2.includes(searchString)) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return 1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
function getRegExp(filterString: string) {
|
|
51
|
+
return new RegExp(
|
|
34
52
|
filterString.split('').map(s => s.trim()).filter(Boolean).join('.*').replace('.*.*', '.*'),
|
|
35
53
|
'gi',
|
|
36
54
|
);
|
|
37
|
-
|
|
38
|
-
return reg.test(item);
|
|
39
55
|
}
|