Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Latest commit

 

History

History
54 lines (36 loc) · 1.42 KB

README.md

File metadata and controls

54 lines (36 loc) · 1.42 KB

fluent-decoders

npm latest version Minified Size

fluent-decoders is a Fluent-style API wrapper around nvie/decoders.

Note: Version is ALWAYS locked to same number as upstream decoders library

Example

import { array, boolean, string, tuple3 } from "@tdreyno/fluent-decoders"

interface Person {
  name: string
  age: string
  isActive: boolean
}

const toPerson = ([name, age, isActive]): Person => ({ name, age, isActive })

const containsInt = (s: any): s is StringInt => !isNaN(parseInt(s, 10))

const personDecoder = tuple3(string, string.refine(containsInt), boolean).map(
  toPerson,
)

const person = personDecoder.validate(["Name", "42", true])

// Compose
const people = array(personDecoder).validate([
  ["A", "4", true],
  ["B", "2", false],
])

Installation

Yarn

yarn add @tdreyno/fluent-decoders

NPM

npm install --save @tdreyno/fluent-decoders

License

fluent-decoders is licensed under the Hippocratic License. It is an Ethical Source license derived from the MIT License, amended to limit the impact of the unethical use of open source software.