0.0.6 • Published 11 days ago

@winches/type-tools v0.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
11 days ago

@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 }
0.0.6

11 days ago

0.0.5

23 days ago

0.0.4

2 months ago

0.0.3

8 months ago

0.0.2-dev.4

8 months ago

0.0.2-dev.5

8 months ago

0.0.2-dev.2

8 months ago

0.0.2-dev.3

8 months ago

0.0.2-dev.1

8 months ago

0.0.2

1 year ago

0.0.1

1 year ago