2.0.2 • Published 2 years ago

ts-expand v2.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

ts-expand

Operate TS type as loadash

introduce

install

npm install ts-expand

use

import * as _ from 'ts-expand'

interface Person {
  name: string
  age: number
  sex: string
  other: Symbol
}

const nameInfo: _.Filter<Person, 'name'> = {
  name: 'hello world'
}

types

'_.' can find all types

tssql

  • only support 'and'
  • only support 'key'、'is_readonly'、'is_require'
  • ignore case
import * as _ from 'ts-expand'

interface Person {
  readonly name: string
  age: number
  sex?: string
  other: Symbol
}

type SubPerson = _.TsSql(`select * from ? where key = ?`, Person)

// result:
/**
 * SubPerson = {
 *  readonly name: string
    age: number
    sex?: string
    other: Symbol
 * }
 */
type SubPerson_1 = _.TsSql(`select * from ? where key = ?`, Person, 'name' | 'age')

// result:
/**
 * SubPerson_1 = {
 *  readonly name: string
 *  age: number
 * }
 */

type SubPerson_2 = _.TsSql(`select * from ? where key = ? and is_require`, Person)
// result:
/**
 * SubPerson_2 = {
 *  readonly name: string
 *  age: number
 *  other: Symbol
 * }
 */

type SubPerson_3 = _.TsSql(`select * from ? where key = ? and is_require and is_readonly`, Person)

// result:
/**
 * SubPerson_3 = {
 *  readonly name: string
 * }
 */


// TsSqlV2

type SubPerson = _.TsSqlV2(`
  select
    name, age
  from
    ?
  where
    is_require
`, Test)

// result:
/**
 * SubPerson_1 = {
 *  readonly name: string
 *  age: number
 * }
 */

type SubPerson_all = _.TsSqlV2('select * from ?', Test)
2.0.2

2 years ago

2.0.1

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago