yaml-utility
v0.0.1
Published
yaml-utility package will help to read and get parent key & target value for given target key from yaml
Downloads
2
Maintainers
Readme
yaml-utility
The yaml-utility module will help to read yaml and get parent and target value based on the given target key
Installation
npm install yaml-utility
yarn add yaml-utility
Usage
Javascript
const { getYAMLObj, getYamlParentkeyAndDynamicTargetValue, getYamlParentkeyAndTargetValue } = require("yaml-utility");
TypeScript
import { getYAMLObj, getYamlParentkeyAndDynamicTargetValue, getYamlParentkeyAndTargetValue } from "yaml-utility";
import { join } from "path";
const filepath = join(process.cwd(), "src\\__tests__\\data\\data2")
const output = getYAMLObj(filepath)
console.log(output)
const { parentkey, targetvalue } = getYamlParentkeyAndTargetValue(output, "login_username_txt");
console.log("Parent Key:", parentkey)
console.log("Target Value:", targetvalue)
const replaceList = ["result1", "result2"]
const { parentkey, targetvalue } = getYamlParentkeyAndDynamicTargetValue(
output, "replaceable_loc", replaceList
);
console.log("Parent Key:", parentkey)
console.log("Target Value:", targetvalue)
const replaceList = ["result3", "result4"]
const { parentkey, targetvalue } = getYamlParentkeyAndDynamicTargetValue(
output, "replaceable_loc2", replaceList, "restore"
);
console.log("Parent Key:", parentkey)
console.log("Target Value:", targetvalue)
Output:
{
File1: {
id: {
'test.test1': 'test1',
'test.test2': 'test2',
'test.test3': 'test3',
'test.test4': 'test4'
},
xpath: {
'test.test5': 'test5',
'test.test6': 'test6',
'test.test7': 'test7',
'test.test8': 'test8',
'replaceable_loc': "//test[@id='replace']/test/replace",
'replaceable_loc2': "//test[@id='restore']/test/restore"
}
}
}
Parent Key: id
Target Key: username
Parent Key: xpath
Target Key: //test[@id='result1']/test/result2
Parent Key: xpath
Target Key: //test[@id='result3']/test/result4
License
MIT License
Copyright (c) 2021 Muralidharan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Release Notes
Notes for the released versions
0.0.1
Initial release