Skip to content

Commit 9bee782

Browse files
Merge pull request #26 from pascalduez/features/hashprefix-option
Add the hashPrefix option
2 parents fe80fc5 + a3bd227 commit 9bee782

File tree

7 files changed

+34
-4
lines changed

7 files changed

+34
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ npm install --save-dev babel-plugin-css-modules-transform
7070
"generateScopedName": "[name]__[local]___[hash:base64:5]", // in case you don't want to use a function
7171
"generateScopedName": "./path/to/module-exporting-a-function.js", // in case you want to use a function
7272
"generateScopedName": "npm-module-name",
73+
"hashPrefix": "string",
7374
"ignore": "*css",
7475
"ignore": "./path/to/module-exporting-a-function-or-regexp.js",
7576
"preprocessCss": "./path/to/module-exporting-a-function.js",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"homepage": "https://github.com/michalkvasnicak/babel-plugin-css-modules-transform#readme",
2727
"dependencies": {
28-
"css-modules-require-hook": "^4.0.2",
28+
"css-modules-require-hook": "^4.0.3",
2929
"mkdirp": "^0.5.1"
3030
},
3131
"devDependencies": {

src/options_resolvers/hashPrefix.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { isString } from '../utils';
2+
3+
/**
4+
* Resolves hashPrefix option for css-modules-require-hook
5+
*
6+
* @param {*} value
7+
* @returns {String}
8+
*/
9+
export default function hashPrefix(value/* , currentConfig */) {
10+
if (!isString(value)) {
11+
throw new Error(`Configuration 'hashPrefix' is not a string`);
12+
}
13+
14+
return value;
15+
}

src/options_resolvers/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { default as camelCase } from './camelCase';
33
export { default as createImportedName } from './createImportedName';
44
export { default as devMode } from './devMode';
55
export { default as generateScopedName } from './generateScopedName';
6+
export { default as hashPrefix } from './hashPrefix';
67
export { default as ignore } from './ignore';
78
export { default as mode } from './mode';
89
export { default as prepend } from './prepend';

src/options_resolvers/mode.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isString } from '../utils';
44
* Resolves mode option for css-modules-require-hook
55
*
66
* @param {*} value
7-
* @returns {boolean}
7+
* @returns {String}
88
*/
99
export default function mode(value/* , currentConfig */) {
1010
if (!isString(value)) {

src/options_resolvers/rootDir.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { statSync } from 'fs';
33
import { isString } from '../utils';
44

55
/**
6-
* Resolves mode option for css-modules-require-hook
6+
* Resolves rootDir option for css-modules-require-hook
77
*
88
* @param {*} value
9-
* @returns {boolean}
9+
* @returns {String}
1010
*/
1111
export default function rootDir(value/* , currentConfig */) {
1212
if (!isString(value)) {
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'chai';
2+
3+
import hashPrefix from '../../src/options_resolvers/hashPrefix';
4+
5+
describe('options_resolvers/hashPrefix', () => {
6+
it('should throw if hashPrefix value is not a string', () => {
7+
expect(
8+
() => hashPrefix(null)
9+
).to.throw();
10+
11+
expect(hashPrefix('hashPrefix')).to.be.equal('hashPrefix');
12+
});
13+
});

0 commit comments

Comments
 (0)