js-yaml#DEFAULT_SCHEMA TypeScript Examples

The following examples show how to use js-yaml#DEFAULT_SCHEMA. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: read-file-or-url.ts    From graphql-mesh with MIT License 6 votes vote down vote up
function getSchema(filepath: string, logger?: Logger): Schema {
  return DEFAULT_SCHEMA.extend([
    new Type('!include', {
      kind: 'scalar',
      resolve(path: string) {
        return typeof path === 'string';
      },
      construct(path: string) {
        const newCwd = pathModule.dirname(filepath);
        const absoluteFilePath = pathModule.isAbsolute(path) ? path : pathModule.resolve(newCwd, path);
        const content = fs.readFileSync(absoluteFilePath, 'utf8');
        return loadYaml(absoluteFilePath, content, logger);
      },
    }),
    new Type('!includes', {
      kind: 'scalar',
      resolve(path: string) {
        return typeof path === 'string';
      },
      construct(path: string) {
        const newCwd = pathModule.dirname(filepath);
        const absoluteDirPath = pathModule.isAbsolute(path) ? path : pathModule.resolve(newCwd, path);
        const files = fs.readdirSync(absoluteDirPath);
        return files.map(filePath => {
          const absoluteFilePath = pathModule.resolve(absoluteDirPath, filePath);
          const fileContent = fs.readFileSync(absoluteFilePath, 'utf8');
          return loadYaml(absoluteFilePath, fileContent, logger);
        });
      },
    }),
  ]);
}
Example #2
Source File: helpers.ts    From backstage with Apache License 2.0 6 votes vote down vote up
MKDOCS_SCHEMA = DEFAULT_SCHEMA.extend([
  new Type('', {
    kind: 'scalar',
    multi: true,
    representName: o => (o as UnknownTag).type,
    represent: o => (o as UnknownTag).data ?? '',
    instanceOf: UnknownTag,
    construct: (data: string, type?: string) => new UnknownTag(data, type),
  }),
  new Type('', {
    kind: 'sequence',
    multi: true,
    representName: o => (o as UnknownTag).type,
    represent: o => (o as UnknownTag).data ?? '',
    instanceOf: UnknownTag,
    construct: (data: string, type?: string) => new UnknownTag(data, type),
  }),
])