yarn add json-ref-escodegen
or if npm is package manager of your choice
npm install json-ref-escodegen --save
- generates JS code instead of object literal supposed to be eventually serialized back to JSON / YAML / any other text format
- highly scalable - it's expected to work on projects rather than single files
- very performant - one of the quickest (if not the quickest) $ref resolver
- excellent long-term caching possibilities - each $ref is as a separate module (file)
- first-class support for all kinds of circularity
- truly environment agnostic - does not depend on any fs module or browser global
- no concept of resolvers - you are in charge of the whole reading & path parsing process
- no parser included - bring your own!
- no CLI
;;;;const __dirname = path
How does it work?
json-ref-escodegen generates valid JS code for each processed document. Each $ref is a getter pointing at external referenced module, or the same module if it's an internal ref.
How do I serialize my crap back to other text format, such as JSON or YAML?
It's as simple as importing the generated module and running
JSON.stringify or YAML counterpart.
I strongly recommend usage of YAML due to anchors, or a safe JSON stringifer.