diff --git a/docs/classes/jsonpointer.html b/docs/classes/jsonpointer.html index b41998c..c565c6b 100644 --- a/docs/classes/jsonpointer.html +++ b/docs/classes/jsonpointer.html @@ -13,45 +13,45 @@
import { JsonPointer } from 'json-ptr';
export type SupportedVersion = '1.0' | '1.1';
interface PrimaryGuestNamePointers {
name: JsonPointer;
surname: JsonPointer;
honorific: JsonPointer;
}
const versions: Record<SupportedVersion, PrimaryGuestNamePointers> = {
'1.0': {
name: JsonPointer.create('/guests/0/name'),
surname: JsonPointer.create('/guests/0/surname'),
honorific: JsonPointer.create('/guests/0/honorific'),
},
'1.1': {
name: JsonPointer.create('/primary/primaryGuest/name'),
surname: JsonPointer.create('/primary/primaryGuest/surname'),
honorific: JsonPointer.create('/primary/primaryGuest/honorific'),
}
};
interface Reservation extends Record<string, unknown> {
version?: SupportedVersion;
}
function primaryGuestName(reservation: Reservation): string {
const pointers = versions[reservation.version || '1.0'];
const name = pointers.name.get(reservation) as string;
const surname = pointers.surname.get(reservation) as string;
const honorific = pointers.honorific.get(reservation) as string;
const names: string[] = [];
if (honorific) names.push(honorific);
if (name) names.push(name);
if (surname) names.push(surname);
return names.join(' ');
}
// The original layout of a reservation (only the parts relevant to our example)
const reservationV1: Reservation = {
guests: [{
name: 'Wilbur',
surname: 'Finkle',
honorific: 'Mr.'
}, {
name: 'Wanda',
surname: 'Finkle',
honorific: 'Mrs.'
}, {
name: 'Wilma',
surname: 'Finkle',
honorific: 'Miss',
child: true,
age: 12
}]
// ...
};
// The new layout of a reservation (only the parts relevant to our example)
const reservationV1_1: Reservation = {
version: '1.1',
primary: {
primaryGuest: {
name: 'Wilbur',
surname: 'Finkle',
honorific: 'Mr.'
},
additionalGuests: [{
name: 'Wanda',
surname: 'Finkle',
honorific: 'Mrs.'
}, {
name: 'Wilma',
surname: 'Finkle',
honorific: 'Miss',
child: true,
age: 12
}]
// ...
}
// ...
};
console.log(primaryGuestName(reservationV1));
console.log(primaryGuestName(reservationV1_1));
There are many uses for pointers.
-Creates a new instance.
a string representation of a JSON Pointer, or a decoded array of path segments.
-The pointer's decoded path segments.
-This pointer's JSON Pointer encoded string representation.
-This pointer's URI fragment identifier encoded string representation.
-Creates a new instance by concatenating the specified pointer's path onto this pointer's path.
the string representation of a pointer, it's decoded path, or an instance of JsonPointer indicating the additional path to concatenate onto the pointer.
-Gets the target object's value at the pointer's location.
the target of the operation
-Determines if the specified target's object graph has a value at the pointer's location.
the target of the operation
-Gets the value in the object graph that is the parent of the pointer location.
the target of the operation
-Resolves the specified relative pointer path against the specified target object, and gets the target object's value at the relative pointer's location.
the target of the operation
the relative pointer (relative to this)
the value at the relative pointer's resolved path; otherwise undefined.
-Creates a new JsonPointer instance, pointing to the specified relative location in the object graph.
the relative pointer (relative to this)
A new instance that points to the relative location.
-Sets the target object's value, as specified, at the pointer's location.
If any part of the pointer's path does not exist, the operation aborts without modification, unless the caller indicates that pointer's location @@ -62,14 +62,14 @@
the value to set
indicates whether the pointer's location should be created if it doesn't already exist.
-Emits the JSON Pointer encoded string representation.
-Removes the target object's value at the pointer's location.
the target of the operation
the value that was removed from the object graph.
-Factory function that creates a JsonPointer instance.
const ptr = JsonPointer.create('/deeply/nested/data/0/here');
@@ -78,17 +78,17 @@
the pointer or path.
-Decodes the specified pointer into path segments.
a string representation of a JSON Pointer
-Evaluates the target's object graph, returning a Record<Pointer, unknown> populated with pointers and the corresponding values from the graph.
the target of the operation
indicates whether the results are populated with fragment identifiers rather than regular pointers
-Gets the target
object's value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.get(target, '/third/2/sixth'));
// seventh
console.log(JsonPointer.get(target, '/tenth'));
// undefined
@@ -96,7 +96,7 @@
the target of the operation
the pointer or path.
-Determines if the specified target
's object graph has a value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.has(target, '/third/0'));
// true
console.log(JsonPointer.has(target, '/tenth'));
// false
@@ -104,21 +104,21 @@
the target of the operation
the pointer or path
-Evaluates the target's object graph, returning a UriFragmentIdentifierPointerListItem for each location in the graph.
the target of the operation
-Evaluates the target's object graph, returning a JsonStringPointerListItem for each location in the graph.
the target of the operation
-Evaluates the target's object graph, returning a Map<Pointer,unknown> populated with pointers and the corresponding values form the graph.
the target of the operation
indicates whether the results are populated with fragment identifiers rather than regular pointers
-Sets the target
object's value, as specified, at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.set(target, '/third/2/sixth', 'tenth'));
// seventh
console.log(JsonPointer.set(target, '/tenth', 'eleventh', true));
// undefined
console.log(JSON.stringify(target, null, ' '));
// {
// "first": "second",
// "third": [
// "fourth",
// "fifth",
// {
// "sixth": "tenth"
// }
// ],
// "eighth": "ninth",
// "tenth": "eleventh"
// }
@@ -131,7 +131,7 @@
indications whether the operation should force the pointer's location into existence in the object graph.
the prior value at the pointer's location in the object graph.
-Removes the target
object's value at the pointer
's location.
const target = {
first: 'second',
third: ['fourth', 'fifth', { sixth: 'seventh' }],
eighth: 'ninth'
};
console.log(JsonPointer.unset(target, '/third/2/sixth'));
// seventh
console.log(JsonPointer.unset(target, '/tenth'));
// undefined
console.log(JSON.stringify(target, null, ' '));
// {
// "first": "second",
// "third": [
// "fourth",
// "fifth",
// {}
// ],
// "eighth": "ninth",
// }
@@ -140,7 +140,7 @@
the pointer or path
the value that was removed from the object graph.
-Evaluates the target's object graph, calling the specified visitor for every unique pointer location discovered while walking the graph.
the target of the operation
diff --git a/docs/classes/jsonreference.html b/docs/classes/jsonreference.html index 551d2bc..3d01602 100644 --- a/docs/classes/jsonreference.html +++ b/docs/classes/jsonreference.html @@ -2,22 +2,22 @@A reference to a location in an object graph.
This type is used by this module to break cycles in an object graph and to reference locations that have already been visited when enumerating pointers.
-Creates a new instance.
a JSON Pointer for the reference.
-A reference to a position if an object graph.
-Gets the reference's pointer.
-Resolves the reference against the target
object, returning the value at
the referenced pointer's location.
the target object
-Gets the reference pointer's string representation (a URI fragment identifier).
-Determines if the specified candidate
is a JsonReference.
the candidate
diff --git a/docs/interfaces/jsonstringpointerlistitem.html b/docs/interfaces/jsonstringpointerlistitem.html index 1030486..b63034f 100644 --- a/docs/interfaces/jsonstringpointerlistitem.html +++ b/docs/interfaces/jsonstringpointerlistitem.html @@ -1,7 +1,7 @@List item used when listing pointers and their values in an object graph.
-Contains the location of the value in the evaluated object graph.
-The value at the pointer's location in the object graph.
Generated using TypeDoc
List item used when listing fragment identifiers and their values in an object graph.
-Contains the location (as a fragmentId) of the value in the evaluated object graph.
-The value at the pointer's location in the object graph.
Generated using TypeDoc
Signature of visitor functions, used with JsonPointer.visit method. Visitors are callbacks invoked for every segment/branch of a target's object graph.
Tree descent occurs in-order, breadth first.
-Generated using TypeDoc
Generated using TypeDoc