解析编辑并在节点 js 中保存 js 文件



我有一个包含对象数组的javascript文件。该数组还包含一些作为对象的函数。所以请记住,我不能使用 JSON 解析,因为它会返回错误。现在我需要读取该 js 文件并访问该数组,并在该数组中添加另一个函数作为对象并将其保存到硬盘。是否有任何解析库可以帮助我以及如何?

这是 js 文件

let notifications = {
"Welcome": {
    title: "Welcome",
    body: "",
    icon: ""
}};
let script = {
"Start": [
    "notify Welcome",
    {
        "Input": {
            "Text": "What is your name?",
            "Validation": function (input) {
                return input.trim().length > 0;
            },
            "Save": function (input) {
                storage.player.Name = input;
                return true;
            },
            "Warning": "You must enter a name!"
        }
    },
    "h Hi {{player.Name}} Welcome!",
    "h Currently you have {{player.intelligence}} points of Intelligence but you seem far more intelligent, how about we add five points?",
    {"Function":{
        "Apply": function () {
            storage.player.intelligence += 5;
            return true;
        },
        "Reverse": function () {
            storage.player.intelligence -= 5;
        }
    }},
    "h There you have it, you now have {{player.intelligence}} points of Intelligence",
    {
        "Choice": {
            "Dialog": "h Have you already read some documentation?",
            "Yes": {
                "Text": "Yes",
                "Do": "jump Yes"
            },
            "No": {
                "Text": "No",
                "Do": "jump No"
            }
        }
    }
],
"Yes": [
    "h That's awesome!",
    "h Then you are ready to go ahead and create an amazing Game!",
    "h I can't wait to see what story you'll tell!",
    "end"
],
"No": [
    "h You can do it now.",
    "display message Help",
    "h Go ahead and create an amazing Game!",
    "h I can't wait to see what story you'll tell!",
    "end"
]};

现在我需要以编程方式在脚本数组中添加更多选项并保存它。

你应该看看 JSON-fn。它可用于执行以下操作:

Javascript(节点.js和浏览器(插件,用于字符串化/解析/克隆jsvascript对象

  • 功能
  • 正则表达式
  • 日期

相关内容

  • 没有找到相关文章

最新更新