• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

manuelstofer/json-pointer: Some utilities for the JSON pointers described by RFC ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

manuelstofer/json-pointer

开源软件地址:

https://github.com/manuelstofer/json-pointer

开源编程语言:

JavaScript 95.9%

开源软件介绍:

json-pointer

Build Status npm version Coverage Status

Some utilities for JSON pointers described by RFC 6901

Provides some additional stuff i needed but is not included in node-jsonpointer

Installation

node.js

$ npm install json-pointer

API

var pointer = require('json-pointer');

.get(object, pointer)

Looks up a JSON pointer in an object.

Array of reference tokens, e.g. returned by api.parse, can be passed as a pointer to .get, .set and .remove methods.

var obj = {
    example: {
        bla: 'hello'
    }
};
pointer.get(obj, '/example/bla');

.set(object, pointer, value)

Sets a new value on object at the location described by pointer.

var obj = {};
pointer.set(obj, '/example/bla', 'hello');

.remove(object, pointer)

Removes an attribute of object referenced by pointer.

var obj = {
    example: 'hello'
};
pointer.remove(obj, '/example');
// obj -> {}

.dict(object)

Creates a dictionary object (pointer -> value).

var obj = {
    hello: {bla: 'example'}
};
pointer.dict(obj);

// Returns:
// {
//    '/hello/bla': 'example'
// }

.walk(object, iterator)

Just like:

each(pointer.dict(obj), iterator);

.has(object, pointer)

Tests if an object has a value for a JSON pointer.

var obj = {
    bla: 'hello'
};

pointer.has(obj, '/bla');               // -> true
pointer.has(obj, '/non/existing');      // -> false

.escape(str)

Escapes a reference token.

pointer.escape('hello~bla');            // -> 'hello~0bla'
pointer.escape('hello/bla');            // -> 'hello~1bla'

.unescape(str)

Unescape a reference token.

pointer.unescape('hello~0bla');         // -> 'hello~bla'
pointer.unescape('hello~1bla');         // -> 'hello/bla'

.parse(str)

Converts a JSON pointer into an array of reference tokens.

pointer.parse('/hello/bla');            // -> ['hello', 'bla']

.compile(array)

Builds a json pointer from an array of reference tokens.

pointer.compile(['hello', 'bla']);      // -> '/hello/bla'

pointer(object, [pointer, [value]])

Convenience wrapper around the api.

pointer(object)                 // bind object
pointer(object, pointer)        // get
pointer(object, pointer, value) // set

The wrapper supports chainable object oriented style.

var obj = {anything: 'bla'};
var objPointer = pointer(obj);
objPointer.set('/example', 'bla').dict();



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap