How to use the tv4.validate 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 mhhf / spore / src / lib / publish.es6 View on Github external
// Compile Contracts
  var compiledContracts = compileContracts( config.working_dir, json.files );
  
  
  // pick the contracts specified in the json
  json.contracts = _.pick( compiledContracts, json.contracts );
  
  // transform json to internal
  delete json.files;
  delete json.ignore;
  
  json.pv = config.version;
  

  var valide = tv4.validate( json, require('../specs/ipfs_' + config.ipfs_version + '.json') );
  if( !valide ) {
    console.log('ERROR'.red + ': Could not create package. Please report this!:\n'+tv4.error.message);
    process.exit();
  }

  var jsonHash = addJsonToIPFS( json );
    
  // TODO - Check if cliet has funds to publish the package
  // web3.eth.estimateGas({
  //   to: address, 
  //   data: 
  // });
  // 
  // Inform the user about the gas price
  if( config.cli )
    console.log('brace yourself, gas will be spend!');
github kr1sp1n / node-vault / src / index.js View on Github external
client.request = (options = {}) => {
    const valid = tv4.validate(options, requestSchema);
    if (!valid) return Promise.reject(tv4.error);
    let uri = `${client.endpoint}/${client.apiVersion}${client.pathPrefix}${options.path}`;
    // Replace unicode encodings.
    uri = uri.replace(///g, '/');
    options.headers = options.headers || {};
    if (typeof client.token === 'string' && client.token.length) {
      options.headers['X-Vault-Token'] = options.headers['X-Vault-Token'] || client.token;
    }
    options.uri = uri;
    debug(options.method, uri);
    if (options.json) debug(options.json);
    return requestPromise(options).then(client.handleVaultResponse);
  };
github sockethub / sockethub / src / validate.ts View on Github external
function validateActivityStream(msg) {
  // TODO figure out a way to allow for special objects from platforms, without
  // ignoring failed activity stream schema checks
  if (! tv4.validate(msg, SockethubSchemas.ActivityStream)) {
    return tv4.getSchema(`http://sockethub.org/schemas/v0/context/${msg.context}/messages`);
  }
  return true;
}
github vega / vega / test / _start.js View on Github external
return function(data) {
    return tv4.validate(data, schema);
  };
};
github sockethub / sockethub / src / validate.ts View on Github external
function validateActivityObject(msg) {
  return tv4.validate({ object: msg }, SockethubSchemas.ActivityObject);
}
github JamesMessinger / swagger-server / lib / validation / validate-schema.js View on Github external
function jsonValidate(value, schema, detailedErrorMessage) {
    if (tv4.validate(value, schema)) {
      return true;
    }
    else if (detailedErrorMessage) {
      throw syntaxError('%s \nData path: "%s" \nSchema path: "%s"\n',
        tv4.error.message, tv4.error.dataPath, tv4.error.schemaPath);
    }
    else {
      throw syntaxError(tv4.error.message);
    }
  }
github Azure / azure-resource-manager-schemas / tools / Tests / tv4Tests.js View on Github external
  testThrows(function () { tv4.validate("I'm not a schema!", undefined); }, "Cannot read property '$ref' of undefined");
}
github sockethub / sockethub / src / validate.ts View on Github external
function validateCredentials(msg, schema) {
  return tv4.validate(msg, schema);
}
github nteract / nteract / packages / transform-dataresource / src / types / geojson.js View on Github external
export function castGeojson(format, value) {
  if (!lodash.isObject(value)) {
    if (!lodash.isString(value)) {
      return ERROR;
    }
    try {
      value = JSON.parse(value);
    } catch (error) {
      return ERROR;
    }
  }
  if (format === "default") {
    try {
      const valid = tv4.validate(value, profile);
      if (!valid) {
        return ERROR;
      }
    } catch (error) {
      return ERROR;
    }
  } else if (format === "topojson") {
    if (!lodash.isPlainObject(value)) {
      return ERROR;
    }
  }
  return value;
}
github IngloriousCoderz / react-property-grid / src / utilities / schema.js View on Github external
  return schemas.find(schema => tv4.validate(cleanData, schema))
}