| 1441 |
ariadna |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* The note types.
|
|
|
18 |
*
|
|
|
19 |
* Matches the suggested order in https://keepachangelog.com/en/1.1.0/.
|
|
|
20 |
* @type {Object<string, string>}
|
|
|
21 |
*/
|
|
|
22 |
const noteTypes = {
|
|
|
23 |
'improved': 'Added',
|
|
|
24 |
'changed': 'Changed',
|
|
|
25 |
'deprecated': 'Deprecated',
|
|
|
26 |
'removed': 'Removed',
|
|
|
27 |
'fixed': 'Fixed',
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* The preferred order of note types.
|
|
|
32 |
*
|
|
|
33 |
* @type {string[]}
|
|
|
34 |
*/
|
|
|
35 |
const preferredOrder = Object.keys(noteTypes);
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Comparison method to sort note types.
|
|
|
39 |
*
|
|
|
40 |
* @param {String} a
|
|
|
41 |
* @param {String} b
|
|
|
42 |
* @returns {Number}
|
|
|
43 |
*/
|
|
|
44 |
export const sortNoteTypes = (a, b) => {
|
|
|
45 |
const aIndex = preferredOrder.indexOf(a);
|
|
|
46 |
const bIndex = preferredOrder.indexOf(b);
|
|
|
47 |
|
|
|
48 |
if (aIndex === -1) {
|
|
|
49 |
return 1;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
if (bIndex === -1) {
|
|
|
53 |
return -1;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
return aIndex - bIndex;
|
|
|
57 |
};
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Get the note names.
|
|
|
61 |
*
|
|
|
62 |
* @returns {string[]}
|
|
|
63 |
*/
|
|
|
64 |
export const getNoteNames = () => Object.keys(noteTypes);
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Get the human-readable note name.
|
|
|
68 |
*
|
|
|
69 |
* @param {string} type
|
|
|
70 |
* @returns {string}
|
|
|
71 |
*/
|
|
|
72 |
export const getNoteName = (type) => noteTypes[type];
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Whether the note name is valid.
|
|
|
76 |
*
|
|
|
77 |
* @param {string} type
|
|
|
78 |
* @returns {boolean}
|
|
|
79 |
*/
|
|
|
80 |
export const isValidNoteName = (type) => noteTypes[type] !== undefined;
|