Files
n8n-nodes-gwezz-changdunovel/node_modules/n8n-workflow/dist/cjs/node-parameters/path-utils.js
2025-10-26 23:10:15 +08:00

33 lines
1.3 KiB
JavaScript

(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveRelativePath = resolveRelativePath;
/**
* Resolve relative paths starting in & in the context of a given full path including parameters,
* which will be dropped in the process.
* If `candidateRelativePath` is not relative, it is returned unchanged.
*
* `parameters.a.b.c`, `&d` -> `a.b.d`
* `parameters.a.b[0].c`, `&d` -> `a.b[0].d`
* `parameters.a.b.c`, `d` -> `d`
*/
function resolveRelativePath(fullPathWithParameters, candidateRelativePath) {
if (candidateRelativePath.startsWith('&')) {
const resolvedLeaf = candidateRelativePath.slice(1);
const pathToLeaf = fullPathWithParameters.split('.').slice(1, -1).join('.');
if (!pathToLeaf)
return resolvedLeaf;
return `${pathToLeaf}.${resolvedLeaf}`;
}
return candidateRelativePath;
}
});
//# sourceMappingURL=path-utils.js.map