Skip to content

Commit

Permalink
init : lib/util
Browse files Browse the repository at this point in the history
  • Loading branch information
kangjuhyup committed Dec 26, 2024
1 parent 5a488f6 commit d59e12f
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 19 deletions.
2 changes: 2 additions & 0 deletions packages/lib/dto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
"compile": "tsc"
},
"peerDependencies": {
"@lib/util": "*",
"@nestjs/swagger": "^7.4.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1"
},
"devDependencies": {
"@lib/util": "*",
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/swagger": "^8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/dto/src/letter/request/add.letter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LetterCategoryCode } from '@app/util/category';
import { LetterCategoryCode } from '@lib/util';
import { ApiProperty } from '@nestjs/swagger';
import {
IsBoolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/dto/src/letter/response/get.page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LetterCategoryCode } from '@app/util/category';
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
Expand All @@ -9,6 +8,7 @@ import {
IsString,
ValidateNested,
} from 'class-validator';
import { LetterCategoryCode } from '@lib/util';

class LetterPageItem {
@ApiProperty({
Expand Down
42 changes: 42 additions & 0 deletions packages/lib/util/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@lib/util",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"build": "yarn clean && yarn compile",
"clean": "rimraf -rf ./dist",
"compile": "tsc"
},
"devDependencies": {
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/node-imap": "^0",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unused-imports": "^4.1.4",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tsconfig-paths-jest": "^0.0.1",
"typescript": "^5.1.3"
},
"packageManager": "[email protected]"
}
21 changes: 21 additions & 0 deletions packages/lib/util/src/attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const LetterAttachmentCode = {
THUMBNAIL: 'LA001',
LETTER: 'LA002',
BACKGROUND: 'LA003',
COMPONENT: 'LA004',
} as const;

export type LetterAttachmentCode =
(typeof LetterAttachmentCode)[keyof typeof LetterAttachmentCode];

export const pathToLetterAttachmentCode = (path: string) => {
return path.includes('thm/')
? LetterAttachmentCode.THUMBNAIL
: path.includes('ltr/')
? LetterAttachmentCode.LETTER
: path.includes('bgr/')
? LetterAttachmentCode.BACKGROUND
: path.includes('cpn')
? LetterAttachmentCode.COMPONENT
: undefined;
};
51 changes: 51 additions & 0 deletions packages/lib/util/src/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export const LetterCategory = {
WEDDING: '결혼식', // 결혼식
BIRTHDAY: '생일', // 생일
ANNIVERSARY: '기념일', // 기념일
PARTY: '파티', // 파티
GRADUATION: '졸업', // 졸업
CORPORATE: '행사', // 회사 행사
} as const;

export type LetterCategory =
(typeof LetterCategory)[keyof typeof LetterCategory];

export const LetterCategoryCode = {
WEDDING: 'LT001', // 결혼식
BIRTHDAY: 'LT002', // 생일
ANNIVERSARY: 'LT003', // 기념일
PARTY: 'LT004', // 파티
GRADUATION: 'LT005', // 졸업
CORPORATE: 'LT006', // 회사 행사
} as const;

export type LetterCategoryCode =
(typeof LetterCategoryCode)[keyof typeof LetterCategoryCode];

const categoryToCodeMap: Record<LetterCategory, LetterCategoryCode> = {
[LetterCategory.WEDDING]: LetterCategoryCode.WEDDING,
[LetterCategory.BIRTHDAY]: LetterCategoryCode.BIRTHDAY,
[LetterCategory.ANNIVERSARY]: LetterCategoryCode.ANNIVERSARY,
[LetterCategory.PARTY]: LetterCategoryCode.PARTY,
[LetterCategory.GRADUATION]: LetterCategoryCode.GRADUATION,
[LetterCategory.CORPORATE]: LetterCategoryCode.CORPORATE,
};

const codeToCategoryMap: Record<LetterCategoryCode, LetterCategory> = {
[LetterCategoryCode.WEDDING]: LetterCategory.WEDDING,
[LetterCategoryCode.BIRTHDAY]: LetterCategory.BIRTHDAY,
[LetterCategoryCode.ANNIVERSARY]: LetterCategory.ANNIVERSARY,
[LetterCategoryCode.PARTY]: LetterCategory.PARTY,
[LetterCategoryCode.GRADUATION]: LetterCategory.GRADUATION,
[LetterCategoryCode.CORPORATE]: LetterCategory.CORPORATE,
};

export function getCategoryFromCode(code: LetterCategoryCode): LetterCategory {
return codeToCategoryMap[code];
}

export function getCodeFromCategory(
category: LetterCategory,
): LetterCategoryCode {
return categoryToCodeMap[category];
}
4 changes: 4 additions & 0 deletions packages/lib/util/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './attachment';
export * from './category';
export * from './random';
export * from './yn';
14 changes: 14 additions & 0 deletions packages/lib/util/src/random.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 랜덤한 문자열을 반환한다. ( 기본 길이 10 )
* @param length
* @returns string
*/
export const randomString = (length: number = 10): string => {
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
};
10 changes: 10 additions & 0 deletions packages/lib/util/src/yn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const YN = {
Y: 'Y',
N: 'N',
} as const;

export type YN = (typeof YN)[keyof typeof YN];

export const booleanToYN = (data: boolean): YN => {
return data === true ? YN.Y : YN.N;
};
4 changes: 4 additions & 0 deletions packages/lib/util/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends" : "./tsconfig.json",
"exclude": ["node_modules","test","dist","**/*spec.ts"]
}
13 changes: 13 additions & 0 deletions packages/lib/util/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"include": ["./src"],
"extends" : "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
"rootDir": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"composite": true
}
}

38 changes: 21 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"baseUrl": "./",
"composite": true
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2021",
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"baseUrl": "./",
"composite": true,
"paths": {
"@lib/util/*": ["packages/lib/util/src/*"],
"@lib/dto/*": ["packages/lib/dto/src/*"]
}
}
}
29 changes: 29 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@lib/dto@workspace:packages/lib/dto"
dependencies:
"@lib/util": "npm:*"
"@nestjs/cli": "npm:^10.0.0"
"@nestjs/schematics": "npm:^10.0.0"
"@nestjs/swagger": "npm:^8.1.0"
Expand Down Expand Up @@ -2234,12 +2235,40 @@ __metadata:
typescript: "npm:^5.1.3"
webpack: "npm:^5.97.1"
peerDependencies:
"@lib/util": "*"
"@nestjs/swagger": ^7.4.2
class-transformer: ^0.5.1
class-validator: ^0.14.1
languageName: unknown
linkType: soft

"@lib/util@npm:*, @lib/util@workspace:packages/lib/util":
version: 0.0.0-use.local
resolution: "@lib/util@workspace:packages/lib/util"
dependencies:
"@types/jest": "npm:^29.5.2"
"@types/node": "npm:^20.3.1"
"@types/node-imap": "npm:^0"
"@types/supertest": "npm:^6.0.0"
"@typescript-eslint/eslint-plugin": "npm:^6.0.0"
"@typescript-eslint/parser": "npm:^6.0.0"
eslint: "npm:^8.42.0"
eslint-config-prettier: "npm:^9.1.0"
eslint-plugin-prettier: "npm:^5.2.1"
eslint-plugin-unused-imports: "npm:^4.1.4"
jest: "npm:^29.5.0"
prettier: "npm:^3.0.0"
source-map-support: "npm:^0.5.21"
supertest: "npm:^6.3.3"
ts-jest: "npm:^29.1.0"
ts-loader: "npm:^9.5.1"
ts-node: "npm:^10.9.1"
tsconfig-paths: "npm:^4.2.0"
tsconfig-paths-jest: "npm:^0.0.1"
typescript: "npm:^5.1.3"
languageName: unknown
linkType: soft

"@ljharb/through@npm:^2.3.12":
version: 2.3.13
resolution: "@ljharb/through@npm:2.3.13"
Expand Down

0 comments on commit d59e12f

Please sign in to comment.