How to use the load function from js-yaml
Find comprehensive JavaScript js-yaml.load code examples handpicked from public code repositorys.
js-yaml.load is a function that parses a YAML string into a JavaScript object.
105 106 107 108 109 110 111 112 113
if (!data && !current_cfg) { return; } if (data) { let config = yaml.load(data, { filename: cfg_path }); // Normalize config - convert all types to array config.type = config.type || {};
GitHub: nodeca/js-yaml
56 57 58 59 60 61 62 63 64 65
const yaml = require('js-yaml'); const fs = require('fs'); // Get document, or throw exception on error try { const doc = yaml.load(fs.readFileSync('/home/ixti/example.yml', 'utf8')); console.log(doc); } catch (e) { console.log(e); }
How does js-yaml.load work?
js-yaml.load is a function provided by the js-yaml library that takes a YAML string as input and returns a JavaScript object. The function uses a parser to convert the YAML syntax into an abstract syntax tree (AST), which is then converted into a JavaScript object. The resulting object will have keys and values that correspond to the keys and values in the YAML document. The parser supports many features of the YAML format, such as complex data structures, references, and aliases. You can also provide options to the js-yaml.load function to customize its behavior, such as disabling certain features or specifying a custom schema for the data.
5 6 7 8 9 10 11 12 13 14
const typeFolder = path.join(__dirname, '../src/universal/types') const languageFile = path.join(i18nFolder, languageFileName) const langFile = fs.readFileSync(languageFile, 'utf8') const obj = yaml.load(langFile) const keys = Object.keys(obj) const types =
GitHub: naturalcrit/homebrewery
19 20 21 22 23 24 25 26 27 28
const splitTextStyleAndMetadata = (brew)=>{ brew.text = brew.text.replaceAll('\r\n', '\n'); if(brew.text.startsWith('```metadata')) { const index = brew.text.indexOf('```\n\n'); const metadataSection = brew.text.slice(12, index - 1); const metadata = yaml.load(metadataSection); Object.assign(brew, _.pick(metadata, ['title', 'description', 'tags', 'systems', 'renderer', 'theme', 'lang'])); brew.text = brew.text.slice(index + 5); } if(brew.text.startsWith('```css')) {
+ 3 other calls in file
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12
const yaml = require("js-yaml"); const yamlString = ` - name: John Doe age: 42 - name: Jane Smith age: 35 `; const people = yaml.load(yamlString); console.log(people);
In this example, we have a YAML string that represents an array of people with names and ages. We use the js-yaml library to load the YAML string into a JavaScript object using the yaml.load function. The resulting people variable is an array of objects that corresponds to the data in the YAML string. We can then manipulate this data using standard JavaScript operations, such as iterating over the array or accessing individual properties.
GitHub: tropy/tropy
41 42 43 44 45 46 47 48 49
let name = m[2] let locale = m[3] say(`importing ${locale} labels into ${name} menu...`) let labels = load(join(home, file))[locale] let menu = yaml.load(yaml.dump(open(name).en, { noRefs: true })) translate(menu, labels) save({ [locale]: menu }, name, locale) rm(join(home, file))
+ 7 other calls in file
GitHub: taskcluster/taskcluster
377 378 379 380 381 382 383 384 385 386
e.repo = repo; e.ref = ref; throw e; } return yaml.load(Buffer.from(response.data.content, 'base64').toString()); } _handlerStarted(name) { if (typeof this.handlersCount[name] === 'undefined') {
+ 4 other calls in file
278 279 280 281 282 283 284 285 286
constants.DEBUG && console.log("File: " + fileToCheck + " exists loading it."); constants.DEBUG && console.log("Loading as YAML file."); // Load in as yml or yaml file and return this object return YAML.load(fs.readFileSync(fileToCheck), 'utf8'); } } else { constants.DEBUG && console.log("Trying to load as json or js.");
+ 4 other calls in file
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
require('dotenv').config(); PAPI_URL = "https://api.segmentapis.com" const regionalSupport = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/regional-support.yml`))) const slugOverrides = yaml.load(fs.readFileSync(path.resolve(__dirname, `../src/_data/catalog/slugs.yml`))) const slugify = (displayName) => {
+ 7 other calls in file
37 38 39 40 41 42 43 44 45 46 47
// bump only when is not snapshot if(!isSnapshot) { // bump docker-compose.js version const dockerComposePath = 'docker-compose.yml'; let dockerComposeYml = yaml.load(fs.readFileSync(dockerComposePath)); dockerComposeYml.services.relay.image = `ghcr.io/hashgraph/hedera-json-rpc-relay:${newVersion}` fs.writeFileSync(dockerComposePath, yaml.dump(dockerComposeYml)); console.log(dockerComposePath);
GitHub: agateblue/tempo
600 601 602 603 604 605 606 607 608 609 610
end: end.toISOString().slice(0, 10) } } export function yamlToJson(str) { return yaml.load(str) } export function jsonToYaml(data) { return yaml.dump(data) }
+ 5 other calls in file
GitHub: Azure/load-testing
214 215 216 217 218 219 220 221 222 223
return __awaiter(this, void 0, void 0, function* () { yield getAccessToken("https://management.core.windows.net"); YamlPath = core.getInput('loadTestConfigFile'); if (!(pathLib.extname(YamlPath) === ".yaml" || pathLib.extname(YamlPath) === ".yml")) throw new Error("The Load Test configuration file should be of type .yaml or .yml"); const config = yaml.load(fs.readFileSync(YamlPath, 'utf8')); if (util_1.isNullOrUndefined(config.testName) && util_1.isNullOrUndefined(config.testId)) throw new Error("The required field testId is missing in " + YamlPath + "."); if (!util_1.isNullOrUndefined(config.testName)) { testId = config.testName;
+ 4 other calls in file
28 29 30 31 32 33 34 35 36 37 38 39 40
module.exports = function (eleventyConfig) { let pathPrefix = "/"; eleventyConfig.addDataExtension("yaml", contents => yaml.load(contents)); eleventyConfig.addDataExtension("yml", contents => yaml.load(contents)); eleventyConfig.addPlugin(pluginRss); //Blog excerpts eleventyConfig.addPlugin(description);
+ 3 other calls in file
108 109 110 111 112 113 114 115 116 117
console.log("Reading changelogs file"); const file = fs.readFileSync( `../../${process.env.CHANGELOG_DIR}`, "utf8" ); const data = yaml.load(file); const changelogs = data && data.Entries ? Array.from(data.Entries) : []; // Check if 'Entries:' already exists and remove it
+ 9 other calls in file
9 10 11 12 13 14 15 16 17 18 19
try { internal = require('@next-theme/plugins'); } catch (error) { } const vendorsFile = fs.readFileSync(path.join(__dirname, '../../../_vendors.yml')); const dependencies = yaml.load(vendorsFile); module.exports = hexo => { const { vendors, creative_commons, pace } = hexo.theme.config; if (typeof internal === 'function') {
46 47 48 49 50 51 52 53 54 55
let contentPath = contentDir + parsedPath.replace('.html', '.json'); // frontmatter and url: /explore const pathMarkdown = 'docs/' + path.split('docs/.vitepress/dist/')[1].replace('.html', '.md'); let frontmatter = yaml.load( fs.readFileSync(pathMarkdown, 'utf8').split('---')[1] ); // Get the html files and extract the text from the html
+ 11 other calls in file
23 24 25 26 27 28 29 30 31 32
break; case 'yaml': case 'yml': try { template = jsYaml.load( readFileSync(templatePath, 'utf8'), { schema: schema } ); break;
+ 4 other calls in file
37 38 39 40 41 42 43 44 45
} load_blocks() { fs.readdirSync(this.blocks_path).forEach(file => { let file_name = file.split('.')[0]; let module = yaml.load(fs.readFileSync(path.join(this.blocks_path, file), 'utf8')); this.blocks[file_name] = module[file_name]; }); }
+ 7 other calls in file
44 45 46 47 48 49 50 51 52
} load_modules() { fs.readdirSync(this.modules_path).forEach(file => { let file_name = file.split('.')[0]; let module = yaml.load(fs.readFileSync(path.join(this.modules_path, file), 'utf8')); this.modules[file_name] = module[file_name]; }); }
+ 15 other calls in file
248 249 250 251 252 253 254 255 256 257
const notion = new Client({ auth: secret }); const nowFormat = moment().format("YYYY-MM-DD HH:mm:ss"); const projectInfo = yaml.load(fs.readFileSync('./info.yml', "utf8")); const title = projectInfo.title; const _version = ver; const host = projectInfo.host;
+ 2 other calls in file
js-yaml.dump is the most popular function in js-yaml (432 examples)