The `javascript-natural-sort` package provides a comparator function implementing a natural sort algorithm, designed for use with JavaScript's `Array.prototype.sort()`. It intelligently handles various complex string patterns beyond simple lexicographical sorting, including numerical values (integers, floats, scientific notation), IP addresses, filenames, dates, and currency. The current stable version is `0.7.1`. Given its last update over six years ago, the package is considered abandoned and does not receive active maintenance or new feature development. Its key differentiator is its comprehensive approach to handling diverse data types within a single, self-contained sorting utility, offering a simple API for common sorting challenges where standard string comparison falls short, with an option for case-insensitive sorting.
npm install javascript-natural-sortVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic natural sorting for mixed numeric data and IP addresses, plus how to enable and disable global case-insensitive sorting.
Always explicitly set `naturalSort.insensitive = false;` after performing case-insensitive sorts if subsequent sorts require case-sensitive behavior, or wrap your usage in a function that manages the state.
Consider migrating to a more actively maintained natural sort library that supports modern JavaScript features and best practices, or be prepared to fork and maintain the code yourself.
Use CommonJS `require` for Node.js environments, or rely on a bundler (like Webpack, Rollup, or esbuild) to correctly handle the CJS-to-ESM transformation for browser environments.
For CommonJS, use `const naturalSort = require('javascript-natural-sort');`. For ESM, use `import naturalSort from 'javascript-natural-sort';`.Enable case-insensitive sorting by setting the global flag: `naturalSort.insensitive = true;` (remember to reset it if needed).
Set the property directly: `naturalSort.insensitive = true;` (or `false`).
No dependency data recorded yet.