New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@prelude-io/core

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prelude-io/core

Type-save runtime IO library based on PreludeTS

  • 1.6.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53
decreased by-44.21%
Maintainers
1
Weekly downloads
 
Created
Source

Prelude-IO

npm version documentation

This library aims to provide easy to use run- and compiletime type-safety combined with the benefits of immutability through Prelude-ts.

Interop with Prelude-ts is a key feature of this library, but not strictly required for operation.

Core library

Prelude-IO's base unit is the Bus<I, O> class, which provides basic functionality and abstractions around creating reversible data pipelines. The core library also includes a few basic types to represent most data formats, found here under Presets.

Examples can be found here. Alternatively, here's an overview of some basic functionality:

import * as io from "prelude-io";
import { Predicate } from "prelude-ts";

// Conditional types
const rating = io.number.if(Predicate.of((n) => n > 0 && n <= 5));

// Complex types
const roomType = io.Complex("Room", {
  name: io.string.
  description: io.Optional(io.string),
  rating: rating,
});

// Nesting
const hotelType = io.Complex("Hotel", {
  address: io.string,
  website: io.string,
  rating: rating
  rooms: io.Vector(Room)
});

// Deserialising
fetch("http://example.com/hotels.json")
  .then(response => response.json())
  // (de)serialising
  .then(HotelType.deserialise)
  .then(hotel => {
    // Either-based error handling
    if(hotel.isLeft()) {
      // Built-in debugger
      console.error(io.humanizeErrors(hotel.getLeft()))
    } else {
      LocalStorage.setItem("hotel", hotel.get())
    }
  });

Documentation

You can read typedoc documentation here

Installation

npm install --save @prelude-io/core prelude-ts

Principles

  • Busses split parsing and conditional logic into seperate functions
  • IO returns Either objects rather than throw exceptions
  • Functions can be chained or turned into a union

Additional libraries

Roadmap

  • Add extra commonly used types
  • @prelude-io/test: A set of functions to run basic tests on your data types

Inspirations

  • Prelude-ts: Provides functional programming concepts in an accessible manner. Though a similar name, this project is not directly affiliated with prelude-ts or its authors.
  • io-ts: Runtime type checking, encoding and decoding, based on fp-ts.

Keywords

FAQs

Package last updated on 17 Jul 2023

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc