Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = {
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]);
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]);
}
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);
}
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 || "");
}
}
}
}
},
);
}
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 || "");
}
}
}
}
},
index.addAdditionalFormatForValidationSchemas = function(ref, fn) {
tv4.addFormat(ref, fn);
};
exports.addFormat = function (format, validationFunction) {
tv4.addFormat(format, validationFunction);
};
'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);
'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');