diff --git a/src/abortsignal-timeout.ts b/src/abortsignal-timeout.ts deleted file mode 100644 index e9f6fac..0000000 --- a/src/abortsignal-timeout.ts +++ /dev/null @@ -1,27 +0,0 @@ -export function abortSignalTimeout(ms: number) { - const controller = new AbortController() - setTimeout(() => controller.abort(new DOMException('TimeoutError')), ms) - return controller.signal -} - -declare global { - interface AbortController { - abort(reason: unknown): void - } -} - -/*#__PURE__*/ -export function isSupported(): boolean { - return 'abort' in AbortSignal && typeof AbortSignal.timeout === 'function' -} - -/*#__PURE__*/ -export function isPolyfilled(): boolean { - return AbortSignal.timeout === abortSignalTimeout -} - -export function apply(): void { - if (!isSupported()) { - AbortSignal.timeout = abortSignalTimeout - } -} diff --git a/src/index.ts b/src/index.ts index 53bb5b8..ac1003d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import * as abortSignalTimeout from './abortsignal-timeout.js' import * as clipboardItem from './clipboarditem.js' import * as elementCheckVisibility from './element-checkvisibility.js' import * as navigatorClipboard from './navigator-clipboard.js' @@ -30,7 +29,7 @@ export const baseSupport = 'hasOwn' in Object && // ESNext 'abort' in AbortSignal && - // 'timeout' in AbortSignal && // Polyfilled + 'timeout' in AbortSignal && // DOM / HTML and other specs typeof queueMicrotask === 'function' && typeof HTMLDialogElement === 'function' && @@ -44,7 +43,6 @@ export const baseSupport = true export const polyfills = { - abortSignalTimeout, clipboardItem, elementCheckVisibility, navigatorClipboard, diff --git a/test/abortsignal-timeout.js b/test/abortsignal-timeout.js deleted file mode 100644 index a584bbb..0000000 --- a/test/abortsignal-timeout.js +++ /dev/null @@ -1,27 +0,0 @@ -import {abortSignalTimeout, apply, isPolyfilled, isSupported} from '../lib/abortsignal-timeout.js' - -describe('abortSignalTimeout', () => { - it('has standard isSupported, isPolyfilled, apply API', () => { - expect(isSupported).to.be.a('function') - expect(isPolyfilled).to.be.a('function') - expect(apply).to.be.a('function') - expect(isSupported()).to.be.a('boolean') - expect(isPolyfilled()).to.equal(false) - }) - - it('returns signal that will timeout', async () => { - expect(abortSignalTimeout()).to.be.instanceOf(AbortSignal) - const signal = abortSignalTimeout(0) - const longerSignal = abortSignalTimeout(20) - expect(signal.aborted).to.equal(false) - await new Promise(resolve => setTimeout(resolve, 10)) - expect(signal.aborted).to.equal(true) - expect(longerSignal.aborted).to.equal(false) - await new Promise(resolve => setTimeout(resolve, 20)) - expect(longerSignal.aborted).to.equal(true) - }) - - it('creates a new signal each time', () => { - expect(abortSignalTimeout()).to.not.equal(abortSignalTimeout()) - }) -})