🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

js-laravel-validation

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-laravel-validation

Laravel style form validation for JavaScript

1.0.8
Source
npm
Version published
Weekly downloads
132
-35.29%
Maintainers
1
Weekly downloads
 
Created
Source

JS-Laravel-validation npm version

All rules are base on documentation from https://laravel.com/docs/5.7/validation#available-validation-rules

  • No dependencies
  • Works in Node.js and browser
  • Works with any front-end framework

Setup

Install: npm install js-laravel-validation

Usage

  import { validateForm } from 'js-laravel-validation'
  
  const formData = {
    username: {
      value: 'test1',
      validation: 'required|string'
    },
    password: {
      value null,
      validation: 'required|string'
    }
  }
  
  const result = validateForm({ formData });
  
  if (result.errors) {
    console.log(formData.errors); // will be { password: 'required' }
  }

API

Function NameDescription
validateForm(options)Takes a number of options to validate the specified form data
getMessage(rule, fieldData)Gets an error message for the specified rule and field data
setMessageHandler(rule, createMessage)Sets or replaces the current message handler for the specified rule
setMessageHandlers(messages)Replaces multiple message handers
getMessageHandler(rule)Returns the current message handler function for the specified rule

validateForm

OptionDescription
formDataThe form data to validate
includeMessageserrors.field will be a message instead of rule name

Function documentation to come

Missing Rules

  • active_url
    • This cannot be supported because JS does not support hostname lookups (dns_get_record in PHP)
    • This could be implemented if there was a reliable way to host a small API to do the lookup
  • date_format
    • This can be added with something like return new Date(value).format(params[0]) === value;
  • dimensions
    • This requires named params which could be pair = params[i].split('='); namedParams = { [pair[0]]: pair[1] }
  • mimetypes
  • mime
  • not_regex
  • regex
    • Regex requires extra parsing to remove forward slashes around regex

Keywords

laravel

FAQs

Package last updated on 09 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts