Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thi.ng/compare

Package Overview
Dependencies
Maintainers
1
Versions
158
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/compare

Comparators with support for types implementing the @thi.ng/api/ICompare interface

  • 1.3.34
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @thi.ng/compare?

@thi.ng/compare is a utility library for various comparison operations in JavaScript. It provides a collection of comparator functions for different data types and use cases, making it easier to perform sorting, equality checks, and other comparison-based operations.

What are @thi.ng/compare's main functionalities?

Basic Comparators

Provides basic comparator functions for general use, including ascending and descending numerical comparisons.

const { compare, compareNumAsc, compareNumDesc } = require('@thi.ng/compare');

console.log(compare(5, 10)); // -1
console.log(compareNumAsc(5, 10)); // -1
console.log(compareNumDesc(5, 10)); // 1

String Comparators

Includes specialized comparators for string values, with options for case-sensitive and case-insensitive comparisons.

const { compareStr, compareStrCaseInsensitive } = require('@thi.ng/compare');

console.log(compareStr('apple', 'banana')); // -1
console.log(compareStrCaseInsensitive('Apple', 'apple')); // 0

Array Comparators

Allows for comparison of arrays, element by element, to determine their order or equality.

const { compareArrays } = require('@thi.ng/compare');

console.log(compareArrays([1, 2, 3], [1, 2, 4])); // -1
console.log(compareArrays([1, 2, 3], [1, 2, 3])); // 0

Object Comparators

Provides comparators for objects based on specific keys, useful for sorting arrays of objects.

const { compareByKey } = require('@thi.ng/compare');

const obj1 = { id: 1, name: 'Alice' };
const obj2 = { id: 2, name: 'Bob' };
console.log(compareByKey('id')(obj1, obj2)); // -1

Other packages similar to @thi.ng/compare

Keywords

FAQs

Package last updated on 03 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc