0.1.0-beta.21 • Published 4 years ago
@winexy/fuji v0.1.0-beta.21
🗻 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
4 years ago
0.1.0-beta.20
4 years ago
0.1.0-beta.18
4 years ago
0.1.0-beta.19
4 years ago
0.1.0-beta.12
4 years ago
0.1.0-beta.17
4 years ago
0.1.0-beta.14
4 years ago
0.1.0-beta.13
4 years ago
0.1.0-beta.16
4 years ago
0.1.0-beta.15
4 years ago
0.1.0-beta.10
4 years ago
0.1.0-beta.11
4 years ago
0.1.0-beta.9
4 years ago
0.1.0-beta.8
4 years ago
0.1.0-beta.5
5 years ago
0.1.0-beta.7
5 years ago
0.1.0-beta.6
5 years ago
0.1.0-beta.4
5 years ago
0.1.0-beta.3
5 years ago
0.1.0-beta.2
5 years ago
0.1.0-beta.1
5 years ago
0.1.0-beta.0
5 years ago