Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@qvvg/mario

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@qvvg/mario

pipes and stuff

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

MARIO

Because pipes...

Install

npm install --save @qvvg/mario

use pipe as composition

import {pipe} from "@qvvg/mario"

const double = x => x * 2
const result = await pipe(4, [double, double, double, double])

assert(result.value, 64)

use pipe as validation

import {pipe, Ok, Nope, isOk, isNope} from "@qvvg/mario"

const isString = value => {
  return typeof value === "string"
    ? Ok(value)
    : Nope(value, "Needs to be a string!")
}

const hasAt = value => {
  return /@/.test(value) ? Ok(value) : Nope(value, "Must have an @...")
}

const validateEmail = email => pipe(email, [isString, hasAt])

const v1 = await validateEmail("bob@bob.bob")
assert(v1.value, "bob@bob.bob")
assert(isOk(v1), true)
assert(isNope(v1), false)

const v2 = await validateEmail(1234)
assert(v2.value, 1234)
assert(isOk(v2), false)
assert(isNope(v2), true)
assert(v2.reason, "Needs to be a string!")

const v3 = await validateEmail("bobbob.bob")
assert(v3.value, "bobbob.bob")
assert(isOk(v3), false)
assert(isNope(v3), true)
assert(v3.reason, "Must have an @...")

pipes can be async

import {pipe, Ok, Nope, log} from "@qvvg/mario"

await pipe(null, [
  _ => fetch(url),
  r => (r.ok ? Ok(r.json()) : Nope(r.json(), r.statusText)),
  log("DATA"),
])

pipes can handle errors

import {pipe, log} from "@qvvg/mario"

const double = x => x * 2
const bang = x => {
  throw new Error("EXPLOSION!!!")
}

const result = await pipe(4, [
  double,
  double,
  bang,
  log("I will never happen because bang"),
  double,
])

assert(result.value, 16)
assert(isOk(result), false)
assert(isNope(result), true)
assert(result.reason, "pipe::throw")
assert(result.error.message, "EXPLOSION!!!")

pipes can be composed

import {pipe, Ok} from "@qvvg/mario"
const add = x => y => Ok(x + y)

const result = await pipe(10, [
  pipe([add(3), add(-2)]), // +1
  pipe([add(-9), add(15)]), // +6
  pipe([add(-5)]), // -5
])

assert(result.value, 12)

FAQs

Package last updated on 18 Mar 2020

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