parse-listing

raw JSON →
1.1.3 verified Sat May 09 auth: no javascript maintenance

Small library to parse file listings (e.g., ls, dir) into JavaScript objects. Currently at v1.1.3, last released in 2018 with a fix for MS-DOS folder names containing numbers. It supports Unix and DOS/Windows formats automatically. The library is stable but in maintenance mode; no new features are expected. Compared to alternatives, it is minimal and has no dependencies.

error Cannot find module 'parse-listing'
cause Package not installed or module path incorrect.
fix
Run 'npm install parse-listing' and ensure require('parse-listing') is correct.
error TypeError: Parser.parseEntries is not a function
cause Using import instead of require (ESM vs CJS).
fix
Use const Parser = require('parse-listing'); instead of import.
error undefined is not a function (callback)
cause Passing undefined as callback to parseEntries.
fix
Ensure callback is a function: Parser.parseEntries(str, function(err, entries) { ... });
breaking Callback error handling: if you pass invalid input (e.g., null or non-string), the library may throw synchronously or call callback with error depending on the method.
fix Always wrap in try-catch for parseEntry or check input validity before calling parseEntries.
gotcha Time parsing: The 'time' field is a timestamp in milliseconds, but some entries may not parse correctly (e.g., non-standard date formats).
fix Use a library like moment.js to parse the raw date string if needed; check entry.time for NaN.
deprecated No updates since 2018: The package is in maintenance-only mode. Security or compatibility issues may not be addressed.
fix Consider switching to 'ftp-parse-listing' or writing a custom parser if you need active maintenance.
npm install parse-listing
yarn add parse-listing
pnpm add parse-listing

Parses a Unix 'ls -la' formatted string into objects, logging name, type, and size for each entry.

const Parser = require('parse-listing');

const unixListing = `drwxr-xr-x    5 1001     1001         4096 Jan 09 11:52 .
drwxr-xr-x    4 0        0            4096 Sep 19 13:50 ..
-rw-------    1 1001     1001         1118 Jan 09 12:09 .bash_history
-rw-------    1 1001     1001          943 Jan 09 11:52 .viminfo
drwxrwxr-x    5 1001     1001         4096 Jan 09 11:52 inaccessible
drwxrwxrwx    2 1001     1001         4096 Sep 21 11:20 project1
drwx------    2 1001     1001         4096 Oct 19 16:17 project2`;

Parser.parseEntries(unixListing, function(err, entries) {
  if (err) {
    console.error(err);
    return;
  }
  entries.forEach(function(entry) {
    console.log('Name:', entry.name, 'Type:', entry.type, 'Size:', entry.size);
  });
});