diff --git a/README.md b/README.md index 88897af..5ece863 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ equal(+0, -0) // true The following objects work correctly. - [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) -- [`Typed Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) ( [Int8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array), [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) ) +- [`Typed Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays) ( [Int8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array), [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), [Uint8ClampedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) ) - [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) - [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) - [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) ( [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError), [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError), [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError), [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError), [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError), [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError), [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) ) diff --git a/_is.ts b/_is.ts index afa3018..b3273c2 100644 --- a/_is.ts +++ b/_is.ts @@ -35,6 +35,7 @@ const isBothURL = instanceofFactory(URL); const isBothURLSearchParams = instanceofFactory(URLSearchParams); const isBothInt8Array = instanceofFactory(Int8Array); const isBothUint8Array = instanceofFactory(Uint8Array); +const isBothUint8ClampedArray = instanceofFactory(Uint8ClampedArray); export { isBothArray, @@ -50,6 +51,7 @@ export { isBothRegExp, isBothSet, isBothUint8Array, + isBothUint8ClampedArray, isBothURL, isBothURLSearchParams, }; diff --git a/equal.ts b/equal.ts index 802110a..8b2b9dd 100644 --- a/equal.ts +++ b/equal.ts @@ -14,6 +14,7 @@ import { isBothRegExp, isBothSet, isBothUint8Array, + isBothUint8ClampedArray, isBothURL, isBothURLSearchParams, } from "./_is.ts"; @@ -57,6 +58,7 @@ const equal = (a: T, b: U): boolean => { [isBothSet, equalSet], [isBothInt8Array, equalInt8Array], [isBothUint8Array, equalUint8Array], + [isBothUint8ClampedArray, equalUint8ClampedArray], [isBothURL, equalURL], [isBothURLSearchParams, equalURLSearchParams], [isBothObjectExcludeJSON, equalObjectExcludeJson], @@ -194,6 +196,11 @@ const equalUint8Array = ( b: U, ): boolean => equalArray([...a], [...b]); +const equalUint8ClampedArray = ( + a: T, + b: U, +): boolean => equalArray([...a], [...b]); + const equalURL = (a: T, b: U): boolean => a.toString() === b.toString(); const equalURLSearchParams = ( @@ -217,6 +224,7 @@ export { equalRegExp, equalSet, equalUint8Array, + equalUint8ClampedArray, equalURL, equalURLSearchParams, }; diff --git a/equal_test.ts b/equal_test.ts index b580301..c7561e5 100644 --- a/equal_test.ts +++ b/equal_test.ts @@ -16,6 +16,7 @@ import { equalRegExp, equalSet, equalUint8Array, + equalUint8ClampedArray, equalURL, equalURLSearchParams, } from "./equal.ts"; @@ -310,6 +311,48 @@ Deno.test("equalUint8Array", () => { }); }); +Deno.test("equalUint8ClampedArray", () => { + const table: [Uint8ClampedArray, Uint8ClampedArray, boolean][] = [ + [new Uint8ClampedArray(), new Uint8ClampedArray(), true], + [new Uint8ClampedArray([]), new Uint8ClampedArray(), true], + [new Uint8ClampedArray(), new Uint8ClampedArray([]), true], + [new Uint8ClampedArray([]), new Uint8ClampedArray([]), true], + [new Uint8ClampedArray(0), new Uint8ClampedArray(0), true], + [new Uint8ClampedArray(0), new Uint8ClampedArray(), true], + [new Uint8ClampedArray(), new Uint8ClampedArray(0), true], + [new Uint8ClampedArray(0), new Uint8ClampedArray(1), false], + [new Uint8ClampedArray(1), new Uint8ClampedArray(1), true], + [new Uint8ClampedArray([1, 2, 3]), new Uint8ClampedArray([1, 2, 3]), true], + [ + new Uint8ClampedArray([255, -128, 0]), + new Uint8ClampedArray([255, -128, 0]), + true, + ], + [ + new Uint8ClampedArray([256]), + new Uint8ClampedArray([255]), + true, + ], + [ + new Uint8ClampedArray([255, -128, 0]), + new Uint8ClampedArray([127, -128, 1]), + false, + ], + [ + new Uint8ClampedArray([255, 0]), + new Uint8ClampedArray([255, 0, 0]), + false, + ], + ]; + table.forEach(([a, b, expected]) => { + assertEquals( + equalUint8ClampedArray(a, b), + expected, + `equalUint8ClampedArray(${a}, ${b}) -> ${expected}`, + ); + }); +}); + Deno.test("equalRegExp", () => { const table: [RegExp, RegExp, boolean][] = [ [/s/, /s/, true], @@ -1012,6 +1055,7 @@ Deno.test("equal", () => { ], [new Int8Array(), new Int8Array(), true], [new Uint8Array(), new Uint8Array(), true], + [new Uint8ClampedArray(), new Uint8ClampedArray(), true], [new Uint16Array(), new Uint16Array(), false], ]; table.forEach(([a, b, expected]) => {