https://github.com/bsm/validation-rules-js
https://github.com/bsm/validation-rules-js
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bsm/validation-rules-js
- Owner: bsm
- License: apache-2.0
- Created: 2020-04-15T16:01:26.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2024-07-18T14:35:02.000Z (almost 2 years ago)
- Last Synced: 2025-10-08T08:54:07.362Z (8 months ago)
- Language: TypeScript
- Size: 495 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BSM Validation Rules
Validation rule builder, written in TypeScript.
## Usage
```javascript
import vrb from 'bsm-validation-rules';
const percentage = [
vrb.typeOf('number'),
vrb.numericality({ min: 0, max: 100 }),
];
const tag = [
vrb.presence(),
vrb.typeOf('string'),
vrb.length({ max: 20 }),
];
export const taskRules = {
title: [
vrb.presence(),
vrb.typeOf('string'),
vrb.length({ max: 50 }),
],
status: [
vrb.presence(),
vrb.typeOf('string'),
vrb.inclusion(['pending', 'complete']),
],
progress: [
vrb.presence(),
...percentage,
],
tags: [
vrb.typeOf('array'),
vrb.every([tag]),
]
});
```
In Vue/Vuetify:
```vue
import vrb from 'bsm-validation-rules';
const rules = {
email: [
vrb.presence(),
vrb.typeOf('string'),
vrb.format(/\S+@\S+\.\S+/),
],
state: [
vrb.dig('abbr', [
vrb.presence(),
vrb.typeOf('string'),
]),
],
};
export default {
data: () => ({
rules,
item: {},
states: [
{ state: 'Florida', abbr: 'FL' },
{ state: 'Georgia', abbr: 'GA' },
{ state: 'Nebraska', abbr: 'NE' },
{ state: 'California', abbr: 'CA' },
{ state: 'New York', abbr: 'NY' },
],
}),
}
```