@teamsparta/utils
는 React, NextJS, NestJS 등 JavaScript 환경에서 사용할 수 있으며 type - safe한 유틸리티성 함수들을 모아놓은 패키지입니다.
npm install @teamsparta/utils # npm
yarn add @teamsparta/utils # yarn
pnpm add @teamsparta/utils # pnpm
입력값을 최솟값과 최댓값 사이로 제한합니다.
function clamp(value: number, min: number, max: number): number;
import { clamp } from '@teamsparta/utils';
function setTime(date: Date, hour: number, minute: number, second: number) {
return date.setHours(
clamp(hour, 0, 23),
clamp(minute, 0, 59),
clamp(second, 0, 59),
);
}
국제적으로 통용되는 만 나이를 계산합니다.
function calculateAge(target: Date, standard: Date = new Date()): number;
import { calculateAge } from '@teamsparta/utils';
const age = calculateAge(new Date('1995-06-22'));