概要
🛰 Skema は、入力データの検証・変換・サニタイズを手軽に組み合わせて行える方法を提供します。
その他のプロジェクト計測したスター増加
- 24時間
- 0
- 7日間
- 0
- 15日間
- 0
- 1か月
- 履歴を収集中
期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。
README.md
オリジナルskema
skema provides a handy and composable way to validate/transform JavaScript variables:
Supports both async and sync flows. Skema has two working modes to support either async or sync validators, setters, etc, making it capable with much more complicated challenges.
NOT only type checker. Unlike TypeScript, joi, and many others, Skema is not only a JavaScript type checker, but also a good solution for your Anti-Corruption Layer (ACL) to transform and purify the input data. And Skema could also be configured as a simple schema validator too.
Pluggable basic types. Even basic types such as
Numbercould also be replaced and customized if using Skema. Actually, in the core of Skema, there is NOT a single definition of one type.Powerful custom types. Every single type is able to be customized that you can handle almost everything including descriptor, conditions, default values, validators and so on.
Composable structures. You could build a much bigger schema with the small ones into the whole world.
Install
npm i skema
Basic Usage
import {shape} from 'skema'
// Schema definitions are ONLY objects.
const User = shape({
id: 'number?',
name: String
})
// Then use these definitions to purify our data.
const user = User.from({
id: '1',
name: 'Steve'
})
console.log(user)
// {
// id: 1,
// name: 'Steve'
// }
user.id = 'boooom!'
// throw TypeError
// - message: 'not a number'
// - code: 'VALIDATION_FAILS'
Documentations
- API References
- Shape Definition
- Working Mode: Sync or Async
- Assign a Property after
from() - Error Handling
- Contributing
Many Examples
- Shape Definition
- Type Definition
- Errors🔬
Related Packages
- @skema/basic The default built-in javascript types of skema.
License
MIT
関連プロジェクトを探す
読み込み中…