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

mapped-yaml

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

mapped-yaml

A simple yaml parser providing source map

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mapped-yaml

tests coverage version

A simple yaml parser providing source map as well.

npm i mapped-yaml

Usage

import { readFile } from 'fs/promises'
import { parse } from 'mapped-yaml'


async main() {
  const content = await readFile('./stuff.yml', 'utf8')
  const parsed = parse(content, './stuff.yml')

  // 👉 access parsed contents of each node using `.object` property
  assert(parsed.object['hellow'].object === 'world')
  assert(parsed.object['stuff'].object[0].object === 42)
  assert(parsed.object['stuff'].object[1].object['foo'].object === 'bar')
  
  // 👉 access location of each node using `.location` property
  console.log(parsed.object['stuff'].object[1].location)

  // {
  //   file: File { ... },
  //   range: {
  //     start: { line: 4, character: 4 },
  //     end: { line: 4, character: 11 }
  //   }
  // }
  
  // 👉 get the contents of the file maybe with some surrounding lines even
  console.log(
    parsed.location.file.range(                          // --> returns the contents of the file for given range
      parsed.object['stuff'].object[0].location.range,   // --> the range of '- 42'
      { surrounding: 1 }                                 // --> also return 1 surrounding line.
    )
  )
  
  // {
  //   2: { content: 'stuff:', surround: true },
  //   3: { content: '  - 42', surround: false },
  //   4: { content: '  - foo: bar', surround: true }
  // }
}
# stuff.yml
hellow: world
stuff:
  - 42
  - foo: bar

⚠️ Line and character indexes are ZERO-BASED. ⚠️


Acknowledgement

This is a simple wrapper over yaml. If you don't need source mapping, most probably you should just use that package.



Keywords

FAQs

Package last updated on 17 Jul 2022

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