0.1.0 • Published 4 years ago

yaml-to-object-path-record v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

yaml-to-object-path-record

NPM Version node Build Status Dependency Status Dev Dependency Status

Parses yaml into a Record<string, string> with object paths as key

This is often useful when having translation files in yaml and access them by object path. For example this is used in telegraf-i18n.

The name of the package is inspired by the TypeScript type Record<Key, Value> as thats the structure of the result. An object path is the path in dot notation needed to uniquely identify a key within the object. For example {some: {deep: {object: {structure: 'value'}}}} would have some.deep.object.structure as object path.

Install

$ npm install yaml-to-object-path-record

Usage

const yamlToObjectPathRecord = require('yaml-to-object-path-record');

const yamlString = `
foo: bar
some: value
something:
	deep: 'is a path'
	else: 'also works'
`;

yamlToObjectPathRecord('unicorns');
//=> {foo: 'bar', some: 'value', 'something.deep': 'is a path', 'something.else': 'also works'}