Skip to content

Commit d84d2e6

Browse files
committed
possibility to specify the string pattern
1 parent 67d7bff commit d84d2e6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ export default function setup(opts = {}) {
6868
}
6969

7070
terminalPlugins = get('append', null, 'array', opts) || [];
71-
generateScopedName = get('generateScopedName', null, 'function', opts)
72-
|| genericNames('[name]__[local]___[hash:base64:5]', {context: rootDir});
7371
const prepend = get('prepend', null, 'array', opts) || [];
7472
const mode = get('mode', null, 'string', opts);
7573
const createImportedName = get('createImportedName', null, 'function', opts);
74+
const scopeOption = get('generateScopedName', null, ['function', 'string'], opts)
75+
|| genericNames('[name]__[local]___[hash:base64:5]', {context: rootDir});
76+
generateScopedName = typeof scopeOption === 'string'
77+
? genericNames(scopeOption, {context: rootDir})
78+
: scopeOption;
7679

7780
plugins = [
7881
...prepend,

src/utility.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ const check = {
1818
*/
1919
export function get(prop, aliases, type, source) {
2020
if (source[prop]) {
21+
if (isArray(type)) {
22+
if (type.some(tp => is(tp, source[prop]))) {
23+
return source[prop];
24+
}
25+
26+
throw new Error(format('should specify %s for %s', type.join('|'), prop));
27+
}
28+
2129
if (!is(type, source[prop])) {
2230
throw new Error(format('should specify %s for %s', type, prop));
2331
}

0 commit comments

Comments
 (0)