How to use the tv4.addFormat function in tv4

To help you get started, we’ve selected a few tv4 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 mozilla / webmaker-android / test / unit / templates.js View on Github external
var assert = require('assert');
var jsonValidator = require('tv4');
var validate = jsonValidator.validateMultiple;
var templates = require('../../lib/templates.json');

// Localization strings
var localeFile = require('../../locale/en_US/webmaker-app.json');
var localizedStrings = [];
Object.keys(localeFile).forEach(function (localizedStr) {
	localizedStrings.push(localizedStr.toLowerCase());
});

jsonValidator.addFormat('localized', function (data) {
	if(typeof data === 'string' && localizedStrings.indexOf(data.toLowerCase()) !== -1) {
		// No error
		return null;
	}

	return 'must be localized';
});

/*
 * JSON schemas
 */
// Type schemas
var stringSchema = {
	type: 'string'
};
var nonEmptyStringSchema = {
github Talend / ui / packages / forms / src / UIForm / UIFormFn.js View on Github external
useEffect(() => {
		// control the tv4 language here.
		const mergedLanguage = getLanguage(t);
		if (language != null) {
			Object.assign(mergedLanguage, language);
			// Force update of language @talend even if already set
			tv4.addLanguage('@talend', mergedLanguage);
			tv4.language('@talend');
		}
		if (!tv4.language('@talend')) {
			tv4.addLanguage('@talend', mergedLanguage);
			tv4.language('@talend'); // set it
		}
		const allFormats = Object.assign(customFormats(t), userCustomFormat);
		tv4.addFormat(allFormats);
	}, [t]);
github Talend / ui / packages / forms / src / UIForm / hooks / useLanguageEffect.js View on Github external
useEffect(() => {
		// control the tv4 language here.
		const mergedLanguage = getLanguage(t);
		if (language != null) {
			Object.assign(mergedLanguage, language);
			// Force update of language @talend even if already set
			tv4.addLanguage('@talend', mergedLanguage);
			tv4.language('@talend');
		}
		if (!tv4.language('@talend')) {
			tv4.addLanguage('@talend', mergedLanguage);
			tv4.language('@talend'); // set it
		}
		const allFormats = Object.assign(customFormats(t), userCustomFormats);
		tv4.addFormat(allFormats);
	}, [t]);
}
github Talend / ui / packages / forms / src / UIForm / UIForm.component.js View on Github external
this.focusFirstError = this.focusFirstError.bind(this);
		this.setFormRef = this.setFormRef.bind(this);
		// control the tv4 language here.
		const language = getLanguage(props.t);
		if (props.language != null) {
			Object.assign(language, props.language);
			// Force update of language @talend even if already set
			tv4.addLanguage('@talend', language);
			tv4.language('@talend');
		}
		if (!tv4.language('@talend')) {
			tv4.addLanguage('@talend', language);
			tv4.language('@talend'); // set it
		}
		const allFormats = Object.assign(customFormats(props.t), props.customFormats);
		tv4.addFormat(allFormats);
	}
github blackmiaool / vue-form10 / src / components / Form10.vue View on Github external
return format.name === formatConfig.name;
                    });
                    if (index > -1) {
                        this.provide.formats.splice(index, 1, formatConfig);
                    } else {
                        this.provide.formats.push(formatConfig);
                    }
                    if (formatConfig.format instanceof RegExp) {
                        tv4.addFormat(formatConfig.name, data => {
                            if (!formatConfig.format.test(data)) {
                                return this.$t("Invalid format");
                            }
                            return null;
                        });
                    } else {
                        tv4.addFormat(formatConfig.name, formatConfig.format || "");
                    }
                }
            }
        }
    },
github blackmiaool / vue-form10 / src / components / Form10.vue View on Github external
);
            }
            if (plugin.render) {
                const pluginConfig = plugin.form10 || {};
                if (pluginConfig.format) {
                    const formatConfig = getFormatConfig();
                    const index = this.provide.formats.findIndex((format) => {
                        return format.name === formatConfig.name;
                    });
                    if (index > -1) {
                        this.provide.formats.splice(index, 1, formatConfig);
                    } else {
                        this.provide.formats.push(formatConfig);
                    }
                    if (formatConfig.format instanceof RegExp) {
                        tv4.addFormat(formatConfig.name, data => {
                            if (!formatConfig.format.test(data)) {
                                return this.$t("Invalid format");
                            }
                            return null;
                        });
                    } else {
                        tv4.addFormat(formatConfig.name, formatConfig.format || "");
                    }
                }
            }
        }
    },
github adrai / devicestack / index.js View on Github external
index.addAdditionalFormatForValidationSchemas = function(ref, fn) {
  tv4.addFormat(ref, fn);
};
github BlueOakJS / blueoak-server / services / swagger.js View on Github external
exports.addFormat = function (format, validationFunction) {
    tv4.addFormat(format, validationFunction);
};
github dogenzaka / react-manager / src / js / components / forms / SchemaForm.jsx View on Github external
'use strict';

import React from 'react';
import { FlatButton, RaisedButton, FontIcon } from 'material-ui';
import _ from 'lodash';
import tv4 from 'tv4';
import tv4formats from 'tv4-formats';
tv4.addFormat(tv4formats);

import SchemaItem from './SchemaItem.jsx';
import { Theme } from '../../styles';
import i18n from '../../i18n';

/**
 * SchemaForm is generating form from JSON schema definitions
 */
class SchemaForm extends React.Component {

  constructor(props) {
    super(props);
    this.state = {};
    this._didSubmit = this._didSubmit.bind(this);
    this._didCancel = this._didCancel.bind(this);
    this._didChange = this._didChange.bind(this);
github pwa-builder / pwabuilder-lib / lib / manifestTools / validationRules / w3cManifestSchema.js View on Github external
'use strict';

var fs = require('fs'),
    path = require('path'),
    tv4 = require('tv4');

var validationConstants = require('../../constants').validation,
    utils = require('../../utils');
    
tv4.addFormat('uri', function (data) {
  if (!utils.isURL(data)) {
    return '\'' + data + '\' is not a valid URL.';
  }
  return null;
});

var errorCodeLookup = {};
for (var key in tv4.errorCodes) {
  errorCodeLookup[tv4.errorCodes[key]] = key.toLowerCase();
}

module.exports = function (manifestContent, callback) {
  var schemaFile = path.resolve(__dirname, '..', 'assets', 'web-manifest.json');
  var schema = JSON.parse(fs.readFileSync(schemaFile).toString());
  
  var extendedSchemaFile = path.resolve(__dirname, '..', 'assets', 'web-manifest-extended.json');