'how to include multiple yaml configuration in the same file using js-yaml

am working on a project that include generating yaml files and am using js-yaml and it did help me so far but the problem is that the library work this way

  const yaml = require('js-yaml');

  const kyaml = {
    apiVersion: 'v1',
    kind: 'Namespace',
    metadata: {
      name: username,
    },
  };

  await writeFile(
    `tenant.yaml`,
    yaml.dump(kyaml),
    'utf8',
  );

and that will produce

apiVersion: v1
kind: Namespace
metadata:
  name: sara

now my probelm that i need to generate file that have multiple configs separted with triple dashes like this

apiVersion: v1
kind: Namespace
metadata:
  name: sara
---
apiVersion: v1
kind: Namespace
metadata:
  name: joe

so far i did search for some help to achieve that and i didnt find any so any help here is apriciated



Solution 1:[1]

js-yaml specifically decided not to support that. They give this workaround:

[docs_to_dump].map(doc => yaml.safeDump(doc)).join('---\n');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 flyx