UNPKG

json8-patch

Version:
26 lines (22 loc) 776 B
"use strict"; const remove = require("./remove"); const add = require("./add"); /** * @typedef OperationResult * @type Object * @property {Any} doc - The patched document * @property {Any} previous - The previous/replaced value if any */ /** * Move the value at the specified JSON Pointer location to an other location * http://tools.ietf.org/html/rfc6902#section-4.4 * * @param {Object|Array} doc - JSON document to move the value from and to * @param {String|Array} path - JSON Pointer string or tokens path * @param {String} dest - JSON Pointer string destination of the value * @return {OperationResult} */ module.exports = function move(doc, path, dest) { const r = remove(doc, path); return add(r.doc, dest, r.previous); };