npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonuri

v3.4.5

Published

Use URI path to get or set data

Downloads

1,700

Readme

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