0.0.2 • Published 3 months ago

jslt-node v0.0.2

Weekly downloads
-
License
-
Repository
github
Last release
3 months ago

JSLT

Everyones favorite XSLT but for json

Node* port for Schibsted's jslt

import { compile, transform } from 'jslt-node';

const SCHEMA = compile(
  `
    {
      "result" : {
        for (.menu.popup.menuitem)
          .value : .onclick
      }
    }
  `
);

const input = {
  menu: {
    popup: {
      menuitem: [
        {
          value: 'Open',
          onclick: 'OpenDoc()'
        },
        {
          value: 'Close',
          onclick: 'CloseDoc()'
        }
      ]
    }
  }
};

/*
{
  result : {
    Open: 'OpenDoc()',
    Close: 'CloseDoc()'
  }
}
*/
console.log(transform(SCHEMA, input));

Status: POC

There is very minial support for selectors, constants and for loops and no garantee this will continue any further in the current phase.

Quick support reference:

  • .
  • .<name>
  • .[<index>]
  • .[<from> : <to>]
  • if (<expr>) <expr> else <expr>
  • let <name> = <expr>
  • $<name>
  • [for (<expr>) <expr>]
  • {for (<expr>) <expr> : <expr>}
  • def <name>(<name>, <name>...) <expr>
  • // <anything up to end of line>
  • { <key> : <expr> }
  • { <key> : <expr>, * : . }
  • 5 * 7 + 23.2
  • 7 < 5
  • 7 < 5 and .foo == "yes"

Based on Quick reference