Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface Options {
context: string;
hashPrefix: string;
regExp?: RegExp;
}

type Generator = (localName: string, filepath: string) => string;
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var path = require("path");
* @param {object} options
* @param {string} options.context
* @param {string} options.hashPrefix
* @param {RegExp} options.regExp
* @return {function}
*/
module.exports = function createGenerator(pattern, options) {
Expand Down Expand Up @@ -37,6 +38,7 @@ module.exports = function createGenerator(pattern, options) {
"\x00" +
localName,
context: context,
regExp: options.regExp,
};

var genericName = interpolateName(loaderContext, name, loaderOptions);
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ test("generate distinct hash for the provided hashPrefix", t => {
);
t.end();
});

test("use group matches if regExp was provided", t => {
const generate = genericNames('[1]__[2]', { regExp: /([^/]*)\/([^/]*)$/ })

t.equal(
generate("foo", path.join(__dirname, "test/case/source.css")),
"case__source-css"
);
t.end()
})