rafamel/yaml-import

Support passing objects in addition to files

henhal opened this issue · 0 comments

Hi,

Any thoughts on supporting invoking yaml-import with parsed objects instead of only with file paths? Or even invoking the different import modes directly, programmatically?

In my use-case I want to merge a number of files, and depending on some parameters I want to include or exclude some of them. It's not very convenient to have to create input files for all my scenarios just to be able to call yaml-import on them (since it only supports files), nor having a preprocessor that creates the files that are then fed to yaml-import.

Even if yimp.read() would support taking objects representing yaml files with !!import tags, the custom yimp !!import tags are not very user friendly to manually construct from code since I guess they look like {"tag:yaml.org,2002:import/merge": ["file1.yml", "file2.yml"]}, right?

So, have you considered adding programmatic API to create object representations of the different import tags, so that they could then be passed to yimp.read or directly used to produce output for a single import tag?

Some food for thought:

// parse a yimp tag equivalent to !!import/merge [file1.yml, file2.yml] 
// and returns the javascript object for the merged result
const myObj = yimp.merge(['file1.yml', 'file2.yml']) 

// parse a yimp tag equivalent to !!import/single file3.yml
// and returns the javascript object for the merged result
const myObj = yimp.single('file3.yml') 

Ideally, each of these would in turn also accept paths or objects, so that in the end you could mix files and data and even call nested sub objects such as yimp.merge(['file1.yml', {foo: 42, baz: 3}, yimp.single('file3.yml')])

Thoughts?