Nucleus Powered Mitochondria
Miss any of our Open RFC calls?Watch the recordings here! »

transform-protocol-template

1.0.0 • Public • Published

transform-protocol-template

协议模版转换

install

npm install --save transform-protocol-template

examples


import transformProtocolTemplate from 'transform-protocol-template';

let template = `
<?
    var obj = {
        z:1,b:2
    };

    print( obj2xml(obj) );
?>
<?if(1) {?>
    IF<?=Math.random()?>
<?}?> 
=============JSON=============
{
    status: <?=ret?>,
    message: <?!msg?>,
    data: {
        columns: <?!Object.keys(data.rows[0] || {})?>,
        list: <?!data.rows?>,
        total: <?=data.total?>
    }
}
==============XML=============
<?xml!data?>
==============Other===========
<?=abc?>1
<?!abc?>2
<?=isNew?>3
<?!isNew?>4
\${msg}
`;

const ret = parseTemplateToCode(template, {
    isNew: null,
    ret: 0,
    msg: "success",
    data: {
        total: 11092,
        rows: [
            { name: 'nobo1', age: 18 },
            { name: 'nobo2', age: 18 }
        ]
    }
});

console.log(ret);

Keywords

Install

npm i transform-protocol-template

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.65 kB

Total Files

4

Last publish

Collaborators

  • avatar