Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse YAML in the browser? [duplicate]

Tags:

I would like to parse YAML in the browser. Ideally I'm looking for a browser-ready library. The ones I've found are not written to run in a browser (they make synchronous calls to require() or assume the existence of an exports variable).

Alternatively, I'll accept example code that shows how to load a YAML-parsing library into the browser via RequireJS.

like image 499
Chris Calo Avatar asked Jan 28 '12 07:01

Chris Calo


People also ask

How do I view YAML in browser?

If you cannot open your YAML file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a YAML file directly in the browser: Just drag the file onto this browser window and drop it.

Can Javascript read YAML files?

If you want to parse it in web browser, you can load the yaml file you want to parse in script tag and read it's content using js code, which will provide you string result. And if you want to parse yaml in nodejs environment, you can read file directly and also got string.

What is YAML parser?

PyYAML is a YAML parser and emitter for Python. Using the PyYAML module, we can perform various actions such as reading and writing complex configuration YAML files, serializing and persisting YMAL data. Use it to convert the YAML file into a Python dictionary.

What is YAML file in Javascript?

YAML, a recursive acronym for “YAML Ain't Markup Language”, is a human-readable data-serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted.


1 Answers

Similar question: JavaScript YAML Parser.

The most promising library that seems to work in the browser is js-yaml. A snippet from the project page for loading the library in HTML:

<script src="js-yaml.min.js"></script>
<script type="text/javascript">
var doc = jsyaml.load('greeting: hello\nname: world');
</script>

They claim to also support AMD loaders like RequireJS.

Here is the "browserified" version of the library: with comments and minified.

like image 196
Chris Calo Avatar answered Oct 05 '22 01:10

Chris Calo