@atomist/yaml-updater
Version:
Update YAML documents while ensuring clean diffs
74 lines (73 loc) • 2.94 kB
TypeScript
export interface Options {
keepArrayIndent?: boolean;
updateAll?: boolean;
}
/**
* Parse the provides update string as JSON and use the keys in the
* provided object to update, insert, or delete keys in the provided
* YAML.
*
* @param updates string of updates
* @param currentYaml YAML document to update
* @param options format settings
* @return updated YAML document as a string
*/
export declare function updateYamlDocumentWithString(updatesString: string, currentYaml: string, options?: Options): string;
/**
* Use the keys in the provided object to update, insert, or delete
* keys in the provided YAML. The YAML can be multiple documents.
*
* The updating follows two possible strategies depending on the ̀updateAll`
* option. When `false`, the default, if the keys are found in any of the
* documents, they are updated in the first document the key exists in. If a key
* is not found in any document, it is added to the first document. When
* `̀updateAll` is `true`, the updates append on all documents.
*
* @param updates object of updates
* @param currentYaml YAML document to update
* @param options format settings
* @return updated YAML document as a string
*/
export declare function updateYamlDocuments(updates: {
[key: string]: any;
}, yamlDocuments: string, options?: Options): string;
/**
* Use the keys in the provided object to update, insert, or delete
* keys in the provided YAML document.
*
* @param updates object of updates
* @param currentYaml YAML document to update
* @param options format settings
* @return updated YAML document as a string
*/
export declare function updateYamlDocument(updates: {
[key: string]: any;
}, currentYaml: string, options?: Options): string;
/**
* Update, insert, or delete the value of a key in `currentYml`, a
* string containing valid YAML. It does its best to retain the same
* formatting, but empty lines and trailing whitespace may disappear
* if adjacent lines are edited and comments that are parsed as part
* of a value that is deleted will be deleted.
*
* @param key the key whose value should be replaced
* @param value the value to set the key to, set to `null` or `undefined` to remove the key
* @param options settings for the formatting
* @return updated YAML document as a string
*/
export declare function updateYamlKey(key: string, value: any, currentYaml: string, options?: Options): string;
/**
* Format a key and value into a YAML string.
*
* @param key key to serialize
* @param value value to serialize
* @param options settings for the formatting
*/
export declare function formatYamlKey(key: string, value: any, options?: Options): string;
/**
* Format object into a YAML string.
*
* @param obj object to serialize
* @param options settings for the formatting
*/
export declare function formatYaml(obj: any, options?: Options): string;