javascript 如何在浏览器中解析 YAML?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9043765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:25:51  来源:igfitidea点击:

How to parse YAML in the browser?

javascriptparsingbrowseryaml

提问by Chris Calo

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 exportsvariable).

我想在浏览器中解析 YAML。理想情况下,我正在寻找一个浏览器就绪的库。我发现的那些不是为了在浏览器中运行而编写的(它们require()exports变量进行同步调用或假设存在变量)。

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

或者,我将接受展示如何通过RequireJS将 YAML 解析库加载到浏览器中的示例代码。

采纳答案by Chris Calo

Similar question: JavaScript YAML Parser.

类似问题: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:

似乎在浏览器中工作的最有前途的库是js-yaml。项目页面中用于加载 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.

他们声称还支持像RequireJS这样的 AMD 加载器。

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

这是库的“浏览器化”版本:带有注释缩小的.