@rollup/pluginutils
Advanced tools
+18
-3
@@ -358,7 +358,10 @@ 'use strict'; | ||
| function exactRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}$`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| function prefixRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}`, flags); | ||
| } | ||
| function suffixRegex(str, flags) { | ||
| return new RegExp(`${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; | ||
@@ -368,2 +371,12 @@ function escapeRegex(str) { | ||
| } | ||
| function combineMultipleStrings(str) { | ||
| if (Array.isArray(str)) { | ||
| const escapeStr = str.map(escapeRegex).join('|'); | ||
| if (escapeStr && str.length > 1) { | ||
| return `(?:${escapeStr})`; | ||
| } | ||
| return escapeStr; | ||
| } | ||
| return escapeRegex(str); | ||
| } | ||
@@ -380,3 +393,4 @@ // TODO: remove this in next major | ||
| normalizePath, | ||
| prefixRegex | ||
| prefixRegex, | ||
| suffixRegex | ||
| }; | ||
@@ -394,3 +408,4 @@ | ||
| exports.prefixRegex = prefixRegex; | ||
| exports.suffixRegex = suffixRegex; | ||
| module.exports = Object.assign(exports.default, exports); | ||
| //# sourceMappingURL=index.js.map |
+18
-3
@@ -358,7 +358,10 @@ 'use strict'; | ||
| function exactRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}$`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| function prefixRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}`, flags); | ||
| } | ||
| function suffixRegex(str, flags) { | ||
| return new RegExp(`${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; | ||
@@ -368,2 +371,12 @@ function escapeRegex(str) { | ||
| } | ||
| function combineMultipleStrings(str) { | ||
| if (Array.isArray(str)) { | ||
| const escapeStr = str.map(escapeRegex).join('|'); | ||
| if (escapeStr && str.length > 1) { | ||
| return `(?:${escapeStr})`; | ||
| } | ||
| return escapeStr; | ||
| } | ||
| return escapeRegex(str); | ||
| } | ||
@@ -380,3 +393,4 @@ // TODO: remove this in next major | ||
| normalizePath, | ||
| prefixRegex | ||
| prefixRegex, | ||
| suffixRegex | ||
| }; | ||
@@ -394,3 +408,4 @@ | ||
| exports.prefixRegex = prefixRegex; | ||
| exports.suffixRegex = suffixRegex; | ||
| module.exports = Object.assign(exports.default, exports); | ||
| //# sourceMappingURL=index.js.map |
+18
-4
@@ -354,7 +354,10 @@ import { extname, win32, posix, isAbsolute, resolve } from 'path'; | ||
| function exactRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}$`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| function prefixRegex(str, flags) { | ||
| return new RegExp(`^${escapeRegex(str)}`, flags); | ||
| return new RegExp(`^${combineMultipleStrings(str)}`, flags); | ||
| } | ||
| function suffixRegex(str, flags) { | ||
| return new RegExp(`${combineMultipleStrings(str)}$`, flags); | ||
| } | ||
| const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g; | ||
@@ -364,2 +367,12 @@ function escapeRegex(str) { | ||
| } | ||
| function combineMultipleStrings(str) { | ||
| if (Array.isArray(str)) { | ||
| const escapeStr = str.map(escapeRegex).join('|'); | ||
| if (escapeStr && str.length > 1) { | ||
| return `(?:${escapeStr})`; | ||
| } | ||
| return escapeStr; | ||
| } | ||
| return escapeRegex(str); | ||
| } | ||
@@ -376,6 +389,7 @@ // TODO: remove this in next major | ||
| normalizePath, | ||
| prefixRegex | ||
| prefixRegex, | ||
| suffixRegex | ||
| }; | ||
| export { addExtension, attachScopes, createFilter, dataToEsm, index as default, exactRegex, extractAssignedNames, makeLegalIdentifier, normalizePath, prefixRegex }; | ||
| export { addExtension, attachScopes, createFilter, dataToEsm, index as default, exactRegex, extractAssignedNames, makeLegalIdentifier, normalizePath, prefixRegex, suffixRegex }; | ||
| //# sourceMappingURL=index.js.map |
+1
-1
| { | ||
| "name": "@rollup/pluginutils", | ||
| "version": "5.2.0", | ||
| "version": "5.3.0", | ||
| "publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
+21
-2
@@ -230,3 +230,3 @@ [npm]: https://img.shields.io/npm/v/@rollup/pluginutils | ||
| Parameters: `(str: String, flags?: String)`<br> | ||
| Parameters: `(str: String | Array[...String], flags?: String)`<br> | ||
| Returns: `RegExp` | ||
@@ -240,2 +240,3 @@ | ||
| exactRegex('foobar'); // /^foobar$/ | ||
| exactRegex(['foo', 'bar']); // /^(?:foo|bar)$/ | ||
| exactRegex('foo(bar)', 'i'); // /^foo\(bar\)$/i | ||
@@ -280,3 +281,3 @@ ``` | ||
| Parameters: `(str: String, flags?: String)`<br> | ||
| Parameters: `(str: String | Array[...String], flags?: String)`<br> | ||
| Returns: `RegExp` | ||
@@ -290,5 +291,23 @@ | ||
| prefixRegex('foobar'); // /^foobar/ | ||
| prefixRegex(['foo', 'bar']); // /^(?:foo|bar)/ | ||
| prefixRegex('foo(bar)', 'i'); // /^foo\(bar\)/i | ||
| ``` | ||
| ### suffixRegex | ||
| Constructs a RegExp that matches a value that has the specified suffix. This is useful for plugin hook filters. | ||
| Parameters: `(str: String | Array[...String], flags?: String)`<br> | ||
| Returns: `RegExp` | ||
| #### Usage | ||
| ```js | ||
| import { suffixRegex } from '@rollup/pluginutils'; | ||
| suffixRegex('foobar'); // /foobar$/ | ||
| suffixRegex(['foo', 'bar']); // /(?:foo|bar)$/ | ||
| suffixRegex('foo(bar)', 'i'); // /foo\(bar\)$/i | ||
| ``` | ||
| ## Meta | ||
@@ -295,0 +314,0 @@ |
+11
-2
@@ -70,3 +70,3 @@ import type { BaseNode } from 'estree'; | ||
| */ | ||
| export function exactRegex(str: string, flags?: string): RegExp; | ||
| export function exactRegex(str: string | string[], flags?: string): RegExp; | ||
@@ -94,4 +94,11 @@ /** | ||
| */ | ||
| export function prefixRegex(str: string, flags?: string): RegExp; | ||
| export function prefixRegex(str: string | string[], flags?: string): RegExp; | ||
| /** | ||
| * Constructs a RegExp that matches a value that has the specified suffix. | ||
| * @param str the string to match. | ||
| * @param flags flags for the RegExp. | ||
| */ | ||
| export function suffixRegex(str: string | string[], flags?: string): RegExp; | ||
| export type AddExtension = typeof addExtension; | ||
@@ -106,2 +113,3 @@ export type AttachScopes = typeof attachScopes; | ||
| export type PrefixRegex = typeof prefixRegex; | ||
| export type SuffixRegex = typeof suffixRegex; | ||
@@ -118,3 +126,4 @@ declare const defaultExport: { | ||
| prefixRegex: PrefixRegex; | ||
| suffixRegex: SuffixRegex; | ||
| }; | ||
| export default defaultExport; |
63048
3.68%1285
4.22%314
6.44%