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 🙏

© 2026 – Pkg Stats / Ryan Hefner

unitmaster

v1.4.0

Published

Unit Converter Library

Readme

UnitConvert

TypeScript 기반의 강력하고 유연한 단위 변환 라이브러리입니다. 컴퓨터 용량, 전력, 거리 등 다양한 도메인의 단위 변환을 지원하며, 사용자 정의 단위를 쉽게 확장할 수 있습니다.

설치 (Installation)

npm install unitmaster

주요 기능 (Features)

  • 다양한 기본 변환기 제공: 컴퓨터 용량, 전력 용량/사용량, 거리 등
  • 상대적 단위 정의: 이전 단위 대비 배수(Step)를 통한 직관적인 단위 정의
  • 최적 단위 자동 변환: 값을 가장 읽기 쉬운 단위로 자동 포맷팅 (formatBest)
  • 타입 안전성: TypeScript로 작성되어 완벽한 타입 지원
  • 확장 가능: UnitConverter 클래스를 상속받아 나만의 변환기 제작 가능

사용법 (Usage)

1. 컴퓨터 용량 변환 (Computer Capacity)

Byte, KB, MB, GB, TB, PB, EB, ZB, YB 등을 지원합니다. (1024 배수 기준)

import { ComputerCapacityConverter } from 'unitmaster';

const converter = new ComputerCapacityConverter();

// 1. 단순 단위 변환
// 1024 Byte -> 1 KB
console.log(converter.convertTo(1024, 'Byte', 'KB')); // 1

// 1 MB -> Byte
console.log(converter.convertTo(1, 'MB', 'Byte')); // 1048576

// 2. 최적 단위 자동 포맷팅
console.log(converter.formatBest(1048576)); // { value: 1, unit: 'MB' }
console.log(converter.formatBest(2048));    // { value: 2, unit: 'KB' }

2. 거리 변환 (Distance)

mm, cm(10), m(100), km(1000) 단위를 지원합니다.

import { DistanceConverter } from 'unitmaster';

const distConverter = new DistanceConverter();

// 1 km -> m
console.log(distConverter.convertTo(1, 'km', 'm')); // 1000

// 100 cm -> 1 m
// 100 cm -> 1 m
console.log(distConverter.formatBest(100, undefined)); // { value: 1, unit: 'm' }
// formatBest는 값이 1 이상이 되는 가장 큰 단위를 찾습니다.

3. 전력 변환 (Power)

  • PowerCapacityConverter: W, kW, MW, GW, TW (1000 배수)
  • PowerUsageConverter: Wh, kWh, MWh, GWh, TWh (1000 배수)
import { PowerCapacityConverter } from 'unitmaster';

const powerConverter = new PowerCapacityConverter();
console.log(powerConverter.formatBest(1500)); // { value: 1.5, unit: 'kW' } (기본 단위 W 기준)

고급 사용법 (Advanced)

사용자 정의 단위 추가 (Custom Units)

기존 변환기에 새로운 단위를 추가할 수 있습니다. registerUnit으로 추가하는 단위는 마지막 단위를 기준으로 계산됩니다.

const converter = new ComputerCapacityConverter();
// YB(YottaByte) 다음 단위로 BrontoByte(BB)를 추가한다고 가정 (1024배)
converter.registerUnit([{ unit: 'BB', unitValue: 1024 }]);

나만의 변환기 만들기 (Custom Converter)

UnitConverter를 상속받아 새로운 도메인의 변환기를 만들 수 있습니다.

import { UnitConverter } from 'unitmaster';

class TimeConverter extends UnitConverter {
    constructor() {
        super();
        this.registerUnit([
            { unit: 'Sec', unitValue: 1 },      // 기준 단위
            { unit: 'Min', unitValue: 60 },     // 이전 단위(Sec) * 60
            { unit: 'Hour', unitValue: 60 },    // 이전 단위(Min) * 60
            { unit: 'Day', unitValue: 24 }      // 이전 단위(Hour) * 24
        ]);
    }
}

const timeConverter = new TimeConverter();
console.log(timeConverter.formatBest(3600)); // { value: 1, unit: 'Hour' }

복합 입력값 처리

값과 단위 정의를 객체로 전달하여 처리할 수도 있습니다. 이 경우 동적으로 전달된 단위 정의를 사용합니다.

const complexInput = {
    value: 2048,
    unit: [
        { unit: 'Byte', unitValue: 1 },
        { unit: 'KB', unitValue: 1024 }
    ]
};
// converter 인스턴스의 종류와 상관없이 formatBest는 입력받은 unit 정의를 우선할 수 있습니다.
// (단, formatBest 구현 상세에 따라 사용법이 다를 수 있음. 주로 내부 로직용)

라이선스

MIT