diff --git a/polyfill.ts b/polyfill.ts new file mode 100644 index 0000000..d697dcf --- /dev/null +++ b/polyfill.ts @@ -0,0 +1,27 @@ +// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license. +// This module is browser compatible. + +/** + * @example + * ```ts + * import "https://deno.land/x/composition_key@$VERSION/polyfill.ts"; + * import { assert } from "https://deno.land/std/testing/asserts.ts"; + * + * assert(compositeKey); + * assert(compositeSymbol); + * ``` + */ + +// deno-lint-ignore-file no-var ban-types + +import { compositeKey, compositeSymbol, type Ref } from "./composite.ts"; + +declare global { + var compositeKey: ( + ...parts: [object, ...unknown[]] | [...unknown[], object] + ) => Ref; + var compositeSymbol: (...parts: readonly unknown[]) => symbol; +} + +globalThis.compositeKey = compositeKey; +globalThis.compositeSymbol = compositeSymbol; diff --git a/polyfill_test.ts b/polyfill_test.ts new file mode 100644 index 0000000..e2d88eb --- /dev/null +++ b/polyfill_test.ts @@ -0,0 +1,20 @@ +// Copyright 2023-latest Tomoki Miyauchi. All rights reserved. MIT license. + +import "./polyfill.ts"; +import { assert, describe, it } from "./_dev_deps.ts"; +import { + compositeKey as _compositeKey, + compositeSymbol as _compositeSymbol, +} from "./composite.ts"; + +describe("compositeKey", () => { + it("should define global", () => { + assert(compositeKey === _compositeKey); + }); +}); + +describe("compositeSymbol", () => { + it("should define global", () => { + assert(compositeSymbol === _compositeSymbol); + }); +});