gson-pointer
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -13,3 +13,3 @@ "use strict"; | ||
var toParent = properties; | ||
var target = get.run(data, toParent); | ||
var target = get(data, toParent); | ||
if (target) { | ||
@@ -16,0 +16,0 @@ delete target[lastProperty]; |
@@ -7,2 +7,3 @@ "use strict"; | ||
var simpleJoin = Array.prototype.join; | ||
var matchMutlipleSlashes = /\/+/g; | ||
@@ -24,3 +25,3 @@ | ||
var pointer = (isURI ? "#/" : "/") + list.join("/"); | ||
return pointer.replace(/\/+/g, "/"); | ||
return pointer.replace(matchMutlipleSlashes, "/"); | ||
} | ||
@@ -27,0 +28,0 @@ |
"use strict"; | ||
var matchSlashes = /~1/g; | ||
var matchTildes = /~0/g; | ||
var matchMutlipleSlashes = /\/+/g; | ||
var matchPointerPrefixes = /(^[#/]*|\/+$)/g; | ||
function sanitizeProperty(property) { | ||
return property.replace(/\~1/g, "/").replace(/~0/g, "~"); | ||
return property.replace(matchSlashes, "/").replace(matchTildes, "~"); | ||
} | ||
@@ -19,4 +25,4 @@ | ||
const sanitize = pointer.indexOf("#") >= 0 ? sanitizeAndDecodeProperty : sanitizeProperty; | ||
pointer = pointer.replace(/\/+/g, "/"); // remove multiple slashes | ||
pointer = pointer.replace(/(^[#/]*|\/+$)/g, ""); // strip pointer prefixes | ||
pointer = pointer.replace(matchMutlipleSlashes, "/"); // remove multiple slashes | ||
pointer = pointer.replace(matchPointerPrefixes, ""); // strip pointer prefixes | ||
@@ -23,0 +29,0 @@ var result = pointer.split("/"); |
{ | ||
"name": "gson-pointer", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "json pointer - failsafe data retrieval on js and json objects", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,3 +31,3 @@ # gson-pointer - a json-pointer implementation | ||
| delete(data, pointer) -> data | removes a property from data | ||
| join(pointer*) -> pointer | joins multiple pointers to a single one | ||
| join(...pointers) -> pointer | joins multiple pointers to a single one | ||
| join([properties], isURI) -> pointer | joins all properties in the given mode | ||
@@ -38,3 +38,3 @@ | split(pointer) -> [array] | returns a json-pointer as an array | ||
> The methods `get`, `set`, `delete` and `join` also accept a list of properties as pointer. Using join with a list | ||
> of properties, its signature changes to `join(properties:Array, isURI:Boolean):String` | ||
> of properties, its signature changes to `join(properties:string[], isURI=false) -> string` | ||
@@ -44,4 +44,6 @@ | ||
### pointer.get(data, pointer):value | ||
### pointer.get | ||
> get(data:object|array, pointer:string|array) -> value:any | ||
returns nested values | ||
@@ -71,4 +73,6 @@ | ||
### pointer.set(data, pointer, value) | ||
### pointer.set | ||
> set(data:object|array, pointer:string|array, value:any) -> data:object|array | ||
changes a nested value | ||
@@ -110,4 +114,6 @@ | ||
### pointer.delete(data, pointer) | ||
### pointer.delete | ||
> delete(data:object|array, pointer:string|array) -> data:object|array | ||
deletes a nested property or item | ||
@@ -130,4 +136,6 @@ | ||
### pointer.split(pointer) | ||
### pointer.split | ||
> split(pointer:string) -> properties:array | ||
returns a json-pointer as a list of (escaped) properties | ||
@@ -151,4 +159,6 @@ | ||
### pointer.join(pointer, pointer, ...) | ||
### pointer.join | ||
> join(...pointers:string[]) -> pointer:string | ||
joins all arguments to a valid json pointer | ||
@@ -169,3 +179,4 @@ | ||
in order to join an array received from split, you can use `join(properties, isURI=false)` to retrieve a valid pointer | ||
in order to join an array received from split, you can use `join(properties:string[], isURI=false) -> string` to | ||
retrieve a valid pointer | ||
@@ -179,3 +190,14 @@ ```js | ||
To join an array of pointer, you must use it with `join(...pointers)` or all pointers will be treated as properties: | ||
```js | ||
const gp = require('gson-pointer'); | ||
const pointer = gp.join(...['/path/to/value', '../object']); | ||
console.log(pointer); // output: '/path/to/object' | ||
// passing the array directly, will treat each entry as a property, which will be escaped and resolves to: | ||
gp.join(['/path/to/value', '../object']); // output: '/~1path/to/value/..~1object' | ||
``` | ||
## Fragment identifier | ||
@@ -182,0 +204,0 @@ |
31640
170
214