1 line
No EOL
2.9 KiB
JavaScript
1 line
No EOL
2.9 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("jsonPointer",[],t):"object"==typeof exports?exports.jsonPointer=t():e.jsonPointer=t()}("undefined"!=typeof self?self:this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function n(e){return"#"===e||""===e||Array.isArray(e)&&0===e.length||!1}e.r(t),e.d(t,{default:()=>S,get:()=>c,isRoot:()=>n,join:()=>_,remove:()=>j,removeUndefinedItems:()=>v,set:()=>y,split:()=>s,splitLast:()=>x});const r=/~1/g,o=/~0/g,i=/\/+/g,l=/(^[#/]*|\/+$)/g;function u(e){return e.replace(r,"/").replace(o,"~")}function f(e){return u(decodeURIComponent(e))}function s(e){if(null==e||"string"!=typeof e||n(e))return Array.isArray(e)?e:[];const t=e.indexOf("#")>=0?f:u,r=(e=(e=e.replace(i,"/")).replace(l,"")).split("/");for(let e=0,n=r.length;e<n;e+=1)r[e]=t(r[e]);return r}function c(e,t,r=void 0){if(null==t||null==e)return r;if(n(t))return e;const o=p(e,s(t));return void 0===o?r:o}function p(e,t){const n=t.shift();if(void 0!==e)return void 0!==n?p(e[n],t):e}const a=/^\[.*\]$/,d=/^\[(.+)\]$/;function g(e,t){return"__proto__"===e||"constructor"==e&&t.length>0&&"prototype"==t[0]}function y(e,t,n){if(null==t)return e;const r=s(t);if(0===r.length)return e;null==e&&(e=a.test(r[0])?[]:{});let o,i,l=e;for(;r.length>1;)o=r.shift(),i=a.test(r[0]),g(o,r)||(l=m(l,o,i));return o=r.pop(),h(l,o,n),e}function h(e,t,n){let r;const o=t.match(d);"[]"===t&&Array.isArray(e)?e.push(n):o?(r=o.pop(),e[r]=n):e[t]=n}function m(e,t,n){if(null!=e[t])return e[t];const r=n?[]:{};return h(e,t,r),r}function v(e){let t=0,n=0;for(;t+n<e.length;)void 0===e[t+n]&&(n+=1),e[t]=e[t+n],t+=1;return e.length=e.length-n,e}function j(e,t,n){const r=s(t),o=r.pop(),i=c(e,r);return i&&delete i[o],Array.isArray(i)&&!0!==n&&v(i),e}const b=/\/+/g,A=/~/g,P=/\//g;function O(e,t){if(0===e.length)return t?"#":"";for(let n=0,r=e.length;n<r;n+=1)e[n]=e[n].replace(A,"~0").replace(P,"~1"),t&&(e[n]=encodeURIComponent(e[n]));return((t?"#/":"/")+e.join("/")).replace(b,"/")}function _(e,...t){const n=[];if(Array.isArray(e))return O(e,!0===arguments[1]);const r=arguments[arguments.length-1],o="boolean"==typeof r?r:e&&"#"===e[0];for(let e=0,t=arguments.length;e<t;e+=1)n.push.apply(n,s(arguments[e]));const i=[];for(let e=0,t=n.length;e<t;e+=1)if(".."===n[e]){if(0===i.length)return o?"#":"";i.pop()}else i.push(n[e]);return O(i,o)}function x(e){const t=s(e);if(0===t.length)return"string"==typeof e&&"#"===e[0]?["#",t[0]]:["",void 0];if(1===t.length)return"#"===e[0]?["#",t[0]]:["",t[0]];const n=t.pop();return[_(t,"#"===e[0]),n]}const S={get:c,set:y,remove:j,join:_,split:s,splitLast:x,isRoot:n,removeUndefinedItems:v};return t})())); |