1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const lodash_1 = require("lodash");
|
4 | exports.alphabetical = (targetVal, opts) => {
|
5 | const results = [];
|
6 | if (!targetVal) {
|
7 | return results;
|
8 | }
|
9 | let targetArray = targetVal;
|
10 | if (!Array.isArray(targetVal)) {
|
11 | targetArray = Object.keys(targetVal);
|
12 | }
|
13 | const copiedArray = targetArray.slice();
|
14 | if (copiedArray.length < 2) {
|
15 | return results;
|
16 | }
|
17 | const { keyedBy } = opts;
|
18 | if (keyedBy) {
|
19 | copiedArray.sort((a, b) => {
|
20 | if (typeof a !== 'object') {
|
21 | return 0;
|
22 | }
|
23 | if (a[keyedBy] < b[keyedBy]) {
|
24 | return -1;
|
25 | }
|
26 | else if (a[keyedBy] > b[keyedBy]) {
|
27 | return 1;
|
28 | }
|
29 | return 0;
|
30 | });
|
31 | }
|
32 | else {
|
33 | copiedArray.sort();
|
34 | }
|
35 | if (!lodash_1.isEqual(targetArray, copiedArray)) {
|
36 | results.push({
|
37 | message: 'properties are not in alphabetical order',
|
38 | });
|
39 | }
|
40 | return results;
|
41 | };
|
42 |
|
\ | No newline at end of file |