# jslidate

> Library for faster JS validation

Latest version **1.0.0** (published 2017-11-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install jslidate
pnpm add jslidate
yarn add jslidate
bun add jslidate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-11-09 |
| First published | 2017-11-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Rekseto |
| Maintainers | rekseto |
| Keywords | Validation, JS |

## Links

- npm: https://www.npmjs.com/package/jslidate
- Repository: https://github.com/Rekseto/jslidate
- Homepage: https://github.com/Rekseto/jslidate#readme
- Issues: https://github.com/Rekseto/jslidate/issues
- npm.io page: https://npm.io/package/jslidate

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-11-09

## README

# JSLidate
JSLidate is libraray for JS validation

## Sample usage
Code below creates Form object

```javascript
    const impForm = new JSLidate({
        inputs: [{
            selector: '.input_1' ,
            rules: [minLength (1), maxLength (5)] ,
        }, {
            selector: '.input_2' ,
            rules: [minLength (2), maxLength (4), patternRule(/[a-b]/img, 'a-b alphanumeric')] ,
        }],
         form: {
            selector: '.form',
        },
        rejected: (wrongFilled) => document.getElementById('output').innerText = wrongFilled,
        config: {alwaysCancelSubmit : false}
    });
```
## API
### Creating rules
Rules are based on currying functions (sample functions are visible in RuleTypes.js file)

Example:

```javascript
// ES6
const minLength = (length, pattern = length) => value => ({
    validate: value.length >= length,
    message: ['Minimal length', pattern],
});
// ES5
var maxLength = function(length, pattern) {
    return function(value) {
        return {
            validate: value.length <= length,
            message: ['Minimal length', pattern || length]
        };
    }
}
```
### Callback function
JSlidate object applies callback for wrong filled form.
```javascript
(wrongFilled) => console.log(wrongFilled);
```
+ wrongFilled: Array
   This contains an array of elements which did not get through the validation process.

### EventListener
JSlidate object has EventListener (Observer).

eventListener is fully chainable.

```javascript
class callbackObject {
    constructor() {

    }

    success() {
        console.log('We did it, form has been passed.');
    }
    
    reject() {
        console.log('We got some problems here!');
    }
}

impForm.eventListener
.add(new callbackObject())
.add(new callbackObject())
```

#### Adding callbackObject
```javascript
impForm.eventListener
.add(new callbackObject());
```

callbackObject must contain success and reject functions.

#### Removing callbackObject

```javascript
impForm.eventListener
.remove(callbackObject);
```

## Contribution
### Install packages
```
npm install
```
### Rollup CLI
```
npm install -g rollup
```
### Build
```
rollup -c
```
### Development
```
rollup -c -w
```

---
_Source: https://npm.io/package/jslidate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
