added definitions for json-pointer

This commit is contained in:
Bart van der Schoor
2014-04-01 00:43:53 +02:00
parent f354504a25
commit 0d1397aba6
3 changed files with 125 additions and 0 deletions
+1
View File
@@ -169,6 +169,7 @@ List of Definitions
* [jScrollPane](http://jscrollpane.kelvinluck.com) (by [Dániel Tar](https://github.com/qcz))
* [JSDeferred](http://cho45.stfuawsc.com/jsdeferred/) (by [Daisuke Mino](https://github.com/minodisk))
* [JSONEditorOnline](https://github.com/josdejong/jsoneditoronline) (by [Vincent Bortone](https://github.com/vbortone/))
* [JSON-Pointer](https://www.npmjs.org/package/json-pointer) (by [Bart van der Schoor](https://github.com/Bartvds))
* [jStorage](http://www.jstorage.info/) (by [Danil Flores](https://github.com/dflor003/))
* [JWPlayer](http://developer.longtailvideo.com/trac/) (by [Martin Duparc](https://github.com/martinduparc/))
* [KeyboardJS](https://github.com/RobertWHurst/KeyboardJS) (by [Vincent Bortone](https://github.com/vbortone/))
+41
View File
@@ -0,0 +1,41 @@
/// <reference path="json-pointer.d.ts" />
import JsonPointer = require('json-pointer');
var value: any;
var str: string;
var strArr: string[];
var pointer: string;
var bool: any;
var object:Object;
bool = JsonPointer.has(object, pointer);
value = JsonPointer.get(object, pointer);
JsonPointer.set(object, pointer, value);
JsonPointer.remove(object, pointer);
object = JsonPointer.dict(object);
JsonPointer.walk(object, (elem) => {
});
str = JsonPointer.escape(str);
str = JsonPointer.unescape(str);
strArr = JsonPointer.parse(str);
str = JsonPointer.compile(strArr);
var wrap = JsonPointer(object);
bool = wrap.has(pointer);
value = wrap.get(pointer);
wrap.set(pointer, value);
wrap.remove(pointer);
object = wrap.dict();
wrap.walk((elem, key) => {
value = elem;
str = key;
});
+83
View File
@@ -0,0 +1,83 @@
// Type definitions for json-pointer 1.0 l
// Project: https://www.npmjs.org/package/json-pointer
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "json-pointer" {
function JSON_Pointer(object: Object): JSON_Pointer.JSON_PointerWrap;
module JSON_Pointer {
/**
* Wrap an object with accessors
*/
/**
* Looks up a JSON pointer in an object.
*/
function get(object: Object, pointer: string): any;
/**
* Set a value for a JSON pointer on object.
*/
function set(object: Object, pointer: string, value: any): void;
/**
* Removes an attribute of object referenced by pointer
*/
function remove(object: Object, pointer: string): void;
/**
* Creates a dictionary object (pointer -> value).
*/
function dict(object: Object): Object;
/**
* Just like: each(pointer.dict(obj), iterator);
*/
function walk(object: Object, iterator: (value: any, key: string) => void): void;
/**
* Tests if an object has a value for a JSON pointer.
*/
function has(object: Object, pointer: string): boolean;
/**
* Escapes a reference token.
*/
function escape(str: string): string;
/**
* Unescape a reference token.
*/
function unescape(str: string): string;
/**
* Converts a JSON pointer into an array of reference tokens.
*/
function parse(str: string): string[];
/**
* Builds a json pointer from an array of reference tokens.
*/
function compile(str: string[]): string;
interface JSON_PointerWrap {
/**
* Looks up a JSON pointer in an object.
*/
get(pointer: string): any;
/**
* Set a value for a JSON pointer on object.
*/
set(pointer: string, value: any): void;
/**
* Removes an attribute of object referenced by pointer
*/
remove(pointer: string): void;
/**
* Creates a dictionary object (pointer -> value).
*/
dict(): Object;
/**
* Just like: each(pointer.dict(obj), iterator);
*/
walk(iterator: (value: any, key: string) => void): void;
/**
* Tests if an object has a value for a JSON pointer.
*/
has(pointer: string): boolean;
}
}
export = JSON_Pointer;
}