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.11 to 0.1.13

src/either.js

2

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

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

@@ -21,2 +21,11 @@ declare global {

type EnumFromAsserts<A extends Record<string, Assert>, K> = K extends string
? { [K_ in K]: A[K] extends Assert<any, infer O> ? O : never }
: never
export function expectEnum<A extends Record<string, Assert>>(
input: unknown,
assertT: A,
msg: string | undefined = undefined
): asserts input is EnumFromAsserts<A, keyof A>
/**

@@ -23,0 +32,0 @@ * Must be imported explicitly in order to override default JSON namespace

export { JSONSafe as JSON } from "./json.js"
/**
* @type {null}
*/
export const None = null
/**
* @template T
* @param {Option<T>[]} list
* @returns {Option<T[]>}
*/
export function allOrNone(list) {
return list.every(isSome) ? /** @type {any} */ (list) : None
}
/**
* @template T
* @param {Option<T>} option
* @param {string} msg
* @returns {T}
*/
export function expectSome(
option,
msg = `expected Option.some, got ${option}`
) {
if (option !== null && option !== undefined) {
return option
} else {
throw new Error(msg)
}
}
/**
* @template T
* @param {Option<T>} option
* @returns {opt is T}
*/
export function isSome(option) {
return option !== null && option !== undefined
}
/**
* @template T
* @param {Option<T>} option
* @returns {opt is (null | undefined)}
*/
export function isNone(option) {
return option === null || option === undefined
}
/**
* @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 ${JSON.stringify(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
}
export * from "./either.js"
export { expectEnum } from "./enum.js"
export * from "./option.js"
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