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

@pansy/types

v0.2.0

Published

<h1 align="center"> @pansy/types </h1>

Downloads

52

Readme

TypeScript >= 3.4

🏗 安装

# npm install
$ npm install @pansy/types --save

# yarn install
$ yarn add @pansy/types

🔨 使用

import { NonUndefined } from '@pansy/types';

type FooWithoutRainbow = NonUndefined<string | null | undefined>;
//=> string | null

目录

Partial<T>

T中所有的属性设为可选。

interface NodeConfig {
  appName: string;
  port: number;
}
// Expect: { appName?: string; port?: number; }
Partial<NodeConfig>;

⇧ 回到目录

Readonly<T>

T中所有的属性设为只读。

interface NodeConfig {
  appName: string;
  port?: number;
}
// Expect: { readonly appName: string; readonly port?: number; }
Readonly<NodeConfig>;

⇧ 回到目录

Pick<T, K>

T 中过滤出属性 K

interface NodeConfig {
  name: string;
  appName: string;
  port?: number;
}
// Expect: { name: string; }
Pick<NodeConfig, 'name'>;

⇧ 回到目录

Record<T,K>

标记对象的 key value类型。

// Expect: { [key: string]: number; }
Record<string, number>;

⇧ 回到目录

Exclude<T,U>

T可分配给的类型中排除U

// Expect: 'b' | 'd'
Exclude<"a" | "b" | "c" | "d", "a" | "c" | "f">;

⇧ 回到目录

Extract<T,U>

T可分配给的类型中提取U

// Expect: 'a' | 'c'
Extract<"a" | "b" | "c" | "d", "a" | "c" | "f">;

⇧ 回到目录

NonNullable<T>

T中排除nullundefined

// Expect: string
NonNullable<string | null | undefined>;

⇧ 回到目录

ReturnType<T>

获取函数类型T的返回类型。

// Expect: string
ReturnType<() => string>;

⇧ 回到目录

InstanceType<T>

获取构造函数类型T的实例类型。

class C {
  x = 0;
  y = 0;
}

// Expect: C
InstanceType<typeof C>;

⇧ 回到目录

Required<T>

T中所有的属性设为必填。

interface NodeConfig {
  appName?: string;
  port?: number;
}
// Expect: { appName: string; port: number; }
Required<NodeConfig>;

⇧ 回到目录

Parameters<T>

获取一个函数的所有参数类型。

function shuffle(input: string, input1: number): void {}

// Expect: { input: string; input1: number; }
Parameters<typeof shuffle>;

⇧ 回到目录

ConstructorParameters<T>

获取构造函数的所有参数类型

class A {
  constructor(input: string, input1: number) {}
}

// Expect: { input: string; input1: number; }
ConstructorParameters<typeof A>;

⇧ 回到目录

Omit<T,K>

通过从T选取所有属性然后删除K来构造类型。

interface Animal {
  	imageUrl: string;
  	species: string;
  	images: string[];
  	paragraphs: string[];
}

// Expect: { images: string[]; paragraphs: string[]; }
Omit<Animal, 'imageUrl' | 'species'>;

⇧ 回到目录

Uppercase<S>

将字符串中的每个字符转换为大写

// Expect: 'HELLO'
Uppercase<'hello'>;

⇧ 回到目录

Lowercase<S>

将字符串中的每个字符转换为小写

// Expect: 'hello'
Uppercase<'HELLO'>;

⇧ 回到目录

Capitalize<S>

将字符串中的第一个字符转换为大写

// Expect: 'Hello'
Capitalize<'hello'>;

⇧ 回到目录

Uncapitalize<S>

将字符串中的第一个字符转换为小写

// Expect: 'hello'
Uncapitalize<'Hello'>;

⇧ 回到目录