Skip to content

Commit 541d280

Browse files
committed
feat: implement regExp option
1 parent b53ae2a commit 541d280

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
interface Options {
22
context: string;
33
hashPrefix: string;
4+
regExp?: RegExp;
45
}
56

67
type Generator = (localName: string, filepath: string) => string;

index.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var path = require("path");
88
* @param {object} options
99
* @param {string} options.context
1010
* @param {string} options.hashPrefix
11+
* @param {RegExp} options.regExp
1112
* @return {function}
1213
*/
1314
module.exports = function createGenerator(pattern, options) {
@@ -37,6 +38,7 @@ module.exports = function createGenerator(pattern, options) {
3738
"\x00" +
3839
localName,
3940
context: context,
41+
regExp: options.regExp,
4042
};
4143

4244
var genericName = interpolateName(loaderContext, name, loaderOptions);

test/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ test("generate distinct hash for the provided hashPrefix", t => {
4040
);
4141
t.end();
4242
});
43+
44+
test("use group matches if regExp was provided", t => {
45+
const generate = genericNames('[1]__[2]', { regExp: /([^/]*)\/([^/]*)$/ })
46+
47+
t.equal(
48+
generate("foo", path.join(__dirname, "test/case/source.css")),
49+
"case__source-css"
50+
);
51+
t.end()
52+
})

0 commit comments

Comments
 (0)