The `array-timsort` package provides a JavaScript implementation of Python's highly optimized Timsort algorithm for stable array sorting. It is currently at version 1.0.3, with an apparent maintenance-only release cadence based on its last commit over two years ago. Unlike the `timsort` package it was forked from, `array-timsort` returns an array representing the original indices of elements after sorting, rather than `undefined`. Timsort is an adaptive, stable sorting algorithm that leverages existing order in data, achieving O(n) performance on partially sorted arrays and O(n log n) worst-case time complexity, with O(n) memory usage. Benchmarks suggest it can significantly outperform `Array.prototype.sort()` in Node.js for specific data distributions, such as descending arrays or those with many duplicates, while potentially being slower on certain random distributions.
npm install array-timsortVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic array sorting with a custom comparator, in-place modification, and sorting a specific subrange, highlighting the returned index map.
Adjust logic to handle the returned index mapping, or if in-place modification and `undefined` return is desired, consider using the original `timsort` package.
Benchmark with your specific data sets and array sizes to determine if `array-timsort` offers a performance benefit for your use case.
Use `const { sort } = require('array-timsort')` for Node.js projects, or configure your bundler (e.g., Webpack, Rollup) to handle CJS modules in an ESM project.Either convert your project to use ES modules exclusively, configure your build process to transpile/bundle CJS modules, or use dynamic `import()` within an async context if you must load CJS.
For TypeScript/ESM, ensure your `tsconfig.json` (`moduleResolution`) and build setup correctly handle CommonJS interop. Alternatively, use `import * as Timsort from 'array-timsort'; const { sort } = Timsort;` or revert to `const { sort } = require('array-timsort');` in a CJS context.No dependency data recorded yet.