Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yaml-transmute

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-transmute

YAML parser that lets you write back the YAML file later without loosing the file structure (comments, field order, etc..)

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
602
increased by19.21%
Maintainers
1
Weekly downloads
 
Created
Source

Yaml Transmute Logo

Build Status

Yaml Transmute

If you need to change the content of a YAML file, without losing the key order or field comments, this is the right package for you.

While parsing, yaml-transmute builds a context (key order + comments) that is returned to the caller and can be later used to stringify the original object that was slightly modified.

This package is based on Eemeli's YAML npm package.

Example

import { parse, stringify, YAMLContext } from "yaml-transmute";

const [obj, ctx]: [unknown, YAMLContext] = parse(`# Comment
foo:
  bar: a # Inline comment
  baz: b
qux: 0
`);

console.log(obj); // { foo: {bar: "a", baz: "b" }, qux: 0 }

// Create a new object, similar to the original one
const newObj = { foo: { bar: 1 }, qux: true, quux: false };

// Stringify the new object, using the context gathered from `parse`
const stringifiedYaml = stringify(newObj, ctx);

console.log(stringifiedYaml);
// # Comment
// foo:
//   bar: 1 # Inline comment
// qux: true
// quux: false

Keywords

FAQs

Package last updated on 04 Mar 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc