Skip to content

Commit 956787f

Browse files
committed
feat: add removeUnfound class/id/attrs, close #44, close #34
1 parent 7d77c7a commit 956787f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const selectorParser = require('postcss-selector-parser');
55
const nameGenerators = require('./name-generators');
66

77
class MinifyClassnames {
8-
constructor({genNameClass, genNameId, filter, customAttributes = []} = {}) {
8+
constructor({genNameClass, genNameId, filter, customAttributes = [], removeUnfound = true} = {}) {
99
this.filter = filter || /^.js-/;
1010
// TODO: Pass a seed for emojinamestring, make this better
1111
this.genNameClass = this.getNameGenerator(genNameClass, 7);
1212
this.genNameId = this.getNameGenerator(genNameId, 5);
1313
this.classMap = {};
1414
this.idMap = {};
1515
this.customAttributes = customAttributes;
16+
this.removeUnfound = removeUnfound;
1617
}
1718

1819
getNameGenerator(value, seed) {
@@ -75,7 +76,7 @@ class MinifyClassnames {
7576
return value;
7677
}
7778

78-
return this.classMap[value] || '';
79+
return this.classMap[value] || (this.removeUnfound ? '' : value);
7980
})
8081
.filter(Boolean)
8182
.join(' ')
@@ -93,7 +94,7 @@ class MinifyClassnames {
9394
return value;
9495
}
9596

96-
return this.classMap[value] || '';
97+
return this.classMap[value] || (this.removeUnfound ? '' : value);
9798
})
9899
.filter(Boolean)
99100
.join(' ')
@@ -109,11 +110,11 @@ class MinifyClassnames {
109110
return value;
110111
}
111112

112-
if (!this.idMap[value]) {
113+
if (!this.idMap[value] && this.removeUnfound) {
113114
this.idMap[value] = this.genNameId.next().value;
114115
}
115116

116-
return this.idMap[value];
117+
return this.idMap[value] || (this.removeUnfound ? '' : value);
117118
})
118119
.join(' ');
119120
}

0 commit comments

Comments
 (0)