Skip to content

Commit 334f212

Browse files
author
Sebastian Prein
committed
Improve wording of error message when pattern option is invalid
1 parent 5f7c8b6 commit 334f212

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Dependencies
22
const postcss = require('postcss');
33
const deep = require('deep-get-set');
4+
const kindOf = require('kind-of');
45

56
// Default options, see README.md
67
const defaults = {
@@ -22,7 +23,7 @@ module.exports = postcss.plugin('postcss-replace', (opts = defaults) => {
2223
} else if (typeof options.pattern === 'string') {
2324
regex = new RegExp(options.pattern, 'gi');
2425
} else {
25-
throw new TypeError('Did you provide a valid regex pattern?');
26+
throw new TypeError(`Invalid pattern provided. It is expected to be a string or an instance of RegExp. Got: ${kindOf(options.pattern)}`);
2627
}
2728

2829
const replacementArgs = [regex, (match, key) => {

package-lock.json

Lines changed: 36 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"dependencies": {
2727
"deep-get-set": "^1.1.0",
28+
"kind-of": "^6.0.2",
2829
"postcss": "^6.0.14"
2930
},
3031
"devDependencies": {

0 commit comments

Comments
 (0)