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

@nolawnchairs/types

v1.0.0

Published

A library of idiomatic type definitions for TypeScript

Downloads

3

Readme

Types Package

This package contains type definitions for various function signatures. When imported, these types are added to the global scope.

Installation

npm install @nolawnchairs/types

# Or.... (see caveats below)
npm install -D @nolawnchairs/types

Usage

Import the package in your code once, preferably in your main entry point:

import '@nolawnchairs/types'

Caveats

If installing as a development dependency, be aware that when installing as a production build via npm install --production or npm ci --only=production, any dev dependencies will not be installed. This will cause imports of this package to fail. To avoid this, install this package as a production dependency.

API

The API is simple the contents of the index.d.ts file:


/**
 * Represents a value that may be null or undefined.
 * @template T the type of the value
 */
type Nullable<T> = T | null | undefined

/**
 * Represents a function that accepts one argument and produces a result.
 * @template T the parameter type
 * @template U the return type
 */
interface UnaryFunction<T, U> {
  (value: T): U
}

/**
 * Represents a function that accepts one argument and produces a result
 * that may be null or undefined.
 * @template T the parameter type
 * @template U the return type
 */
interface NullableUnaryFunction<T, U> {
  (value: T): Nullable<U>
}

/**
 * Represents a function that accepts one argument and produces a result asynchronously.
 * @template T the parameter type
 * @template U the return type
 */
interface AsyncUnaryFunction<T, U> {
  (value: T): Promise<U>
}

/**
 * Represents a function that accepts one argument and produces a result
 * that may be null or undefined asynchronously.
 * @template T the parameter type
 * @template U the return type
 */
interface NullableAsyncUnaryFunction<T, U> {
  (value: T): Promise<Nullable<U>>
}

/**
 * Represents a function that accepts one optional argument and produces a result.
 * @template T the parameter type
 * @template U the return type
 */
interface OptionalUnaryFunction<T, U> {
  (value?: T): U
}

/**
 * Represents a function that accepts one optional argument and produces a result
 * that may be null or undefined asynchronously.
 * @template T the parameter type
 * @template U the return type
 */
interface OptionalAsyncUnaryFunction<T, U> {
  (value?: T): Promise<U>
}

/**
 * Represents a function that accepts two arguments and produces a result.
 * @template T the first argument type
 * @template U the second argument type
 * @template R the return type
 */
interface BiFunction<T, U, R> {
  (value1: T, value2: U): R
}
/**
 * Represents a function that accepts two arguments and produces a result
 * that may be null or undefined.
 * @template T the first argument type
 * @template U the second argument type
 * @template R the return type
 */
interface NullableBiFunction<T, U, R> {
  (value1: T, value2: U): Nullable<R>
}

/**
 * Represents a function that accepts two arguments and produces a result asynchronously.
 * @template T the first argument type
 * @template U the second argument type
 */
interface AsyncBiFunction<T, U, R> {
  (value1: T, value2: U): Promise<R>
}

/**
 * Represents a function that accepts two arguments and produces a result
 * that may be null or undefined asynchronously.
 * @template T the first argument type
 * @template U the second argument type
 * @template R the return type
 */
interface NullableAsyncBiFunction<T, U, R> {
  (value1: T, value2: U): Promise<Nullable<R>>
}

/**
 * Represents a function that accepts two optional arguments and produces a result asynchronously.
 * @template T the first argument type
 * @template U the second argument type
 * @template R the return type
 */
interface OptionalBiFunction<T, U, R> {
  (value1?: T, value2?: U): R
}

/**
 * Represents a function that accepts two optional arguments and produces a result
 * that may be null or undefined asynchronously.
 * @template T the first argument type
 * @template U the second argument type
 * @template R the return type
 */
interface OptionalAsyncBiFunction<T, U, R> {
  (value1?: T, value2?: U): Promise<R>
}

/**
 * Represents a supplier of a result.
 * @template T the return type
 */
interface Supplier<T> {
  (): T
}

/**
 * Represents a supplier of a result that may be null or undefined.
 * @template T the return type
 */
interface NullableSupplier<T> {
  (): Nullable<T>
}

/**
 * Represents a supplier of a promise.
 * @template T the return type
 */
interface AsyncSupplier<T> {
  (): Promise<T>
}

/**
 * Represents a supplier of a promise whose resolved value may be
 * null or undefinded.
 * @template T the return type
 */
interface NullableAsyncSupplier<T> {
  (): Promise<Nullable<T>>
}

/**
 * Represents an operation that accepts a single input argument
 * and returns no result.
 * @template T the argument type
 */
interface Consumer<T> {
  (value: T): void
}

/**
 * Represents an operation that accepts a single input argument
 * and returns no result asynchronously.
 * @template T the argument type
 */
interface AsyncConsumer<T> {
  (value: T): Promise<void>
}

/**
 * Represents an operation that accepts a single optional input argument
 * and returns no result.
 * @template T the argument type
 */
