npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

isotropic-natural-sort

v0.8.1

Published

A configurable natural sorting implementation

Readme

isotropic-natural-sort

npm version License

A configurable natural sorting implementation for JavaScript that intelligently sorts strings containing numbers, lexicographic orderings, and special characters.

Why Use This?

  • Smarter Than Standard Sorting: Sorts numerically within strings (e.g., "file2" comes before "file10")
  • Highly Configurable: Customize case sensitivity, direction, special character handling, and more
  • Handles Mixed Content: Works properly with arrays containing both numbers and strings
  • Lexicographic Ordering Support: Properly sorts version numbers and IP addresses
  • Prefix Positioning: Control where items with specific prefixes appear in sorted results

Installation

npm install isotropic-natural-sort

Usage

import _naturalSort from 'isotropic-natural-sort';

// Basic usage with default options
[
    'file10.txt',
    'file2.txt',
    'file1.txt'
].sort(_naturalSort());
// Result: ['file1.txt', 'file2.txt', 'file10.txt']

// With custom options
const _customSortFunction = _naturalSort({
    caseSensitive: true,
    direction: 'desc',
    ignoreSpecialCharacters: false,
    prefixPositions: {
        'important-': 'first',
        'archive-': 'last'
    }
});

myArray.sort(_customSortFunction);

Configuration Options

The naturalSort function accepts an options object with the following properties:

| Option | Type | Default | Description | |--------|------|---------|-------------| | caseSensitive | Boolean | false | Whether to consider character case when sorting strings | | direction | String | 'asc' | Sort direction, either 'asc' or 'desc' | | ignoreSpecialCharacters | Boolean | true | Whether to ignore special characters (accents, diacritics) when sorting | | prefixPositions | Object | {} | Object mapping prefixes to positions ('first' or 'last') |

Examples

Basic Sorting

import _naturalSort from 'isotropic-natural-sort';

// Natural sorting of filenames
const _files = [
  'file10.txt',
  'file2.txt',
  'file1.txt',
  'file20.txt'
];

_files.sort(_naturalSort());
// Result: ['file1.txt', 'file2.txt', 'file10.txt', 'file20.txt']

Case-Sensitive Sorting

import _naturalSort from 'isotropic-natural-sort';

const _items = [
    'B',
    'a',
    'C',
    'b'
];

// Case-insensitive (default)
_items.sort(_naturalSort());
// Result: ['a', 'B', 'b', 'C']

// Case-sensitive
_items.sort(_naturalSort({
    caseSensitive: true
}));
// Result: ['B', 'C', 'a', 'b']

Descending Order

import _naturalSort from 'isotropic-natural-sort';

const _numbers = [
    1,
    10,
    2,
    20
];

_numbers.sort(_naturalSort({
    direction: 'desc'
}));
// Result: [20, 10, 2, 1]

Special Character Handling

import _naturalSort from 'isotropic-natural-sort';

const _names = [
    'cáfé charlotte',
    'cafe blue',
    'café amanda'
];

// Ignoring special characters (default)
_names.sort(_naturalSort());
// Result: ['café amanda', 'cafe blue', 'cáfé charlotte']

// Considering special characters
_names.sort(_naturalSort({
    ignoreSpecialCharacters: false
}));
// Result order depends on Unicode points of the accented characters
// Result: ['cafe blue', 'café amanda', 'cáfé charlotte']

Lexicographic Ordering (IP Addresses, Versions)

import _naturalSort from 'isotropic-natural-sort';

const _ips = [
        '192.168.0.10',
        '192.168.0.2',
        '10.0.0.1',
        '192.168.1.1'
    ],
    _versions = [
        '1.10.0',
        '1.2.0',
        '1.1.0',
        '1.2.1'
    ];

_ips.sort(_naturalSort());
// Result: ['10.0.0.1', '192.168.0.2', '192.168.0.10', '192.168.1.1']

_versions.sort(_naturalSort());
// Result: ['1.1.0', '1.2.0', '1.2.1', '1.10.0']

Prefix Positioning

import _naturalSort from 'isotropic-natural-sort';

const _tasks = [
    'normal-task3',
    'urgent-task1',
    'normal-task1',
    'low-priority-task',
    'urgent-task2'
];

_tasks.sort(_naturalSort({
    prefixPositions: {
        'low-priority-': 'last',
        'urgent-': 'first'
    }
}));
// Result: ['urgent-task1', 'urgent-task2', 'normal-task1', 'normal-task3', 'low-priority-task']

Mixed Content

import _naturalSort from 'isotropic-natural-sort';

const _mixed = [
    5,
    '10',
    'item3',
    2,
    'item10',
    'item1'
];

_mixed.sort(_naturalSort());
// Result: [2, 5, '10', 'item1', 'item3', 'item10']

Handling Falsy Values

By default, null, undefined, and NaN values are sorted to the end of the array:

import _naturalSort from 'isotropic-natural-sort';

const _withFalsy = [
    'b',
    null,
    'a',
    undefined,
    'c'
];

_withFalsy.sort(_naturalSort());
// Result: ['a', 'b', 'c', null, undefined]

Contributing

Please refer to CONTRIBUTING.md for contribution guidelines.

Issues

If you encounter any issues, please file them at https://github.com/ibi-group/isotropic-natural-sort/issues