Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
write-yaml-file
Advanced tools
The write-yaml-file npm package allows you to write YAML files easily from JavaScript objects. It is useful for configuration management, data serialization, and other tasks where YAML is preferred over JSON or other formats.
Write a simple YAML file
This feature allows you to write a simple YAML file from a JavaScript object. The code sample demonstrates how to create a YAML file named 'output.yaml' with basic user information.
const writeYamlFile = require('write-yaml-file');
const data = {
name: 'John Doe',
age: 30,
occupation: 'Software Developer'
};
writeYamlFile('output.yaml', data).then(() => {
console.log('YAML file written successfully!');
});
Write a nested YAML file
This feature allows you to write a nested YAML file from a JavaScript object. The code sample demonstrates how to create a YAML file named 'nested_output.yaml' with nested user information.
const writeYamlFile = require('write-yaml-file');
const data = {
user: {
name: 'Jane Doe',
details: {
age: 28,
occupation: 'Data Scientist'
}
}
};
writeYamlFile('nested_output.yaml', data).then(() => {
console.log('Nested YAML file written successfully!');
});
Write a YAML file with custom options
This feature allows you to write a YAML file with custom options such as indentation. The code sample demonstrates how to create a YAML file named 'custom_output.yaml' with a custom indentation of 4 spaces.
const writeYamlFile = require('write-yaml-file');
const data = {
name: 'Alice',
age: 25,
occupation: 'Graphic Designer'
};
const options = {
indent: 4
};
writeYamlFile('custom_output.yaml', data, options).then(() => {
console.log('YAML file with custom options written successfully!');
});
js-yaml is a popular YAML parser and dumper for JavaScript. It provides more comprehensive functionality for both reading and writing YAML files compared to write-yaml-file. However, it requires more setup and configuration for writing files.
yaml is another robust YAML parser and stringifier for JavaScript. It offers a wide range of features for working with YAML data, including schema support and custom types. It is more feature-rich but also more complex to use than write-yaml-file.
yamljs is a lightweight YAML parser and writer for JavaScript. It is similar to write-yaml-file in terms of simplicity and ease of use but offers additional features like converting YAML to JSON and vice versa.
Stringify and write YAML to a file atomically
Creates directories for you as needed.
<pnpm|yarn|npm> add write-yaml-file
const writeYamlFile = require('write-yaml-file')
writeYamlFile('foo.yaml', {foo: true}).then(() => {
console.log('done')
})
writeYamlFile(filepath, data, [options])
Returns a promise.
writeYamlFile.sync(filepath, data, [options])
options
Same options that can be passed in to js-yaml
Type: number
Default 438
(0666 in octal)
Mode used when writing the file.
FAQs
Stringify and write YAML to a file atomically
The npm package write-yaml-file receives a total of 420,449 weekly downloads. As such, write-yaml-file popularity was classified as popular.
We found that write-yaml-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.