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

@helios-lang/type-utils

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helios-lang/type-utils - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

2

package.json
{
"name": "@helios-lang/type-utils",
"version": "0.1.6",
"version": "0.1.7",
"description": "Global utility types",

@@ -5,0 +5,0 @@ "main": "src/index.js",

declare global {
type Only<T, C, R> = T extends C ? R : never
type Option<T> = null | undefined | T
type Either<L, R> = { left: L } | { right: R } // use right to represent a correct value, left for errors
}

@@ -10,1 +10,6 @@

export function isSome<T>(option: Option<T>): option is T
export function expectLeft<L, R>(either: Either<L, R>, msg?: string): L
export function expectRight<L, R>(either: Either<L, R>, msg?: string): R
export function isLeft<L, R>(either: Either<L, R>): either is { left: L }
export function isRight<L, R>(either: Either<L, R>): either is { right: R }

@@ -12,3 +12,6 @@ /**

*/
export function expectSome(option, msg = `unexpected ${option}`) {
export function expectSome(
option,
msg = `expected Option.some, got ${option}`
) {
if (option !== null && option !== undefined) {

@@ -38,1 +41,57 @@ return option

}
/**
* @template L
* @template R
* @param {Either<L, R>} either
* @param {string} msg
* @returns {L}
*/
export function expectLeft(
either,
msg = `expected Either.left, got ${either}`
) {
if ("left" in either) {
return either.left
} else {
throw new Error(msg)
}
}
/**
* @template L
* @template R
* @param {Either<L, R>} either
* @param {string} msg
* @returns {R}
*/
export function expectRight(
either,
msg = `expected Either.right, got ${either}`
) {
if ("right" in either) {
return either.right
} else {
throw new Error(msg)
}
}
/**
* @template L
* @template R
* @param {Either<L, R>} either
* @returns {either is {left: L}}
*/
export function isLeft(either) {
return "left" in either
}
/**
* @template L
* @template R
* @param {Either<L, R>} either
* @returns {either is {right: R}}
*/
export function isRight(either) {
return "right" in either
}
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