jsonuri
Use URI path to get or set data
Last updated 5 years ago by haozime .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install jsonuri 
SYNC missed versions from official npm registry.

JSON URI


Use URI style methods to operate data. All operations friendly support Vue-like frameworks.

Build Status codecov npm dependencies Status devDependencies Status

Use

$ npm install jsonuri --save
import * as jsonuri from 'jsonuri'
// or
import { get, set, ... } from 'jsonuri' // recommended practice, friendly to tree-shaking

Example Data:

{
  "menu": {
    "id": 123,
    "list": [0, 1, 2, 3, 4],
    "popup": {
      "menuitem": [{
          "value": "New",
          "onclick": "CreateNewDoc()"
        },
        {
          "value": "Open",
          "onclick": "OpenDoc()"
        },
        {
          "value": "Close",
          "onclick": "CloseDoc()"
        }
      ]
    }
  }
}

Methods:

get (data, path)

Get the value of the specified data for the path.

Example:

jsonuri.get(data, 'menu/id')
// return 123

jsonuri.get(data, 'menu/popup/menuitem/0/value')
// return 'New'

jsonuri.get(data, 'menu/popup/menuitem/0/value/..')
// {value: "New", onclick: "CreateNewDoc()"}

see more

set (data, path, value)

Set the value of the specified data for the path.

Example:

jsonuri.set(data, 'menu/id/', 789)
jsonuri.get(data, 'menu/id')
//789

see more

rm (data, path)

Remove the value of the specified data for the path.

Example:

jsonuri.rm(data, 'menu/id')
jsonuri.get(data, 'menu/id') // undefined

see more

mv (data, pathA, pathB, sequence)

Data A moved to target B before or after.

Example:

jsonuri.mv(data, 'menu/list/0', 'menu/list/3')
jsonuri.get(data, 'menu/list') // [1, 2, 3, 0, 4]
[see more](test/spec/mv_spec.js)


jsonuri.set(data, 'menu/list/',[0,1,2,3,4])
jsonuri.mv(data, 'menu/list/0', 'menu/list/3', 'before')
jsonuri.get(data, 'menu/list') // [1, 2, 0, 3, 4]

see more

swap (data, pathA, pathB)

Data swap in an array.

Example:

jsonuri.swap(data, 'menu/list/0', 'menu/list/4')
jsonuri.get(data, 'menu/list') // [4, 1, 2, 3, 0]

jsonuri.swap(data, 'menu/list/0', 'menu/list/4')
jsonuri.get(data, 'menu/list') // [4, 1, 2, 3, 0]

see more

insert (data, pathA, value, direction)

Insert data into an array that is described in the path.

Example:

jsonuri.insert(data, 'menu/list/0', 9999, 'before') // [9999, 0, 1, 2, 3, 4]

see more

up(data, path, gap)

see more

down(data, path, gap)

see more

walk(data, descentionFn, ascentionFn)

Traverse each data of each node and value.

Example:

jsonuri.walk({a:{a1:'x'}}, (value, key, parent, { path }) => {
  console.log(value, key, parent, path)
})

// { a1: 'x' } 'a' { a: { a1: 'x' } } 'a'
// x a1 { a1: 'x' } 'a/a1'

see more

normalizePath(path1, path2, ...)

Example:

jsonuri.normalizePath('a', 'b') // a/b

jsonuri.normalizePath(['a', 'b', '../'], 'c') // a/c


see more

isCircular(obj)

Example:

jsonuri.isCircular({}) // return false
jsonuri.isCircular(window) // return true

var a = {}
jsonuri.set(a, '/b/c/d/e/f/g', a)
jsonuri.isCircular(a) // return true


see more

Current Tags

  • 3.4.5                                ...           latest (6 months ago)

85 Versions

  • 3.4.5                                ...           6 months ago
  • 3.4.4                                ...           9 months ago
  • 3.4.2                                ...           a year ago
  • 3.4.1                                ...           a year ago
  • 3.4.0                                ...           a year ago
  • 3.3.0                                ...           2 years ago
  • 3.2.2                                ...           2 years ago
  • 3.2.1                                ...           2 years ago
  • 3.1.1                                ...           2 years ago
  • 3.1.0                                ...           2 years ago
  • 3.0.1                                ...           3 years ago
  • 2.6.0                                ...           3 years ago
  • 2.5.0                                ...           3 years ago
  • 2.4.11                                ...           3 years ago
  • 2.4.10                                ...           3 years ago
  • 2.4.9                                ...           3 years ago
  • 2.4.8                                ...           3 years ago
  • 2.4.7                                ...           3 years ago
  • 2.4.6                                ...           3 years ago
  • 2.4.5                                ...           3 years ago
  • 2.4.4                                ...           3 years ago
  • 2.4.3                                ...           3 years ago
  • 2.4.2                                ...           3 years ago
  • 2.4.1                                ...           3 years ago
  • 2.4.0                                ...           3 years ago
  • 2.3.1                                ...           3 years ago
  • 2.2.8                                ...           4 years ago
  • 2.2.6                                ...           4 years ago
  • 2.2.7                                ...           4 years ago
  • 2.2.5                                ...           4 years ago
  • 2.2.4                                ...           5 years ago
  • 2.2.3                                ...           5 years ago
  • 2.2.2                                ...           5 years ago
  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.12                                ...           5 years ago
  • 2.1.10                                ...           5 years ago
  • 2.1.9                                ...           5 years ago
  • 2.1.8                                ...           5 years ago
  • 2.1.7                                ...           5 years ago
  • 2.1.6                                ...           5 years ago
  • 2.1.5                                ...           5 years ago
  • 2.1.4                                ...           5 years ago
  • 2.1.3                                ...           5 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 2.0.0-rc.5                                ...           7 years ago
  • 2.0.0-rc.4                                ...           7 years ago
  • 2.0.0-rc.3                                ...           7 years ago
  • 2.0.0-rc2                                ...           7 years ago
  • 2.0.0-rc.1                                ...           7 years ago
  • 2.0.0-alpha.4                                ...           7 years ago
  • 2.0.0-alpha.3                                ...           7 years ago
  • 2.0.0-alpha.2                                ...           7 years ago
  • 2.0.0-alpha.1                                ...           7 years ago
  • 1.7.1                                ...           7 years ago
  • 1.7.0                                ...           7 years ago
  • 1.6.0                                ...           7 years ago
  • 1.5.15                                ...           7 years ago
  • 1.5.14                                ...           7 years ago
  • 1.5.13                                ...           8 years ago
  • 1.5.12                                ...           8 years ago
  • 1.5.11                                ...           8 years ago
  • 1.5.10                                ...           8 years ago
  • 1.5.9                                ...           8 years ago
  • 1.5.8                                ...           8 years ago
  • 1.5.7                                ...           8 years ago
  • 1.5.6                                ...           8 years ago
  • 1.5.5                                ...           8 years ago
  • 1.5.4                                ...           8 years ago
  • 1.5.3                                ...           8 years ago
  • 1.5.2                                ...           8 years ago
  • 1.5.1                                ...           8 years ago
  • 1.4.3                                ...           8 years ago
  • 1.4.2                                ...           8 years ago
  • 1.4.1                                ...           8 years ago
  • 1.4.0                                ...           8 years ago
  • 1.3.0                                ...           8 years ago
  • 1.2.3                                ...           8 years ago
  • 1.2.2                                ...           8 years ago
  • 1.2.1                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (2)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (14)

© 2010 - cnpmjs.org x YWFE | Home | YWFE