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

string-natural-compare

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-natural-compare

Compare alphanumeric strings the same way a human would, using a natural order algorithm

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.1M
increased by4.77%
Maintainers
1
Weekly downloads
 
Created

What is string-natural-compare?

The string-natural-compare npm package provides a way to compare strings in a human-friendly manner, often referred to as 'natural order' comparison. This is particularly useful for sorting lists of strings that include numbers, where you want the numbers to be sorted in numerical order rather than lexicographical order.

What are string-natural-compare's main functionalities?

Basic Natural Comparison

This feature allows you to compare two strings in a natural order. In this example, 'file10' is compared to 'file2', and the result is 1, indicating that 'file10' comes after 'file2' in natural order.

const naturalCompare = require('string-natural-compare');

const result = naturalCompare('file10', 'file2');
console.log(result); // Output: 1

Sorting an Array

This feature allows you to sort an array of strings in natural order. In this example, the array ['file10', 'file2', 'file1'] is sorted to ['file1', 'file2', 'file10'].

const naturalCompare = require('string-natural-compare');

const files = ['file10', 'file2', 'file1'];
files.sort(naturalCompare);
console.log(files); // Output: ['file1', 'file2', 'file10']

Case-Insensitive Comparison

This feature allows you to perform a case-insensitive natural comparison. In this example, 'File10' is compared to 'file2' with case insensitivity, and the result is 1, indicating that 'File10' comes after 'file2' in natural order.

const naturalCompare = require('string-natural-compare');

const result = naturalCompare('File10', 'file2', { caseInsensitive: true });
console.log(result); // Output: 1

Other packages similar to string-natural-compare

Keywords

FAQs

Package last updated on 08 May 2015

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