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

@kcuf/ts-missing-helpers

v0.0.1

Published

Some TypeScript utility helpers.

Downloads

5

Readme

@kcuf/ts-missing-helpers

Supplements to TypeScript type helpers.

import {
  PartialPick,
  RequiredPick,
  PartialSelected,
  RequiredSelected,
  PartialUnselected,
  RequiredUnselected,
  PartialBut,
  RequiredBut
} from '@kcuf/ts-missing-helpers';

PartialPick

Pick properties defined by K from T make them optional.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a?: string;
//   b?: number;
// }
type Alt = PartialPick<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1 };
const o2: Alt = { a: '' };
const o3: Alt = { b: 1 };
const o4: Alt = {};
// Error: Object literal may only specify known properties...
const o5: Alt = { c: true };
const o6: Alt = { d: new Date };

RequiredPick

Pick properties defined by K from T make them required.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a: string;
//   b: number;
// }
type Alt = RequiredPick<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1 };
// Error
const o2: Alt = { a: '' }; // missing b
const o3: Alt = { b: 1 }; // missing a
const o4: Alt = {}; // missing a, b
const o5: Alt = { a: '', b: 1, c: true }; // unknown property c

PartialSelected

Make properties defined by K in T optional, the rest untouched.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a?: string;
//   b?: number;
//   c: boolean;
//   d?: Date;
// }
type Alt = PartialSelected<Original, 'a' | 'b'>;

// OK
const o1: Alt = { c: true, d: new Date() };
const o2: Alt = { b: 1, c: true, d: new Date() };
const o3: Alt = { a: '', b: 1, c: true, d: new Date() };
const o4: Alt = { c: true };
// Error
const o5: Alt = { b: 1, d: new Date() }; // missing c
const o6: Alt = { a: '', b: 1 }; // missing c
const o7: Alt = { a: '', b: 1, c: true, d: new Date(), e: null }; // e does not exist

RequiredSelected

Make properties defined by K in T required, the rest untouched.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a: string;
//   b: number;
//   c: boolean;
//   d?: Date;
// }
type Alt = RequiredSelected<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1, c: false };
const o2: Alt = { a: '', b: 1, c: true, d: new Date() };
// Error
const o3: Alt = { b: 1, c: true, d: new Date() }; // missing a
const o4: Alt = { a: '', b: 1, d: new Date() }; // missing c
const o5: Alt = { a: '', b: 1, c: false, e: null }; // unknown e

PartialUnselected

Properties defined by K in T untouched, the rest made optional.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a?: string;
//   b: number;
//   c?: boolean;
//   d?: Date;
// }
type Alt = PartialUnselected<Original, 'a' | 'b'>;

// OK
const o1: Alt = { b: 1 };
const o2: Alt = { a: '', b: 1, c: false };
// Error
const o3: Alt = { a: '', c: false }; // missing b

RequiredUnselected

Properties defined by K in T untouched, the rest made required.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a?: string;
//   b: number;
//   c: boolean;
//   d: Date;
// }
type Alt = RequiredUnselected<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1, c: false, d: new Date() };
const o2: Alt = { b: 1, c: false, d: new Date() };
// Error
const o3: Alt = { }; // missing b, c, d
const o4: Alt = { a: '' }; // missing b, c, d
const o5: Alt = { a: '', b: 1 }; // missing c, d
const o6: Alt = { a: '', b: 1, c: false }; // missing d

PartialBut

Properties defined by K in T required, the rest made optional.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a: string;
//   b: number;
//   c?: boolean;
//   d?: Date;
// }
type Alt = PartialBut<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1 }; // missing c, d
const o2: Alt = { a: '', b: 1, c: false }; // missing d
const o3: Alt = { a: '', b: 1, d: new Date() }; // missing c
const o4: Alt = { a: '', b: 1, c: false, d: new Date() };
// Error
const o5: Alt = { b: 1, c: false, d: new Date() }; // missing a
const o6: Alt = { c: false, d: new Date() }; // missing a, b
const o7: Alt = { a: '' }; // missing b
const o8: Alt = { }; // missing a, b

RequiredBut

Properties defined by K in T optional, the rest made required.

interface Original {
  a?: string;
  b: number;
  c: boolean;
  d?: Date;
}

// Alt === {
//   a?: string;
//   b?: number;
//   c: boolean;
//   d: Date;
// }
type Alt = RequiredBut<Original, 'a' | 'b'>;

// OK
const o1: Alt = { a: '', b: 1, c: false, d: new Date() };
const o2: Alt = { b: 1, c: false, d: new Date() };
const o3: Alt = { c: false, d: new Date() };
// Error
const o4: Alt = { }; // missing c, d
const o5: Alt = { a: '' }; // missing c, d
const o6: Alt = { a: '', b: 1 }; // missing c, d
const o7: Alt = { a: '', b: 1, c: false }; // missing d
const o8: Alt = { a: '', b: 1, d: new Date() }; // missing c