Skip to content

Commit 818a25b

Browse files
committed
sort plot schema object before writting to file
1 parent 09dfb34 commit 818a25b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tasks/schema.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ var path = require('path');
33

44
var constants = require('./util/constants');
55
var plotlyNode = require('./util/plotly_node');
6+
var sortObject = require('./util/sort_object');
67

78
function makeSchema(plotlyPath, schemaPath) {
89
var Plotly = plotlyNode(plotlyPath);
910

10-
var plotSchema = Plotly.PlotSchema.get();
11+
var plotSchema = sortObject(Plotly.PlotSchema.get());
1112
var plotSchemaStr = JSON.stringify(plotSchema, null, 1);
1213
fs.writeFileSync(schemaPath, plotSchemaStr);
1314

tasks/util/sort_object.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function caseInsensitive(a, b) {
2+
return a.toLowerCase().localeCompare(b.toLowerCase());
3+
}
4+
5+
function sortObject(obj) {
6+
var allKeys = Object.keys(obj);
7+
allKeys.sort(caseInsensitive);
8+
9+
var newObj = {};
10+
for(var i = 0; i < allKeys.length; i++) {
11+
var key = allKeys[i];
12+
var v = obj[key];
13+
newObj[key] = (typeof v === 'object' && v !== null && !(v instanceof Array)) ?
14+
sortObject(v) :
15+
newObj[key] = v;
16+
}
17+
18+
return newObj;
19+
}
20+
21+
module.exports = sortObject;

0 commit comments

Comments
 (0)