Socket
Socket
Sign inDemoInstall

natural-compare-lite

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    natural-compare-lite

Natural compare


Version published
Maintainers
1
Install size
4.77 kB
Created

Package description

What is natural-compare-lite?

The natural-compare-lite npm package is designed for comparing strings in a way that humans might naturally order them. This is particularly useful when sorting lists of strings that include numbers, as it ensures that numerical parts are compared numerically rather than lexicographically. For example, 'item2' will come before 'item10', which is not the case with standard string comparison.

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

Natural String Comparison

This feature allows for the natural comparison of strings, especially useful for sorting arrays where elements contain numbers. The provided code demonstrates sorting an array of strings in a natural order.

"use strict";\nconst naturalCompare = require('natural-compare-lite');\nconsole.log(['item10', 'item2'].sort(naturalCompare)); // ['item2', 'item10']

Other packages similar to natural-compare-lite

Readme

Source

Natural Compare

Download compressed (348 bytes or 229 bytes gzipped) or uncompressed source.

Usage

var a = ["z1.doc", "z10.doc", "z17.doc", "z2.doc", "z23.doc", "z3.doc"]
a.sort(String.natural_compare)

Licence

Copyright (c) 2012 Lauri Rooden <lauri@rooden.ee>
The MIT License

Keywords

FAQs

Last updated on 01 Apr 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc