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

@skybaer0804/tdd

v1.1.8

Published

TDD 방식으로 개발된 유틸리티 라이브러리

Readme

TDD Utility Library

A utility function library developed using TDD (Test-Driven Development). Provides various features including mathematical operations, data validation, and formatting.

Installation

npm install @skybaer0804/tdd

or

yarn add @skybaer0804/tdd

Usage

// Method 1: Import all functions at once
import { add, subtract, pow, divide, percent, isNum, isPositiveNum, isUrl, isInputXssSafe, toNum, toStringComma, toRenderXssSafe } from '@skybaer0804/tdd';

// Method 2: Import by category
import { add, subtract, pow, divide, percent } from '@skybaer0804/tdd/math';
import { isNum, isPositiveNum, isUrl, isInputXssSafe } from '@skybaer0804/tdd/validate';
import { toNum, toStringComma, toRenderXssSafe } from '@skybaer0804/tdd/format';

// Math functions
console.log(add(2, 3)); // 5
console.log(add('1', '2')); // 3
console.log(subtract(5, 3)); // 2
console.log(pow(2, 3)); // 8
console.log(divide(10, 2)); // 5
console.log(percent(50, 100)); // 50

// Validation functions
console.log(isNum(123)); // true
console.log(isUrl('https://example.com')); // true
console.log(isInputXssSafe('<script>alert(1)</script>')); // false

// Format functions
console.log(toNum('123')); // 123
console.log(toStringComma(1234)); // '1,234'
console.log(toRenderXssSafe('<script>alert(1)</script>')); // '&lt;script&gt;alert(1)&lt;/script&gt;'

API Documentation

Math Functions

add(a, b)

Adds two numbers. Automatically converts string numbers.

  • a (number|string): First number
  • b (number|string): Second number
  • Returns: (number) Sum of two numbers
add(2, 3); // 5
add('1', '2'); // 3
add('1,000', '2,000'); // 3000

subtract(a, b)

Subtracts two numbers. Automatically converts string numbers.

  • a (number|string): First number
  • b (number|string): Second number
  • Returns: (number) Difference of two numbers
subtract(5, 3); // 2
subtract('5', '3'); // 2

pow(base, exponent)

Power function. Automatically converts string numbers.

  • base (number|string): Base
  • exponent (number|string): Exponent
  • Returns: (number) Base raised to the power of exponent
pow(2, 3); // 8
pow('2', '3'); // 8

divide(dividend, divisor)

Division function. Automatically converts string numbers.

  • dividend (number|string): Number to be divided
  • divisor (number|string): Number to divide by
  • Returns: (number) Result of division
divide(10, 2); // 5
divide('10', '2'); // 5

percent(value, total)

Calculates percentage.

  • value (number|string): Value to calculate
  • total (number|string): Total value
  • Returns: (number) Percentage
percent(50, 100); // 50
percent(25, 100); // 25
percent(1, 3); // 33.333...

Validate Functions

isNum(value)

Checks if a value is a number.

  • value (*): Value to check
  • Returns: (boolean) true if number, false otherwise
isNum(123); // true
isNum('123'); // false
isNum(null); // false

isPositiveNum(value)

Checks if a value is a non-negative integer.

  • value (*): Value to check
  • Returns: (boolean) true if non-negative integer, false otherwise
isPositiveNum(0); // true
isPositiveNum(1); // true
isPositiveNum(-1); // false

isUrl(value)

Checks if a value is a valid URL format.

  • value (*): Value to check
  • Returns: (boolean) true if valid URL, false otherwise
isUrl('https://example.com'); // true
isUrl('not-a-url'); // false

isInputXssSafe(value)

Checks if input value is safe from XSS attacks.

  • value (*): Value to check
  • Returns: (boolean) true if safe, false if dangerous
isInputXssSafe('Safe text'); // true
isInputXssSafe('<script>alert("XSS")</script>'); // false

Format Functions

toNum(value)

Converts a value to a number.

  • value (*): Value to convert
  • Returns: (number) Converted number
toNum('123'); // 123
toNum(' 12,340 '); // 12340
toNum('abc'); // NaN

toStringComma(value)

Converts a number to a string with thousand separators.

  • value (number|string): Number or string to convert
  • Returns: (string) String with commas
toStringComma(1234); // '1,234'
toStringComma(1234567); // '1,234,567'

toRenderXssSafe(value)

Escapes HTML special characters to prevent XSS attacks.

  • value (*): Value to escape
  • Returns: (string) Escaped safe string
toRenderXssSafe('Safe text'); // 'Safe text'
toRenderXssSafe('<script>alert("XSS")</script>'); // '&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;'

Running Tests

npm test

Development

This project follows the TDD Red-Green-Blue cycle:

  1. Red Phase: Write failing test code
  2. Green Phase: Write minimal code to pass tests
  3. Blue Phase: Refactor and clean up code

Changelog

1.1.0 (2024-11-10)

New Features

  • Added format category (toNum, toStringComma, toRenderXssSafe)
  • Extended validate category (isUrl, isInputXssSafe)
  • Extended math category (percent)

Improvements

  • Improved non-number input handling in math functions
  • Support for automatic string number conversion
  • Support for string numbers with spaces and commas

1.0.2

  • Initial version
  • Basic math functions (add, subtract, pow, divide)
  • Basic validation functions (isNum, isPositiveNum)

License

MIT