Skip to content

Commit fa2c61d

Browse files
committed
Merge pull request #223 from plotly/fix-compress-attributes
Fix compress attributes
2 parents b578058 + 10188d1 commit fa2c61d

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

build/ploticon.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* jshint quotmark:true */
2-
31
'use strict';
42

53
module.exports = {

tasks/util/compress_attributes.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@ var through = require('through2');
55
* of the plotly.js bundles
66
*/
77

8-
var attributeNamesToRemove = [
9-
'description', 'requiredOpts', 'otherOpts', 'hrName', 'role'
10-
];
11-
12-
// ref: http://www.regexr.com/3bj6p
13-
var regexStr = '';
14-
attributeNamesToRemove.forEach(function(attr, i) {
15-
// one line string with or without trailing comma
16-
regexStr += attr + ': \'.*\'' + ',?' + '|';
17-
// array of strings with or without trailing comma
18-
regexStr += attr + ':.*\\n*.*\\.join\\(\\\'\\s\\\'\\)';
19-
20-
// attr:.*\n.*\.join\(\'\s\'\)
21-
22-
if(i !== attributeNamesToRemove.length-1) regexStr += '|';
23-
});
8+
9+
// one line string with or without trailing comma
10+
function makeStringRegex(attr) {
11+
return attr + ': \'.*\'' + ',?';
12+
}
13+
14+
// joined array of strings with or without trailing comma
15+
function makeJoinedArrayRegex(attr) {
16+
return attr + ': \\[[\\s\\S]*?\\]' + '\\.join\\(.*' + ',?';
17+
}
18+
19+
// array with or without trailing comma
20+
function makeArrayRegex(attr) {
21+
return attr + ': \\[[\\s\\S]*?\\]' + ',?';
22+
}
23+
24+
// ref: http://www.regexr.com/3cmac
25+
var regexStr = [
26+
makeStringRegex('description'),
27+
makeJoinedArrayRegex('description'),
28+
makeArrayRegex('requiredOpts'),
29+
makeArrayRegex('otherOpts'),
30+
makeStringRegex('hrName'),
31+
makeStringRegex('role')
32+
].join('|');
2433

2534
var regex = new RegExp(regexStr, 'g');
2635

0 commit comments

Comments
 (0)