• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Some utilities for the JSON pointers described by RFC 6901

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();

More Repositories

1

pinchzoom

A Javascript library providing multi-touch gestures for zooming and dragging on any DOM element.
JavaScript
915
star
2

foreach

Foreach component + npm package
JavaScript
25
star
3

qry

Creates match functions from MongoDB query objects.
JavaScript
10
star
4

led-ticker

Network daemon for my AM03128-H11 led ticker
Python
7
star
5

websocket-multiplexer

Multiple virtual channels over a web socket / SockJS connection
JavaScript
6
star
6

component-travis-mocha-phantomjs-chai

test setup for components with travis support
JavaScript
4
star
7

pflock

Two way data bindings
JavaScript
3
star
8

each

Underscore's each function packed as a component
JavaScript
3
star
9

esformatter-limit-linebreaks

esformatter linebreak limit plugin
JavaScript
3
star
10

is

type checking component
JavaScript
3
star
11

bibimbap

JavaScript
2
star
12

backbone-pflock

Two way data bindings for Backbone models using Pflock
JavaScript
2
star
13

content-element

Experimental real-time content editing
JavaScript
2
star
14

ahead

An experiment with promises
JavaScript
2
star
15

websocket-rpc-stream

RPC over websockets with progress updates.
JavaScript
2
star
16

toolbar

Flyout toolbar
JavaScript
2
star
17

repo

Experimental real-time storage API for MongoDB over socket.io
JavaScript
1
star
18

md5

Yoshinori Kohyama's md5 implementation packed as component
JavaScript
1
star
19

drums

Drum machine component built with the web audio api
JavaScript
1
star
20

load-samples

Loads audio samples for use with Web-Audio-API
JavaScript
1
star
21

insert

Insert HTML/Elements to the DOM
JavaScript
1
star
22

extend

Underscore's extend function packed as a component
JavaScript
1
star
23

mapr

Map for objects
JavaScript
1
star
24

listener

addEventListener with ie fallback
JavaScript
1
star
25

papply

Left and right partial application without context
JavaScript
1
star
26

ce-images

Image upload plugin for content-element
JavaScript
1
star
27

elm-gameoflife

Elm
1
star
28

range

Underscore's range function packed as a component
JavaScript
1
star
29

slow-click

Edit linked content editables with slow clicks
JavaScript
1
star
30

claim

Util to check if dom elements belong to a view or sub view
JavaScript
1
star
31

es6map

Paul Millr's es6-shim Map implementation packed as a component
JavaScript
1
star
32

templates

Dummy component for generated templates
JavaScript
1
star
33

sockjs-websockify

SockJS connection wrapper. Makes connections more web socket like.
JavaScript
1
star
34

koboldmaki

Views inspired by backbone, built with components only.
JavaScript
1
star