-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-class-name.js
More file actions
32 lines (29 loc) · 838 Bytes
/
extract-class-name.js
File metadata and controls
32 lines (29 loc) · 838 Bytes
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
(function (root, factory) {
// export this module
if (typeof define === 'function' && define.amd) {
// amd mode
define([], factory);
// define(['depName'], factory);
} else if (typeof module === 'object' && module.exports) {
// cmd mode
module.exports = factory();
// module.exports = factory(require('depName'))
} else {
// browser global: window
root['extractClassName'] = factory();
// root['moduleName'] = factory(root.depName);
}
}(this, function () {
var reg = /(?:class)\s*=\s*['"](.+?)['"]/ig;
return function extractClassName(html) {
var retArr = [];
var raw = reg.exec(html)
while(raw) {
var split = raw[1].trim().split(' ')
retArr = retArr.concat(split)
raw = reg.exec(html)
}
// unique
return Array.from(new Set(retArr));
}
}));