npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chkt/maybe

v1.0.0-beta.8

Published

Minimalistic application flow handling

Downloads

10

Readme

Tests Version Node Dependencies Licence Language Size

maybe

Minimalistic application flow handling

Install

yarn add @chkt/maybe

Modules

compose

./source/compose.ts

Functions

function apply<T, R0, R1>(b:process<T, R0, R1>, a:transform<T, R0>) : transform<T, R1>;

convert

./source/convert/index.ts

References

export { all as allAsync, resolve } from "./async"
export { all, blank, may } from "./sync"

convert/async

./source/convert/async.ts

Functions

function all<T, R, F extends Failure>(fn:(value:T) => Promise<Maybe<R, F>>, values:readonly T[]) : Promise<Maybe<R[], F>>;
function resolve<T, R>(fn:(v:T) => Maybe<Promise<R>>, value:T) : Promise<Maybe<R>>;

convert/sync

./source/convert/sync.ts

Functions

function all<T, R, F extends Failure>(fn:(v:T) => Maybe<R, F>, values:readonly T[]) : Maybe<R[], F>;
function blank<T, M extends Failure>(maybe:Maybe<T, M>) : Maybe<void, M>;
function may<T, R>(fn:(v:T) => Maybe<R>, value:T) : Maybe<R>;

flow

./source/flow/index.ts

References

export {
  and as andAsync,
  failureIf as failureIfAsync,
  onFailure as onFailureAsync,
  onResult as onResultAsync,
  or as orAsync,
  resultIf as resultIfAsync
} from "./async"
export {
  and,
  failureIf,
  onFailure,
  onResult,
  or,
  resultIf
} from "./sync"

flow/async

./source/flow/async.ts

Functions

function and<T, R, M extends Failure, F extends Failure>(fn:(value:T) => Promise<Maybe<R, F>>, maybe:Maybe<T, M>) : Promise<Maybe<R, M | F>>;
function failureIf<T, M extends Failure, F extends Failure>(shouldFail:(value:T) => boolean, fail:(value:T) => F, maybe:Promise<Maybe<T, M>>) : Promise<Maybe<T, M | F>>;
function onFailure<T, F extends Failure>(fn:(failure:F) => Promise<Maybe<unknown>>, maybe:Maybe<T, F>) : Promise<Maybe<T, F>>;
function onResult<T, F extends Failure>(fn:(value:T) => Promise<Maybe<unknown>>, maybe:Maybe<T, F>) : Promise<Maybe<T, F>>;
function or<T, R, M extends Failure, F extends Failure>(fn:(failure:M) => Promise<Maybe<R, F>>, maybe:Maybe<T, M>) : Promise<Maybe<T | R, F>>;
function resultIf<T, R, M extends Failure>(shouldSucceed:(failure:M) => boolean, succeed:(failure:M) => Result<R>, maybe:Promise<Maybe<T, M>>) : Promise<Maybe<T | R, M>>;

flow/sync

./source/flow/sync.ts

Functions

function and<T, R, M extends Failure, F extends Failure>(fn:(value:T) => Maybe<R, F>, maybe:Maybe<T, M>) : Maybe<R, M | F>;
function failureIf<T, M extends Failure, F extends Failure>(shouldFail:(value:T) => boolean, fail:(value:T) => F, maybe:Maybe<T, M>) : Maybe<T, M | F>;
function onFailure<T, F extends Failure>(fn:(failure:F) => Maybe<unknown>, maybe:Maybe<T, F>) : Maybe<T, F>;
function onResult<T, F extends Failure>(fn:(value:T) => Maybe<unknown>, maybe:Maybe<T, F>) : Maybe<T, F>;
function or<T, R, M extends Failure, F extends Failure>(fn:(value:M) => Maybe<R, F>, maybe:Maybe<T, M>) : Maybe<T | R, F>;
function resultIf<T, R, M extends Failure>(shouldSucceed:(failure:M) => boolean, succeed:(failure:M) => Result<R>, maybe:Maybe<T, M>) : Maybe<T | R, M>;

index

./source/index.ts

References

export { apply } from "./compose"
export { all as allAsync, resolve } from "./convert/async"
export { all, blank, may } from "./convert/sync"
export {
  and as andAsync,
  failureIf as failureIfAsync,
  onFailure as onFailureAsync,
  onResult as onResultAsync,
  or as orAsync,
  resultIf as resultIfAsync
} from "./flow/async"
export {
  and,
  failureIf,
  onFailure,
  onResult,
  or,
  resultIf
} from "./flow/sync"
export {
  Failure,
  Maybe,
  Result,
  createFailure,
  createResult,
  isFailure,
  isResult
} from "./maybe"
export {
  CardinalMessage,
  DataMessage,
  DataRecord,
  DataValue,
  ErrorMessage,
  Message,
  MessageSeverity,
  Messages,
  TextMessage,
  containsMessage,
  createCardinalMessage,
  createDataMessage,
  createErrorMessage,
  createMessage,
  createTextMessage,
  flattenMessage,
  flattenMessages,
  isCardinalMessage,
  isDataMessage,
  isErrorMessage,
  isTextMessage,
  messageSeverity,
  resolveMessageValue
} from "./message"
export { failureFrom as failureAsync, maybeFrom as maybeAsync, resultFrom as resultAsync } from "./native/async"
export { filterAll } from "./native/common"
export { failureFrom, maybeFrom, resultFrom } from "./native/sync"

