node-yaml-path
v1.0.4
Published
>[!CAUTION] > DEPRECATED: This package was replaced by https://www.npmjs.com/package/@alell/jsonpath-plus-q > Simple yaml-path to `yaml` library.
Downloads
28
Readme
node-yaml-path
[!CAUTION] DEPRECATED: This package was replaced by https://www.npmjs.com/package/@alell/jsonpath-plus-q
Simple yaml-path to yaml
library.
Using get
import { Document, parseDocument } from 'yaml'
import { get, set } from 'node-yaml-path'
const yaml = `
metadata:
annotations:
simple-annotation: "string value"
`
doc = parseDocument(content)
const path = '$.metadata.annotations.simple-annotation'
const result = get(path, doc)
console.log(result)
// > 'string value'
Using set
import { Document, parseDocument } from 'yaml'
import { get, set } from 'node-yaml-path'
const yaml = `
metadata:
annotations:
simple-annotation: "string value"
`
const newValue = 'new string value'
set(path, newValue, doc)
const newDoc = parseDocument(doc.toString())
const newResult = get(path, newDoc)
console.log(newResult)
// > 'new string value'
console.log(newDoc.toString())
// > '
// metadata:
// annotations:
// simple-annotation: "new string value"
'