nqm-wrangler-utils

0.1.2 • Public • Published

nqm-wrangler-utils

utility functions for nqm wranglers

install

npm install nqm-wrangler-utils

usage

const utils = require("nqm-wrangler-utils");

age group generation

usage

const includeCatchAll = true;
const ageGroups = utils.ageGroupGenerator(5, 0, 90, includeCatchAll);

gives

["0-4", "5-9", ..., "85-89", "90-"]

csv parsing

usage

const csvParser = utils.csvParser;

// Generate the output file based on the given output name input.
const outputFilePath = output.getFileStorePath(`${input.outputName}.json`);

// Create the output stream.
const destStream = fs.createWriteStream(outputFilePath, {flags: input.appendOutput ? "a" : "w"});

// Get a wrangler class based on the input source type, e.g. 'estimates' or 'projections'.
const ONSWrangler = wranglerFactory(input.sourceType);

// Load the source stream based on the type of source data given.
let sourceStream;
if (input.sourceFilePath) {
  // Source is a file on local disk.
  sourceStream = fs.createReadStream(source);
} else if (input.sourceResource) {
  // Source is a TDX resource.
  sourceStream = context.tdxApi.getRawFile(source);
} else {
  // Source is a remote URL.
  sourceStream = request.get(source);
}

// Create a wrangler instance.
const wrangler = new ONSWrangler(input, output, destStream);

// The parser will read the source and pipe it through the wrangler to the destination stream.
return csvParser(wrangler, sourceStream, destStream);

Readme

Keywords

none

Package Sidebar

Install

npm i nqm-wrangler-utils

Weekly Downloads

2

Version

0.1.2

License

ISC

Last publish

Collaborators

  • jr7g19
  • ionut_nqm
  • nqminds-bot
  • nqminds-org
  • mereacre
  • antmcc
  • toby.ealden
  • aloisklink
  • cbrafter
  • ashleysetter