-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
1 lines (1 loc) · 8.64 KB
/
bundle.js
1
!function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){return o(e[i][1][r]||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){var renderString=require("./string");function walkObject(object,handler){if(Array.isArray(object))return function(array,handler){return array.map(function(input){return walk(input,handler,null)})}(object,handler);var result={};for(var key in object)result[walk(key,handler,null)]=walk(object[key],handler,key);return result}function walk(input,handler,key){switch(typeof input){case"object":return input?walkObject(input,handler):input;case"string":return handler(input,key);default:return input}}module.exports=function(object,view,handler){return handler=handler||renderString,walk(object,function(value,key){return handler(value,view,key)},null)}},{"./string":2}],2:[function(require,module,exports){var REGEX=new RegExp("{{([a-zA-Z.-_0-9]+)}}","g");module.exports=function(input,view){if(-1===input.indexOf("{{"))return input;var result,replaced=input.replace(REGEX,function(original,path){var value=function(path,view){if(view&&view[path])return view[path];for(var parts=path.split(".");view&&(part=parts.shift());)view="object"==typeof view&&part in view?view[part]:void 0;return view}(path,view);return null==value?original:"object"!=typeof value?value:void(result=value)});return void 0!==result?result:replaced}},{}],3:[function(require,module,exports){var root,factory;root=this,factory=function(exports){var JSONPatch,JSONPointer,_operationRequired,isArray;function InvalidPatch(message){Error.call(this,message),this.message=message}function PatchApplyError(message){Error.call(this,message),this.message=message}function compileOperation(operation,mutate){!function(operation){var i,required;if(!operation.op)throw new InvalidPatch("Operation missing!");if(!_operationRequired.hasOwnProperty(operation.op))throw new InvalidPatch("Invalid operation!");if(!("path"in operation))throw new InvalidPatch("Path missing!");for(required=_operationRequired[operation.op],i=0;i<required.length;i++)if(!(required[i]in operation))throw new InvalidPatch(operation.op+" must have key "+required[i])}(operation);var op=operation.op,path=new JSONPointer(operation.path),value=operation.value,from=operation.from?new JSONPointer(operation.from):null;switch(op){case"add":return function(doc){return path.add(doc,value,mutate)};case"remove":return function(doc){return path.remove(doc,mutate)};case"replace":return function(doc){return path.replace(doc,value,mutate)};case"move":if(path.subsetOf(from))throw new InvalidPatch("destination must not be a child of source");return function(doc){var value=from.get(doc),intermediate=from.remove(doc,mutate);return path.add(intermediate,value,mutate)};case"copy":return function(doc){var value=from.get(doc);return path.add(doc,value,mutate)};case"test":return function(doc){if(!function deepEqual(a,b){var key;if(a===b)return!0;if(typeof a!=typeof b)return!1;if("object"!=typeof a)return!1;var aIsArray=isArray(a);if(aIsArray!==isArray(b))return!1;if(!aIsArray){for(key in a)if(Object.hasOwnProperty(a,key)&&(!Object.hasOwnProperty(b,key)||!deepEqual(a[key],b[key])))return!1;for(key in b)if(Object.hasOwnProperty(b,key)&&!Object.hasOwnProperty(a,key))return!1;return!0}if(a.length!=b.length)return!1;for(var i=0;i<a.length;i++)return deepEqual(a[i],b[i])}(path.get(doc),value))throw new PatchApplyError("Test operation failed. Value did not match.");return doc}}}isArray=Array.isArray||function(obj){return"[object Array]"==Object.prototype.toString.call(obj)},exports.apply_patch=function(doc,patch){return new JSONPatch(patch).apply(doc)},(exports.InvalidPatch=InvalidPatch).prototype=new Error,(exports.PatchApplyError=PatchApplyError).prototype=new Error,exports.JSONPointer=JSONPointer=function(pathStr){var i,split,path=[];if(""!==(split=pathStr.split("/"))[0])throw new InvalidPatch("JSONPointer must start with a slash (or be an empty string)!");for(i=1;i<split.length;i++)path[i-1]=split[i].replace(/~1/g,"/").replace(/~0/g,"~");this.path=path,this.length=path.length},JSONPointer.prototype._get_segment=function(index,node){var segment=this.path[index];if(isArray(node))if("-"===segment)segment=node.length;else{if(!segment.match(/^[0-9]*$/))throw new PatchApplyError("Expected a number to segment an array");segment=parseInt(segment,10)}return segment},JSONPointer.prototype._action=function(doc,handler,mutate){var that=this;return function follow_pointer(node,index){var segment,subnode;if(mutate||(node=function(o){var cloned,key;if(isArray(o))return o.slice();if(null===o)return o;if("object"==typeof o){for(key in cloned={},o)Object.hasOwnProperty.call(o,key)&&(cloned[key]=o[key]);return cloned}return o}(node)),segment=that._get_segment(index,node),index==that.path.length-1)node=handler(node,segment);else{if(isArray(node)){if(node.length<=segment)throw new PatchApplyError("Path not found in document")}else{if("object"!=typeof node)throw new PatchApplyError("Path not found in document");if(!Object.hasOwnProperty.call(node,segment))throw new PatchApplyError("Path not found in document")}subnode=follow_pointer(node[segment],index+1),mutate||(node[segment]=subnode)}return node}(doc,0)},JSONPointer.prototype.add=function(doc,value,mutate){return 0===this.length?value:this._action(doc,function(node,lastSegment){if(isArray(node)){if(lastSegment>node.length)throw new PatchApplyError("Add operation must not attempt to create a sparse array!");node.splice(lastSegment,0,value)}else node[lastSegment]=value;return node},mutate)},JSONPointer.prototype.remove=function(doc,mutate){if(0!==this.length)return this._action(doc,function(node,lastSegment){if(!Object.hasOwnProperty.call(node,lastSegment))throw new PatchApplyError("Remove operation must point to an existing value!");return isArray(node)?node.splice(lastSegment,1):delete node[lastSegment],node},mutate)},JSONPointer.prototype.replace=function(doc,value,mutate){return 0===this.length?value:this._action(doc,function(node,lastSegment){if(!Object.hasOwnProperty.call(node,lastSegment))throw new PatchApplyError("Replace operation must point to an existing value!");return isArray(node)?node.splice(lastSegment,1,value):node[lastSegment]=value,node},mutate)},JSONPointer.prototype.get=function(doc){var value;return 0===this.length?doc:(this._action(doc,function(node,lastSegment){if(!Object.hasOwnProperty.call(node,lastSegment))throw new PatchApplyError("Path not found in document");return value=node[lastSegment],node},!0),value)},JSONPointer.prototype.subsetOf=function(otherPointer){if(this.length<=otherPointer.length)return!1;for(var i=0;i<otherPointer.length;i++)if(otherPointer.path[i]!==this.path[i])return!1;return!0},_operationRequired={add:["value"],replace:["value"],test:["value"],remove:[],move:["from"],copy:["from"]},exports.JSONPatch=JSONPatch=function(patch,mutate){this._compile(patch,mutate)},JSONPatch.prototype._compile=function(patch,mutate){var i;if(this.compiledOps=[],"string"==typeof patch&&(patch=JSON.parse(patch)),!isArray(patch))throw new InvalidPatch("Patch must be an array of operations");for(i=0;i<patch.length;i++){var compiled=compileOperation(patch[i],mutate);this.compiledOps.push(compiled)}},exports.JSONPatch.prototype.apply=function(doc){var i;for(i=0;i<this.compiledOps.length;i++)doc=this.compiledOps[i](doc);return doc}},"object"==typeof exports?factory(module.exports):"function"==typeof define&&define.amd?define(["exports"],factory):(root.jsonpatch={},root.returnExports=factory(root.jsonpatch))},{}],4:[function(require,module,exports){var jsonpatch=require("jsonpatch"),render=require("json-templater/string");console.log(render('<div class="font-size:{{size}}">{{xfoo}} {{say.what}}</div>',{xfoo:"yep",say:{what:"yep"},size:"100px"}));var object=require("json-templater/object");console.log(object({"magic_key_{{magic}}":{key:"interpolation is nice {{value}}"},"appname_{{name}}":{value:"{{name}}"},appinfo:"{{appinfo}}",appversion:"{{appversion}}",biscuits:"{{biscuits}}"},jsonpatch.apply_patch({name:"dalong",age:333,appinfo:"demoapp",magic:"key",value:"value"},[{op:"replace",path:"/name",value:"boo"},{op:"move",from:"/appinfo",path:"/appversion"},{op:"add",path:"/biscuits",value:[]},{op:"add",path:"/biscuits/0",value:{name:"dalong"}},{op:"add",path:"/biscuits/1",value:{name:"appdemo"}},{op:"copy",from:"/biscuits",path:"/newbiscuits"}]),function(value,data,key){return"appinfo"==key?"my default info":render(value,data)}))},{"json-templater/object":1,"json-templater/string":2,jsonpatch:3}]},{},[4]);