[JS,TS,Node]

[Js] 고급 문법

grape.store 2022. 3. 2. 13:26
반응형

pipe() : pipe 함수는 함수로 인자를 받아 함수들을 합성해 하나의 함수를 리턴한다., 받은 함수들을 연속적으로 실행해주는 함수를 리턴하는 함수

 

const pipe = (...funcs) => arg => funcs.reduce((a, f) => f(a), arg);

// 위에서부터 차례대로 return하여 다음 함수에 영향을 줌
const p = pipe(
  a => a + 1,
  a => a + 10,
  a => a + 100
); 

console.log(p(0)); // 111

 

Class-transformer 설치

$ yarn add class-transformer
$ yarn add reflect-metadata

plainToClass method

import moment = require('moment');
import { plainToClass, Expose} from 'class-transformer'

const fromPlainUser = {
    id: 1,
    uuid: "50CC75F5-537C-4407-B4B3-951F95E16F90",
    name: "cherrypick",
    isActive: true,
    createdAt: moment("2019-08-17").toDate(),
    updatedAt: moment("2019-08-17").toDate()
}

class GetUserResponse {
    id: number
    uuid: string
    name: string
    isActive: boolean
    createdAt: Date
    updatedAt: Date
}

console.log(fromPlainUser)
console.log(plainToClass(GetUserResponse, fromPlainUser))