aboutsummaryrefslogtreecommitdiff
path: root/packages/webapi/src/lib
diff options
context:
space:
mode:
authorGravatar Erika <3019731+Princesseuh@users.noreply.github.com> 2023-01-10 15:29:06 +0100
committerGravatar GitHub <noreply@github.com> 2023-01-10 15:29:06 +0100
commitc55fbcb8edca1fe118a44f68c9f9436a4719d171 (patch)
tree2bde21dfe19aee8a984a3f5b678b2ee6603876da /packages/webapi/src/lib
parentcf5dc2adae04c1ab3fcf95bb2426e82733737852 (diff)
downloadastro-c55fbcb8edca1fe118a44f68c9f9436a4719d171.tar.gz
astro-c55fbcb8edca1fe118a44f68c9f9436a4719d171.tar.zst
astro-c55fbcb8edca1fe118a44f68c9f9436a4719d171.zip
Remove more unnecessary polyfills from webapi for Node 16 (#5814)
* feat(webapi): Remove unnecessary polyfills now that we dropped support for Node 14 * feat(webapi): Removed more unnecessary polyfills for Node 16 * chore: changeset
Diffstat (limited to 'packages/webapi/src/lib')
-rw-r--r--packages/webapi/src/lib/Base64.ts7
-rw-r--r--packages/webapi/src/lib/ContextEvent.ts57
-rw-r--r--packages/webapi/src/lib/Object.ts21
-rw-r--r--packages/webapi/src/lib/Promise.ts28
-rw-r--r--packages/webapi/src/lib/String.ts30
-rw-r--r--packages/webapi/src/lib/utils.ts35
6 files changed, 0 insertions, 178 deletions
diff --git a/packages/webapi/src/lib/Base64.ts b/packages/webapi/src/lib/Base64.ts
deleted file mode 100644
index 593c56ae0..000000000
--- a/packages/webapi/src/lib/Base64.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-export function atob(data: string): string {
- return Buffer.from(data, 'base64').toString('binary')
-}
-
-export function btoa(data: string): string {
- return Buffer.from(data, 'binary').toString('base64')
-}
diff --git a/packages/webapi/src/lib/ContextEvent.ts b/packages/webapi/src/lib/ContextEvent.ts
deleted file mode 100644
index e712c4da1..000000000
--- a/packages/webapi/src/lib/ContextEvent.ts
+++ /dev/null
@@ -1,57 +0,0 @@
-import { Event } from 'event-target-shim'
-
-/** An event fired by a context requester to signal it desires a named context. */
-export class ContextEvent<T = unknown> extends Event<'context-request'> {
- constructor(init: ContextEventInit<T>) {
- super('context-request', { bubbles: true, composed: true })
-
- init = Object(init) as Required<ContextEventInit<T>>
-
- this.context = init.context
- }
-
- context!: Context<T>
- multiple!: boolean
- callback!: ContextCallback<Context<T>>
-}
-
-interface ContextEventInit<T = unknown> {
- context: Context<T>
- multiple?: boolean
- callback: ContextCallback<Context<T>>
-}
-
-/** A Context object defines an optional initial value for a Context, as well as a name identifier for debugging purposes. */
-export type Context<T = unknown> = {
- name: string
- initialValue?: T
-}
-
-/** A helper type which can extract a Context value type from a Context type. */
-export type ContextType<T extends Context> = T extends Context<infer Y>
- ? Y
- : never
-
-/** A function which creates a Context value object */
-export function createContext<T>(
- name: string,
- initialValue?: T
-): Readonly<Context<T>> {
- return {
- name,
- initialValue,
- }
-}
-
-/** A callback which is provided by a context requester and is called with the value satisfying the request. */
-export type ContextCallback<ValueType> = (
- value: ValueType,
- dispose?: () => void
-) => void
-
-declare global {
- interface HTMLElementEventMap {
- /** A 'context-request' event can be emitted by any element which desires a context value to be injected by an external provider. */
- 'context-request': ContextEvent
- }
-}
diff --git a/packages/webapi/src/lib/Object.ts b/packages/webapi/src/lib/Object.ts
deleted file mode 100644
index cfc1ea4a4..000000000
--- a/packages/webapi/src/lib/Object.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import * as _ from './utils'
-
-export const hasOwn = {
- hasOwn(instance: object, property: any) {
- return _.__object_hasOwnProperty(instance, property)
- },
-}.hasOwn
-
-export const initObject = (target: any, exclude: Set<string>) => {
- if (exclude.has('Object') || exclude.has('object') || exclude.has('hasOwn'))
- return
-
- const Class = target.Object || globalThis.Object
-
- Object.defineProperty(Class, 'hasOwn', {
- value: hasOwn,
- writable: true,
- enumerable: false,
- configurable: true,
- })
-}
diff --git a/packages/webapi/src/lib/Promise.ts b/packages/webapi/src/lib/Promise.ts
deleted file mode 100644
index 2591fb56a..000000000
--- a/packages/webapi/src/lib/Promise.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-export const any = {
- async any<T>(iterable: Iterable<T | PromiseLike<T>>): Promise<T> {
- return Promise.all(
- [...iterable].map((promise) => {
- return new Promise((resolve, reject) =>
- Promise.resolve(promise).then(reject, resolve)
- )
- })
- ).then(
- (errors) => Promise.reject(errors),
- (value) => Promise.resolve<T>(value)
- )
- },
-}.any
-
-export const initPromise = (target: any, exclude: Set<string>) => {
- if (exclude.has('Promise') || exclude.has('any')) return
-
- const Class = target.Promise || globalThis.Promise
-
- if (!Class.any)
- Object.defineProperty(Class, 'any', {
- value: any,
- writable: true,
- enumerable: false,
- configurable: true,
- })
-}
diff --git a/packages/webapi/src/lib/String.ts b/packages/webapi/src/lib/String.ts
deleted file mode 100644
index 92d39f39a..000000000
--- a/packages/webapi/src/lib/String.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-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,
- })
-}
diff --git a/packages/webapi/src/lib/utils.ts b/packages/webapi/src/lib/utils.ts
index 0086f75b6..61a78e97b 100644
--- a/packages/webapi/src/lib/utils.ts
+++ b/packages/webapi/src/lib/utils.ts
@@ -1,8 +1,5 @@
import { performance } from 'node:perf_hooks'
-/** Returns the milliseconds elapsed since January 1, 1970 00:00:00 UTC. */
-export const __date_now = Date.now
-
/** Returns the function bound to the given object. */
export const __function_bind = Function.bind.bind(
Function.call as unknown as any
@@ -12,34 +9,6 @@ export const __function_bind = Function.bind.bind(
...args: TArgs
) => TFunc
-/** Returns the function called with the specified values. */
-export const __function_call = Function.call.bind(
- Function.call as unknown as any
-) as <TArgs extends any, TFunc extends (...args: TArgs[]) => any>(
- callback: TFunc,
- thisArg: unknown,
- ...args: TArgs[]
-) => ReturnType<TFunc>
-
-/** Returns an object with the specified prototype. */
-export const __object_create = Object.create as {
- <T extends any = any>(value: T): any extends T ? Record<any, any> : T
-}
-
-/** Returns whether an object has a property with the specified name. */
-export const __object_hasOwnProperty = Function.call.bind(
- Object.prototype.hasOwnProperty
-) as {
- <T1 extends object, T2>(object: T1, key: T2): T2 extends keyof T1
- ? true
- : false
-}
-
-/** Returns a string representation of an object. */
-export const __object_toString = Function.call.bind(
- Object.prototype.toString
-) as { (value: any): string }
-
/** Returns whether the object prototype exists in another object. */
export const __object_isPrototypeOf = Function.call.bind(
Object.prototype.isPrototypeOf
@@ -48,10 +17,6 @@ export const __object_isPrototypeOf = Function.call.bind(
/** Current high resolution millisecond timestamp. */
export const __performance_now = performance.now as () => number
-/** Returns the string escaped for use inside regular expressions. */
-export const __string_escapeRegExp = (value: string) =>
- value.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&')
-
// @ts-ignore
export const INTERNALS = new WeakMap<unknown, any>()