How to use the yaml.default.Document function in yaml

To help you get started, we’ve selected a few yaml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github back4app / antframework / packages / ant / lib / config / Config.js View on Github external
if (configFileContent) {
          try {
            this._config = yaml.parseDocument(configFileContent);
            const configJson = this._config.toJSON();
            if(typeof configJson === 'string') {
              throw new AntError(`The configuration "${configJson}" is invalid`);
            }
            return;
          } catch (e) {
            throw new AntError(
              `Could not load config ${this._path}`,
              e
            );
          }
        }
        this._config = new yaml.Document();
        this._config.contents = new Map();
        fs.writeFileSync(this._path, this._config.toString());
        logger.log(`Configuration file successfully written at: ${this._path}`);
      } else {
        throw new AntError(`Could not load config at "${this._path}".`);
      }
    } else {
      // Stringifies the configuration at "params" and then parses it to
      // generate our YAML document tree.
      this._config = yaml.parseDocument(yaml.stringify(params));
    }
  }