0.0.3 • Published 6 months ago

@txjs/make v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@txjs/make

方法仅用于typescript定义字段

支持方法

使用示例

makeString

const str1 = makeString()
// => string | undefined

const str2 = makeString('Hello, World!')
// => string

type FruitType = 'apple' | 'banana'
const str3 = makeString<FruitType>('apple')
// => FruitType

makeStringMap

const strMap = makeStringMap(['key1', 'key2'])
// => {key1: number | undefined, key2: number | undefined}

const strMap2 = makeStringMap(['key1', 'key2'], (key) => `${key}-hello world`)
// => {key1: string, key2: string}

makeNumber

const num1 = makeNumber()
// => number | undefined

const num2 = makeNumber(100)
// => number

makeNumberMap

const numMap = makeNumberMap(['key1', 'key2'])
// => {key1: number | undefined, key2: number | undefined}

const numMap2 = makeNumberMap(['key1', 'key2'], () => 0)
// => {key1: number, key2: number}

makeArray

const arr1 = makeArray()
// => any[] | undefined

const arr2 = makeArray([])
// => any[]

const arr3 = makeArray<number>([])
// => number[]

interface Option {
  title: string
  desc: string
}

const arr4 = makeArray<Option>([])
// => Option[]

makeNumeric

type Numeric = number | string

const numeric1 = makeNumeric()
// => Numeric | undefined

const numeric2 = makeNumeric(100)
// => Numeric

const numeric3 = makeNumeric('hello world')
// => Numeric
0.0.3

6 months ago

0.0.2

6 months ago

0.0.1

7 months ago