@sap-ux/yaml
Advanced tools
Comparing version 0.15.1 to 0.16.0
@@ -8,2 +8,3 @@ "use strict"; | ||
class YAMLError extends Error { | ||
code; | ||
/** | ||
@@ -10,0 +11,0 @@ * Constructor taking a message and any object. |
@@ -18,10 +18,9 @@ "use strict"; | ||
? template | ||
: template === null || template === void 0 ? void 0 : template.replace(/{{-?([^{}]*)}}/g, (match, captureGroup1) => { | ||
var _a; | ||
const key = captureGroup1 === null || captureGroup1 === void 0 ? void 0 : captureGroup1.trim(); | ||
: template?.replace(/{{-?([^{}]*)}}/g, (match, captureGroup1) => { | ||
const key = captureGroup1?.trim(); | ||
// Use replacement only if it can be converted to a string | ||
return ((_a = replacements[key]) === null || _a === void 0 ? void 0 : _a.toString()) || match; | ||
return replacements[key]?.toString() || match; | ||
}); | ||
} | ||
catch (_a) { | ||
catch { | ||
return ''; | ||
@@ -28,0 +27,0 @@ } |
@@ -25,11 +25,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -60,2 +51,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
class YamlDocument { | ||
documents; | ||
/** | ||
@@ -69,6 +61,4 @@ * Returns a new instance of YamlDocument. | ||
*/ | ||
static newInstance(serializedYaml) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new YamlDocument(serializedYaml); | ||
}); | ||
static async newInstance(serializedYaml) { | ||
return new YamlDocument(serializedYaml); | ||
} | ||
@@ -138,3 +128,3 @@ /** | ||
const newNode = this.documents[0].createNode(value); | ||
if (comments === null || comments === void 0 ? void 0 : comments.length) { | ||
if (comments?.length) { | ||
for (const c of comments) { | ||
@@ -291,3 +281,3 @@ const nodeIndex = newNode.items.findIndex((item) => { | ||
const seq = this.documents[0].getIn(pathArray); | ||
if (!(seq === null || seq === void 0 ? void 0 : seq.items)) { | ||
if (!seq?.items) { | ||
throw new errors_1.YAMLError((0, texts_1.interpolate)(errors_1.errorTemplate.seqDoesNotExist, { path }), errors_1.errorCode.seqDoesNotExist); | ||
@@ -323,3 +313,3 @@ } | ||
const node = start || this.documents[0]; | ||
const targetNode = node === null || node === void 0 ? void 0 : node.getIn(pathArray); | ||
const targetNode = node?.getIn(pathArray); | ||
if (!targetNode) { | ||
@@ -381,3 +371,7 @@ throw new errors_1.YAMLError((0, texts_1.interpolate)(errors_1.errorTemplate.nodeNotFound, { path }), errors_1.errorCode.nodeNotFound); | ||
toPathArray(path) { | ||
const result = path === null || path === void 0 ? void 0 : path.toString().split('.').filter((p) => p !== '').map((p) => (isNaN(Number(p)) ? p : Number(p))); // to add comments to array elements e.g arr.0.prop | ||
const result = path | ||
?.toString() | ||
.split('.') | ||
.filter((p) => p !== '') | ||
.map((p) => (isNaN(Number(p)) ? p : Number(p))); // to add comments to array elements e.g arr.0.prop | ||
if (!result || result.length === 0) { | ||
@@ -384,0 +378,0 @@ throw new errors_1.YAMLError(errors_1.errorTemplate.pathCannotBeEmpty, errors_1.errorCode.pathCannotBeEmpty); |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "0.15.1", | ||
"version": "0.16.0", | ||
"main": "dist/index.js", | ||
@@ -15,0 +15,0 @@ "license": "Apache-2.0", |
42646
727