npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravalidatejs

v2.0.2

Published

LaraValidateJS brings the robust and intuitive validation techniques of Laravel to JavaScript environments

Downloads

28

Readme

LaraValidateJS

LaraValidateJS brings the robust and intuitive validation techniques of Laravel to JavaScript environments. Leveraging the power of ValidatorJS npm internally, this package offers a seamless and familiar validation experience for JavaScript developers, reminiscent of Laravel's validation methods.

With LaraValidateJS, effortlessly implement validation rules similar to Laravel's syntax, ensuring your data meets predefined criteria before proceeding. This package allows you to define rules for various data types, perform custom validations, and handle complex validation scenarios with ease.

Installation

Using npm

npm install laravalidatejs

Using yarn

yarn add laravalidatejs

Browserify

// ES6
import Validators from 'laravalidatejs'

Basic Usage

      const rules = {
        email: 'required|email|max:10|min:20'
      }

      const [formState, setFormState] = useState({
        email: ""
      });

       const handleSubmit = (formData) => {
          // apply your logic
        };

      <Validators formData={formState} rules={rules}>
				{({ onSubmit, errors, resetValidation }) => {
					return (
						<form>
							<input
								name="email"
								label="Email Address"
								type="email"
								value={formState?.email}
								onChange={onChange}
								placeholder="[email protected]"
							/>
							{/* Add other form inputs */}
							<button type="button" onClick={() => onSubmit(handleSubmit)}>
								Submit
							</button>
							{/* Display validation errors if any */}
							{errors && errors.email && (
								<p style={{ color: 'red' }}>{errors.email[0]}</p>
							)}
							{/* Add more error displays if needed */}
						</form>
					);
				}}
			</Validators>

formData {Object} - This prop contains the current state of the form data. It's typically an object that holds various field values that a user has entered or modified within a form

rules {Object} - The rules prop defines the validation criteria for each form field. It's often an object containing rules that specify how the data in each field should be validated. These rules typically include conditions such as required fields, minimum and maximum length, valid email format, numeric values.

onSubmit {Function} - The onSubmit is a callback prop where we define the original function (handleSubmit) responsible for executing actions like API calls or other necessary tasks. After defining this function, when we click the submit button on the form, it triggers a validation process.

During this validation process, if the form data meets all the validation criteria without any errors, the onSubmit function proceeds to call the handleSubmit function that we provided as a parameter. This means that if everything is correct according to the validation rules, the handleSubmit function is executed.

However, if there are any validation errors found in the form data based on the specified rules, the onSubmit function won’t call the handleSubmit function. Instead, it captures these validation errors and stores them in the errors variable. This allows us to handle and display these errors to the user, indicating what specific corrections need to be made before the form can be successfully submitted.

errors {Object} - we will receive all the validation errors in a format similar to the example below:

Example

let errors = {
  email: [
    'Email format is invalid.',
    'Email is required.',
  ]
};

Options

| Property | Type | Description | |----------|------|-------------| | setErrors | function | put here custom validation error comes from backend like above format. |

Here are some custom rules that do not exist in the validatorjs library.

  let rules = {
    image: 'mimes:png,jpg,jpeg,svg,webp|max_file_size:1048576|min_file_size:1048576',
    password: "required|password",
	  confirm_password: "required|confirm_password",
  }

Note

if you want to know about the validation rules then check validatorjs npm library