xport-js

0.1.4 • Public • Published

xport-js

Library to read in v5/v6 XPORT files using Node.js .

Installation

To add xport-js to your project, run

npm install xport-js

Usage and Documentation

See the library documentation for details on methods and options available.

import Library from 'xport-js';
// Create a library instance
const lib = new Library('/path/to/ds.xpt');
// Get variable metadata
const metadata = await lib.getMetadata();
// Get dataset records as objects
let records = [];
for await (let obs of lib.read({ rowFormat: 'object' })) {
    records.push(obs);
}
// Output contents of XPT file to CSV file(s)
await lib.toCsv('/outDir/')

Library.read method

This method return AsyncIterable which can be used in for await ... of statement.

lib.read(options);
  • dsNames List of dataset names to read, by default all datasets are read.
  • rowFormat [default=array] Output observation format. array: [value1, value2, value3, ...] object: { var1: value1, var: value2, var3: value3, ... }
  • keep [default=[]] Array of variables to keep in the result (case-insensitive)
  • skipHeader [default=false] Flag to control whether the first record contains variable names.
  • encoding [default=binary] String encoding, default is latin1 (binary). See the list of encodings supported by Node.js.

Library.toCsv method

Creates CSV file(s) in the outDir.

lib.read(outDir, options);

See read method options description for details.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

Dependents (0)

Package Sidebar

Install

npm i xport-js

Weekly Downloads

110

Version

0.1.4

License

MIT

Unpacked Size

384 kB

Total Files

48

Last publish

Collaborators

  • dmitrymk