interface OptionalConsumer<T> {
  (value?: T): void
}

/**
 * Represents an operation that accepts a single optional input argument
 * and returns no result asynchronously.
 * @template T the argument type
 */
interface OptionalAsyncConsumer<T> {
  (value?: T): Promise<void>
}

/**
 * Represents an operation that accepts two input arguments and returns no result.
 * @template T the first argument type
 * @template U the second argument type
 */
interface BiConsumer<T, U> {
  (value1: T, value2: U): void
}

/**
 * Represents an operation that accepts a optional arguments and returns no result.
 * @template T the first argument type
 * @template U the second argument type
 */
interface OptionalBiConsumer<T, U> {
  (value1?: T, value2?: U): void
}

/**
 * Represents an operation that accepts two input arguments and returns no result asynchronously.
 * @template T the first argument type
 * @template U the second argument type
 */
interface OptionalAsyncBiConsumer<T, U> {
  (value1?: T, value2?: U): Promise<void>
}

/**
 * Represents an operation on a single operand that produces a
 * result of the same type as its operand.
 * @template T the type of the operand and return type
 */
interface UnaryOperator<T> {
  (value: T): T
}

/**
 * Represents an operation on a single operand that produces an optional
 * result of the same type as its operand.
 * @template T the type of the operand and return type
 */
interface NullableUnaryOperator<T> {
  (value: T): Nullable<T>
}

/**
 * Represents an asynchronous operation on a single operand that produces a
 * result of the same type as its operand.
 * @template T the type of the operand and return type
 */
interface AsyncUnaryOperator<T> {
  (value: T): Promise<T>
}

/**
 * Represents an asynchronous operation on a single operand that produces an optional
 * result of the same type as its operand.
 * @template T the type of the operand and return type
 */
interface NullableAsyncUnaryOperator<T> {
  (value: T): Promise<Nullable<T>>
}

/**
 * Represents an operation upon two operands of the same type,
 * producing a result of the same type as the operands.
 * @template T the type of the operands and return type
 */
interface BinaryOperator<T> {
  (value1: T, value2: T): T
}

/**
 * Represents an asynchronous operation upon two operands of the same type,
 * producing a result of the same type as the operands.
 * @template T the type of the operands and return type
 */
interface AsyncBinaryOperator<T> {
  (value1: T, value2: T): Promise<T>
}

/**
 * Represents an operation upon two operands of the same type,
 * producing an optional result of the same type as the operands.
 * @template T the type of the operands and return type
 */
interface OptionalBinaryOperator<T> {
  (value1?: T, value2?: T): T
}

/**
 * Represents an operation upon two operands of the same type,
 * producing an optional result of the same type as the operands.
 * @template T the type of the operands and return type
 */
interface NullableBinaryOperator<T> {
  (value1: T, value2: T): Nullable<T>
}

/**
 * Represents an asynchronous operation upon two operands of the same type,
 * producing an optional result of the same type as the operands.
 * @template T the type of the operands and return type
 */
interface NullableAsyncBinaryOperator<T> {
  (value1: T, value2: T): Promise<Nullable<T>>
}

/**
 * Represents a predicate operation that takes a single argument.
 * @template T the argument type
 */
interface Predicate<T> {
  (value: T): boolean
}

/**
 * Represents an asynchronous predicate operation that takes a single argument.
 * @template T the argument type
 */
interface AsyncPredicate<T> {
  (value: T): Promise<boolean>
}

/**
 * Represents a predicate operation that takes a single optional argument.
 * @template T the argument type
 */
interface OptionalPredicate<T> {
  (value?: T): boolean
}

/**
 * Represents a predicate operation that takes two arguments.
 * @template T the first argument type
 * @template U the second argument type
 */
interface BiPredicate<T, U> {
  (value1: T, value2: U): boolean
}

/**
 * Represents an asynchronous predicate operation that takes two arguments.
 * @template T the first argument type
 * @template U the second argument type
 */
interface AsyncBiPredicate<T, U> {
  (value1: T, value2: U): Promise<boolean>
}

/**
 * Represents a predicate operation that takes two optional arguments.
 * @template T the first argument type
 * @template U the second argument type
 */
interface OptionalBiPredicate<T, U> {
  (value1?: T, value2?: U): boolean
}

/**
 * Represents an asynchronous predicate operation that takes two optional arguments.
 * @template T the first argument type
 * @template U the second argument type
 */
interface AsyncOptionalBiPredicate<T, U> {
  (value1?: T, value2?: U): Promise<boolean>
}

/**
 * Represents an operation that compares two operands of the same type
 * and produces a number (integer) for comparison purposes
 * @template T the argument type
 */
type Comparator<T> = BiFunction<T, T, number>

/**
 * Represents an operation that compares two operands of the same type
 * and produces a boolean result for comparison purposes
 * @template T the argument type
 */
type EqualityOperator<T> = BiFunction<T, T, boolean>