1.0.5 • Published 4 years ago

bufx v1.0.5

Weekly downloads
471
License
MIT
Repository
github
Last release
4 years ago

The bufx library contains various utility functions that read and write line-oriented string buffers. These functions are particularly useful for emitting output a bit at a time, and then writing them or printing them to the console. JSON, YAML, and JavaScript are supported. You can split your output into multiple channels going to separate buffers, or work with one default buffer. Please refer to the bufx.js source file for details about function arguments.

Function nameWhat it does
clearBufClear a buffer
emitEmit a string to a buffer
emitJsEmit a JavaScript string to a buffer with formatting
emitJsonEmit an object to a buffer as compact JSON
emitLineEmit a string to a buffer terminated by a newline
emitPrettyJsonEmit an object to a buffer as formatted JSON
emitYamlEmit an object to a buffer as YAML
getBufGet buffer contents as a string
linesSplit a string into lines that may have Windows or Unix line endings
loadYamlParse a YAML string into an object
numNumeric value of a string or number
openOpen a buffer for writing
prPrint a string to the console
printPrint a string to the console
printaPrint an array
printBufPrint a buffer to the console
printJsonPrint an array or object as JSON
printYamlPrint an array or object as YAML
printuPrint a sorted, unique array
readRead a UTF-8 file into a string
readYamlRead an array or object from a YAML file
sortaalphanumeric sort
sortnnumeric sort
sortusort -u equivalent
writeWrite a string to a UTF-8 file
writeBufWrite a buffer to a file
writeJsonWrite an array or object as JSON to a file
writeYamlWrite an array or object as YAML to a file

This example reads a JSON file and prints a formatted version to the console.

const B = require('bufx')
const pr = B.pr
let pathname = process.argv[2]
if (!pathname) {
  pr('usage: pretty-json js-file')
  process.exit()
}
let input = B.read(pathname)
let o = eval(input)
B.emitPrettyJson(o)
B.printBuf()