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

alphanum-compare

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alphanum-compare

Compare alphanumeric strings

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
103
decreased by-61.57%
Maintainers
1
Weekly downloads
 
Created
Source

alphanum-compare

npm version Node.js CI codecov Known Vulnerabilities FOSSA Status

Compare function extrated from alphanum-sort. It can be used as compareFunction in Array.prototype.sort().

Install

yarn add alphanum-compare

Usage

import compareFn from "alphanum-compare";

console.log("5".localeCompare("10")); // 1, NO GOOD
console.log(compareFn("5", "10")); // -1, GOOD

console.log(compareFn("-5", "5")); // 1, NO GOOD
console.log(compareFn("-5", "5", { sign: true })); // -1, GOOD

console.log(["item20", "item19", "item1", "item10", "item2"].sort(compareFn));
// ['item1', 'item2', 'item10', 'item19', 'item20']

CodeSandbox

compareFn(a: number | string, b: number | string, opts?: Options): number

It returns a negative value if first argument is less than second argument, zero if they're equal and a positive value otherwise.

Options
  • insensitive?: boolean

    Compares items case insensitively. (Default: false)

  • sign?: boolean

    Allows + and - characters before numbers. (Default: false)

License

FOSSA Status

Keywords

FAQs

Package last updated on 13 Oct 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