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

@voire/type-utils

v1.2.1

Published

Provides some new types for your typescript project.

Downloads

11

Readme

@voire/type-utils

Provides some new types for your typescript project.

View the package on npm

Bigint types

import type { HexString } from './hex'
import type { MaybeStringified, Stringified } from './stringified'

/**
 * bigint or a bigint-like string
 * @since 1.2.0
 */
export type StringifiedBigint = Stringified<bigint>

/**
 * bigint or a bigint-serializable string
 * @since 1.2.0
 */
export type BigintLike = MaybeStringified<bigint> | HexString

Core types

/**
 * Default key signature
 * @since 1.2.0
 */
export type Key = string | number | symbol

/**
 * Value or `null`
 */
export type Nullable<T> = T | null

/**
 * Value or `undefined`
 */
export type Optional<T> = T | undefined

/**
 * Number-serializable type - `string` or `number`
 * @deprecated Use more safe `NumberLike` instead
 * @see {@link NumberLike}
 */
export type Numeric = string | number

/**
 * Promise returning the type or the type itself
 */
export type MaybePromise<T> = T | Promise<T>

/**
 * Type or an array of the type
 * Useful for API filters' types definitions
 */
export type MaybeArray<T> = T | T[]

/**
 * Definition for a class constructor's signature
 */
export type ModelConstructor<TData, TModel = TData> = {
  new (data: TData): TModel
}

/**
 * Entry
 */
export type Entry<TKey = string, TValue = any> = [TKey, TValue]

/**
 * List of the entries
 */
export type Entries<TKey = string, TValue = any> = Entry<TKey, TValue>[]

/**
 * ISO Date-like string format
 */
export type DateISO = `${number}${number}${number}${number}-${number}${number}-${number}${number}T${number}${number}:${number}${number}:${number}${number}.${number}${number}${number}Z`

/**
 * The Record type with optional fields
 */
export type PartialRecord<TKey extends Numeric | symbol, TValue> = {
  [Key in TKey]?: TValue
}

/**
 * Object of boolean flags of specified keys
 * @since 1.2.0
 */
export type Flags<T extends string> = {
  [key in T]: boolean
}

/**
 * An object type without `on*` fields
 * May be useful for defining some UI components' props
 * @since 1.2.0
 */
export type OmitListeners<T> = Omit<T, `on${string}`>

/**
 * Map function from one type to another
 */
export type Mapper<TSource = any, TTarget = any> = (data: TSource) => TTarget

/**
 * The Record with the type or a new Record as a value
 */
export interface NestedRecord<T, K extends Key = Key> extends Record<string, T | NestedRecord<T, K>> {}

Hex types

/**
 * Hex string with prefix
 * @since 1.2.0
 */
export type HexString = `0x${string}`

Infer types

import { Key } from './core'

/**
 * Key of the input object
 * @since 1.2.0
 */
export type InferKey<T> = keyof T

/**
 * Value of the input object
 * @since 1.2.0
 */
export type InferValue<T> = T extends Record<keyof T, infer Value>
  ? Value
  : never

/**
 * Item of the input array
 * @since 1.2.0
 */
export type InferItem<T> = T extends Record<number, any>
  ? T[number]
  : never

/**
 * Type of the certain field of the input object
 * @since 1.2.0
 */
export type InferField<T, K extends keyof T> = T extends Record<K, infer Field>
  ? Field
  : never

Number types

import type { HexString } from './hex'
import type { MaybeStringified, Stringified } from './stringified'

/**
 * Number or a number-like string
 * @since 1.2.0
 */
export type StringifiedNumber = Stringified<number>

/**
 * Number or a number-serializable string
 * @since 1.2.0
 */
export type NumberLike = MaybeStringified<number> | HexString

Stringified types

/**
 * Provided type casted to string
 * @since 1.2.0
 */
export type Stringified<T extends string | number | bigint | boolean> = `${T}`

/**
 * Provided type or the type casted to string
 * @since 1.2.0
 */
export type MaybeStringified<
  T extends string | number | bigint | boolean | symbol,
> = T | Stringified<Exclude<T, symbol>>

Ui types

/**
 * Horizontal position
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type PositionX = 'left' | 'right'

/**
 * Vertical position
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type PositionY = 'top' | 'bottom'

/**
 * Position
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type Position = PositionX | PositionY

/**
 * X-Axis alignment
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type AlignX = PositionX | 'center'

/**
 * Y-Axis alignment
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type AlignY = PositionY | 'center'

/**
 * Alignment
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type Align = Position | 'center'

/**
 * Direction
 * Useful for defining some UI components' and animations' props
 * @since 1.2.0
 */
export type Direction = 'x' | 'y'

/**
 * Range of sizes
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type Size = 'sm' | 'md' | 'lg'

/**
 * Extended range of sizes
 * Useful for defining some UI components' props
 * @since 1.2.0
 */
export type SizeExtra = 'xs' | Size | 'xl'

Development

Set up linting

Git hooks

To update README.md with new code snippet.

Use simple-git-hooks to auto-update README.md with new code snippet.

  • Update packages with yarn / @antfu/ni
  • Set git's hooks directory
    git config core.hooksPath .git/hooks/
    rm -rf .git/hooks
    * It's important because your local git hooks dir's path might be overriden by similar package - husky - if you have tried it.
  • Say simple-git-hooks to start doing its magic:
    npx simple-git-hooks