A fixed-width file format toolset with streaming support and flexible options.

Overview

fixed-width

JavaScript Style Guide ci

A fixed-width file format toolset with streaming support and flexible options.

Features

  • Flexible: lot of options
  • Zero dependencies: small footprint
  • Native streaming support
  • Well tested: code coverage above 90%
  • Support big datasets: production ready
  • Native ESM support: future proof
  • TypeScript support

Install

npm i @evologi/fixed-width

Examples

Parse

import { parse } from '@evologi/fixed-width'

const text = 'alice       024\nbob         030\n'

// Buffers are working too!
const users = parse(text, {
  eol: '\n',
  fields: [
    {
      property: 'username',
      width: 12
    },
    {
      property: 'age',
      width: 3
    }
  ]
})

console.log(users) // [{ username: 'alice', age: '024' }, { username: 'bob', age: '030' }]

Stringify

import { stringify } from '@evologi/fixed-width'

const users = [
  { username: 'alice', age: 24 },
  { username: 'bob', age: 30 }
]

const text = stringify(users, {
  eol: '\n',
  fields: [
    {
      align: 'left',
      property: 'username',
      width: 12
    },
    {
      align: 'right',
      property: 'age',
      width: 3
    }
  ]
})

console.log(text) // 'alice        24\nbob          30'

Parse with Node.js streams

import { Parser } from '@evologi/fixed-width'

const stream = Parser.stream({
  eol: '\n',
  fields: [
    {
      property: 'username',
      width: 12
    },
    {
      property: 'age',
      width: 3
    }
  ]
})

stream
  .on('error', err => console.error(err))
  .on('data', data => console.log(data))
  .on('end', () => console.log('end'))

// Write any buffer or string
stream.write('alice       ')
stream.write('024')
stream.write('\n')
stream.write('bob         ')
stream.write('030')
stream.end()

Stringify with Node.js streams

import { Stringifier } from '@evologi/fixed-width'

const stream = Stringifier.stream({
  eol: '\n',
  fields: [
    {
      align: 'left',
      property: 'username',
      width: 12
    },
    {
      align: 'right',
      property: 'age',
      width: 3
    }
  ]
})

let text = ''

stream
  .on('error', err => console.error(err))
  .on('data', buffer => {
    text += buffer.toString()
  })
  .on('end', () => {
    console.log(text)
  })

stream.write({ username: 'alice', age: 24 })
stream.write({ username: 'bob', age: 30 })
stream.end()
You might also like...

Fixed-point math for Bitcoin Script

bsv-fixmath Fixed-point implementations of exp, log, root and pow for Bitcoin SV. This repo contains two equivalent implementations, one in Typescript

Oct 18, 2022

Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Nov 2, 2022

Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Dec 15, 2022

A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

Welcome to the Generative GIF Engine v2.0.4 🐤 [8 minute read] This python and node app generates layered-based gifs to create NFT gif art! It is fast

Jan 2, 2023

A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

A generative engine that takes various png layers on a sprite sheet format, combines them and then converts them into a .gif file

Welcome to the Generative Animated Engine v3.0.1 🐤 [8 minute read] This repo used to be called jalagar/Generative_Gif_Engine but because it now suppo

May 24, 2022

A Javascript library to export svg charts from the DOM and download them as an SVG file, PDF, or raster image (JPEG, PNG) format. Can be done all in client-side.

svg-exportJS An easy-to-use client-side Javascript library to export SVG graphics from web pages and download them as an SVG file, PDF, or raster imag

Oct 5, 2022

Flexible survey webapp with multi-languages support

Civic-echo Civic-echo is a light app used for dynamic survey generation based on YAML files. Coupled with DeepL, it can handle multiple languages easi

Jul 4, 2022

Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mathematical properties.

Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mathematical properties.

Math-Calc Math Calc is a simple algebra calculator with options for basic addition, subtraction, multiplication, and division as well as many more mat

Dec 25, 2021

A dashboard to display options-related data around PsyOptions markets and Serum orderbooks.

A dashboard to display options-related data around PsyOptions markets and Serum orderbooks.

PsyOptions Data Dashboard Digestible data around options activity on Solana is pretty inaccessible at the moment. PsyViz provides a clean and user-fri

May 13, 2022
Releases(v0.3.0)
Owner
Evologi Srl
Evologi Srl
A powerful simple JavaScript function-like toolset.

PrueEval PureEval 因 VoxelGeometry 项目而生,意在打造一个精巧而强大的 JavaScript 函数式工具包。 PureEval 具有以下特点: 具有独特的非变量绑定式 iterate 策略。 支持对任意参数已知函数函数的柯里化。 体积小、代码精简,嵌入成本极低。 Us

null 20 Dec 28, 2022
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
Store data using zero width spaces! Might be useful for discord bots.

ZWSP Store data using zero width spaces! Might be useful for discord bots. Installation npm i zwsp Usage Import the library: import { encode, decode}

Xaro 8 Dec 12, 2022
Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Stephanie Eckles 65 Nov 2, 2022
Framework for interacting with instagrams private api in a usable manner (forked from andre's work and improved and fixed)

node-ig-framework Framework for interacting with instagrams private api in a usable manner (forked from andre's work and improved and fixed) Installat

nine ecksen 3 Dec 31, 2022
Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all with IndexedDB. Perfectly suitable for your next (PWA) app.

BrowstorJS ?? ?? ?? Persistent key/value data storage for your Browser and/or PWA, promisified, including file support and service worker support, all

Nullix 8 Aug 5, 2022
The best Blooket hacks on the platform! These hacks are always working, all gamemode hacks work and will be fixed when broke.

Support Discord Server: https://discord.gg/UCHtVM4A Blooket Hack The Blooket Hack provided by Jude Why you should use this tool: Always working. When

Jude 26 Dec 20, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Simple fixed background parallax effect in vanilla js.

Simple Parallax Simple fixed background parallax effect in vanilla js. See demo on Codepen. JS Initialise the plugin. The first argument identifies th

null 6 Jun 27, 2022
Javascript library for switching fixed elements on scroll through sections. Like Midnight.js, but without jQuery

Library for Switching Fixed Elements on Scroll Sometimes designers create complex logic and fix parts of the interface. Also they colour page sections

Vladimir Lysov 38 Sep 19, 2022