summaryrefslogtreecommitdiff
path: root/packages/webapi/src/lib/String.ts
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-03-07 15:36:22 -0600
committerGravatar GitHub <noreply@github.com> 2022-03-07 15:36:22 -0600
commitf18ee36dc0abdc5c8ec87734de7962966d16fe65 (patch)
treec01a7034186cb0bbe5e1d042f4a5dd09bad21ed5 /packages/webapi/src/lib/String.ts
parent10a9c3412b4f6e8607687a74eafdb150d3222047 (diff)
downloadastro-f18ee36dc0abdc5c8ec87734de7962966d16fe65.tar.gz
astro-f18ee36dc0abdc5c8ec87734de7962966d16fe65.tar.zst
astro-f18ee36dc0abdc5c8ec87734de7962966d16fe65.zip
Add `@astrojs/webapi` package (#2729)@astrojs/webapi@0.11.0
* chore: add @astrojs/webapi * chore: update package.json * fix: update file case * fix: remove lowercase file * chore: update tests to use mocha * chore: update LICENSE
Diffstat (limited to 'packages/webapi/src/lib/String.ts')
-rw-r--r--packages/webapi/src/lib/String.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/webapi/src/lib/String.ts b/packages/webapi/src/lib/String.ts
new file mode 100644
index 000000000..49df3261c
--- /dev/null
+++ b/packages/webapi/src/lib/String.ts
@@ -0,0 +1,22 @@
+import * as _ from './utils'
+
+export const replaceAll = {
+ replaceAll(this: string, searchValue: RegExp | string, replaceValue: string | ((substring: string, ...args: any[]) => string)) {
+ return _.__object_isPrototypeOf(RegExp.prototype, searchValue)
+ ? this.replace(searchValue as RegExp, replaceValue as string)
+ : this.replace(new RegExp(_.__string_escapeRegExp(searchValue as string), 'g'), replaceValue as string)
+ }
+}.replaceAll
+
+export const initString = (target: any, exclude: Set<string>) => {
+ if (exclude.has('String') || exclude.has('replaceAll')) return
+
+ const Class = target.String || globalThis.String
+
+ if (!Class.prototype.replaceAll) Object.defineProperty(Class.prototype, 'replaceAll', {
+ value: replaceAll,
+ writable: true,
+ enumerable: false,
+ configurable: true
+ })
+}