Skip to content

Commit d57cb1c

Browse files
chore(release): 2.0.1 (#7)
1 parent 771c43a commit d57cb1c

File tree

6 files changed

+81
-52
lines changed

6 files changed

+81
-52
lines changed

index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
interface Options {
2-
context: string,
3-
hashPrefix: string,
2+
context: string;
3+
hashPrefix: string;
44
}
55

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

8-
declare function createGenerator(pattern: string, options?: Partial<Options>): Generator;
8+
declare function createGenerator(
9+
pattern: string,
10+
options?: Partial<Options>
11+
): Generator;
912

1013
export = createGenerator;

index.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
'use strict';
1+
"use strict";
22

3-
var interpolateName = require('loader-utils').interpolateName;
4-
var path = require('path');
5-
var util = require('util');
3+
var interpolateName = require("loader-utils").interpolateName;
4+
var path = require("path");
65

76
/**
87
* @param {string} pattern
@@ -13,12 +12,12 @@ var util = require('util');
1312
*/
1413
module.exports = function createGenerator(pattern, options) {
1514
options = options || {};
16-
var context = options && typeof options.context === 'string'
17-
? options.context
18-
: process.cwd();
19-
var hashPrefix = options && typeof options.hashPrefix === 'string'
20-
? options.hashPrefix
21-
: '';
15+
var context =
16+
options && typeof options.context === "string"
17+
? options.context
18+
: process.cwd();
19+
var hashPrefix =
20+
options && typeof options.hashPrefix === "string" ? options.hashPrefix : "";
2221

2322
/**
2423
* @param {string} localName Usually a class name
@@ -32,16 +31,17 @@ module.exports = function createGenerator(pattern, options) {
3231
};
3332

3433
var loaderOptions = {
35-
content: util.format('%s%s+%s',
36-
hashPrefix,
37-
path.relative(context, filepath),
38-
localName),
34+
content:
35+
hashPrefix +
36+
path.relative(context, filepath).replace(/\\/g, "/") +
37+
"+" +
38+
localName,
3939
context: context
4040
};
4141

4242
var genericName = interpolateName(loaderContext, name, loaderOptions);
4343
return genericName
44-
.replace(new RegExp('[^a-zA-Z0-9\\-_\u00A0-\uFFFF]', 'g'), '-')
44+
.replace(new RegExp("[^a-zA-Z0-9\\-_\u00A0-\uFFFF]", "g"), "-")
4545
.replace(/^((-?[0-9])|--)/, "_$1");
4646
};
4747
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generic-names",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Helper for building generic names, similar to webpack",
55
"main": "index.js",
66
"types": "index.d.ts",

test/cssspec.js

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
1-
'use strict';
1+
"use strict";
22

3-
const genericNames = require('../index');
4-
const test = require('tape');
5-
const path = require('path');
3+
const genericNames = require("../index");
4+
const test = require("tape");
5+
const path = require("path");
66

77
// According to the CSS spec, identifiers cannot
88
// start with a digit, two hyphens, or a hyphen
99
// followed by a digit.
1010
//
1111
// relates: https://github.com/webpack/css-loader/commit/da27c07d0df25a38699344c13b6614c53a469fd9
1212

13-
test('identity', t => {
14-
const generate = genericNames('[local]');
13+
test("identity", t => {
14+
const generate = genericNames("[local]");
1515

16-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), 'foo');
16+
t.equal(generate("foo", path.join(__dirname, "test/case/source.css")), "foo");
1717
t.end();
1818
});
1919

20-
test('leading digit', t => {
21-
const generate = genericNames('0[local]');
20+
test("leading digit", t => {
21+
const generate = genericNames("0[local]");
2222

23-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), '_0foo');
23+
t.equal(
24+
generate("foo", path.join(__dirname, "test/case/source.css")),
25+
"_0foo"
26+
);
2427
t.end();
2528
});
2629

27-
test('leading digit in the token', t => {
28-
const generate = genericNames('[local]');
30+
test("leading digit in the token", t => {
31+
const generate = genericNames("[local]");
2932

30-
t.equal(generate('0foo', path.join(__dirname, 'test/case/source.css')), '_0foo');
33+
t.equal(
34+
generate("0foo", path.join(__dirname, "test/case/source.css")),
35+
"_0foo"
36+
);
3137
t.end();
3238
});
3339

34-
test('leading two hyphens', t => {
35-
const generate = genericNames('--[local]');
40+
test("leading two hyphens", t => {
41+
const generate = genericNames("--[local]");
3642

37-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), '_--foo');
43+
t.equal(
44+
generate("foo", path.join(__dirname, "test/case/source.css")),
45+
"_--foo"
46+
);
3847
t.end();
3948
});
4049

41-
test('leading hyphen and digit', t => {
42-
const generate = genericNames('-0[local]');
50+
test("leading hyphen and digit", t => {
51+
const generate = genericNames("-0[local]");
4352

44-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), '_-0foo');
53+
t.equal(
54+
generate("foo", path.join(__dirname, "test/case/source.css")),
55+
"_-0foo"
56+
);
4557
t.end();
4658
});

test/index.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
1-
'use strict';
1+
"use strict";
22

3-
const genericNames = require('../index');
4-
const test = require('tape');
5-
const path = require('path');
3+
const genericNames = require("../index");
4+
const test = require("tape");
5+
const path = require("path");
66

7-
const pattern = '[name]__[local]___[hash:base64:5]';
7+
const pattern = "[name]__[local]___[hash:base64:5]";
88

9-
test('use `cwd` if no context was provided', t => {
9+
test("use `cwd` if no context was provided", t => {
1010
const generate = genericNames(pattern);
1111

12-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), 'source__foo___3D34a');
12+
t.equal(
13+
generate("foo", path.join(__dirname, "test/case/source.css")),
14+
"source__foo___3D34a"
15+
);
1316
t.end();
1417
});
1518

16-
test('generate distinct hash for the provided context', t => {
17-
const generate = genericNames(pattern, {context: path.join(__dirname, '/test') });
19+
test("generate distinct hash for the provided context", t => {
20+
const generate = genericNames(pattern, {
21+
context: path.join(__dirname, "/test")
22+
});
1823

19-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), 'source__foo___19xFw');
24+
t.equal(
25+
generate("foo", path.join(__dirname, "test/case/source.css")),
26+
"source__foo___19xFw"
27+
);
2028
t.end();
2129
});
2230

23-
test('generate distinct hash for the provided hashPrefix', t => {
24-
const generate = genericNames(pattern, {context: path.join(__dirname, '/test'), hashPrefix: '--'});
31+
test("generate distinct hash for the provided hashPrefix", t => {
32+
const generate = genericNames(pattern, {
33+
context: path.join(__dirname, "/test"),
34+
hashPrefix: "--"
35+
});
2536

26-
t.equal(generate('foo', path.join(__dirname, 'test/case/source.css')), 'source__foo___3T0Un');
37+
t.equal(
38+
generate("foo", path.join(__dirname, "test/case/source.css")),
39+
"source__foo___3T0Un"
40+
);
2741
t.end();
2842
});

0 commit comments

Comments
 (0)