npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lauqe

v1.5.0

Published

(=equal) TypeScript-first deep equivalence comparison between two values

Downloads

87

Readme

test GitHub release deno land nest badge deno doc deno version node support version npm download

GitHub (Pre-)Release Date dependencies Status codecov Codacy Badge npm type definitions Commitizen friendly Gitmoji semantic-release License: MIT


Equivalent comparison of Object data structures. It supports many built-in objects and can be compared with Date, Array or Object.

The supported built-in objects are here.

It provides equal functions and specific data types functions . The equal function works correctly in all situations. The specific data types functions works correctly only for specific data types, but it has good performance. Please check bundle size optimization for details.

:bookmark: Table of Contents

:sparkles: Features

  • :zap: Multi runtime support (Deno, Node.js and Browsers)
  • :books: Pure TypeScript and provides type definition
  • :white_check_mark: Rambda's all test case is passed
  • :earth_americas: Universal module, providing ES modules and Commonjs
  • :package: Optimized, super slim size
  • :page_facing_up: TSDoc-style comments

Package name

Deno: equal (deno.land, nest.land)

Node.js: lauqe (npm)

:zap: Example

Primitive

equal("", ""); // true
equal(NaN, NaN); // true
equal(0, 0); // true
equal(+0, 0); // true
equal(-0, 0); // true
equal(+0, -0); // true
equal(0n, 0n); // true
equal(undefined, undefined); // true
equal(null, null); // true
equal(undefined, null); // false
equal(true, false); // false
const symbol = Symbol("hello");
equal(symbol, symbol); // true
equal(Symbol("hello"), Symbol("hello")); // false

Object

equal({}, {}) // true
equal({ "": undefined }, { "": undefined }) // true
equal({ "": undefined }, { "": undefined, a: 1 }) // false
equal({ a: 1, b: undefined}, { b: undefined, a: 1}) // true
equal([], []) // true
equal([[[]]], [[[]]]) // true
equal(new Date("2000/1/1"), new Date("2000/1/1")) // true
equal(() => true, () => true) // true
equal(AggregateError([ Error("error"), TypeError("type error") ]), AggregateError([ Error("error"), TypeError("type error") ])) // true
equal(/s/, /s/) // true
equal(new String('hello'), new String('hello')) // true
equal(new Number(0), new Number(0)) // true
equal(new Boolean(true), new Boolean(true)) // true
equal(new Map([[1, 2], [3, 4]]), new Map([[3, 4], [1, 2]]) // true

:dizzy: Usage

equal provides multi platform modules.

🦕 Deno

deno.land

import { equal } from "https://deno.land/x/equal/mod.ts";

equal([1, 2, 3], [1, 2, 3]); // true

nest.land

import { equal } from "https://x.nest.land/equal/mod.ts";

equal([1, ['hello', ['world']], [1, ['hello', ['world']]); // true

:package: Node.js

NPM package name is lauqe .

Install

npm i lauqe
or
yarn add lauqe

ES modules

import { equal } from "lauqe";

equal(new Date("2000/1/1"), new Date("2000/1/1")); // true

Commonjs

const { equal } = require("lauqe");

equal(/hello/g, /hello/g); // true

:globe_with_meridians: Browser

The module that bundles the dependencies is obtained from skypack.

<script type="module">
  import { equal } from "https://cdn.skypack.dev/lauqe";
  console.log(equal(() => {}, () => {}); // true
</script>

:memo: API

Definition of Equality

Equality is defined as the data structure and property values are equivalent.

Same-value-zero

Numerical equivalence is based on Same-value-zero.
That is, all of the following comparisons are considered equivalent.

equal(NaN, NaN); // true
equal(0, 0); // true
equal(+0, 0); // true
equal(-0, 0); // true
equal(+0, -0); // true

Built-in objects

The following objects work correctly.

Do not guarantee the behavior of objects not on this list.

Bundle size optimization

The equal function works correctly for all supported built-in objects. The price is an increase in bundle size.

If the data to be compared for equivalence is of multiple data types, or if the data types are unclear, the equal function may be the best choice.

If the data type is predetermined, you can reduce the bundle size by using the specific function instead.

Type definition

equal

Compare the equivalence of the all supported built-in objects and primitive values .

declare const equal: <T, U extends T>(a: T, b: U) => boolean;

| Parameter | Description | | --------- | ----------- | | a | Any value | | b | Any value |

=> Return true if the reference memory is the same or the property members and their values are the same

equalDate

Compare the equivalence of Date objects.

declare const equalDate: (a: Date, b: Date) => boolean;
Example
equalDate(new Date(0), new Date(0)) // true
equalDate(new Date(0), new Date(1)) // false
equalDate(new Date("1999/1/1 00:00:01"), new Date("1999/1/1")) // false
// invalid date
[new Date("a"), new Date("a"), true],
[new Date("a"), new Date("b"), true],

equalPrimitive

Compare the equivalence of Primitive values.

declare const equalPrimitive: <T extends Primitive, U extends T>(
  a: T,
  b: U,
) => boolean;

type Primitive =
  | string
  | number
  | bigint
  | boolean
  | symbol
  | undefined
  | null;
Example
equalPrimitive(NaN, NaN); // true
equalPrimitive(0, +0); // true
equalPrimitive(-0, +0); // true

equalError

Compare the equivalence of the Error object and its Derived object.

declare const equalError: (a: Error, b: Error) => boolean;
Example
equalError(Error("test"), Error("test")); // true
equalError(
  AggregateError([TypeError("test")]),
  AggregateError([TypeError("test")]),
); // true
equalError(Error("test"), Error("hello")); // false
equalError(Error("test"), TypeError("test")); // false

equalURL

Compare the equivalence of URL objects.

declare const equalURL: (a: URL, b: URL) => boolean;
Example
equalURL(new URL("https://google.com", "https://google.com")); // true
equalURL(new URL("https://google.com", "https://google.com/")); // true

equalArrayBuffer

Compare the equivalence of ArrayBuffer objects.

declare const equalArrayBuffer: (a: ArrayBuffer, b: ArrayBuffer) => boolean;

Example

equalArrayBuffer(new ArrayBuffer(0), new ArrayBuffer(0)); // true
equalArrayBuffer(new ArrayBuffer(0), new ArrayBuffer(1)); // false

:green_heart: Supports

ie is no longer supported to reduce bundle size.

The TypeScript version must be 4.1.0 or higher.

This project provides ES modules and Commonjs.

If you have an opinion about what to support, you can open an issue to discuss it.

The browserslist has the following settings.

defaults
last 8 version
not IE <= 11
not ie_mob <= 11
node 6

| Deno | Node.js | Edge | Firefox | Chrome | Safari | iOS Safari | Samsung | Opera | | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | ^1.6.0 | ^6.17.0 | ^83 | ^78 | ^83 | ^11 | ^12.0 | ^7.2 | ^68 |

:handshake: Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues.

Contributing guide

:seedling: Show your support

Give a ⭐️ if this project helped you!

:bulb: License

Copyright © 2021-present TomokiMiyauci.

Released under the MIT license