Socket
Socket
Sign inDemoInstall

@discoveryjs/natural-compare

Package Overview
Dependencies
0
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @discoveryjs/natural-compare

Compare strings in a natural order


Version published
Weekly downloads
289K
increased by2.59%
Maintainers
3
Install size
55.7 kB
Created
Weekly downloads
 

Changelog

Source

1.1.0 (2022-09-16)

  • Refactored to improve a bundle minification (for bundling with esbuild 2354 -> 1890 bytes)
  • Added dist/natural-compare.esm.js
  • Removed npm version assertion in package.json (#1)

Readme

Source

NPM version Build Status Coverage Status

@discoveryjs/natural-compare

Compare strings in a natural order

Install

npm install @discoveryjs/natural-compare

Usage

import { naturalCompare } from '@discoveryjs/natural-compare';

[
    'file10.js',
    'file1.js',
    'file2.js',
    'file12.js',
    'file9.js'
].sort(naturalCompare);
// file1.js
// file2.js
// file9.js
// file10.js
// file12.js

// standart sorting
[
    'file10.js',
    'file1.js',
    'file2.js',
    'file12.js',
    'file9.js'
].sort();
// file1.js
// file10.js
// file12.js
// file2.js
// file9.js

In browser:

    <!-- ESM -->
    <script type="module">
        import { natualCompare } from "@discoveryjs/natural-compare/dist/natural-compare.esm.js";

        array.sort(naturalCompare);
    </script>

    <!-- Old way -->
    <script src="@discoveryjs/natural-compare/dist/natural-compare.js"></script>
    <script>
        array.sort(naturalCompare);
    </script>

License

MIT

Keywords

FAQs

Last updated on 16 Sep 2022

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