Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-columns

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-columns

Parse text columns, like the output of unix commands

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

parse-columns Build Status

Parse text columns, like the output of unix commands

Install

$ npm install --save parse-columns

Usage

$ df -kP
Filesystem 1024-blocks      Used Available Capacity  Mounted on
/dev/disk1   487350400 467871060  19223340    97%    /
devfs              185       185         0   100%    /dev
map -hosts           0         0         0   100%    /net
var childProcess = require('child_process');
var parseColumns = require('parse-columns');

childProcess.execFile('df', ['-kP'], function (err, stdout) {
	console.log(parseColumns(stdout, {
		transform: function (el, header, columnIndex) {
			// coerce elements in column index 1 to 3 to a number
			if (columnIndex >= 1 && columnIndex <= 3) {
				return Number(el);
			}

			return el;
		}
	}));
	/*
	[{
		Filesystem: '/dev/disk1',
		'1024-blocks': 487350400,
		Used: 467528020,
		Available: 19566380,
		Capacity: '96%',
		'Mounted on': '/'
	}, ...]
	*/
});

API

parseColumns(input, [options])

input

Required
Type: string

Text columns to parse.

options
separator

Type: string
Default: ' '

Separator to split columns on.

headers

Type: array

Headers to use instead of the existing ones.

transform

Type: function

Transform elements.

Useful for being able to cleanup or change the type of elements.

The supplied function gets the following arguments and is expected to return the element:

  • element (string)
  • header (string)
  • columnIndex (number)
  • rowIndex (number)

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 07 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc