New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@winches/type-tools

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@winches/type-tools

日常ts(typescript)工具函数 泛型 ts工具 type gymnastics

latest
Source
npmnpm
Version
0.0.6
Version published
Maintainers
1
Created
Source

@winches/type-tools

ts(typescript) 工具函数 泛型 ts工具

install

npm i @winches/type-tools -D
# or
yarn add @winches/type-tools -D
# or
pnpm add @winches/type-tools -D

Usage

get the union length

import type { GetUnionLastValue } from '@winches/type-tools'

interface union {
  a: 'a'
  b: 'b'
  c: 'c'
}
type unionLength = GetUnionLastValue<keyof union> // 3

add prefix key to object

import type { AddPrefixKeyToObject } from '@winches/type-tools'

interface union {
  ab: 'a'
  bc: 'b'
  cd: 'c'
}
type prefixUnion = AddPrefixKeyToObject<union, 'prefix'> // { prefixAb: 'a', ... }

union to tuple

import type { Union2Tuple } from '@winches/type-tools'

type tuple = Union2Tuple<'a' | 'b' | 'c'> // ['a'|'b'|'c', 'a'|'b'|'c', 'a'|'b'|'c']

union to array

import type { UnionToArray } from '@winches/type-tools'

type array = UnionToArray<'a' | 'b' | 'c'> // ['a'|'b'|'c', ...('a'|'b'|'c')[]]

the keyof unionObject to new type interface (获取联合对象里的key值到新对象类型)

import type { UnionObjectKeysToObject } from '../dist'

type obj = {
  key1: 'v1'
  key2: 'v2'
} | {
  key3: 'v3'
  key1: 'v1'
}
type ObjKeyType = UnionObjectKeysToObject<obj> // { key1: 'v1'; key2: 'v2'; key3: 'v3' }

parse query parameter

import type { ParseQueryStr } from '../dist'

type QueryStr = ParseQueryStr<'a=1'> // { a: 1 }
type QueryStr2 = ParseQueryStr<'a=1&b=2'> // { a: 1; b: 2 }

Keywords

ts(typescript)工具

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts