-
Notifications
You must be signed in to change notification settings - Fork 61
/
checkAlphabeticalOrder.js
35 lines (28 loc) · 1012 Bytes
/
checkAlphabeticalOrder.js
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
import { shorthandData } from './shorthandData.js';
import * as vendor from '../utils/vendor.js';
function isShorthand(a, b) {
const longhands = shorthandData[a] || [];
return longhands.includes(b);
}
export function checkAlphabeticalOrder(firstPropData, secondPropData) {
// OK if the first is shorthand for the second:
if (isShorthand(firstPropData.unprefixedName, secondPropData.unprefixedName)) {
return true;
}
// Not OK if the second is shorthand for the first:
if (isShorthand(secondPropData.unprefixedName, firstPropData.unprefixedName)) {
return false;
}
// If unprefixed prop names are the same, compare the prefixed versions
if (firstPropData.unprefixedName === secondPropData.unprefixedName) {
// If first property has no prefix and second property has prefix
if (
!vendor.prefix(firstPropData.name).length &&
vendor.prefix(secondPropData.name).length
) {
return false;
}
return true;
}
return firstPropData.unprefixedName < secondPropData.unprefixedName;
}