Skip to content

Commit

Permalink
Merge pull request #21 from TomokiMiyauci/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
TomokiMiyauci authored Jun 1, 2021
2 parents 7df0d53 + e0b3690 commit 37c5ec0
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 3 deletions.
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// IntelliSense を使用して利用可能な属性を学べます。
// 既存の属性の説明をホバーして表示します。
// 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Deno",
"request": "launch",
"type": "pwa-node",
"program": "${file}",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--unstable",
"--inspect",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# [v1.4.0-beta.2](https://github.com/TomokiMiyauci/equal/compare/v1.4.0-beta.1...v1.4.0-beta.2) (2021-05-31)

## ✨ New Features
- [`dfb37b4`](https://github.com/TomokiMiyauci/equal/commit/dfb37b4) Add equality of ArrayBuffer (Issues: [`#20`](https://github.com/TomokiMiyauci/equal/issues/20))

# [v1.4.0-beta.1](https://github.com/TomokiMiyauci/equal/compare/v1.3.0...v1.4.0-beta.1) (2021-05-31)

## ✨ New Features
- [`ffe286c`](https://github.com/TomokiMiyauci/equal/commit/ffe286c) Add equality of Int8Array (Issues: [`#16`](https://github.com/TomokiMiyauci/equal/issues/16))
- [`abbc99a`](https://github.com/TomokiMiyauci/equal/commit/abbc99a) Add equality of UIint8Array (Issues: [`#17`](https://github.com/TomokiMiyauci/equal/issues/17))
- [`495666e`](https://github.com/TomokiMiyauci/equal/commit/495666e) Add equality of Uint8ClampedArray (Issues: [`#18`](https://github.com/TomokiMiyauci/equal/issues/18))
- [`439993b`](https://github.com/TomokiMiyauci/equal/commit/439993b) Add equality of TypedArray (Issues: [`#19`](https://github.com/TomokiMiyauci/equal/issues/19))

# [v1.3.0](https://github.com/TomokiMiyauci/equal/compare/v1.2.0...v1.3.0) (2021-05-31)

## ✨ New Features
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TypeScript-first deep equivalence comparison between two values
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/equal)
[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/equal/mod.ts)
[![deno version](https://img.shields.io/badge/deno-^1.6.0-lightgrey?logo=deno)](https://github.com/denoland/deno)
![node support version](https://img.shields.io/badge/node-%5E14.16.0-yellow)
![node support version](https://img.shields.io/badge/node-%5E6.17.0-yellow)
![bundle size](https://img.shields.io/bundlephobia/min/lauqe)
![npm download](https://img.shields.io/npm/dw/lauqe?color=blue)

Expand Down Expand Up @@ -154,6 +154,8 @@ 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), [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray), [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array), [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array), [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array), [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array), [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array), [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array), [`BigInt64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array), [`BigUint64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array) )
- [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
- [`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) )
Expand Down
25 changes: 25 additions & 0 deletions _is.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021-present the Equal authors. All rights reserved. MIT license.
import {
and,
ifElse,
isArray,
isFunction,
isJSONObject,
Expand Down Expand Up @@ -32,10 +33,33 @@ const isBothError = instanceofFactory(Error);
const isBothMap = instanceofFactory(Map);
const isBothSet = instanceofFactory(Set);
const isBothURL = instanceofFactory(URL);
const isBothArrayBuffer = instanceofFactory(ArrayBuffer);
const isBothURLSearchParams = instanceofFactory(URLSearchParams);
const isBothTypedArray = <T, U extends T>(a: T, b: U): [boolean, boolean] => {
const result = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array,
BigInt64Array,
BigUint64Array,
]
.some((obj) => {
const [f1, f2] = instanceofFactory(obj)(a, b);
return and(f1, f2);
});

return ifElse(result, [true, true], [false, false]);
};

export {
isBothArray,
isBothArrayBuffer,
isBothDate,
isBothError,
isBothFunction,
Expand All @@ -46,6 +70,7 @@ export {
isBothPrimitive,
isBothRegExp,
isBothSet,
isBothTypedArray,
isBothURL,
isBothURLSearchParams,
};
29 changes: 29 additions & 0 deletions equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { and, AnyFn, entries, F, has, ifElse, length, N, xor } from "./deps.ts";
import {
isBothArray,
isBothArrayBuffer,
isBothDate,
isBothError,
isBothFunction,
Expand All @@ -12,6 +13,7 @@ import {
isBothPrimitive,
isBothRegExp,
isBothSet,
isBothTypedArray,
isBothURL,
isBothURLSearchParams,
} from "./_is.ts";
Expand Down Expand Up @@ -53,6 +55,8 @@ const equal = <T, U extends T>(a: T, b: U): boolean => {
[isBothError, equalError],
[isBothMap, equalMap],
[isBothSet, equalSet],
[isBothTypedArray, equalTypedArray],
[isBothArrayBuffer, equalArrayBuffer],
[isBothURL, equalURL],
[isBothURLSearchParams, equalURLSearchParams],
[isBothObjectExcludeJSON, equalObjectExcludeJson],
Expand Down Expand Up @@ -180,6 +184,29 @@ const equalArray = <T extends unknown[], U extends T>(a: T, b: U): boolean => {
return a.every((val, index) => equal(val, b[index]));
};

const equalTypedArray = <
T extends
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array,
>(
a: T,
b: T,
): boolean => equalArray([...a], [...b]);

const equalArrayBuffer = <T extends ArrayBuffer, U extends T>(
a: T,
b: U,
): boolean => a.byteLength === b.byteLength;

const equalURL = <T extends URL, U extends T>(a: T, b: U): boolean =>
a.toString() === b.toString();
const equalURLSearchParams = <T extends URLSearchParams, U extends T>(
Expand All @@ -190,6 +217,7 @@ const equalURLSearchParams = <T extends URLSearchParams, U extends T>(
export {
equal,
equalArray,
equalArrayBuffer,
equalConstructor,
equalDate,
equalError,
Expand All @@ -201,6 +229,7 @@ export {
equalObjectExcludeJson,
equalRegExp,
equalSet,
equalTypedArray,
equalURL,
equalURLSearchParams,
};
81 changes: 80 additions & 1 deletion equal_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { assertEquals, isSymbol } from "./dev_deps.ts";
import {
equal,
equalArray,
equalArrayBuffer,
equalConstructor,
equalDate,
equalError,
Expand All @@ -14,6 +15,7 @@ import {
equalObjectExcludeJson,
equalRegExp,
equalSet,
equalTypedArray,
equalURL,
equalURLSearchParams,
} from "./equal.ts";
Expand Down Expand Up @@ -258,6 +260,52 @@ Deno.test("equalArray", () => {
});
});

Deno.test("equalTypedArray", () => {
type ArrayLike =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array;
const table: [ArrayLike, ArrayLike, boolean][] = [
[new Int8Array(), new Int8Array(), true],
[new Int8Array([21, 31]), new Int8Array([21, 31]), true],
[new Uint8Array(), new Uint8Array(), true],
[new Uint8Array([21, 31]), new Uint8Array([21, 31]), true],
[new Uint8ClampedArray(), new Uint8ClampedArray(), true],
[new Uint8ClampedArray([21, 31]), new Uint8ClampedArray([21, 31]), true],
[new Int16Array(), new Int16Array(), true],
[new Int16Array([21, 31]), new Int16Array([21, 31]), true],
[new Uint16Array(), new Uint16Array(), true],
[new Uint16Array([21, 31]), new Uint16Array([21, 31]), true],
[new Int32Array(), new Int32Array(), true],
[new Int32Array([21, 31]), new Int32Array([21, 31]), true],
[new Uint32Array(), new Uint32Array(), true],
[new Uint32Array([21, 31]), new Uint32Array([21, 31]), true],
[new Float32Array(), new Float32Array(), true],
[new Float32Array([21, 31]), new Float32Array([21, 31]), true],
[new Float64Array(), new Float64Array(), true],
[new Float64Array([21, 31]), new Float64Array([21, 31]), true],
[new BigInt64Array(), new BigInt64Array(), true],
[new BigInt64Array([21n, 31n]), new BigInt64Array([21n, 31n]), true],
[new BigUint64Array(), new BigUint64Array(), true],
[new BigUint64Array([0n, 31n]), new BigUint64Array([0n, 31n]), true],
];
table.forEach(([a, b, expected]) => {
assertEquals(
equalTypedArray(a, b),
expected,
`equalTypedArray(${a}, ${b}) -> ${expected}`,
);
});
});

Deno.test("equalRegExp", () => {
const table: [RegExp, RegExp, boolean][] = [
[/s/, /s/, true],
Expand All @@ -275,6 +323,26 @@ Deno.test("equalRegExp", () => {
});
});

Deno.test("equalArrayBuffer", () => {
const table: [ArrayBuffer, ArrayBuffer, boolean][] = [
[new ArrayBuffer(0), new ArrayBuffer(0), true],
[new ArrayBuffer(0), new ArrayBuffer(1), false],
[new ArrayBuffer(1), new ArrayBuffer(1), true],
[
new ArrayBuffer(1000),
new ArrayBuffer(1000),
true,
],
];
table.forEach(([a, b, expected]) => {
assertEquals(
equalArrayBuffer(a, b),
expected,
`equalArrayBuffer(${a}, ${b}) -> ${expected}`,
);
});
});

Deno.test("equalSet", () => {
const symbol = Symbol("hello");
const table: [Set<unknown>, Set<unknown>, boolean][] = [
Expand Down Expand Up @@ -958,7 +1026,18 @@ Deno.test("equal", () => {
new URLSearchParams({ b: "tom", a: "hello" }),
false,
],
[new Uint16Array(), new Uint16Array(), false],
[new Int8Array(), new Int8Array(), true],
[new Uint8Array(), new Uint8Array(), true],
[new Uint8ClampedArray(), new Uint8ClampedArray(), true],
[new Int16Array(), new Int16Array(), true],
[new Uint16Array(), new Uint16Array(), true],
[new Int32Array(), new Int32Array(), true],
[new Uint32Array(), new Uint32Array(), true],
[new Float32Array(), new Float32Array(), true],
[new Float64Array(), new Float64Array(), true],
[new BigInt64Array(), new BigInt64Array(), true],
[new BigUint64Array(), new BigUint64Array(), true],
[new ArrayBuffer(0), new ArrayBuffer(0), true],
];
table.forEach(([a, b, expected]) => {
assertEquals(
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lauqe",
"description": "(=equal) TypeScript-first deep equivalence comparison between two values",
"version": "1.3.0",
"version": "1.4.0-beta.2",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"types": "dist/index.es.d.ts",
Expand Down

0 comments on commit 37c5ec0

Please sign in to comment.