How to use the validate.js function in validate

To help you get started, we’ve selected a few validate 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 twobucks / slack-message / lib / url-generator.js View on Github external
function generateSlackUrl(message) {
  const notValid = validate(message, constraints.postMessageSchema)
  if (notValid) {
    // convert it to array because notValid is an object
    const notValidArray = Object.keys(notValid).map(key => notValid[key][0])
    return notValidArray
  }
  return `https://slack.com/api/chat.postMessage?token=${message.token}` +
          `&channel=${message.channel}&text=${message.text}`
}
github reime005 / react-native-spaceviewer / src / lib / form_validation / index.js View on Github external
export const validate = (fieldName, value) => {
  const result = validatejs({ [fieldName]: value }, constraints);

  // If there is an error message, return it!
  if (result && result[fieldName]) {
    // Return only the field error message if there are multiple
    return result[fieldName][0];
  }

  return '';
};
github all-of-us / workbench / ui / src / app / pages / profile / profile-page.tsx View on Github external
render() {
    const {profileState: {profile}} = this.props;
    const {profileEdits, updating} = this.state;
    const {
      givenName, familyName, currentPosition, organization, areaOfResearch,
      institutionalAffiliations = []
    } = profileEdits;
    const errors = validate({
      givenName, familyName, currentPosition, organization, areaOfResearch
    }, validators, {
      prettify: v => ({
        givenName: 'First Name',
        familyName: 'Last Name',
        areaOfResearch: 'Current Research'
      }[v] || validate.prettify(v))
    });

    // render a float value as US currency, rounded to cents: 255.372793 -> $255.37
    const usdElement = (value: number) => {
      value = value || 0.0;
      if (value < 0.0) {
        return <div style="{{fontWeight:">-${(-value).toFixed(2)}</div>;
      } else {
        return <div style="{{fontWeight:">${(value).toFixed(2)}</div>;
github AfricasTalkingLtd / africastalking-node.js / lib / index.js View on Github external
const constraints = {
        format: {
            inclusion: ['json', 'xml']
        },
        username: {
            presence: true,
            isString: true
        },
        apiKey: {
            presence: true,
            isString: true
        }
    };

    const error = validate(this.options, constraints);
    if (error) {
        throw error;
    }

    switch (this.options.format) {
        case "xml":
            this.options.format = "application/xml";
            break;
        case "json": // Get json by default
        default:
            this.options.format = "application/json";
    }

    var isSandbox = this.options.username.toLowerCase() === 'sandbox';
    if (isSandbox) {
        Common.enableSandbox();
github WE-FE-TEAM / grape-cms / src / common / server / bootstrap / controller_base.js View on Github external
validateArgument(data, constraints){
        let validateResult = validate(data, constraints, { fullMessages : false });

        if(validateResult){
            let resultMsg = "";
            for(let key in validateResult){
                resultMsg += key + validateResult[key].join()+ "; " ;
            }
            return resultMsg;
        }

        return true;
    }
github MarcosRava / model-structure / dist / model-structure.js View on Github external
function modelValidator(value, options, key, attributes) {
  if (!value.access('schema'))  return;
  var errors = validate(value, value.access('schema'), validateOptions);
  var strErr;
  for (var attr in errors) {
    strErr = attr + ' -> ' +  errors[attr].join(', ');
  }
  return strErr;
}
github CIMonitor / CIMonitor / app / server.js View on Github external
app.post('/status', function (request, response) {
    var statusValidation = require('./Validation/Status');
    var requestBody = request.body;

    requestBody = validate.cleanAttributes(requestBody, statusValidation.whitelist);
    var validationErrors = validate(requestBody, statusValidation.rules);

    if (validationErrors) {
        response.status(422).json(validationErrors);
        return;
    }

    app.core.handleStatus(requestBody);
    response.sendStatus(200);
});
github scott-w / reps-js / api / workouts / forms.js View on Github external
exports.exerciseQueryErrors = (params) => validate(params, {
  exercise_name: {
    length: {
      minimum: 1
    },
    presence: true
  }
});
github scott-w / reps-js / api / auth / forms.js View on Github external
exports.createUserError = params => validate(params, {
  email: {
    presence: true,
    length: {
      minimum: 2
    }
  },
  first_name: {
    presence: true,
    length: {
      minimum: 1
    }
  },
  last_name: {
    presence: true,
    length: {
      minimum: 1
github scott-w / reps-js / api / user / forms.js View on Github external
exports.userErrors = params => validate(params, {
  first_name: {
    length: {
      minimum: 1
    }
  },
  last_name: {
    length: {
      minimum: 1
    }
  },
  fit_token: {
    length: {
      minimum: 0
    },
    presence: false
  }

validate

Validate object properties in javascript.

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular validate functions