deftreejs

0.0.4 • Public • Published

DefTreeJS

The nodejs module to serialize/deserialize Defold files

Install

DefTreeJs requires Node.js to use it

npm i deftreejs

Usage

const {readFileSync, writeFileSync} = require("fs");            // require methods to read/write files
const {serialize, deserialize} = require("deftreejs");          // require methods to work with defold files
const documentPath = "./main.collection";                       // define path for document to read
const document = readFileSync(documentPath, "utf-8");           // reading the document
const tree = deserialize(document);                             // parse the defold document
tree.getNodes()
    .find((node) => node.getKey() === "name")
    .setValue("newName");                                       // find node by key equals "name" and change it value to "newName"
const serialized = serialize(tree);                             // serialize the modified tree
writeFileSync(documentPath, serialized);                        // write it to document file

DefTreeNode Methods

  • getKey() -> string
  • setKey(string)
  • getType() -> string
  • setType(string)
  • getValue() -> string|number|boolean|node
  • setValue(string|number|boolean|node)
  • getNodes() -> node[]

Package Sidebar

Install

npm i deftreejs

Weekly Downloads

2

Version

0.0.4

License

MIT

Unpacked Size

16.8 kB

Total Files

8

Last publish

Collaborators

  • klopoffa