https://github.com/kevinhellos/jscow
Lightweight model based validation library for Javascript (available via NPM)
https://github.com/kevinhellos/jscow
Last synced: over 1 year ago
JSON representation
Lightweight model based validation library for Javascript (available via NPM)
- Host: GitHub
- URL: https://github.com/kevinhellos/jscow
- Owner: kevinhellos
- License: mit
- Created: 2024-06-10T15:39:25.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-10T16:17:54.000Z (about 2 years ago)
- Last Synced: 2025-01-21T21:08:33.243Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://npmjs.com/package/@kevinhellos/jscow
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jscow
jscow is a lightweight model based validation library for Javascript
## Installation via npm
```sh
npm i @kevinhellos/jscow
```
## Usage
```js
// Sample usage
const validate = require("@kevinhellos/jscow");
// Create a target
var username = "@bob1234";
// Define a validation model
var usernameModel = {
required: true,
minLength: 8,
maxLength: 16,
specialCharacters: false,
}
// Checks a target with the validation model
// use the validate(itemToValidate).with(modelValidation)
if (validate(username).with(usernameModel)) {
console.log("Username is valid");
}
else {
console.log("Username is invalid");
}
```
## API
Below are the available properties to pass into the model validation object
| Properties | Type | Description |
|-------------------|---------|----------------------------------------------------|
| required | boolean | Defines if the current variable is required or not |
| minLength | number | Define the minimum length for a string |
| maxLength | number | Define the maximum length for a string |
| minValue | number | Define the minimum value for a number |
| maxValue | number | Define the maximum value for a number |
| specialCharacters | boolean | Define if special characters are allowed |
| isEmail | boolean | Define if it should follows an email regex format |