onaml

0.0.4 • Public • Published

ONAML

Oh No! Another Markup Language - The Javacript version.

ONAML is a markup language / serialization format similar to JSON and, more closely, YAML. Key features of ONAML are:

  • ONAML (re)stores type information, a serialized RegExp will be restored as a RegExp.
  • The full property descriptor information is stored and restored. A read-only property will be restored as read-only.
  • Every non-trivial object or array is provided with a permanent unique id, user accessible in the (non-enumerable, read-only and hidden) __puid property.
  • Objects are deduplicated and referenced. Every non-trivial item is serialized exactly once.
  • Pluggable input and output handlers.

Usage

Obtaining & initialization:

npm install --save onaml
var ONAML = require('onaml')([configuration]);

The examples directory has two example files. Run write.js first, to populate the local disk store.

Configuration options

So far the only configuration option is:

  • storageDirectory: Directory containing serialized ONAML objects. Used for save and load functions. Default: ./onaml.store

Methods

  • serialize( object ) Serialize the given object or array. Returns a string.
  • restore( puid, string ): Return object or array with given puid, from string or string array source.
  • exists( puid ): Returns true if puid is either loaded in memory or available in the store.
  • load( puid ): Return object or array with given puid from storageDirectory/puid.onaml
  • save( puid ): Serialize object or array with puid and all children to disk.

Format

An ONAML file is only only one level deep, because of the (non-optional) referencing:

7cpfOepkqPe(!!js/Object, @@7cpfOepkqPe):
  count(!!js/number, writable=true, enumerable=true, configurable=true): 5739573
  nope(!!js/null, writable=true, enumerable=true, configurable=true): null
  myBoolean(!!js/boolean, writable=true, enumerable=true, configurable=true): true
  myBuffer(!!js/Buffer, writable=true, enumerable=true, configurable=true): AAAAAAAAAADQzOsAAAAAAA==
  myDate(!!js/Date, writable=true, enumerable=true, configurable=true): 2015-08-28T15:42:14.002Z
  childArray(!!ONAML/reference, writable=true, enumerable=true, configurable=true): 7cpfOeoLez6
  childObject(!!ONAML/reference, writable=true, enumerable=true, configurable=true): 7cpfOepkqPf

The first and non-indented line (object definition):

  1. The puid for this object
  2. Optional property attributes, between brackets:
  3. !!...: Type / prototype name
  4. @@...: puid
  5. : followed by a newline

The subsequent, indented lines:

  1. Property name
  2. Optional property attributes, between brackets:
  3. !!...: Type / prototype name
  4. @@...: puid
  5. ...: property descriptor settings
  6. : followed by the value

A linked object will have ONAML/reference as type and the referenced id as value.

License

This project is licensed as LGPLv3, the license file is included in the project directory.

The ONAML repository on GitHub

Copyright 2015 Stefan Hamminga - prjct.net

Package Sidebar

Install

npm i onaml

Weekly Downloads

0

Version

0.0.4

License

LGPL-3.0

Last publish

Collaborators

  • stefanhamminga