@sap-ux/yaml
Advanced tools
Comparing version 0.9.2 to 0.10.0
# @sap-ux/yaml | ||
## 0.10.0 | ||
### Minor Changes | ||
- d37c8bd: Added support for selecting a custom view name for Fiori freestyle - Basic template | ||
## 0.9.2 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,3 @@ | ||
export { YamlDocument, NodeComment, Path } from './yaml-document'; | ||
export { YamlDocument, NodeComment } from './yaml-document'; | ||
export { Node, YAMLSeq, YAMLMap } from 'yaml'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.YamlDocument = void 0; | ||
exports.YAMLMap = exports.YAMLSeq = exports.YamlDocument = void 0; | ||
var yaml_document_1 = require("./yaml-document"); | ||
Object.defineProperty(exports, "YamlDocument", { enumerable: true, get: function () { return yaml_document_1.YamlDocument; } }); | ||
var yaml_1 = require("yaml"); | ||
Object.defineProperty(exports, "YAMLSeq", { enumerable: true, get: function () { return yaml_1.YAMLSeq; } }); | ||
Object.defineProperty(exports, "YAMLMap", { enumerable: true, get: function () { return yaml_1.YAMLMap; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,6 +0,4 @@ | ||
declare type PathImpl<T, Key extends keyof T> = Key extends string ? T[Key] extends Record<string, any> ? `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` | `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` : never : never; | ||
declare type PathImpl2<T> = PathImpl<T, keyof T> | keyof T; | ||
export declare type Path<T> = PathImpl2<T> extends string | keyof T ? PathImpl2<T> : keyof T; | ||
import { YAMLMap, YAMLSeq } from 'yaml'; | ||
export interface NodeComment<T> { | ||
path: Path<T>; | ||
path: string; | ||
comment: string; | ||
@@ -100,2 +98,58 @@ } | ||
/** | ||
* Updates a node in a sequence in the document. | ||
* | ||
* @param path - hierarchical path where the node will be inserted/updated | ||
* @param {string} path.path - the path object's path | ||
* @param {Object} path.matcher - key/value pair identifying the object | ||
* @param {Object} path.value - the path object's value | ||
* @param path.matcher.key | ||
* @param path.matcher.value | ||
* @returns {YamlDocument} the YamlDocument instance | ||
* @memberof YamlDocument | ||
*/ | ||
updateAt<T = unknown>({ path, matcher, value }: { | ||
path: string; | ||
matcher: { | ||
key: string; | ||
value: string; | ||
}; | ||
value: T; | ||
}): YamlDocument; | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {unknown} | ||
*/ | ||
getNode({ start, path }: { | ||
start?: YAMLMap | YAMLSeq; | ||
path: string; | ||
}): unknown; | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {unknown} | ||
*/ | ||
getSequence({ start, path }: { | ||
start?: YAMLMap | YAMLSeq; | ||
path: string; | ||
}): YAMLSeq; | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {YAMLMap} | ||
*/ | ||
getMap({ start, path }: { | ||
start?: YAMLMap | YAMLSeq; | ||
path: string; | ||
}): YAMLMap; | ||
/** | ||
* @param sequence | ||
* @param predicate | ||
* @returns {unknown} | ||
*/ | ||
findItem(sequence: YAMLSeq, predicate: (o: any) => boolean): unknown; | ||
/** | ||
* Converts to a path object to an array. | ||
@@ -111,3 +165,2 @@ * | ||
} | ||
export {}; | ||
//# sourceMappingURL=yaml-document.d.ts.map |
@@ -34,2 +34,3 @@ "use strict"; | ||
const yaml_1 = __importStar(require("yaml")); | ||
const merge = require("lodash.merge"); | ||
/** | ||
@@ -186,2 +187,86 @@ * Represents a yaml document with utility functions to manipulate the document. | ||
/** | ||
* Updates a node in a sequence in the document. | ||
* | ||
* @param path - hierarchical path where the node will be inserted/updated | ||
* @param {string} path.path - the path object's path | ||
* @param {Object} path.matcher - key/value pair identifying the object | ||
* @param {Object} path.value - the path object's value | ||
* @param path.matcher.key | ||
* @param path.matcher.value | ||
* @returns {YamlDocument} the YamlDocument instance | ||
* @memberof YamlDocument | ||
*/ | ||
updateAt({ path, matcher, value }) { | ||
const pathArray = this.toPathArray(path); | ||
const seq = this.document.getIn(pathArray); | ||
if (!seq) { | ||
throw new Error(i18n_1.t('error.seqDoesNotExist', { path })); | ||
} | ||
const node = seq.items.find((node) => node.toJSON()[matcher.key] === matcher.value); | ||
const newNode = this.document.createNode(merge(node.toJSON(), value)); | ||
seq.items.splice(seq.items.indexOf(node), 1, newNode); | ||
return this; | ||
} | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {unknown} | ||
*/ | ||
getNode({ start, path }) { | ||
if (start) { | ||
if (!(yaml_1.isSeq(start) || yaml_1.isMap(start))) { | ||
throw new Error(i18n_1.t('error.startNodeMustBeCollection')); | ||
} | ||
} | ||
const pathArray = this.toPathArray(path); | ||
const node = start || this.document; | ||
const targetNode = node === null || node === void 0 ? void 0 : node.getIn(pathArray); | ||
if (!targetNode) { | ||
throw new Error(i18n_1.t('error.nodeNotFound', { path })); | ||
} | ||
else { | ||
return targetNode; | ||
} | ||
} | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {unknown} | ||
*/ | ||
getSequence({ start, path }) { | ||
const a = this.getNode({ start, path }); | ||
if (!yaml_1.isSeq(a)) { | ||
throw new Error(i18n_1.t('error.seqDoesNotExist', { path })); | ||
} | ||
else { | ||
return a; | ||
} | ||
} | ||
/** | ||
* @param root0 | ||
* @param root0.start | ||
* @param root0.path | ||
* @returns {YAMLMap} | ||
*/ | ||
getMap({ start, path }) { | ||
const a = this.getNode({ start, path }); | ||
if (!yaml_1.isMap(a)) { | ||
throw new Error(i18n_1.t('error.nodeNotAMap', { path })); | ||
} | ||
else { | ||
return a; | ||
} | ||
} | ||
/** | ||
* @param sequence | ||
* @param predicate | ||
* @returns {unknown} | ||
*/ | ||
findItem(sequence, predicate) { | ||
const toJson = (o) => (o !== undefined && typeof o.toJSON === 'function' && o.toJSON.call(o)) || {}; | ||
return sequence.items.find((item) => predicate(toJson(item))); | ||
} | ||
/** | ||
* Converts to a path object to an array. | ||
@@ -195,2 +280,3 @@ * | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
toPathArray(path) { | ||
@@ -197,0 +283,0 @@ const result = path === null || path === void 0 ? void 0 : path.toString().split('.').filter((p) => p !== ''); |
{ | ||
"name": "@sap-ux/yaml", | ||
"description": "Library to manipulate YAML file contents", | ||
"version": "0.9.2", | ||
"version": "0.10.0", | ||
"main": "dist/index.js", | ||
@@ -24,2 +24,3 @@ "scripts": { | ||
"i18next-fs-backend": "1.1.1", | ||
"lodash.merge": "4.6.2", | ||
"yaml": "2.0.0-6" | ||
@@ -29,2 +30,3 @@ }, | ||
"@types/i18next-fs-backend": "1.0.0", | ||
"@types/lodash.merge": "4.6.6", | ||
"typescript": "4.2.4" | ||
@@ -31,0 +33,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41607
519
4
3
+ Addedlodash.merge@4.6.2
+ Addedlodash.merge@4.6.2(transitive)