0.1.0-beta.21 • Published 3 years ago

@winexy/fuji v0.1.0-beta.21

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

version types minified minified + gzip dependencies tree-shaking

🗻 fuji

🎼  Composable schema validation utility library

Example

import { f, run, string, int, required, oneOf, pattern } from '@winexy/fuji'
import type { Infer } from '@winexy/fuji'

const urlRegex = /.../

const schema = f.shape({
  name: f(string(), required()),
  version: f(pattern(/\d+\.\d+.\d+/)),
  workspaces: f.array(f(string())),
  repository: f.shape({
    type: f(string(), required(), oneOf(['git', 'vcs'])),
    url: f(string(), pattern(urlRegex))
  })
})

type PackageType = Infer<typeof schema>
/*
{
  name: string,
  version?: string,
  workspaces?: string[],
  repository?: {
    type: string,
    url?: string
  }
}
*/


const result = run(schema, {
  name: '@winexy/fuji',
  version: '0.0.0',
  repository: {
    type: 'git',
    url: 'https://github.com/winexy/fuji'
  }
})

if (result.invalid) {
  result.errors // Array<VError>
  result.value // null
} else {
  result.errors // null
  result.value // same as PackageType
}

Troubleshooting

Infer<typeof schema> infers any

Set strictFunctionTypes mode to true in your tsconfig.json compilerOptions section

{
  "compilerOptions": {
    "strictFunctionTypes": true
  } 
}
0.1.0-beta.21

3 years ago

0.1.0-beta.20

3 years ago

0.1.0-beta.18

3 years ago

0.1.0-beta.19

3 years ago

0.1.0-beta.12

3 years ago

0.1.0-beta.17

3 years ago

0.1.0-beta.14

3 years ago

0.1.0-beta.13

3 years ago

0.1.0-beta.16

3 years ago

0.1.0-beta.15

3 years ago

0.1.0-beta.10

3 years ago

0.1.0-beta.11

3 years ago

0.1.0-beta.9

3 years ago

0.1.0-beta.8

3 years ago

0.1.0-beta.5

4 years ago

0.1.0-beta.7

4 years ago

0.1.0-beta.6

4 years ago

0.1.0-beta.4

4 years ago

0.1.0-beta.3

4 years ago

0.1.0-beta.2

4 years ago

0.1.0-beta.1

4 years ago

0.1.0-beta.0

4 years ago