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

comparejs

v4.0.14

Published

comparejs implements JavaScript's comparison operators the way you would expect them to be.

Downloads

118,034

Readme

comparejs

comparejs implements JavaScript's comparison operators the way you would expect them to be.

Status

| Category | Status | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | Version | npm | | Dependencies | David | | Dev dependencies | David | | Build | GitHub Actions | | License | GitHub |

Installation

$ npm install comparejs

Quick Start

To use comparejs you need to reference it from your application by adding the following line:

const { compare } = require('comparejs');

If you use TypeScript, use the following code instead:

import { compare } from 'comparejs';

Features

  • Supports comparison of array, boolean, function, null, number, object, string and undefined.
  • Supports comparison of native data types and constructor-created data types, such as number and new Number().
  • Supports comparison of objects and arrays using deep-equal.
  • Supports comparison of objects and arrays with <, <=, > and >= by handling them as subsets.
  • Supports comparison of objects by structure.
  • Supports comparison with undefined correctly, as <= and >= are problematic in plain JavaScript.
  • Supports comparison in a perfectly type-safe way out-of-the-box.
  • Supports comparison by equality and identity, depending on what makes sense.

Basic usage

Now you are able to use the various comparison operators. All you need to do is access the compare object and use its functions:

| Operator |  Alias | Description | | --------------------------------- | ------------------ | --------------------- | | equal(left, right) | eq(left, right) | equal | | notEqual(left, right) | ne(left, right) | not equal | | lessThan(left, right) | lt(left, right) | less than | | lessThanOrEqual(left, right) | lte(left, right) | less than or equal | | greaterThan(left, right) | gt(left, right) | greater than | | greaterThanOrEqual(left, right) | gte(left, right) | greater than or equal | | identity(left, right) | id(left, right) | identity |

Please note that each comparison operator works on each combination of types and does what you would expect it to do.

Structure comparison operators

For objects, there are special operators that compare by structure. Among other things, they can be used to verify objects against interfaces:

| Operator | Alias | Description | | -------------------------------------------- | ------------------- | ---------------------------------- | | equalByStructure(left, right) | eqs(left, right) | equal by structure | | notEqualByStructure(left, right) | nes(left, right) | not equal by structure | | lessThanByStructure(left, right) | lts(left, right) | less than by structure | | lessThanOrEqualByStructure(left, right) | ltes(left, right) | less than or equal by structure | | greaterThanByStructure(left, right) | gts(left, right) | greater than by structure | | greaterThanOrEqualByStructure(left, right) | gtes(left, right) | greater than or equal by structure |

Please note that these operators only work for objects. For any other type, they return false.

Running quality assurance

To run quality assurance for this module use roboter:

$ npx roboter