organic-dna-fold

1.0.1 • Public • Published

organic-dna-fold

DNA utility function folding DNA structure with support for array manupulations and node overriding

api and usage

var fold = require("organic-dna-fold")
var DNA = require("organic").DNA
var dna = new DNA({
  "modeA": {
    "property": "new value"
  },
  "property": "value",
  "anotherOne": "value"
})

fold(dna, dna.modeA) // fold modeA branch over dna root

console.log(dna.property) // == "new value"
console.log(dna.anotherOne) // == "value"

folding with override instead of merge

var dna = new DNA({
  "modeA": {
    "~plasma": {
      "property": "value"
    },
    "~array": []
  },
  "plasma": {
    "property": "",
    "anotherOne": ""
  },
  "array": ["a", "b", "c"]
})

fold(dna, dna.modeA)

console.log(dna.anotherOne) // == undefined
console.log(dna.property) // == "value"

console.log(dna.array) // == []

folding and push to array merge

var dna = new DNA({
  "modeA": {
    "array": [
      {
        "$push": "atEndOfArray"
      }
    ]
  },
  "array": ["0", 1]
})

fold(dna, dna.modeA)

console.log(dna.array) // == ["0", 1, "atEndOfArray"]

folding and unshift to array merge

var dna = new DNA({
  "modeA": {
    "array": [
      {
        "$unshift": "atStartOfArray"
      }
    ]
  },
  "array": ["0", 1]
})

fold(dna, dna.modeA)

console.log(dna.array) // == ["atStartOfArray", "0", 1]

folding and insert to array

var dna = new DNA({
  "modeA": {
    "array": [
      {
        "$insert": {
          "1": "atMiddleOfArray"
        }
      }
    ]
  },
  "array": ["0", 1]
})

fold(dna, dna.modeA)

console.log(dna.array) // == ["0", "atMiddleOfArray", 1]

folding and merge array element

var dna = new DNA({
  "modeA": {
    "array": [
      {
        "$merge": {
          "2": {
            "newProperty": true
          }
        }
      }
    ]
  },
  "array": ["0", 1, { property: "value" }]
})

fold(dna, dna.modeA)

console.log(dna.array) // == ["0", 1, { property:"value", "newProperty": true }]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.17latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.17
1.0.021
0.1.116
0.1.01
0.0.20
0.0.11

Package Sidebar

Install

npm i organic-dna-fold

Weekly Downloads

39

Version

1.0.1

License

MIT

Unpacked Size

5.78 kB

Total Files

4

Last publish

Collaborators

  • outbounder