Socket
Book a DemoInstallSign in
Socket

@winexy/fuji

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@winexy/fuji

Composable schema validation utility library

0.1.0-beta.21
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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
  } 
}

Keywords

schema

FAQs

Package last updated on 10 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.