npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teamsparta/utils

v1.2.13

Published

`@teamsparta/utils`는 React, NextJS, NestJS 등 JavaScript 환경에서 사용할 수 있으며 type - safe한 유틸리티성 함수들을 모아놓은 패키지입니다.

Downloads

1,089

Readme

@teamsparta/utils

@teamsparta/utils는 React, NextJS, NestJS 등 JavaScript 환경에서 사용할 수 있으며 type - safe한 유틸리티성 함수들을 모아놓은 패키지입니다.

Getting Started

npm install @teamsparta/utils       # npm
yarn add @teamsparta/utils          # yarn
pnpm add @teamsparta/utils          # pnpm

Usage

clamp

입력값을 최솟값과 최댓값 사이로 제한합니다.

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),
  );
}

calculateAge

국제적으로 통용되는 만 나이를 계산합니다.

function calculateAge(target: Date, standard: Date = new Date()): number;
import { calculateAge } from '@teamsparta/utils';

const age = calculateAge(new Date('1995-06-22'));

isDate

값이 Date 객체인지 확인합니다.

function isDate(value: unknown): value is Date;
import { isDate } from '@teamsparta/utils';

isDate(new Date()); // true
// 유효하지 않은 Date 객체도 Date 객체로 인식합니다.
isDate(new Date('invalid')); // true
isDate({}); // false

getDateDiff

두 날짜의 차이를 일, 시, 분, 초로 반환합니다.

function getDateDiff(
  startDate: Date,
  endDate: Date,
): { days: number; hours: number; minutes: number; seconds: number };
import { getDateDiff } from '@teamsparta/utils';

getDateDiff(new Date('2022-08-10'), new Date('2022-09-10')); // { days: 30, hours: 0, minutes: 0, seconds: 0 }
// startDate와 endDate가 동일할 경우 모든 값이 0으로 반환됩니다.
getDateDiff(new Date('2022-08-10'), new Date('2022-08-10')); // { days: 0, hours: 0, minutes: 0, seconds: 0 }
// startDate가 endDate보다 이후일 경우 음수 값이 반환됩니다.
getDateDiff(new Date('2022-09-10'), new Date('2022-09-11')); // { days: -1, hours: 0, minutes: 0, seconds: 0 }

isBeforeOrEqual

첫 번째 날짜가 두 번째 날짜보다 이전이거나 같은지 확인합니다.

function isBeforeOrEqual(date1: Date, date2: Date): boolean;
import { isBeforeOrEqual } from '@teamsparta/utils';

isBeforeOrEqual(new Date(2022, 8, 10), new Date(2022, 8, 10)); // true
isBeforeOrEqual(new Date(2022, 8, 10), new Date(2022, 9, 10)); // true
isBeforeOrEqual(new Date(2022, 9, 10), new Date(2022, 8, 10)); // false

isAfterOrEqual

첫 번째 날짜가 두 번째 날짜보다 이후이거나 같은지 확인합니다.

function isAfterOrEqual(date1: Date, date2: Date): boolean;
import { isAfterOrEqual } from '@teamsparta/utils';

isAfterOrEqual(new Date(2022, 8, 10), new Date(2022, 8, 10)); // true
isAfterOrEqual(new Date(2022, 9, 10), new Date(2022, 8, 10)); // true
isAfterOrEqual(new Date(2022, 8, 10), new Date(2022, 9, 10)); // false