# bsm-validation-rules

> Validation rule builder

Latest version **0.3.1** (published 2021-11-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install bsm-validation-rules
pnpm add bsm-validation-rules
yarn add bsm-validation-rules
bun add bsm-validation-rules
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2021-11-15 |
| First published | 2020-04-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dimitrij Denissenko |
| Maintainers | dim |

## Links

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

## Recent versions

- 0.3.1 (latest) — 2021-11-15
- 0.3.0 — 2021-05-10
- 0.2.0 — 2020-09-11
- 0.1.2 — 2020-05-20
- 0.1.1 — 2020-04-15
- 0.1.0 — 2020-04-15

## 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
<template>
  <v-container fluid>
    <v-row align="center">
      <v-col cols="6">
        <v-text-field
          v-model="item.email"
          label="Email"
          :rules="rules.email"
        ></v-text-field>
      </v-col>

      <v-col cols="6">
        <v-select
          v-model="item.state"
          label="State"
          :rules="rules.email"
          :items="states"
          item-text="state"
          item-value="abbr"
          return-object
        ></v-select>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
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' },
    ],
  }),
}
```

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