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

@stenway/oml-io

v1.1.0

Published

Read and write OML files

Downloads

30

Readme

OML-IO

About

This package gives you OML file reading and writing functionality. Learn more about OML in the @stenway/oml package.

Installation

Using NPM:

npm install @stenway/oml-io

Getting started

The writeSync method of the OmlFile class directly takes a JavaScript object/value as argument, stringifies it and saves it as a text file. The readSync method then loads the text file, parses it and returns an object/value:

import { OmlFile } from '@stenway/oml-io'

let filePath = "Test.oml"
OmlFile.writeSync({test: 123, test2: true}, filePath)
console.log(OmlFile.readSync(filePath))

When you have an OmlDocument object, you can use the loadSync and saveSync method:

import { OmlDocument } from '@stenway/oml'
import { OmlFile } from '@stenway/oml-io'

let filePath = "Test.oml"
let document = OmlDocument.parse(`{test=123 test2=true}`)
OmlFile.saveSync(document, filePath)

let loadedDocument = OmlFile.loadSync(filePath)
console.log(loadedDocument.content)

Asynchronous IO

The read, write, load and save methods are the asynchronous equivalents of the synchronous readSync, writeSync, loadSync and saveSync methods.

let filePath = "Test.oml"
await OmlFile.write({test: 123, test2: true}, filePath)
let result = await OmlFile.read(filePath)
console.log(result)

Formatting, replacing and reviving

The write and save methods have formatting and replacer parameters like the Oml.stringify method and the read and load methods have a reviver parameter like the Oml.parse method, with which you can control how serialization and deserialization will be handled. Here is an example where the number 123 will be replaced with the string "<Replaced>" when serialized, and the other way around when it's deserialized:

let filePath = "Test.oml"
let document = OmlDocument.parse(`{test=123 test2=true}`)
OmlFile.saveSync(document, filePath, {}, (root, owner, key, value) => {
	if (value === 123) { return "<Replaced>" }
	return value
})

let loadedDocument = OmlFile.loadSync(filePath, (owner, key, value) => {
	if (value === "<Replaced>") { return 123 }
	return value
})
console.log(loadedDocument.content)

The resulting OML file will look like this:

{
	test  = <Replaced>
	test2 = true
}

Bye Bye CSV -> Table Data as OML-Files

If you don't want to use CSV to write table data, you can use OML to do that. Because OML doesn't require so many double-quotes like JSON and you don't have to write commas, tabular data looks much more natural:

let tableContent = 
`[
  [FirstName      LastName  Age  PlaceOfBirth]
  [William        Smith     30   Boston]
  [Olivia         Jones     27   "San Francisco"]
  [Lucas          Brown     null Chicago]
]`
OmlFile.saveSync(OmlDocument.parse(tableContent), "Table.oml")

let tableData = OmlFile.readSync("Table.oml")
console.log(Oml.stringify(tableData, {}))

And because OML files are ReliableTXT files, you never need to worry about encoding again.

If you want an even more natural way to write tabular data, have a look at TBL which is an SML-based format.

Videos