# gisele-validation

> An extension to Gisele library that adds field validation

Latest version **0.1.2** (published 2015-12-16) · 0 weekly downloads

## Install

```sh
npm install gisele-validation
pnpm add gisele-validation
yarn add gisele-validation
bun add gisele-validation
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2015-12-16 |
| First published | 2015-12-06 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Darlan Alves |
| Maintainers | darlanalves |

## Links

- npm: https://www.npmjs.com/package/gisele-validation
- Repository: https://github.com/darlanalves/gisele-validation
- Homepage: https://github.com/darlanalves/gisele-validation#readme
- Issues: https://github.com/darlanalves/gisele-validation/issues
- npm.io page: https://npm.io/package/gisele-validation

## Recent versions

- 0.1.2 (latest) — 2015-12-16
- 0.1.1 — 2015-12-14
- 0.1.0 — 2015-12-06

## README

# Validation extension to Gisele model library

Adds validation capabilities to any Gisele.Model instances

## Usage

```js
var User = Gisele.Model.create({
    name: { type: String, required: true, minlength: 15 },
    age: { type: Number, min: 18 }
});

var bob = new User({
	name: 'Bob',
	age: 15
});

// runs the validation rules of each field
bob.$$.validate();

console.log(bob.$$invalid);
// true

console.log(bob.$$errors);
//  {
//     name: { minlength: true },
//     age: { min: true }
//  }

```

## Validation of custom fields

New field types must implement a `validate()` method that either returns `true` (is valid) or an object with the validation errors.

In the builtin fields they are key/value pairs with the key being an error and the value being true, as same as `bob.$$errors` above.

Example:

```js

class Foo() { }

class FooField extends Gisele.Field {
	parse(value) { return new Foo(value); }

	validate(value) {
		// any validation rule can be applied
		if (this.required && value instanceof Foo) {
			return { required: true };
		}

		return true;
	}
}

Gisele.Field.add(Foo, FooField);
```

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