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

tool-types

v0.1.1

Published

Complementing TypeScript built-in types

Downloads

3

Readme

tool-types

Complementing TypeScript built-in types.

Installation

npm install tool-types
# or yarn add tool-types

Usage

import { TupleUnion } from 'tool-types';

type T0 = [number, string];

type T1 = TupleUnion<T0> // number | string

Utility Types

Deprecated API

Intersect

type A = { 
    name: string;
    age: number;
};
type B = { 
    name: string;
    address: string;
    gender: number;
}

// Expect: { name: string; }
type ResultType = Intersect<A, B>;

⇧ back to top

Except

type A = { 
    name: string;
    age: number;
};
type B = { 
    name: string;
    address: string;
    gender: number;
}
// Expect: { age: number; }
type ResultType = Except<A, B>;

⇧ back to top

UnionOmit

type A = { 
    value: string; 
    disabled?: boolean; 
    onChange: () => void;
};
type B = { 
    value: number;
    onChange: () => void;
};
/* Expect: 
{
    value: string, 
    disabled?: boolean;
    onChange: () => void;
   }
*/
type ResultType = UnionOmit<A, B>;

⇧ back to top

TupleUnion

type A = ['a', 'b', 'c'];
// Expect: 'a' | 'b' | 'c'
type ResultType = TupleUnion<A>;

⇧ back to top

RequireAtLeastOne

type A = {
    name: string;
    age: number;
}
/* Expect: 
| {name?: string; age: number;} 
| {name: string; age?: number;}
*/
type ResultType = RequireAtLeastOne<A>;

⇧ back to top

RequireAtLeastOneByKeys

type A = {
    name: string;
    age: number; 
    gender: number;
}
/* Expect: 
| { 
    name?: string; 
    age: number; 
    gender: number;
  } 
| { 
    name: string;
    age: number;
    gender?: number;
  }
*/
type ResultType = RequireAtLeastOneByKeys<A, 'name' | 'gender'>;

⇧ back to top

Weaken

type A = {
    name: string; 
    say(word: string): string;
}
type B = 'name'
// Expect: { name: any; say(word: string): string; }
type ResultType =Weaken<A, B>;

⇧ back to top

Promisify

const foo = (): Promise<string> => {
  return new Promise(resolve => {
      resolve('hello world');
  });
};
// Expect: string
type ResultType = Promisify<typeof foo>;

⇧ back to top

DeepPartial

type A = { 
    value: string; 
    next: { 
        data: number;
    }
}
/* Expect: 
{ 
    value?: string; 
    next?: { 
        data?: number;
    }
}
*/
type ResultType = DeepPartial<A>;

⇧ back to top

DeepRequired

type A = { 
    value?: string;
    next?: { 
        data?: number;
    }
}
/* Expect: 
{ 
    value: string; 
    next: { 
        data: number;
    }
}
*/
type ResultType = DeepRequired<A>;

⇧ back to top

DeepReadOnly

type A = {value: string; next: { data: number; }}
/* Expect: 
{ 
    readonly value: string; 
    readonly next: { 
        readonly data: number; 
    }
}
*/
type ResultType = DeepReadOnly<A>;

⇧ back to top

DeepMutable

type A = { 
    readonly value: string; 
    readonly next: {
        readonly data: number;
    }
}
/* Expect: 
{ 
    value: string; 
    next: { 
        data: number;
    }
}
*/
type ResultType = DeepMutable<A>;

⇧ back to top

RequiredByKeys

type A = { 
    name?: string; 
    age?: number; 
    gender?: number;
}
/* Expect: 
{ 
    name: string; 
    age?: number; 
    gender?: number;
}
*/
type ResultType = RequiredByKeys<A, 'name'>;

⇧ back to top

PartialByKeys

type A = { 
    name: string; 
    age: number; 
    gender: number;
}
/* Expect: 
{ 
    name?: string; 
    age: number; 
    gender: number;
}
*/
type ResultType = PartialKeys<A, 'name'>;

⇧ back to top

ReadOnlyByKeys

type A = { 
    name: string; 
    age: number; 
    gender: number;
}
/* Expect: 
{ 
    readonly name: string; 
    age: number; 
    gender: number;
}
*/
type ResultType = ReadOnlyByKeys<A, 'name'>;

⇧ back to top

MutableByKeys

type A = { 
    readonly name: string; 
    readonly age: number; 
    readonly gender: number;
}
/* Expect: 
{ 
    name: string; 
    readonly age: number; 
    readonly gender: number;
}
*/
type ResultType = MutableByKeys<A, 'name'>;

⇧ back to top

PickAllKeys

type A = { 
    name: string; 
    age?: number; 
    gender?: number;
}
// Expect: name | age | gender
type ResultType = PickAllKeys<A>;

⇧ back to top

PickRequiredKeys

type A = { 
    name: string; 
    age?: number; 
    gender?: number;
}
// Expect: name
type ResultType = PickRequiredKeys<A>;

⇧ back to top

PickPartialKeys

type A = { 
    name: string; 
    age?: number; 
    gender?: number;
}
// Expect: age | gender
type ResultType = PickPartialKeys<A>;

⇧ back to top

PickRequired

type A = { 
    name: string; 
    age?: number; 
    gender?: number;
}
// Expect: { name: string }
type ResultType = PickRequired<A>;

⇧ back to top

PickPartial

type A = { 
    name: string; 
    age?: number; 
    gender?: number;
}
// Expect: { age?: number; gender?: number;}
type ResultType = PickPartial<A>;

⇧ back to top

Equal

type A = { name: string; }
type B = { name?: string; }
// Expect: false
type ResultType = Equal<A, B>;

⇧ back to top

PickReadOnlyKeys

type A = { 
    readonly name: string; 
    age: number; 
}
// Expect: name
type ResultType =  PickReadOnlyKeys<A>;

⇧ back to top

PickReadOnly

type A = { 
    readonly name: string;
    age: number;
}
// Expect: { readonly name: string; }
type ResultType = PickReadOnly<A>;

⇧ back to top

PickMutableKeys

type A = { 
    readonly name: string;
    age: number;
}
// Expect: age
type ResultType = PickMutableKeys<A>;

⇧ back to top

PickMutable

type A = { 
    readonly name: string;
    age: number;
}
// Expect: { age: number; }
type ResultType = PickMutable<A>;

⇧ back to top