dtl-js
Version:
Data Transformation Language - JSON templates and data transformation
50 lines (41 loc) • 1.48 kB
JavaScript
var DTL = require('./lib/DTL.js');
var assert = require('assert');
var util = require('util');
var result;
let transform= {
"out": "(: 5 -> factorial :)",
"factorial": "(: ?(($. == 0) 1 ( $. * (($. - 1) -> factorial))) :)"
}
let input = {
num1: "12",
num2: "-15",
num3: 0
}
let dtl = new DTL();
//result = DTL.apply({}, { out: "(: 1 - 2 * 6 / 3 + 1 :)" });
//result = DTL.apply({}, { out: "(: 6 / 3 + 1 :)" });
//result = DTL.apply({}, { out: "(: 6 / 3 / 1 :)" });
//console.log(util.inspect(result));
//result = DTL.apply({}, { out: "(: 6 / (3 * 2) :)" });
//result = DTL.apply({}, { out: "(: replace('foobaOr' /o/ig '00') :)" });
//console.log(util.inspect(result));
//result = dtl.apply([1,2,4,7,9,12], { out: "(: map($. '(: &(`item_` $item) :)') :)" });
// result = DTL.apply({}, transform);
result = DTL.apply({}, "0.1 + 0.2");
console.log(util.inspect(result));
/*
result = DTL.apply(input, { out: "(: math.max( $num1 -14 $num2 0 ) :)" });
console.log(util.inspect(result));
result = DTL.apply(input, { out: "(: math.max( 12 math.abs(-14) 0 ) :)" });
console.log(util.inspect(result));
*/
//result = DTL.apply(input, { out: "(: [ -12 -14 0 ] :)" });
//console.log(util.inspect(result));
/*
result = DTL.apply(input, { out: "(: map([ -12 -14 0 ] '(: &(`item_` $item) :)') :)" });
console.log(util.inspect(result));
result = DTL.apply(input, { out: "(: ( -12 -14 0 ) :)" });
console.log(util.inspect(result));
*/
;