9.5.5 • Published 4 years ago

skema v9.5.5

Weekly downloads
2,957
License
MIT
Repository
github
Last release
4 years ago

Build Status Coverage

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 Number could 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

🔬 Live Demo with JsFiddle

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

Many Examples

Related Packages

  • @skema/basic The default built-in javascript types of skema.

License

MIT

9.5.5

4 years ago

9.5.4

4 years ago

9.5.1

5 years ago

9.5.0

5 years ago

9.4.3

5 years ago

9.4.2

5 years ago

9.4.1

5 years ago

9.4.0

5 years ago

9.3.9

5 years ago

9.3.8

5 years ago

9.3.7

6 years ago

9.3.5

6 years ago

9.3.4

6 years ago

9.3.3

6 years ago

9.3.1

6 years ago

9.3.0

6 years ago

9.2.1

6 years ago

9.2.0

6 years ago

9.1.2

6 years ago

9.1.1

6 years ago

9.1.0

6 years ago

9.0.10

6 years ago

9.0.9

6 years ago

9.0.8

6 years ago

9.0.7

6 years ago

9.0.6

6 years ago

9.0.5

6 years ago

9.0.4

6 years ago

9.0.3

6 years ago

9.0.1

6 years ago

9.0.0

6 years ago

8.0.5

6 years ago

8.0.4

6 years ago

8.0.3

6 years ago

8.0.2

6 years ago

8.0.1

6 years ago

7.0.1

6 years ago

7.0.0

6 years ago

6.0.0

6 years ago

5.2.2

6 years ago

5.2.1

6 years ago

5.2.0

6 years ago

5.1.1

6 years ago

5.1.0

6 years ago

5.0.1

7 years ago

5.0.0

7 years ago

4.1.0

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.5.2

10 years ago

0.1.0

10 years ago