Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→csv-sortnext

csv-sort7.2.1

Sort double-entry bookkeeping CSV from internet banking

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — SORT()
  • API — FINDTYPE()
  • API — ISNUMERIC()
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Check whether a CSV cell is numeric
  • Handle an empty CSV string
  • Classify CSV cells before sorting
  • Sort a bank statement that has no header row

Purpose

  • Sorts rows in correct order that follows the double-entry format.
  • Trims the empty columns and rows (so-called 2D-Trim^).
2D trim of a CSV contents
2D trim of a CSV contents

In later releases, we would like to be able to recognise and fix any offset columns caused by misinterpreted commas as values.

^ 1D-Trim would be trim of a string. 3D-Trim would be some sort of spatial data trim.

API — sort()

The main function sort() is imported like this:

It’s a function which takes one input argument:

It returns a plain object:

output objectTypeDescription
res
Type: Array
resArrayArray of arrays, each containing a column’s value.
msgContent
Type: String
msgContentStringThis application outputs the messages here.
msgType
Type: String
msgTypeStringCan be either alert or info. That’s similar to an icon on the hypothetical UI.

If the input is anything else than a string, it will throw. If the input is an empty string, the output object’s res key will be equal to [['']].

API — findType()

The function findType() is imported like this:

sort() uses this internally to work out what each cell holds. It’s exported so you can classify cells the same way:

Input argumentTypeObligatoryDescription
something
Type: String
Obligatory: yes
somethingStringyesA single CSV cell.

It returns one of three strings:

ResultMeaning
"numeric"
"numeric"The cell is a number, or becomes one once a known currency symbol and any commas or dots are removed.
"empty"
"empty"The cell is empty or contains only whitespace.
"text"
"text"Everything else.
import { findType } from "csv-sort";

console.log(findType("1.5"));
// => "numeric"
console.log(findType("$5"));
// => "numeric"
console.log(findType("  "));
// => "empty"
console.log(findType("abc"));
// => "text"

The currency-aware step is what separates findType() from a plain number check — a bank statement column full of £1,000.00 still counts as numeric.

API — isNumeric()

The function isNumeric() is imported like this:

The plain number check which findType() builds on:

It returns true for numbers and for strings which convert to a number once trimmed. It does not know about currency symbols or thousand separators — use findType() for those:

import { isNumeric } from "csv-sort";

console.log(isNumeric("-2.30"));
// => true
console.log(isNumeric("$5"));
// => false
console.log(isNumeric(""));
// => false

API — version

You can import version:

API — types

This package is written in TypeScript and exports the type Res, the shape sort() returns, shown above:

import type { Res } from "csv-sort";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab