Socket
Socket
Sign inDemoInstall

@stoplight/json

Package Overview
Dependencies
Maintainers
25
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stoplight/json - npm Package Compare versions

Comparing version 3.12.0 to 3.13.0

__tests__/decycle.spec.d.ts

3

_utils.d.ts
export declare const replaceInString: (str: string, find: string, repl: string) => string;
export declare function isPlainObject(maybeObj: unknown): maybeObj is {
[key in PropertyKey]: unknown;
};

2

index.cjs.js

@@ -1,1 +0,1 @@

"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var lodash=require("lodash"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));const hasRef=e=>lodash.isObject(e)&&"$ref"in e&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&"#"===e[0],replaceInString=(e,r,t)=>{const n=e.toString();let o="",i=n,s=0,a=i.indexOf(r);for(;a>-1;)o+=n.substring(s,s+a)+t,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o},encodePointerFragment=e=>"number"==typeof e?e:replaceInString(replaceInString(e,"~","~0"),"/","~1"),pathToPointer=e=>encodeUriFragmentIdentifier(e),encodeUriFragmentIdentifier=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(encodePointerFragment).join("/")}`},decodePointer=e=>replaceInString(replaceInString(decodeURIComponent(""+e),"~1","/"),"~0","~"),pointerToPath=e=>decodeUriFragmentIdentifier(e),decodeFragmentSegments=e=>{const r=e.length,t=[];let n=-1;for(;++n<r;)t.push(decodePointer(e[n]));return t},decodeUriFragmentIdentifier=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return decodeFragmentSegments(e.substring(2).split("/"))},extractSourceFromRef=e=>{if("string"!=typeof e||0===e.length||isLocalRef(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)};function isObject(e){return"object"==typeof e&&null!==e}function _resolveInlineRef(e,r,t){if(null!==extractSourceFromRef(r))throw new ReferenceError("Cannot resolve external references");const n=pointerToPath(r);let o=e;for(const i of n){if(!(isObject(o)&&i in o))throw new ReferenceError(`Could not resolve '${r}'`);if(isObject(o=o[i])&&"$ref"in o){if(t.includes(o))return t[t.length-1];if(t.push(o),"string"!=typeof o.$ref)throw new TypeError("$ref should be a string");o=_resolveInlineRef(e,o.$ref,t)}}if(0===t.length)return o;const i=t[t.length-1];return isObject(i)&&("summary"in i||"description"in i)?Object.assign(Object.assign(Object.assign({},o),"description"in i?{description:i.description}:null),"summary"in i?{summary:i.summary}:null):o}function resolveInlineRef(e,r){return _resolveInlineRef(e,r,[])}const traverse=(e,r,t=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(r({parent:e,parentPath:t,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&traverse(e[n],r,t.concat(n)))},BUNDLE_ROOT="#/__bundled__",ERRORS_ROOT="#/__errors__",bundleTarget=({document:e,path:r,bundleRoot:t=BUNDLE_ROOT,errorsRoot:n=ERRORS_ROOT},o)=>{if(r===t||r===n)throw new Error("Roots do not make any sense");return bundle(lodash.cloneDeep(e),pointerToPath(t),pointerToPath(n))(r,{[r]:!0},o)},bundle=(e,r,t)=>{const n=new Set,o=(i,s,a,c={},l={},f={})=>{const p=pointerToPath(i),u=lodash.get(e,p);traverse(a||u,({parent:t})=>{if(hasRef(t)&&isLocalRef(t.$ref)){const a=t.$ref;if(f[a])return;if(c[a])return void(t.$ref=c[a]);let p,u,d,h,g;try{let t;if(p=pointerToPath(a),Array.isArray(lodash.get(e,p.slice(0,-1)))){t=`${p[p.length-2]}_${p[p.length-1]}`}else t=p[p.length-1];d=t;let o=1;for(;n.has(d);)if(d=`${t}_${++o}`,o>20)throw new Error(`Keys ${t}_2 through ${t}_20 already taken.`);n.add(d),u=[...r,d],h=pathToPointer(u)}catch(e){f[a]=e.message}if(!p||!u||!h)return;if("object"==typeof e&&null!==e)try{g=resolveInlineRef(Object(e),a)}catch(r){g=lodash.get(e,p)}if(void 0!==g&&(c[a]=h,t.$ref=h,!lodash.has(l,u))){const r=lodash.get(e,p);Array.isArray(r)?lodash.set(l,u,new Array(r.length).fill(null)):"object"==typeof r&&lodash.set(l,u,{}),lodash.set(l,u,g),s[a]||(s[a]=!0,o(i,s,g,c,l,f),s[a]=!1)}}});const d=lodash.get(l,r);return d&&Object.keys(d).length&&lodash.set(u,r,d),(Object.keys(f).length||lodash.has(e,t))&&lodash.set(u,t,lodash.has(e,t)?lodash.get(e,t):f),u};return o},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),encodePointer=e=>replaceInString(replaceInString(e,"~","~0"),"//","/~1"),extractPointerFromRef=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},getFirstPrimitiveProperty=e=>{const r=jsoncParser.createScanner(e,!0);if(r.scan(),1!==r.getToken())return;if(r.scan(),2===r.getToken())return;if(10!==r.getToken())throw new SyntaxError("Unexpected character");const t=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[t,r.getTokenValue()];case 11:return[t,Number(r.getTokenValue())];case 8:return[t,!0];case 9:return[t,!1];case 7:return[t,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},getJsonPathForPosition=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=jsoncParser.findNodeAtOffset(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const s=jsoncParser.getNodePath(i);return 0!==s.length?s:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({lineMap:e,ast:r},t,n=!1)=>{const o=findNodeAtPath(r,t,n);if(void 0!==o&&void 0!==o.range)return{range:o.range}};function findNodeAtPath(e,r,t){e:for(const n of r){const r=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return t?e:void 0;for(const t of e.children)if(Array.isArray(t.children)&&t.children[0].value===String(r)&&2===t.children.length){e=t.children[1];continue e}return t?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return t?e:void 0;e=e.children[r]}return e}const parseWithPointers=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=parseTree(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function parseTree(e,r=[],t){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function l(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function f(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function p(e){return o.children.push(e),e}function u(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function d(e){u(e),c.push(s),s=e,i=null}function h(){s=c.pop()}const g={onObjectBegin:(e,r,n,i)=>{o=p({type:"object",offset:e,length:-1,parent:o,children:[],range:f(n,i,r)}),!1===t.ignoreDuplicateKeys&&a.set(o,[]),d(createObjectLiteral(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,l,u)=>{if((o=p({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===t.ignoreDuplicateKeys){const t=a.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:f(l,u,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&swapKey(s,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,l(e+r),h()},onArrayBegin:(e,r,t,n)=>{o=p({type:"array",offset:e,length:-1,parent:o,children:[],range:f(t,n,r)}),d([])},onArrayEnd:(e,r,t,n)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=n+r),o=o.parent,l(e+r),h()},onLiteralValue:(e,r,t,n,i)=>{p({type:getLiteralNodeType(e),offset:r,length:t,parent:o,value:e,range:f(n,i,t)}),l(r+t),u(e)},onSeparator:(e,r,t)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&l(r))},onError:(e,t,n,o,i)=>{r.push({range:f(o,i,n),message:jsoncParser.printParseErrorCode(e),severity:types.DiagnosticSeverity.Error,code:e})}};jsoncParser.visit(e,g,t);const y=o.children[0];return y&&delete y.parent,{ast:y,data:s[0],lineMap:n}}function getLiteralNodeType(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const computeLineMap=e=>{const r=[0];let t=0;for(;t<e.length;t++)"\n"===e[t]&&r.push(t+1);return r.push(t+1),r};function getJsonPath(e,r=[]){return"property"===e.type&&r.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&r.unshift(e.parent.children.indexOf(e)),getJsonPath(e.parent,r)):r}function createObjectLiteral(e){return e?createOrderedObject__default({}):{}}function swapKey(e,r){if(!(r in e))return;const t=createOrderedObject.getOrder(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}const renameObjectKey=(e,r,t)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===t)return e;const n={};for(const[o,i]of Object.entries(e))o===r?n[t]=i:o in n||(n[o]=i);return n},safeParse=(e,r)=>{if("string"!=typeof e)return e;try{const t=parseNumber(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},parseNumber=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},safeStringify=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return fastStringify(e,r,t)}},startsWith=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const t in r){if(!r.hasOwnProperty(t))continue;const n=parseInt(e[t]),o=parseInt(r[t]);if(isNaN(n)&&isNaN(o)){if(e[t]!==r[t])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},stringify=(e,r,t)=>{const n=safeStringify(e,r,t);if(void 0===n)throw new Error("The value could not be stringified");return n};function toPropertyPath(e){return e.replace(/^(\/|#\/)/,"").split("/").map(decodePointerFragment).map(sanitize).join(".")}function sanitize(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const KEYS=Symbol.for(createOrderedObject.ORDER_KEY_ID),traps={ownKeys:e=>KEYS in e?e[KEYS]:Reflect.ownKeys(e)},trapAccess=e=>new Proxy(e,traps);function trimStart(e,r){if("string"==typeof e&&"string"==typeof r)return lodash.trimStart(e,r);if(!(e&&Array.isArray(e)&&e.length&&r&&Array.isArray(r)&&r.length))return e;let t=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==r[n])break;t++}return e.slice(t)}exports.BUNDLE_ROOT=BUNDLE_ROOT,exports.ERRORS_ROOT=ERRORS_ROOT,exports.KEYS=KEYS,exports.bundleTarget=bundleTarget,exports.decodePointer=decodePointer,exports.decodePointerFragment=decodePointerFragment,exports.encodePointer=encodePointer,exports.encodePointerFragment=encodePointerFragment,exports.extractPointerFromRef=extractPointerFromRef,exports.extractSourceFromRef=extractSourceFromRef,exports.getFirstPrimitiveProperty=getFirstPrimitiveProperty,exports.getJsonPathForPosition=getJsonPathForPosition,exports.getLastPathSegment=getLastPathSegment,exports.getLocationForJsonPath=getLocationForJsonPath,exports.hasRef=hasRef,exports.isLocalRef=isLocalRef,exports.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.resolveInlineRef=resolveInlineRef,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse,exports.trimStart=trimStart;
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var lodash=require("lodash"),jsoncParser=require("jsonc-parser"),createOrderedObject=require("@stoplight/ordered-object-literal"),createOrderedObject__default=_interopDefault(createOrderedObject),types=require("@stoplight/types"),fastStringify=_interopDefault(require("safe-stable-stringify"));const hasRef=e=>lodash.isObject(e)&&"$ref"in e&&"string"==typeof e.$ref,isLocalRef=e=>e.length>0&&"#"===e[0],replaceInString=(e,r,t)=>{const n=e.toString();let o="",i=n,s=0,a=i.indexOf(r);for(;a>-1;)o+=n.substring(s,s+a)+t,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o};function isPlainObject(e){if("object"!=typeof e||null===e)return!1;const r=Object.getPrototypeOf(e);return null===r||r===Object.prototype}const encodePointerFragment=e=>"number"==typeof e?e:replaceInString(replaceInString(e,"~","~0"),"/","~1"),pathToPointer=e=>encodeUriFragmentIdentifier(e),encodeUriFragmentIdentifier=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(encodePointerFragment).join("/")}`},decodePointer=e=>replaceInString(replaceInString(decodeURIComponent(""+e),"~1","/"),"~0","~"),pointerToPath=e=>decodeUriFragmentIdentifier(e),decodeFragmentSegments=e=>{const r=e.length,t=[];let n=-1;for(;++n<r;)t.push(decodePointer(e[n]));return t},decodeUriFragmentIdentifier=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return decodeFragmentSegments(e.substring(2).split("/"))},extractSourceFromRef=e=>{if("string"!=typeof e||0===e.length||isLocalRef(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)};function _resolveInlineRef(e,r,t){if(null!==extractSourceFromRef(r))throw new ReferenceError("Cannot resolve external references");const n=pointerToPath(r);let o=e;for(const i of n){if(!(isPlainObject(o)&&i in o))throw new ReferenceError(`Could not resolve '${r}'`);if(isPlainObject(o=o[i])&&"$ref"in o){if(t.includes(o))return t[t.length-1];if(t.push(o),"string"!=typeof o.$ref)throw new TypeError("$ref should be a string");o=_resolveInlineRef(e,o.$ref,t)}}if(0===t.length)return o;const i=t[t.length-1];return isPlainObject(i)&&("summary"in i||"description"in i)?Object.assign(Object.assign(Object.assign({},o),"description"in i?{description:i.description}:null),"summary"in i?{summary:i.summary}:null):o}function resolveInlineRef(e,r){return _resolveInlineRef(e,r,[])}const traverse=(e,r,t=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(r({parent:e,parentPath:t,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&traverse(e[n],r,t.concat(n)))},BUNDLE_ROOT="#/__bundled__",ERRORS_ROOT="#/__errors__",bundleTarget=({document:e,path:r,bundleRoot:t=BUNDLE_ROOT,errorsRoot:n=ERRORS_ROOT},o)=>{if(r===t||r===n)throw new Error("Roots do not make any sense");return bundle(lodash.cloneDeep(e),pointerToPath(t),pointerToPath(n))(r,{[r]:!0},o)},bundle=(e,r,t)=>{const n=new Set,o=(i,s,a,c={},l={},f={})=>{const p=pointerToPath(i),u=lodash.get(e,p);traverse(a||u,({parent:t})=>{if(hasRef(t)&&isLocalRef(t.$ref)){const a=t.$ref;if(f[a])return;if(c[a])return void(t.$ref=c[a]);let p,u,d,h,g;try{let t;if(p=pointerToPath(a),Array.isArray(lodash.get(e,p.slice(0,-1)))){t=`${p[p.length-2]}_${p[p.length-1]}`}else t=p[p.length-1];d=t;let o=1;for(;n.has(d);)if(d=`${t}_${++o}`,o>20)throw new Error(`Keys ${t}_2 through ${t}_20 already taken.`);n.add(d),u=[...r,d],h=pathToPointer(u)}catch(e){f[a]=e.message}if(!p||!u||!h)return;if("object"==typeof e&&null!==e)try{g=resolveInlineRef(Object(e),a)}catch(r){g=lodash.get(e,p)}if(void 0!==g&&(c[a]=h,t.$ref=h,!lodash.has(l,u))){const r=lodash.get(e,p);Array.isArray(r)?lodash.set(l,u,new Array(r.length).fill(null)):"object"==typeof r&&lodash.set(l,u,{}),lodash.set(l,u,g),s[a]||(s[a]=!0,o(i,s,g,c,l,f),s[a]=!1)}}});const d=lodash.get(l,r);return d&&Object.keys(d).length&&lodash.set(u,r,d),(Object.keys(f).length||lodash.has(e,t))&&lodash.set(u,t,lodash.has(e,t)?lodash.get(e,t):f),u};return o},decodePointerFragment=e=>replaceInString(replaceInString(e,"~1","/"),"~0","~"),decycle=(e,r)=>{const t=new WeakMap;return function e(n,o){let i;if(r&&(n=r(n)),isPlainObject(n)||Array.isArray(n)){const r=t.get(n);return r?{$ref:r}:(t.set(n,o),Array.isArray(n)?i=n.map((r,t)=>e(r,`${o}/${t}`)):(i={},Object.keys(n).forEach(r=>{i[r]=e(n[r],`${o}/${r}`)})),i)}return n}(e,"#")},encodePointer=e=>replaceInString(replaceInString(e,"~","~0"),"//","/~1"),extractPointerFromRef=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},getFirstPrimitiveProperty=e=>{const r=jsoncParser.createScanner(e,!0);if(r.scan(),1!==r.getToken())return;if(r.scan(),2===r.getToken())return;if(10!==r.getToken())throw new SyntaxError("Unexpected character");const t=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[t,r.getTokenValue()];case 11:return[t,Number(r.getTokenValue())];case 8:return[t,!0];case 9:return[t,!1];case 7:return[t,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},getJsonPathForPosition=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=jsoncParser.findNodeAtOffset(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const s=jsoncParser.getNodePath(i);return 0!==s.length?s:void 0};function getLastPathSegment(e){return decodePointerFragment(e.split("/").pop()||"")}const getLocationForJsonPath=({lineMap:e,ast:r},t,n=!1)=>{const o=findNodeAtPath(r,t,n);if(void 0!==o&&void 0!==o.range)return{range:o.range}};function findNodeAtPath(e,r,t){e:for(const n of r){const r=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return t?e:void 0;for(const t of e.children)if(Array.isArray(t.children)&&t.children[0].value===String(r)&&2===t.children.length){e=t.children[1];continue e}return t?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return t?e:void 0;e=e.children[r]}return e}const parseWithPointers=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=parseTree(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function parseTree(e,r=[],t){const n=computeLineMap(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function l(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function f(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function p(e){return o.children.push(e),e}function u(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function d(e){u(e),c.push(s),s=e,i=null}function h(){s=c.pop()}const g={onObjectBegin:(e,r,n,i)=>{o=p({type:"object",offset:e,length:-1,parent:o,children:[],range:f(n,i,r)}),!1===t.ignoreDuplicateKeys&&a.set(o,[]),d(createObjectLiteral(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,l,u)=>{if((o=p({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===t.ignoreDuplicateKeys){const t=a.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:f(l,u,c),message:"DuplicateKey",severity:types.DiagnosticSeverity.Error,path:getJsonPath(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&swapKey(s,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,l(e+r),h()},onArrayBegin:(e,r,t,n)=>{o=p({type:"array",offset:e,length:-1,parent:o,children:[],range:f(t,n,r)}),d([])},onArrayEnd:(e,r,t,n)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=n+r),o=o.parent,l(e+r),h()},onLiteralValue:(e,r,t,n,i)=>{p({type:getLiteralNodeType(e),offset:r,length:t,parent:o,value:e,range:f(n,i,t)}),l(r+t),u(e)},onSeparator:(e,r,t)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&l(r))},onError:(e,t,n,o,i)=>{r.push({range:f(o,i,n),message:jsoncParser.printParseErrorCode(e),severity:types.DiagnosticSeverity.Error,code:e})}};jsoncParser.visit(e,g,t);const y=o.children[0];return y&&delete y.parent,{ast:y,data:s[0],lineMap:n}}function getLiteralNodeType(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const computeLineMap=e=>{const r=[0];let t=0;for(;t<e.length;t++)"\n"===e[t]&&r.push(t+1);return r.push(t+1),r};function getJsonPath(e,r=[]){return"property"===e.type&&r.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&r.unshift(e.parent.children.indexOf(e)),getJsonPath(e.parent,r)):r}function createObjectLiteral(e){return e?createOrderedObject__default({}):{}}function swapKey(e,r){if(!(r in e))return;const t=createOrderedObject.getOrder(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}const renameObjectKey=(e,r,t)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===t)return e;const n={};for(const[o,i]of Object.entries(e))o===r?n[t]=i:o in n||(n[o]=i);return n},safeParse=(e,r)=>{if("string"!=typeof e)return e;try{const t=parseNumber(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},parseNumber=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},safeStringify=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return fastStringify(e,r,t)}},startsWith=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const t in r){if(!r.hasOwnProperty(t))continue;const n=parseInt(e[t]),o=parseInt(r[t]);if(isNaN(n)&&isNaN(o)){if(e[t]!==r[t])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},stringify=(e,r,t)=>{const n=safeStringify(e,r,t);if(void 0===n)throw new Error("The value could not be stringified");return n};function toPropertyPath(e){return e.replace(/^(\/|#\/)/,"").split("/").map(decodePointerFragment).map(sanitize).join(".")}function sanitize(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const KEYS=Symbol.for(createOrderedObject.ORDER_KEY_ID),traps={ownKeys:e=>KEYS in e?e[KEYS]:Reflect.ownKeys(e)},trapAccess=e=>new Proxy(e,traps);function trimStart(e,r){if("string"==typeof e&&"string"==typeof r)return lodash.trimStart(e,r);if(!(e&&Array.isArray(e)&&e.length&&r&&Array.isArray(r)&&r.length))return e;let t=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==r[n])break;t++}return e.slice(t)}exports.BUNDLE_ROOT=BUNDLE_ROOT,exports.ERRORS_ROOT=ERRORS_ROOT,exports.KEYS=KEYS,exports.bundleTarget=bundleTarget,exports.decodePointer=decodePointer,exports.decodePointerFragment=decodePointerFragment,exports.decycle=decycle,exports.encodePointer=encodePointer,exports.encodePointerFragment=encodePointerFragment,exports.extractPointerFromRef=extractPointerFromRef,exports.extractSourceFromRef=extractSourceFromRef,exports.getFirstPrimitiveProperty=getFirstPrimitiveProperty,exports.getJsonPathForPosition=getJsonPathForPosition,exports.getLastPathSegment=getLastPathSegment,exports.getLocationForJsonPath=getLocationForJsonPath,exports.hasRef=hasRef,exports.isLocalRef=isLocalRef,exports.parseTree=parseTree,exports.parseWithPointers=parseWithPointers,exports.pathToPointer=pathToPointer,exports.pointerToPath=pointerToPath,exports.renameObjectKey=renameObjectKey,exports.resolveInlineRef=resolveInlineRef,exports.safeParse=safeParse,exports.safeStringify=safeStringify,exports.startsWith=startsWith,exports.stringify=stringify,exports.toPropertyPath=toPropertyPath,exports.trapAccess=trapAccess,exports.traverse=traverse,exports.trimStart=trimStart;
export * from './bundle';
export * from './decodePointer';
export * from './decodePointerFragment';
export * from './decycle';
export * from './encodePointer';

@@ -5,0 +6,0 @@ export * from './encodePointerFragment';

@@ -1,1 +0,1 @@

import{isObject as e,cloneDeep as r,get as n,has as t,set as o,trimStart as i}from"lodash";import{createScanner as s,findNodeAtOffset as a,getNodePath as c,visit as l,printParseErrorCode as f}from"jsonc-parser";import u,{getOrder as p,ORDER_KEY_ID as h}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as g}from"@stoplight/types";import y from"safe-stable-stringify";const d=r=>e(r)&&"$ref"in r&&"string"==typeof r.$ref,b=e=>e.length>0&&"#"===e[0],m=(e,r,n)=>{const t=e.toString();let o="",i=t,s=0,a=i.indexOf(r);for(;a>-1;)o+=t.substring(s,s+a)+n,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=t.substring(t.length-i.length,t.length)),o},w=e=>"number"==typeof e?e:m(m(e,"~","~0"),"/","~1"),v=e=>O(e),O=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(w).join("/")}`},j=e=>m(m(decodeURIComponent(""+e),"~1","/"),"~0","~"),A=e=>_(e),_=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return(e=>{const r=e.length,n=[];let t=-1;for(;++t<r;)n.push(j(e[t]));return n})(e.substring(2).split("/"))},x=e=>{if("string"!=typeof e||0===e.length||b(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)};function E(e){return"object"==typeof e&&null!==e}function $(e,r){return function e(r,n,t){if(null!==x(n))throw new ReferenceError("Cannot resolve external references");const o=A(n);let i=r;for(const s of o){if(!(E(i)&&s in i))throw new ReferenceError(`Could not resolve '${n}'`);if(E(i=i[s])&&"$ref"in i){if(t.includes(i))return t[t.length-1];if(t.push(i),"string"!=typeof i.$ref)throw new TypeError("$ref should be a string");i=e(r,i.$ref,t)}}if(0===t.length)return i;const s=t[t.length-1];return E(s)&&("summary"in s||"description"in s)?Object.assign(Object.assign(Object.assign({},i),"description"in s?{description:s.description}:null),"summary"in s?{summary:s.summary}:null):i}(e,r,[])}const N=(e,r,n=[])=>{if(e&&"object"==typeof e)for(const t in e)e.hasOwnProperty(t)&&(r({parent:e,parentPath:n,property:t,propertyValue:e[t]}),e[t]&&"object"==typeof e[t]&&N(e[t],r,n.concat(t)))},S="#/__bundled__",k="#/__errors__",T=({document:e,path:n,bundleRoot:t="#/__bundled__",errorsRoot:o="#/__errors__"},i)=>{if(n===t||n===o)throw new Error("Roots do not make any sense");return I(r(e),A(t),A(o))(n,{[n]:!0},i)},I=(e,r,i)=>{const s=new Set,a=(c,l,f,u={},p={},h={})=>{const g=A(c),y=n(e,g);N(f||y,({parent:i})=>{if(d(i)&&b(i.$ref)){const f=i.$ref;if(h[f])return;if(u[f])return void(i.$ref=u[f]);let g,y,d,b,m;try{let t;if(g=A(f),Array.isArray(n(e,g.slice(0,-1)))){t=`${g[g.length-2]}_${g[g.length-1]}`}else t=g[g.length-1];d=t;let o=1;for(;s.has(d);)if(d=`${t}_${++o}`,o>20)throw new Error(`Keys ${t}_2 through ${t}_20 already taken.`);s.add(d),y=[...r,d],b=v(y)}catch(e){h[f]=e.message}if(!g||!y||!b)return;if("object"==typeof e&&null!==e)try{m=$(Object(e),f)}catch(r){m=n(e,g)}if(void 0!==m&&(u[f]=b,i.$ref=b,!t(p,y))){const r=n(e,g);Array.isArray(r)?o(p,y,new Array(r.length).fill(null)):"object"==typeof r&&o(p,y,{}),o(p,y,m),l[f]||(l[f]=!0,a(c,l,m,u,p,h),l[f]=!1)}}});const m=n(p,r);return m&&Object.keys(m).length&&o(y,r,m),(Object.keys(h).length||t(e,i))&&o(y,i,t(e,i)?n(e,i):h),y};return a},P=e=>m(m(e,"~1","/"),"~0","~"),R=e=>m(m(e,"~","~0"),"//","/~1"),K=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},M=e=>{const r=s(e,!0);if(r.scan(),1!==r.getToken())return;if(r.scan(),2===r.getToken())return;if(10!==r.getToken())throw new SyntaxError("Unexpected character");const n=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[n,r.getTokenValue()];case 11:return[n,Number(r.getTokenValue())];case 8:return[n,!0];case 9:return[n,!1];case 7:return[n,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},U=({lineMap:e,ast:r},n)=>{const t=e[n.line],o=e[n.line+1];if(void 0===t)return;const i=a(r,void 0===o?t+n.character:Math.min(o,t+n.character),!0);if(void 0===i)return;const s=c(i);return 0!==s.length?s:void 0};function C(e){return P(e.split("/").pop()||"")}const J=({lineMap:e,ast:r},n,t=!1)=>{const o=function(e,r,n){e:for(const t of r){const r=Number.isInteger(Number(t))?Number(t):t;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return n?e:void 0;for(const n of e.children)if(Array.isArray(n.children)&&n.children[0].value===String(r)&&2===n.children.length){e=n.children[1];continue e}return n?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return n?e:void 0;e=e.children[r]}return e}(r,n,t);if(void 0!==o&&void 0!==o.range)return{range:o.range}};const V=(e,r={disallowComments:!0})=>{const n=[],{ast:t,data:o,lineMap:i}=D(e,n,r);return{data:o,diagnostics:n,ast:t,lineMap:i}};function D(e,r=[],n){const t=W(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function h(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function y(e,r,n){return{start:{line:e,character:r},end:{line:e,character:r+n}}}function d(e){return o.children.push(e),e}function b(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function m(e){b(e),c.push(s),s=e,i=null}function w(){s=c.pop()}l(e,{onObjectBegin:(e,r,t,i)=>{o=d({type:"object",offset:e,length:-1,parent:o,children:[],range:y(t,i,r)}),!1===n.ignoreDuplicateKeys&&a.set(o,[]),m(function(e){return e?u({}):{}}(!0===n.preserveKeyOrder))},onObjectProperty:(e,t,c,l,f)=>{if((o=d({type:"property",offset:t,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:t,length:c,parent:o}),!1===n.ignoreDuplicateKeys){const n=a.get(o.parent);n&&(0!==n.length&&n.includes(e)?r.push({range:y(l,f,c),message:"DuplicateKey",severity:g.Error,path:F(o),code:20}):n.push(e))}!0===n.preserveKeyOrder&&function(e,r){if(!(r in e))return;const n=p(e),t=n.indexOf(r);-1!==t&&(n.splice(t,1),n.push(r))}(s,e),i=e},onObjectEnd:(e,r,t,i)=>{!1===n.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=i+r),o=o.parent,h(e+r),w()},onArrayBegin:(e,r,n,t)=>{o=d({type:"array",offset:e,length:-1,parent:o,children:[],range:y(n,t,r)}),m([])},onArrayEnd:(e,r,n,t)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=t+r),o=o.parent,h(e+r),w()},onLiteralValue:(e,r,n,t,i)=>{d({type:B(e),offset:r,length:n,parent:o,value:e,range:y(t,i,n)}),h(r+n),b(e)},onSeparator:(e,r,n)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&h(r))},onError:(e,n,t,o,i)=>{r.push({range:y(o,i,t),message:f(e),severity:g.Error,code:e})}},n);const v=o.children[0];return v&&delete v.parent,{ast:v,data:s[0],lineMap:t}}function B(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const W=e=>{const r=[0];let n=0;for(;n<e.length;n++)"\n"===e[n]&&r.push(n+1);return r.push(n+1),r};function F(e,r=[]){return"property"===e.type&&r.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&r.unshift(e.parent.children.indexOf(e)),F(e.parent,r)):r}const L=(e,r,n)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===n)return e;const t={};for(const[o,i]of Object.entries(e))o===r?t[n]=i:o in t||(t[o]=i);return t},q=(e,r)=>{if("string"!=typeof e)return e;try{const n=z(e);return"string"==typeof n?n:JSON.parse(e,r)}catch(e){return}},z=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},G=(e,r,n)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,n)}catch(t){return y(e,r,n)}},H=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const n in r){if(!r.hasOwnProperty(n))continue;const t=parseInt(e[n]),o=parseInt(r[n]);if(isNaN(t)&&isNaN(o)){if(e[n]!==r[n])return!1}else if(t!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},Q=(e,r,n)=>{const t=G(e,r,n);if(void 0===t)throw new Error("The value could not be stringified");return t};function X(e){return e.replace(/^(\/|#\/)/,"").split("/").map(P).map(Y).join(".")}function Y(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const Z=Symbol.for(h),ee={ownKeys:e=>Z in e?e[Z]:Reflect.ownKeys(e)},re=e=>new Proxy(e,ee);function ne(e,r){if("string"==typeof e&&"string"==typeof r)return i(e,r);if(!(e&&Array.isArray(e)&&e.length&&r&&Array.isArray(r)&&r.length))return e;let n=0;for(const t in e)if(e.hasOwnProperty(t)){if(e[t]!==r[t])break;n++}return e.slice(n)}export{S as BUNDLE_ROOT,k as ERRORS_ROOT,Z as KEYS,T as bundleTarget,j as decodePointer,P as decodePointerFragment,R as encodePointer,w as encodePointerFragment,K as extractPointerFromRef,x as extractSourceFromRef,M as getFirstPrimitiveProperty,U as getJsonPathForPosition,C as getLastPathSegment,J as getLocationForJsonPath,d as hasRef,b as isLocalRef,D as parseTree,V as parseWithPointers,v as pathToPointer,A as pointerToPath,L as renameObjectKey,$ as resolveInlineRef,q as safeParse,G as safeStringify,H as startsWith,Q as stringify,X as toPropertyPath,re as trapAccess,N as traverse,ne as trimStart};
import{isObject as e,cloneDeep as r,get as t,has as n,set as o,trimStart as i}from"lodash";import{createScanner as s,findNodeAtOffset as a,getNodePath as c,visit as l,printParseErrorCode as f}from"jsonc-parser";import u,{getOrder as p,ORDER_KEY_ID as h}from"@stoplight/ordered-object-literal";import{DiagnosticSeverity as y}from"@stoplight/types";import g from"safe-stable-stringify";const d=r=>e(r)&&"$ref"in r&&"string"==typeof r.$ref,b=e=>e.length>0&&"#"===e[0],m=(e,r,t)=>{const n=e.toString();let o="",i=n,s=0,a=i.indexOf(r);for(;a>-1;)o+=n.substring(s,s+a)+t,i=i.substring(a+r.length,i.length),s+=a+r.length,a=i.indexOf(r);return i.length>0&&(o+=n.substring(n.length-i.length,n.length)),o};function w(e){if("object"!=typeof e||null===e)return!1;const r=Object.getPrototypeOf(e);return null===r||r===Object.prototype}const O=e=>"number"==typeof e?e:m(m(e,"~","~0"),"/","~1"),v=e=>j(e),j=e=>{if(e&&"object"!=typeof e)throw new TypeError("Invalid type: path must be an array of segments.");return 0===e.length?"#":`#/${e.map(O).join("/")}`},A=e=>m(m(decodeURIComponent(""+e),"~1","/"),"~0","~"),$=e=>E(e),E=e=>{if("string"!=typeof e)throw new TypeError("Invalid type: JSON Pointers are represented as strings.");if(0===e.length||"#"!==e[0])throw new URIError("Invalid JSON Pointer syntax; URI fragment identifiers must begin with a hash.");if(1===e.length)return[];if("/"!==e[1])throw new URIError("Invalid JSON Pointer syntax.");return(e=>{const r=e.length,t=[];let n=-1;for(;++n<r;)t.push(A(e[n]));return t})(e.substring(2).split("/"))},_=e=>{if("string"!=typeof e||0===e.length||b(e))return null;const r=e.indexOf("#");return-1===r?e:e.slice(0,r)};function x(e,r){return function e(r,t,n){if(null!==_(t))throw new ReferenceError("Cannot resolve external references");const o=$(t);let i=r;for(const s of o){if(!(w(i)&&s in i))throw new ReferenceError(`Could not resolve '${t}'`);if(w(i=i[s])&&"$ref"in i){if(n.includes(i))return n[n.length-1];if(n.push(i),"string"!=typeof i.$ref)throw new TypeError("$ref should be a string");i=e(r,i.$ref,n)}}if(0===n.length)return i;const s=n[n.length-1];return w(s)&&("summary"in s||"description"in s)?Object.assign(Object.assign(Object.assign({},i),"description"in s?{description:s.description}:null),"summary"in s?{summary:s.summary}:null):i}(e,r,[])}const N=(e,r,t=[])=>{if(e&&"object"==typeof e)for(const n in e)e.hasOwnProperty(n)&&(r({parent:e,parentPath:t,property:n,propertyValue:e[n]}),e[n]&&"object"==typeof e[n]&&N(e[n],r,t.concat(n)))},k="#/__bundled__",S="#/__errors__",T=({document:e,path:t,bundleRoot:n="#/__bundled__",errorsRoot:o="#/__errors__"},i)=>{if(t===n||t===o)throw new Error("Roots do not make any sense");return I(r(e),$(n),$(o))(t,{[t]:!0},i)},I=(e,r,i)=>{const s=new Set,a=(c,l,f,u={},p={},h={})=>{const y=$(c),g=t(e,y);N(f||g,({parent:i})=>{if(d(i)&&b(i.$ref)){const f=i.$ref;if(h[f])return;if(u[f])return void(i.$ref=u[f]);let y,g,d,b,m;try{let n;if(y=$(f),Array.isArray(t(e,y.slice(0,-1)))){n=`${y[y.length-2]}_${y[y.length-1]}`}else n=y[y.length-1];d=n;let o=1;for(;s.has(d);)if(d=`${n}_${++o}`,o>20)throw new Error(`Keys ${n}_2 through ${n}_20 already taken.`);s.add(d),g=[...r,d],b=v(g)}catch(e){h[f]=e.message}if(!y||!g||!b)return;if("object"==typeof e&&null!==e)try{m=x(Object(e),f)}catch(r){m=t(e,y)}if(void 0!==m&&(u[f]=b,i.$ref=b,!n(p,g))){const r=t(e,y);Array.isArray(r)?o(p,g,new Array(r.length).fill(null)):"object"==typeof r&&o(p,g,{}),o(p,g,m),l[f]||(l[f]=!0,a(c,l,m,u,p,h),l[f]=!1)}}});const m=t(p,r);return m&&Object.keys(m).length&&o(g,r,m),(Object.keys(h).length||n(e,i))&&o(g,i,n(e,i)?t(e,i):h),g};return a},P=e=>m(m(e,"~1","/"),"~0","~"),R=(e,r)=>{const t=new WeakMap;return function e(n,o){let i;if(r&&(n=r(n)),w(n)||Array.isArray(n)){const r=t.get(n);return r?{$ref:r}:(t.set(n,o),Array.isArray(n)?i=n.map((r,t)=>e(r,`${o}/${t}`)):(i={},Object.keys(n).forEach(r=>{i[r]=e(n[r],`${o}/${r}`)})),i)}return n}(e,"#")},K=e=>m(m(e,"~","~0"),"//","/~1"),M=e=>{if("string"!=typeof e||0===e.length)return null;const r=e.indexOf("#");return-1===r?null:e.slice(r)},U=e=>{const r=s(e,!0);if(r.scan(),1!==r.getToken())return;if(r.scan(),2===r.getToken())return;if(10!==r.getToken())throw new SyntaxError("Unexpected character");const t=r.getTokenValue();if(r.scan(),6!==r.getToken())throw new SyntaxError("Colon expected");switch(r.scan(),r.getToken()){case 10:return[t,r.getTokenValue()];case 11:return[t,Number(r.getTokenValue())];case 8:return[t,!0];case 9:return[t,!1];case 7:return[t,null];case 16:throw new SyntaxError("Unexpected character");case 17:throw new SyntaxError("Unexpected end of file");default:return}},C=({lineMap:e,ast:r},t)=>{const n=e[t.line],o=e[t.line+1];if(void 0===n)return;const i=a(r,void 0===o?n+t.character:Math.min(o,n+t.character),!0);if(void 0===i)return;const s=c(i);return 0!==s.length?s:void 0};function J(e){return P(e.split("/").pop()||"")}const V=({lineMap:e,ast:r},t,n=!1)=>{const o=function(e,r,t){e:for(const n of r){const r=Number.isInteger(Number(n))?Number(n):n;if("string"==typeof r||"number"==typeof r&&"array"!==e.type){if("object"!==e.type||!Array.isArray(e.children))return t?e:void 0;for(const t of e.children)if(Array.isArray(t.children)&&t.children[0].value===String(r)&&2===t.children.length){e=t.children[1];continue e}return t?e:void 0}if("array"!==e.type||r<0||!Array.isArray(e.children)||r>=e.children.length)return t?e:void 0;e=e.children[r]}return e}(r,t,n);if(void 0!==o&&void 0!==o.range)return{range:o.range}};const D=(e,r={disallowComments:!0})=>{const t=[],{ast:n,data:o,lineMap:i}=W(e,t,r);return{data:o,diagnostics:t,ast:n,lineMap:i}};function W(e,r=[],t){const n=F(e);let o={type:"array",offset:-1,length:-1,children:[],parent:void 0},i=null,s=[];const a=new WeakMap,c=[];function h(e){"property"===o.type&&(o.length=e-o.offset,o=o.parent)}function g(e,r,t){return{start:{line:e,character:r},end:{line:e,character:r+t}}}function d(e){return o.children.push(e),e}function b(e){Array.isArray(s)?s.push(e):null!==i&&(s[i]=e)}function m(e){b(e),c.push(s),s=e,i=null}function w(){s=c.pop()}l(e,{onObjectBegin:(e,r,n,i)=>{o=d({type:"object",offset:e,length:-1,parent:o,children:[],range:g(n,i,r)}),!1===t.ignoreDuplicateKeys&&a.set(o,[]),m(function(e){return e?u({}):{}}(!0===t.preserveKeyOrder))},onObjectProperty:(e,n,c,l,f)=>{if((o=d({type:"property",offset:n,length:-1,parent:o,children:[]})).children.push({type:"string",value:e,offset:n,length:c,parent:o}),!1===t.ignoreDuplicateKeys){const t=a.get(o.parent);t&&(0!==t.length&&t.includes(e)?r.push({range:g(l,f,c),message:"DuplicateKey",severity:y.Error,path:L(o),code:20}):t.push(e))}!0===t.preserveKeyOrder&&function(e,r){if(!(r in e))return;const t=p(e),n=t.indexOf(r);-1!==n&&(t.splice(n,1),t.push(r))}(s,e),i=e},onObjectEnd:(e,r,n,i)=>{!1===t.ignoreDuplicateKeys&&a.delete(o),o.length=e+r-o.offset,o.range&&(o.range.end.line=n,o.range.end.character=i+r),o=o.parent,h(e+r),w()},onArrayBegin:(e,r,t,n)=>{o=d({type:"array",offset:e,length:-1,parent:o,children:[],range:g(t,n,r)}),m([])},onArrayEnd:(e,r,t,n)=>{o.length=e+r-o.offset,o.range&&(o.range.end.line=t,o.range.end.character=n+r),o=o.parent,h(e+r),w()},onLiteralValue:(e,r,t,n,i)=>{d({type:B(e),offset:r,length:t,parent:o,value:e,range:g(n,i,t)}),h(r+t),b(e)},onSeparator:(e,r,t)=>{"property"===o.type&&(":"===e?o.colonOffset=r:","===e&&h(r))},onError:(e,t,n,o,i)=>{r.push({range:g(o,i,n),message:f(e),severity:y.Error,code:e})}},t);const O=o.children[0];return O&&delete O.parent,{ast:O,data:s[0],lineMap:n}}function B(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";default:return"null"}}const F=e=>{const r=[0];let t=0;for(;t<e.length;t++)"\n"===e[t]&&r.push(t+1);return r.push(t+1),r};function L(e,r=[]){return"property"===e.type&&r.unshift(e.children[0].value),void 0!==e.parent?("array"===e.parent.type&&void 0!==e.parent.parent&&r.unshift(e.parent.children.indexOf(e)),L(e.parent,r)):r}const q=(e,r,t)=>{if(!e||!Object.hasOwnProperty.call(e,r)||r===t)return e;const n={};for(const[o,i]of Object.entries(e))o===r?n[t]=i:o in n||(n[o]=i);return n},z=(e,r)=>{if("string"!=typeof e)return e;try{const t=G(e);return"string"==typeof t?t:JSON.parse(e,r)}catch(e){return}},G=e=>{const r=Number(e);return Number.isFinite(r)?String(r)===e?r:e:NaN},H=(e,r,t)=>{if("string"==typeof e)return e;try{return JSON.stringify(e,r,t)}catch(n){return g(e,r,t)}},Q=(e,r)=>{if(e instanceof Array){if(r instanceof Array){if(r.length>e.length)return!1;for(const t in r){if(!r.hasOwnProperty(t))continue;const n=parseInt(e[t]),o=parseInt(r[t]);if(isNaN(n)&&isNaN(o)){if(e[t]!==r[t])return!1}else if(n!==o)return!1}}}else{if("string"!=typeof e)return!1;if("string"==typeof r)return e.startsWith(r)}return!0},X=(e,r,t)=>{const n=H(e,r,t);if(void 0===n)throw new Error("The value could not be stringified");return n};function Y(e){return e.replace(/^(\/|#\/)/,"").split("/").map(P).map(Z).join(".")}function Z(e){return e.includes(".")?`["${e.replace(/"/g,'\\"')}"]`:e}const ee=Symbol.for(h),re={ownKeys:e=>ee in e?e[ee]:Reflect.ownKeys(e)},te=e=>new Proxy(e,re);function ne(e,r){if("string"==typeof e&&"string"==typeof r)return i(e,r);if(!(e&&Array.isArray(e)&&e.length&&r&&Array.isArray(r)&&r.length))return e;let t=0;for(const n in e)if(e.hasOwnProperty(n)){if(e[n]!==r[n])break;t++}return e.slice(t)}export{k as BUNDLE_ROOT,S as ERRORS_ROOT,ee as KEYS,T as bundleTarget,A as decodePointer,P as decodePointerFragment,R as decycle,K as encodePointer,O as encodePointerFragment,M as extractPointerFromRef,_ as extractSourceFromRef,U as getFirstPrimitiveProperty,C as getJsonPathForPosition,J as getLastPathSegment,V as getLocationForJsonPath,d as hasRef,b as isLocalRef,W as parseTree,D as parseWithPointers,v as pathToPointer,$ as pointerToPath,q as renameObjectKey,x as resolveInlineRef,z as safeParse,H as safeStringify,Q as startsWith,X as stringify,Y as toPropertyPath,te as trapAccess,N as traverse,ne as trimStart};
{
"name": "@stoplight/json",
"version": "3.12.0",
"version": "3.13.0",
"description": "Useful functions when working with JSON.",

@@ -27,3 +27,3 @@ "keywords": [

"@stoplight/ordered-object-literal": "^1.0.1",
"@stoplight/types": "^11.9.0",
"@stoplight/types": "^12.2.0",
"jsonc-parser": "~2.2.1",

@@ -30,0 +30,0 @@ "lodash": "^4.17.15",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc