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 🙏

© 2024 – Pkg Stats / Ryan Hefner

taf-parser

v0.0.2

Published

TAF ( Tagged Format ) Sage 50 Format Parser.

Downloads

5

Readme

TAF parser

'Tagged Format' (TAF) files are files that can be used to export and import data sets used by the accounting system of Sage 50 (more about this file format, supported tags and its specification can be found here).

The parser goes through a string content or a stream of data and detects one error at a time in the structure.

Build Status npm version Coverage Status Known Vulnerabilities License: MIT

Installation

To install the parser, just type in your console:

$ npm install taf-parser

Usage

This parser can be used to:

  • Parse a string
    In this case it will return an array of objects that represents the data in the content upon success, or throw an error that shows what and where is the error happening. This method is recomended for small to midsize content that can be passed a string.
    For larger data use the stream capabilities.

  • Parse a stream of data
    When dealing with large content it is recomended to use the parser to create a stream that can be combined with other streams. The stream pushes correctly parsed block of data down to the next stream. In case of an error, an error event is emited.

First, require the parser:

const Parser = require('taf-parser');

Parsing a string

const str = `
    {Blg BlgNr=983984 GFNr=994885 Date=25.10.2017 Orig=0 MType=2
    	{Bk AccId=1022 Type=0 CAcc=div  ValNt=342.6  Text="Explain this some text"}
    }`;
const result = Parser.parse(str);

Or if you have a file:

const fs = require('fs');
const fileName = 'your_taf_file_name.taf';
const result = Parser.parse(fs.readFileSync(fileName, { encoding: 'utf8' }));

In both cases, if the parser finds an error it will throw it, showing what is wrong and where it is located.

If there is no error, the result will be an array of objects, representing the data in the file. In the case of the example string given above, the result array will be as follows:

[
    {
        type: 'Blg',
        BlgNr: 983984,
        GFNr: 994885,
        Date: '2017-10-25T11:43:59.208Z',
        Orig: 0,
        MType: 2,
        Bk: [
            {
                type: 'Bk',
                AccId: '1022',
                Type: 0,
                CAcc: 'div',
                ValNt: 342.6,
                Text: 'Explain this some text'
            }
        ]
    }
]

Parsing/Using streams

To use streams, just create parser stream like this:

const ParseStream = Parser.createStream();

The newly created stream is a Transform stream, that expects data flowing to it and as a result pushes to the next stream javascript object representation of each successfully parsed block of data.
In the case of an error the stream will emit an error event.

Streams example

const fs = require('fs');			// will use fs to create readabele file stream
const { Writable } = require('stream');		// will use writable stream to collect all the data

const Parser = require('taf-parser');	// require the Parser

class W extends Writable {
	constructor() {
		super({ objectMode: true });
		this.data = [];
	}

	_write(block, a, n) {
		this.data.push(block);
		n();
	}
}

const file = 'some_taf_file.taf';
const readStream = fs.createReadStream(file, { encoding: 'utf8' });
const Writer = new W();
const ParseStream = Parser.createStream();	// create stream parser

readStream
	.pipe(ParseStream)
	.pipe(Writer);

// you can listen for an 'error' event from ParseStream
ParseStream.on('error', (error) => {
	console.log(error);
});

// and 'finish' from the Writer where all the data is collected
Writer.on('finish', () => {
	// Writer.data holds all the data
	console.log(Writer.data); // or do something else
});

Licensing

Copyright (c) 2018 eCollect AG. Licensed under the MIT license.