npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

xport-js

v0.5.0

Published

Node.js library to read SAS XPORT v5/v6 data transport files (*.xpt).

Readme

xport-js

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

Installation

npm install xport-js

Usage

import Library from 'xport-js';

const lib = new Library('/path/to/file.xpt');

Named exports

import Library, { Member, Variable } from 'xport-js';
export type { Options, Header, UniqueValues, VariableMetadata } from 'xport-js';

API

new Library(filePath)

Creates a library instance associated with the XPORT file.

getMetadata(format?)

Parses and returns metadata. Default format is dataset-json1.1.

// Variable metadata (xport format)
const vars = await lib.getMetadata('xport');
// vars: Array<{ dataset, name, label, length, type, format?, informat? }>

// Dataset-JSON 1.1 metadata
const meta = await lib.getMetadata();
// meta: { name, label, records, columns, datasetJSONCreationDateTime, ... }

Returns a Promise resolving to metadata in one of the following formats:

  • format = 'xport' — returns VariableMetadata[]
  • format = 'dataset-json1.1' (default) — returns DatasetJsonMetadata (per the Dataset-JSON 1.1 spec)

read(options?)

Async generator that yields observations row-by-row without loading the entire dataset into memory.

for await (const row of lib.read({ rowFormat: 'object' })) {
  console.log(row);
}

Returns an async generator that yields rows in the specified format.

| Option | Type | Default | Description | |--------|------|---------|-------------| | dsNames | string[] | all datasets | Dataset names to read | | rowFormat | 'array' \| 'object' | 'array' | Output format — array of values or key-value object | | keep | string[] | [] | Variables to include (case-insensitive) | | skipHeader | boolean | false | Omit the header row | | encoding | BufferEncoding | 'binary' | String encoding (see Node.js encodings) | | filter | Filter \| BasicFilter | — | Filter observations using js-array-filter | | roundPrecision | number | — | Round numeric values to N decimal places |

getData(props)

Reads all observations into memory (for large datasets prefer read).

Returns a Promise resolving to an object containing:

  • data: Array of rows in the specified format.
  • lastRow: Index of the last row returned (useful for pagination).
  • endReached: Boolean indicating if the end of the dataset has been reached.
const result = await lib.getData({
  start: 0,              // first row to return
  length: 100,           // max rows to return
  type: 'object',        // 'array' | 'object'
  filterColumns: [],     // only these columns
  filter: { ... },       // js-array-filter filter
  skipHeader: true,
  roundPrecision: 2,
});
// result: { data: Array<row>, lastRow: number, endReached: boolean }

| Option | Type | Default | Description | |--------|------|---------|-------------| | start | number | 0 | Index of the first row to return (0-based) | | length | number | all rows | Maximum number of rows to return | | type | 'array' \| 'object' | | 'array' | Output format — array of values or key-value object | | filterColumns | string[] | [] | Only include these columns (case-insensitive) | | filter | Filter \| BasicFilter | — | Filter observations using js-array-filter | | skipHeader | boolean | false | Omit the header row | | roundPrecision | number | — | Round numeric values to N decimal places (optional) |

getUniqueValues(props)

Returns unique values for specified columns.

const unique = await lib.getUniqueValues({
  columns: ['AGE', 'SEX', 'RACE'],
  limit: 10,            // max unique values per column (0 = no limit)
  addCount: true,       // include value counts
  sort: true,           // sort values
  roundPrecision: 0,    // round numeric values to integer
});
// { AGE: { values: [...], counts: { '45': 3, ... } }, ... }

Returns a Promise resolving to an object where each key is a column name and the value is an object with:

  • values: Array of unique values for that column.
  • counts: (if addCount is true) Object mapping value to count.

| Option | Type | Default | Description | |--------|------|---------|-------------| | columns | string[] | — | List of variable names to get unique values for | | limit | number | 0 | Maximum number of unique values per column (0 = no limit) | | addCount | boolean | false | Whether to include counts for each unique value | | sort | boolean | false | Whether to sort the unique values | | roundPrecision | number | — | Rounds numeric values to the specified precision (optional) |

toCsv(outDir, options?)

Writes each dataset to a separate CSV file in outDir.

await lib.toCsv('./output', { skipHeader: false });

Authors

License

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