npm.io
0.1.3 • Published 3d ago

@gmcode/tsv-advanced

Licence
MIT
Version
0.1.3
Deps
1
Size
45 kB
Vulns
0
Weekly
0

@gmcode/tsv-advanced

npm

Typescript schema validations with type conversion and i18n interpolation support.

Installation

npm install @gmcode/tsv-advanced

Usage

import { DateRule, NumberRule, Schema } from '@gmcode/tsv-advanced'

// Define the schema
const schema = new Schema({
  date: new DateRule(),
  number: new NumberRule({
    maxValue: 10,
    minValue: 0,
    parseNumber: true
  })
})

// Validate some values
const result = schema.validate({
  date: 'December 17, 1995 03:24:00',
  number: '6'
})

if (result.success) {
  // The input is valid

  // Converted and typed as Date object
  result.sanitized.date

  // Converted and typed as number
  result.sanitized.integer
} else {
  // Handle rejection
  // ...
}

Keywords