Socket
Socket
Sign inDemoInstall

@winexy/fuji

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @winexy/fuji

Composable schema validation utility library


Version published
Maintainers
1
Install size
49.4 kB
Created

Readme

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

FAQs

Last updated on 10 Oct 2021

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc