Skip to content

Commit

Permalink
Add .gitignore and package.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Codycody31 committed Nov 21, 2023
1 parent e8252d3 commit 1b58207
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Automatically normalize line endings for all text-based files
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
* text=auto

# For the following file types, normalize line endings to LF on
# checkin and prevent conversion to CRLF when they are checked out
# (this is required in order to prevent newline related issues like,
# for example, after the build script is run)
.* text eol=lf
*.css text eol=lf
*.html text eol=lf
*.jade text eol=lf
*.js text eol=lf
*.json text eol=lf
*.less text eol=lf
*.scss text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.txt text eol=lf
*.xml text eol=lf
*.vue text eol=lf
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Ignore IDE files
.idea
.vscode
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,68 @@
# js-validator
A versatile and easy-to-use JavaScript validation library for ensuring data integrity with extensive customization options.
# JS Validator

A versatile and easy-to-use JavaScript validation library, JS Validator ensures the integrity of your data inputs with a range of customization options. Ideal for projects that require detailed, flexible validation rules, from simple forms to complex data structures.

## Features

- Supports a wide range of data types (string, number, boolean).
- Customizable validation rules (required, min/max length, regex matching, etc.).
- Asynchronous and custom validation functions.
- Easy error message customization.
- Options for strict mode validation.
- Methods for retrieving passed fields and current errors.
- Fully documented and TypeScript friendly.

## Installation

```bash
npm install [your-package-name]
```

## Usage

Below is a quick example of how to use the JS Validator:

```javascript
const Validator = require('[your-package-name]');

const rules = {
email: { type: 'string', required: true, validate: 'email' },
age: { type: 'number', min: 18 },
};

const messages = {
email: { required: 'Email is required', validate: 'Invalid email' },
age: { min: 'Age must be at least 18' },
};

const validator = new Validator(rules, messages);

const data = { email: '[email protected]', age: 20 };

validator.validate(data).then(isValid => {
if (isValid) {
console.log('Validation successful');
} else {
console.log('Validation failed', validator.getErrors());
}
});
```

## API Reference

### `Validator(rules, messages, [options])`

- `rules`: Object containing validation rules.
- `messages`: Corresponding error messages for each rule.
- `options`: Optional settings like strict mode.

### Methods

- `validate(input)`: Validates the input against the rules.
- `getErrors()`: Returns validation errors.
- `getPassedFields()`: Returns fields that passed validation.
- `reset()`: Resets the validation state.

## License

This project is licensed under the [MIT License](LICENSE).
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@vmgware/js-validator",
"version": "0.9.0",
"description": "A versatile and easy-to-use JavaScript validation library for ensuring data integrity with extensive customization options.",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/VMGWARE/js-validator.git"
},
"author": "VMG Ware",
"license": "MIT",
"bugs": {
"url": "https://github.com/VMGWARE/js-validator/issues"
},
"homepage": "https://github.com/VMGWARE/js-validator#readme"
}
Loading

0 comments on commit 1b58207

Please sign in to comment.