How to use the js-yaml.Type function in js-yaml

To help you get started, we’ve selected a few js-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 taskcluster / taskcluster / libraries / config / src / schema.js View on Github external
const createType = (env, name, typeName, deserialize) => {
  return new yaml.Type(name, {
    kind: 'scalar', // Takes a string as input
    resolve: (data) => {
      return typeof data === 'string' && /^[A-Z0-9_]+$/.test(data);
    },
    // Deserialize the data, in the case we read the environment variable
    construct: (data) => {
      let value = env[data];
      if (value === undefined) {
        return value;
      }
      assert(typeof value === 'string', `${name} key env vars must be strings: ${data} is ${typeof value}`);
      return deserialize(value);
    },
  });
};
github sigoden / htte / packages / htte / src / init-yamlloader.js View on Github external
function tagToType(yamlTag) {
  let { tag, kind, handler } = yamlTag;
  let tagType = getTagType(tag);
  if (tagType === TAG_TYPES.UNKNOWN) {
    throw new Error(`plugin ${tag} type is invalid`);
  }
  return new yaml.Type(tag, { kind, construct: createTypeConstructor(tagType, handler) });
}
github dennisreimann / uiengine / packages / uiengine / src / util / yaml.js View on Github external
const includeYamlType = (embeddingFilePath, sourcePaths) =>
  new yaml.Type('!include', {
    kind: 'scalar',

    construct (includePath) {
      let basedir
      if (isAbsolute(includePath)) {
        basedir = sourcePaths.base
      } else {
        basedir = dirname(resolve(embeddingFilePath))
      }
      assert(basedir, `YAML Include Schema requires an absolute path (root is ${basedir})`)
      const filePath = join(basedir, includePath)
      return fromExternalFile(embeddingFilePath, sourcePaths, filePath)
    }
  })
github danielcondemarin / serverless-next.js / packages / serverless-nextjs-plugin / utils / yml / cfSchema.js View on Github external
return { "Fn::Select": data };
    }
  }),
  new yaml.Type("!FindInMap", {
    kind: "sequence",
    construct: function(data) {
      return { "Fn::FindInMap": data };
    }
  }),
  new yaml.Type("!GetAtt", {
    kind: "sequence",
    construct: function(data) {
      return { "Fn::GetAtt": data };
    }
  }),
  new yaml.Type("!GetAZs", {
    kind: "scalar",
    construct: function(data) {
      return { "Fn::GetAZs": data };
    }
  }),
  new yaml.Type("!Base64", {
    kind: "mapping",
    construct: function(data) {
      return { "Fn::Base64": data };
    }
  })
]);
github aws / awsmobile-cli / lib / aws-operations / mobile-yaml-schema.js View on Github external
function ConvertibleProject(data) {
    Object.assign(this, data)
    this[typeProperty] = 'ConvertibleProject'
}
let ConvertibleProjectYamlType = new jsyaml.Type('!com.amazonaws.mobilehub.ConvertibleProject', {
    kind: 'mapping',
    construct: data => new ConvertibleProject(data),
    instanceOf: ConvertibleProject
})

function FeatureFactory(data) {
    Object.assign(this, data)
    this[typeProperty] = 'FeatureFactory'
}
let FeatureFactoryYamlType = new jsyaml.Type('!com.amazonaws.mobilehub.FeatureFactory', {
    kind: 'mapping',
    construct: data => new FeatureFactory(data),
    instanceOf: FeatureFactory
})

function FileUploader(data) {
    Object.assign(this, data)
    this[typeProperty] = 'FileUploader'
}
let FileUploaderYamlType = new jsyaml.Type('!com.amazonaws.mobilehub.FileUploader', {
    kind: 'mapping',
    construct: data => new FileUploader(data),
    instanceOf: FileUploader
})

function SharedComponentFactory(data) {
github dennisreimann / uiengine / packages / uiengine / src / util / yaml.js View on Github external
kind: 'scalar',

    construct (includePath) {
      let basedir
      if (isAbsolute(includePath)) {
        basedir = sourcePaths.base
      } else {
        basedir = dirname(resolve(embeddingFilePath))
      }
      assert(basedir, `YAML Include Schema requires an absolute path (root is ${basedir})`)
      const filePath = join(basedir, includePath)
      return fromExternalFile(embeddingFilePath, sourcePaths, filePath)
    }
  })

