Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Extract escapeRegExp().
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 24, 2018
1 parent ffd9e3b commit dad035d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/util/escape-regexp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import shared from "../shared.js"

function init() {
const specialCharRegExp = /[\\^$.*+?()[\]{}|]/g

function escapeRegExp(string) {
return typeof string === "string"
? string.replace(specialCharRegExp, "\\$&")
: ""
}

return escapeRegExp
}

export default shared.inited
? shared.module.utilEscapeRegExp
: shared.module.utilEscapeRegExp = init()
6 changes: 3 additions & 3 deletions src/util/is-native.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import escapeRegExp from "./escape-regexp.js"
import isProxy from "./is-proxy.js"
import shared from "../shared.js"

Expand All @@ -10,11 +11,10 @@ function init() {
// compare other native methods against. Escape special RegExp characters
// and remove method identifiers before converting the template to a regexp.
const markerRegExp = /toString|(function ).*?(?=\\\()/g
const specialCharRegExp = /[\\^$.*+?()[\]{}|]/g

const nativeRegExp = RegExp(
"^" +
toString.call(toString)
.replace(specialCharRegExp, "\\$&")
escapeRegExp(toString.call(toString))
.replace(markerRegExp, "$1.*?") +
"$"
)
Expand Down

0 comments on commit dad035d

Please sign in to comment.