Code Monkey home page Code Monkey logo

jsomatic's Introduction

JsoMatic

Linux CI

JsoMatic provides class primitives to construct representations of XML tags in JavaScript/JSON. It's important to note that the data format for tag persistence is JSON, only.

Requirements

  • Node.js >= v6.1.0

Installation

npm install jsomatic

Examples (for Node.js)

Create Tag and show representation in XML

const {Tag} = require('jsomatic');

let attrs = new Map();
attrs.set('transform', 'translate(0, 250px)');

let tag = new Tag('g', attrs);

console.log(tag.toXml());

/*
    OUTPUT:
    "
    <g transform="translate(0, 250px)"></g>
    "
*/

... show representation in JSON

// ...
console.log(tag.toJson());

/*
    OUTPUT:
    "
    {"name":"g","attrs":{"transform":"translate(0, 250px)"},"childs":[]}
    "
*/

Read JSON file and fill Tag object

  • Create file called "input.json" that contains:
{
    "name": "g",
    "attrs": {"transform":"translate(0, 250px)"},
    "childs": [
        {
            "name": "g",
            "attrs": {"x": "100px", "y": "45px"},
            "childs": []
        }
    ]
}
  • Read file and show object created (JSON file, by default):
const {Tag, Mixin, fsMixin} = require('jsomatic');
Mixin.set(Tag, fsMixin); // mixins to filesystem operations

// Create root element
let tag = new Tag();

// Read file and fill tag
tag.readFile('input.json');

// Show JSON
console.log(tag.toJson());

// Show XML
console.log(tag.toXml());

/*
    OUTPUT:
    "
    {"name":"g","attrs":{"transform":"translate(0, 250px)"},"childs":[{"name":"g","attrs":{"x":"100px","y":"45px"},"childs":[]}]}
    <g transform="translate(0, 250px)"><g x="100px" y="45px"></g></g>
    "
*/
  • Save file (JSON file, by default)
const {Tag, Mixin, fsMixin} = require('jsomatic');
Mixin.set(Tag, fsMixin);

let attrs = new Map();
attrs.set('transform', 'translate(0, 250px)');

let tag2 = new Tag('image', attrs);
let tag3 = new Tag('image');

let tag1 = new Tag('g', attrs, [tag2, tag3]);

tag1.saveToFile('output.json');

/*
    OUTPUT ('output.json'):

    "
    {"name":"g","attrs":{"transform":"translate(0, 250px)"},"childs":[{"name":"image","attrs":{"transform":"translate(0, 250px)"},"childs":[]},{"name":"image","attrs":{},"childs":[]}]}
    "
*/

jsomatic's People

Contributors

cristiancmello avatar

Stargazers

 avatar

Watchers

 avatar  avatar

jsomatic's Issues

Bug to read this JSON...

{
    "name": "g",
    "attrs": {"transform":"translate(0, 250px)"},
    "childs": [
        {
            "name": "g",
            "attrs": {"x": "100px", "y": "45px"},
            "childs": []
        }
    ]
}

This generate...

<g transform="translate(0, 250px)"><g</g></g>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.