const MarkdownYamlType = new yaml.Type('!markdown', {
  kind: 'scalar',

  resolve (data) {
    return typeof data === 'string'
  },

  construct (string) {
    return renderMarkdown(string)
  }
})

const parseString = (string, filename, sourcePaths) => {
  try {
    const IncludeYamlType = includeYamlType(filename, sourcePaths)
    const DataYamlType = dataYamlType(filename, sourcePaths)
    const schema = yaml.Schema.create([IncludeYamlType, DataYamlType, MarkdownYamlType])
github sxfad / config-keeper / suixingpay-config-front / src / pages / base-information / global-config / AddEdit.jsx View on Github external
import util from 'util';
import connectComponent from '../../../redux/store/connectComponent';
import DiffComponent from './DiffComponent';
import './style.less';

export const PAGE_ROUTE = '/base-information/global-config/+add/:profile';

const Option = Select.Option;
const FormItem = Form.Item;
const inspect = util.inspect;

let source,
    result,
    permalink,
    default_text;
const SexyYamlType = new jsyaml.Type('!sexy', {
    kind: 'sequence',
    construct: function (data) {
        return data.map(function (string) {
            return 'sexy ' + string;
        });
    }
});
const SEXY_SCHEMA = jsyaml.Schema.create([SexyYamlType]);

class GlobalConfigAddEdit extends Component {
    state = {
        title: '新增配置',
        isEdit: false,
        globalConfig: [],
        saveAndUpdataLoading: false,
        profile: [],
github aws / awsmobile-cli / lib / feature-operations / scripts / lib / mh-yaml-lib.js View on Github external
kind: 'mapping',
  construct: function (data) {
    return new PinpointMessaging(data.attributes);
  },
  instanceOf: PinpointMessaging
});

var BotsType = new yaml.Type('!com.amazonaws.mobilehub.v0.Bots', {
  kind: 'mapping',
  construct: function (data) {
    return new Bots(data);
  },
  instanceOf: Bots
});

var BotType = new yaml.Type('!com.amazonaws.mobilehub.v0.Bot', {
  kind: 'mapping',
  construct: function (data) {
    return new Bot(data.attributes);
  },
  instanceOf: Bot
});

var UserSettingsType = new yaml.Type('!com.amazonaws.mobilehub.v0.UserSettings', {
  kind: 'mapping',
  construct: function (data) {
    return new UserSettings(data.attributes);
  },
  instanceOf: UserSettings
});

var UserFilesType = new yaml.Type('!com.amazonaws.mobilehub.v0.UserFiles', {
github netlify / netlify-cms / src / formats / yaml.js View on Github external
import yaml from 'js-yaml';
import moment from 'moment';
import AssetProxy from 'ValueObjects/AssetProxy';
import { sortKeys } from './helpers';

const MomentType = new yaml.Type('date', {
  kind: 'scalar',
  predicate(value) {
    return moment.isMoment(value);
  },
  represent(value) {
    return value.format(value._f);
  },
  resolve(value) {
    return moment.isMoment(value) && value._f;
  },
});

const ImageType = new yaml.Type('image', {
  kind: 'scalar',
  instanceOf: AssetProxy,
  represent(value) {
github aws / awsmobile-cli / lib / feature-operations / scripts / lib / mh-yaml-lib.js View on Github external
kind: 'mapping',
  construct: function (data) {
    return new Bot(data.attributes);
  },
  instanceOf: Bot
});

var UserSettingsType = new yaml.Type('!com.amazonaws.mobilehub.v0.UserSettings', {
  kind: 'mapping',
  construct: function (data) {
    return new UserSettings(data.attributes);
  },
  instanceOf: UserSettings
});

var UserFilesType = new yaml.Type('!com.amazonaws.mobilehub.v0.UserFiles', {
  kind: 'mapping',
  construct: function (data) {
    return new UserFiles(data.attributes);
  },
  instanceOf: UserFiles
});

var DatabaseType = new yaml.Type('!com.amazonaws.mobilehub.v0.Database', {
  kind: 'mapping',
  construct: function (data) {
    return new Database(data);
  },
  instanceOf: Database
});

var DatabaseNoSQLType = new yaml.Type('!com.amazonaws.mobilehub.v0.NoSQLDatabase', {