New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pristinejs

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pristinejs - npm Package Compare versions

Comparing version

to
0.1.4

2

package.json
{
"name": "pristinejs",
"version": "0.1.3",
"version": "0.1.4",
"description": "A tiny vanilla javascript form validation library",

@@ -5,0 +5,0 @@ "main": "dist/pristine.js",

@@ -132,10 +132,10 @@ # Pristine - Vanilla javascript form validation library

## API
- **Pristine(form, config, live)**
<br/>*Constructor*
**Pristine(form, config, live)**
<br/>*Constructor*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `form`| - |<center>✔</center> |The form element|
| `config`| [See above](#defaultConfig)|<center>✕</center>| The config object|
| `live` | `true`|<center>✕</center>| Whether pristine should validate as you type|
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | ---- |
| `form`| - |<center>✔</center> |The form element|
| `config`| [See above](#defaultConfig)|<center>✕</center>| The config object|
| `live` | `true`|<center>✕</center>| Whether pristine should validate as you type|

@@ -145,9 +145,9 @@

- **Pristine.validate(inputs, silent)**
**Pristine.validate(inputs, silent)**
<br/>*Validate the form or field(s)*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `inputs`| - | <center>✕</center> | When not given, full form is validated. inputs can be one DOM element or a collection of DOM elements returned by `document.getElement...`, `document.querySelector...` or even `jquery` dom|
| `silent` | `false`|<center>✕</center>| Does not show error error messages when `silent` is `true`|
| Parameter | Default | Required? | Description|
| --- | ---- | ---- | --- |
| `inputs`| - | <center>✕</center> | When not given, full form is validated. inputs can be one DOM element or a collection of DOM elements returned by `document.getElement...`, `document.querySelector...` or even `jquery` dom|
| `silent` | `false`|<center>✕</center>| Does not show error error messages when `silent` is `true`|

@@ -157,52 +157,52 @@

- **Pristine.addValidator(elemOrName, fn, msg, priority, halt)**
<br/>*Add a custom validator*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `elemOrName`| - | <center>✔</center> | The dom element when validator is applied on a specific field. A string (the name of the validator) when it's a global validator, you can then use `data-pristine-<NAME>` attribute in form fields to apply this validator|
| `fn`| - | <center>✔</center> | The function that validates the field. Value of the input field gets passed as the first parameter, and the attribute value (split using comma) as the subsequent parameters. For example, for `<input data-pristine-my-validator="10,20,dhaka" value="myValue"/>`, validator function get called like `fn("myValue", 10, 20, "dhaka")`. Inside the function `this` refers to the input element|
| `message`| - | <center>✔</center> | The message to show when the validation fails. It supports simple templating. `${0}` for the input's value, `${1}` and so on are for the attribute values. For the above example, `${0}` will get replaced by `myValue`, `${1}` by `10`, `${2}` by `20`, `${3}` by `dhaka`.|
| `priority`| 1 | <center>✕</center> | Priority of the validator function. The higher the value, the earlier it gets called when there are multiple validators on one field. |
| `halt`| `false` | <center>✕</center> | Whether to halt validation on the current field after this validation. When `true` after validating the current validator, rest of the validators are ignored on the current field.|
**Pristine.addValidator(elemOrName, fn, msg, priority, halt)**
<br/>*Add a custom validator*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | --- |
| `elemOrName`| - | <center>✔</center> | The dom element when validator is applied on a specific field. A string (the name of the validator) when it's a global validator, you can then use `data-pristine-<NAME>` attribute in form fields to apply this validator|
| `fn`| - | <center>✔</center> | The function that validates the field. Value of the input field gets passed as the first parameter, and the attribute value (split using comma) as the subsequent parameters. For example, for `<input data-pristine-my-validator="10,20,dhaka" value="myValue"/>`, validator function get called like `fn("myValue", 10, 20, "dhaka")`. Inside the function `this` refers to the input element|
| `message`| - | <center>✔</center> | The message to show when the validation fails. It supports simple templating. `${0}` for the input's value, `${1}` and so on are for the attribute values. For the above example, `${0}` will get replaced by `myValue`, `${1}` by `10`, `${2}` by `20`, `${3}` by `dhaka`.|
| `priority`| 1 | <center>✕</center> | Priority of the validator function. The higher the value, the earlier it gets called when there are multiple validators on one field. |
| `halt`| `false` | <center>✕</center> | Whether to halt validation on the current field after this validation. When `true` after validating the current validator, rest of the validators are ignored on the current field.|
<br/>
- **Pristine.getErrors(input)**
<br/>*Get the errors of the form or a specific field*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `input`| - | <center>✕</center> | When `input` is given, it returns the errors of that input element, otherwise returns all errors of the form as an object, using input element as key and corresponding errors as value. `validate()` must be called before expecting this method to return correctly.|
**Pristine.getErrors(input)**
<br/>*Get the errors of the form or a specific field*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | --- |
| `input`| - | <center>✕</center> | When `input` is given, it returns the errors of that input element, otherwise returns all errors of the form as an object, using input element as key and corresponding errors as value. `validate()` must be called before expecting this method to return correctly.|
<br/>
- **Pristine.addError(input, error)**
<br/>*Add A custom error to an input element*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `input`| - | <center>✕</center> | The input element to which the error should be given|
| `error`| - | <center>✔</center> | The error string|
**Pristine.addError(input, error)**
<br/>*Add A custom error to an input element*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | --- |
| `input`| - | <center>✕</center> | The input element to which the error should be given|
| `error`| - | <center>✔</center> | The error string|
<br/>
- **Pristine.setGlobalConfig(config)**
<br/>*Set the global configuration*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | |
| `config`| - | <center>✔</center> | Set the default configuration globally to use in all forms.|
**Pristine.setGlobalConfig(config)**
<br/>*Set the global configuration*
| Parameter | Default | Required? | Description|
| --- | ---- | ----- | --- |
| `config`| - | <center>✔</center> | Set the default configuration globally to use in all forms.|
<br/>
- **Pristine.reset()**
<br/>*Reset the errors in the form*
**Pristine.reset()**
<br/>*Reset the errors in the form*
<br/>
- **Pristine.destroy()**
<br/>*Destroy the pristine object*
**Pristine.destroy()**
<br/>*Destroy the pristine object*

@@ -209,0 +209,0 @@ <br/><br/>