Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Latest commit

 

History

History
103 lines (87 loc) · 1.06 KB

README.md

File metadata and controls

103 lines (87 loc) · 1.06 KB

Squirrel

Data Swapper

Install

$ npm i @fratercula/squirrel

Usage

import Squirrel from '@fratercula/squirrel'

const a = {
  'a|ui1': 'a',
  b: [
    {
      'ba|ui1': 1,
    },
    'bb|ss',
  ],
  'c|ui1': {
    'ca|ui2': true,
    'cb|ui0': [
      {
        'cba|ui0': 3,
      },
    ],
  },
  d: 'a',
  'e|ui0': false,
  'f|ui2': {
    'fa|ui2': 'ss',
  },
}

const data = new Squirrel(a)

console.log(data.value)
/*
{
  "d": "a",
  "a": "a",
  "e": false,
  "b": [
    {
      "ba": 1
    },
    "bb|ss"
  ],
  "c": {
    "ca": true,
    "cb": [
      {
        "cba": 3
      }
    ]
  },
  "f": {
    "fa": "ss"
  }
}
*/
console.log(data.swap({ ui0: '????', ui2: '----' }))
/*
{
  "d": "a",
  "a": "a",
  "f": "----",
  "e": "????",
  "b": [
    {
      "ba": 1
    },
    "bb|ss"
  ],
  "c": {
    "ca": "----",
    "cb": "????"
  }
}
*/

API

const data = new Squirrel([data], [separator]) // default separator is `|`

data.value // get origin data

data.swap({ key, value }) // swap data

License

MIT

Relevance

Squirrel