Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 7x 7x 7x 7x 1x 1x 7x 2x 2x 2x 2x 7x 17x 17x 17x 17x 17x | import * as fs from 'fs/promises';
import * as path from 'path';
import * as YAML from 'js-yaml';
/**
* Reads and parses `yaml` file to object.
*/
export const openYamlFileAsObject = async <T>(filePath: string): Promise<T> => {
const yamlFileBuffer = await fs.readFile(filePath, 'utf8');
return YAML.load(yamlFileBuffer) as T;
};
/**
* Saves given `yaml` dump as a file.
*/
export const saveYamlFileAs = async (object: any, pathToFile: string) => {
const dirPath = path.dirname(pathToFile);
await fs.mkdir(dirPath, {recursive: true});
const yamlString = YAML.dump(object, {noRefs: true});
return fs.writeFile(pathToFile, yamlString);
};
/**
* Checks if given `fileName` is yaml.
*/
export const checkIfFileIsYaml = (fileName: string) => {
const yamlFileTypes = ['yaml', 'yml'];
const splittedParts = fileName.split('.');
const lastIndex = splittedParts.length - 1;
const extension = splittedParts[lastIndex];
return yamlFileTypes.includes(extension);
};
|