maybe

./source/maybe.ts

Interfaces

interface Result<T> extends MessageComposite {
  readonly value : T;
}

Type Aliases

type Failure<T = unknown> = Message<T>;
type Maybe<T, F extends Failure = Failure> = Result<T> | F;

Functions

function createFailure<T>(value:T, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : MessageDistinct<T>;  // 
function createResult<T>(value:T, messages:Messages = []) : Result<T>;
function isFailure<T, F extends Failure<unknown>>(maybe:Maybe<T, F>) : maybe is F;
function isResult<T, F extends Failure<unknown>>(maybe:Maybe<T, F>) : maybe is Result<T>;
function mergeMessagesAb<T extends MessageComposite, F extends Failure<unknown>>(a:T, b:Maybe<unknown, F>) : T;
function mergeMessagesBa<T extends MessageComposite, F extends Failure<unknown>>(a:T, b:Maybe<unknown, F>) : T;

message

./source/message.ts

Enumerations

const enum messageSeverity {
  debug = 6,
  error = 1,
  fatal = 0,
  info = 4,
  notice = 3,
  verbose = 5,
  warn = 2
}

Interfaces

interface CardinalMessage extends MessageCommon {
  readonly code : number;
}
interface DataMessage<T> extends MessageCommon {
  readonly data : T;
}
interface DataValue<T> {
  readonly value : T;
}
interface ErrorMessage<T extends Error = Error> extends MessageCommon {
  readonly error : T;
}
interface MessageComposite {
  readonly messages : Messages;
}
interface TextMessage extends MessageCommon {
  readonly text : string;
}

Type Aliases

type DataRecord = Exclude<object, Error | unknown[]>;
type Message<T = unknown> = ErrorMessage<> | CardinalMessage | TextMessage | DataMessage<> | DataMessage<DataValue<T>>;
type MessageSeverity = messageSeverity;
type Messages = readonly Message[];

Functions

function containsMessage(parent:MessageComposite, message:Message<unknown>) : boolean;
function createCardinalMessage(code:number, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : CardinalMessage;
function createDataMessage<T>(data:T, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : DataMessage<DataDistinct<T>>;
function createErrorMessage<T extends Error>(error:T, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : ErrorMessage<T>;
function createMessage<T>(value:T, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : MessageDistinct<T>;
function createTextMessage(text:string, severity:messageSeverity = messageSeverity.error, messages:Messages = []) : TextMessage;
function flattenMessage(message:Message<unknown>) : Messages;
function flattenMessages(messages:Messages) : Messages;
function isCardinalMessage<T>(message:Message<T>) : message is CardinalMessage;
function isDataMessage<T>(message:Message<T>) : message is DataMessage<DataDistinct<T>>;
function isErrorMessage<T>(message:Message<T>) : message is ErrorMessage<>;
function isTextMessage<T>(message:Message<T>) : message is TextMessage;
function mergeCompositeAb<T extends MessageComposite, U extends MessageComposite>(a:T, b:U) : T;
function mergeCompositeBa<T extends MessageComposite, U extends MessageComposite>(a:T, b:U) : T;
function resolveMessageValue<T>(message:Message<T>) : unknown;

native

./source/native/index.ts

References

export { failureFrom as failureAsync, maybeFrom as maybeAsync, resultFrom as resultAsync } from "./async"
export { filterAll } from "./common"
export { failureFrom, maybeFrom, resultFrom } from "./sync"

native/async

./source/native/async.ts

Functions

function failureFrom<T, R>(fn:(v:T) => Promise<R>, value?:T) : Promise<Failure<R>>;
function maybeFrom<T, R, F extends Failure>(fn:(v:T) => Promise<R>, isResult:filter<R> = filterAll, value?:T) : Promise<Maybe<R, Failure<R> | F>>;
function resultFrom<T, R>(fn:(v:T) => Promise<R>, value?:T) : Promise<Maybe<R>>;

native/common

./source/native/common.ts

Type Aliases

type filter<T> = (value:T) => boolean;

Functions

function filterAll() : boolean;

native/sync

./source/native/sync.ts

Functions

function failureFrom<T, R>(fn:(v:T) => R, value?:T) : Failure<R>;
function maybeFrom<T, R>(fn:(v:T) => R, isResult:filter<R> = filterAll, value?:T) : Maybe<R, Failure<R>>;
function resultFrom<T, R>(fn:(v:T) => R, value?:T) : Result<R>;