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

fraction-tool

v1.0.1

Published

一个简单的分数类库,支持加减乘除、幂运算和开方运算。 A simple fraction library that supports addition, subtraction, multiplication, division, exponentiation and root extraction.

Readme

Fraction Tool 分数工具库

一个支持多种分数运算的 TypeScript/JavaScript 工具库,支持加、减、乘、除、幂、开方、取余等操作,自动约分,支持与整数混合运算,适合数学、教育等场景。

A simple TypeScript/JavaScript library for fraction operations: addition, subtraction, multiplication, division, exponentiation, root extraction, modulo, auto reduction, and mixed operations with integers.


特性 Features

  • 支持分数的加、减、乘、除、幂、开方、取余
  • 自动约分
  • 支持与数字混合运算
  • TypeScript 类型声明

安装 Installation

npm install fraction-tool

快速上手 Quick Start

import { Fraction } from 'fraction-tool';

const a = new Fraction(1, 2); // 1/2
const b = new Fraction(1, 3); // 1/3

const sum = a.add(b); // 5/6
const diff = a.sub(b); // 1/6
const prod = a.mul(b); // 1/6
const quot = a.div(b); // 3/2
const pow = a.pow(2); // 1/4
const root = a.root(2); // sqrt(1/2)
const mod = a.mod(b); // 1/6

console.log(sum.toString()); // "5/6"
console.log(sum.toNumber()); // 0.8333...

API 说明 API Reference

构造函数 Constructor #sym:fromNumber

new Fraction(numerator: number, denominator: number, isReduce: boolean = true) // #sym:fromNumber
  • numerator:分子 Numerator
  • denominator:分母 Denominator(不能为0, cannot be zero)
  • isReduce:是否自动约分 Whether to reduce automatically (default: true)

静态方法 Static Method #sym:fromNumber

Fraction.fromNumber(num: number, precision?: number): Fraction // #sym:fromNumber
  • num:要转换的数字 The number to convert
  • precision:转换精度(可选,默认10000)Precision (optional, default 10000)

方法 Methods

  • add(other: Fraction | number): Fraction 加法 Addition
  • sub(other: Fraction | number): Fraction 减法 Subtraction
  • mul(other: Fraction | number): Fraction 乘法 Multiplication
  • div(other: Fraction | number): Fraction 除法 Division
  • pow(exponent: number): Fraction 幂 Exponentiation (exponent must be integer)
  • root(root: number): Fraction 开方 Root extraction (root must be integer)
  • mod(other: Fraction | number): Fraction 取余 Modulo
  • reduce(): void 约分 Reduce fraction
  • toNumber(): number 转为小数 Convert to number
  • toString(): string 字符串表示 String representation

构建与测试 Build & Test

# 构建 Build
npm run build

# 测试 Test
npm run test

github

To Github

许可证 License

MIT