🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

strictly-formed-io-ts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strictly-formed-io-ts

io-ts wrapper for strictly-formed, a statically typed form library for typescript

latest
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Strictly Formed Io-TS

io-ts wrapper for strictly-formed, a statically typed form library for typescript. Guarantee runtime type safety for custom static types.

API

Validate form input against io-ts runtime types, wrapping input changes in a fp-ts Either<Error, T> type.

StringInput

type Props = {
  type: t.Type<T>,
  value: string | undefined
  className?: string
  placeholder?: string
  forwardedRef?: Ref<HTMLInputElement>
  onChange(validation: t.Validation<T>, value: string | undefined): void
  onSubmit?(value: T): void
  onClear?: () => void
}
import t as * from 'io-ts';
import { StringInput } from 'strictly-formed-io-ts';

// EX - validate trimmed input is not empty
const NonEmptyStringIoTs = t.refinement(t.string, (str) => str.trim() !== '');
type NonEmptyString = t.TypeOf<typeof NonEmptyString>;

<StringInput<NonEmptyString>
  className="string-input"
  type={NonEmptyStringIoTs}
  value={copyDate}
  onChange={(validation, value) => {
    validation.fold(
      (validationErrors) => console.error(validationErrors),
      // ^^^^^^^^^^^^^^ - T.ValidationError[]
      (validValue) => console.log(validValue)
      // ^^^^^^^^ - NonEmptyString
    )
  }}
  onSubmit={submitString}
>

Install

npm install strictly-formed

License

ISC

Keywords

typescript

FAQs

Package last updated on 05 Sep 2018

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