Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/everyday-types

Everyday utility types
https://github.com/stagas/everyday-types

Last synced: 14 days ago
JSON representation

Everyday utility types

Awesome Lists containing this project

README

        


everyday-types

Everyday utility types



npm i everyday-types

pnpm add everyday-types

yarn add everyday-types

## API

# AAt src/string.ts#L3


    A extends List ? number extends A ["length"] ? K extends number | template-literal ? A [never] | undefined : undefined : K extends keyof A ? A [K] : undefined : unknown extends A ? unknown : K extends keyof A ? A [K] : undefined

# Cast src/string.ts#L42 # Key src/string.ts#L1

    string | number | symbol

# LLength – Ask TS to re-check that A1 extends A2.
And if it fails, A2 will be enforced anyway.
Can also be used to add constraints on parameters. src/string.ts#L40

    L ["length"]

# List src/string.ts#L2

    ReadonlyArray<A>

# Literal src/string.ts#L11

    string | number | bigint | boolean

# Pop src/string.ts#L63

    L extends readonly [ rest, any ] | readonly [ rest, optional ] ? LBody : L

# _Replace src/string.ts#L47

    S extends template-literal ? Replace<template-literal, R, W> : S

# __Split src/string.ts#L50

    S extends template-literal ? __Split<AS, D, [ rest, BS ]> : [ rest, S ]

# String src/string.ts#L1 # CustomElement src/everyday-types.ts#L83

    # attributeChangedCallback(name, oldValue, newValue) – Callback that is invoked when one of the {@link withProperties} changes.

      # name – Name of attribute


        string

      # oldValue – Old value

        null | string

      # newValue – New value

        null | string


      attributeChangedCallback(name, oldValue, newValue)  =>


        void


# connectedCallback() – Invoked when the component is added to the document's DOM.


    In `connectedCallback()` you should setup tasks that should only occur when
    the element is connected to the document. The most common of these is
    adding event listeners to nodes external to the element, like a keydown
    event handler added to the window.

    ```ts
    connectedCallback() {
    super.connectedCallback();
    this.addEventListener('keydown', this._handleKeydown);
    }
    ```

    Typically, anything done in `connectedCallback()` should be undone when the
    element is disconnected, in `disconnectedCallback()`.


    connectedCallback()  =>


      void
# disconnectedCallback() – Invoked when the component is removed from the document's DOM.


    This callback is the main signal to the element that it may no longer be
    used. `disconnectedCallback()` should ensure that nothing is holding a
    reference to the element (such as event listeners added to nodes external
    to the element), so that it is free to be garbage collected.

    ```ts
    disconnectedCallback() {
    super.disconnectedCallback();
    window.removeEventListener('keydown', this._handleKeydown);
    }
    ```

    An element may be re-connected after being disconnected.


    disconnectedCallback()  =>


      void
# EventHandler src/everyday-types.ts#L7

EventHandler(this, event)  =>

    any
# SafeMap src/everyday-types.ts#L62

    # get(v)

      # v


      get(v)  =>



# has(v)

    # v


    has(v)  =>


      boolean
# SafeWeakMap src/everyday-types.ts#L67

    # get(v)

      # v


      get(v)  =>



# has(v)

    # v


    has(v)  =>


      boolean
# Any src/everyday-types.ts#L60

    any

# Chunk src/everyday-types.ts#L3

    N extends N ? number extends N ? T [] : _Chunk<T, N, [ ]> : never

# Class src/everyday-types.ts#L5 # Ctor src/everyday-types.ts#L6 # CustomElementConstructor src/everyday-types.ts#L74 # DetailOf src/everyday-types.ts#L54 # EventKeys src/everyday-types.ts#L10 # EventsOf src/everyday-types.ts#L33 # Fn src/everyday-types.ts#L11

    # (args)

      # args


      (args)  =>



# Get src/everyday-types.ts#L12 # Key src/everyday-types.ts#L13

    number | string | symbol

# Keys src/everyday-types.ts#L14 # Mixable src/everyday-types.ts#L15

    {} & Omit<T, "constructor">

# Mutable src/everyday-types.ts#L16

    [P in keyof T ]: T [P]

# Narrow src/everyday-types.ts#L18

    K extends T ? K : never

# NarrowKey src/everyday-types.ts#L17 # NonNull src/everyday-types.ts#L19 # Null src/everyday-types.ts#L20

    null | undefined | void

# ObjectFromList src/everyday-types.ts#L22

    [K in T extends ReadonlyArray<inferred> ? U : never ]: V

# Prefix src/everyday-types.ts#L25

    template-literal

# SansOn src/everyday-types.ts#L26 # StringKeys src/everyday-types.ts#L27 # StringLiteral src/everyday-types.ts#L28

    T extends string ? string extends T ? never : T : never

# StringOf src/everyday-types.ts#L29 # Target src/everyday-types.ts#L30

    HTMLElement | SVGElement | Window | Document | ShadowRoot

# ValueConstructor src/everyday-types.ts#L72

    StringConstructor | NumberConstructor | BooleanConstructor

# ValuesOf src/everyday-types.ts#L31

    T [keyof T]

# _Chunk src/everyday-types.ts#L4

## Credits

- [ts-toolbelt](https://npmjs.org/package/ts-toolbelt) by [Pierre-Antoine Mills](https://github.com/github.com) – TypeScript's largest utility library

## Contributing

[Fork](https://github.com/stagas/everyday-types/fork) or [edit](https://github.dev/stagas/everyday-types) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)