
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
fractions-math
Advanced tools
Implementing fractions module from The Python Standard Library on TypeScript
Implementing fractions
module from The Python Standard Library on TypeScript.
npm i fractions-math
yarn add fractions-math
import { Fraction, fraq } from "fractions-math"
const f1 = new Fraction(1, 2)
const f2 = fraq(1.5)
const f3 = f1.add(f2).toString() // -> "2" (0.5 + 1.5)
const f4 = f3.mul(f2).toString() // -> "3" (2 * 1.5)
const f5 = f4.div(f1).toString() // -> "6" (3 / 0.5)
type Fraq = Fraction | [number, number] | number | string
fraq(val: Fraq)
Helper function to create fraction from various inputs.
fraq(2).toPair() // -> [2, 1]
fraq([2, 1]).toPair() // -> [2, 1]
fraq(0.5).toPair() // -> [1, 2]
fraq("1/2").toPair() // -> [1, 2]
new Fraction(n: number, d = 1, reduce = false)
Creates a fraction taking two numbers – numenator and denominator. Denominator has default value 1
. By default, the fraction is reduced to the minimum form.
new Fraction(1, 2).toPair() // -> [1, 2]
new Fraction(2).toPair() // -> [2, 1]
new Fraction(5, 10).toPair() // -> [5, 10]
new Fraction(5, 10, true).toPair() // -> [1, 2]
.toString()
fraq(1, 2).toString() // -> "1/2"
fraq(3, 3).toString() // -> "3"
fraq(-1).toString() // -> "-1"
fraq(1, -2).toString() // -> "-1/2"
.toNumber()
fraq(1, 2).toString() // -> 0.5
.reduce()
fraq(5, 10).reduce().toPair() // -> [1, 2]
.limit(max: number = 10_000)
Finds the closest Fraction that has denominator at most max
.
fraq(Math.PI).limit(1000).toString() // -> "355/113"
fraq(1.1).limit().toString() // -> "11/10"
.add(b: Fraq)
fraq(1, 2).add([-1, 2]).toString() // -> "0"
fraq(1, 2).add(1).toString() // -> "3/2"
.sub(b: Fraq)
fraq(1, 2).sub([1, 2]).toString() // -> "0"
fraq(1, 2).sub(1).toString() // -> "-1/2"
.mul(b: Fraq)
fraq(1, 2).mul([1, 2]).toString() // -> "1/4"
fraq(1, 2).mul(1.5).toString() // -> "3/4"
.div(b: Fraq)
fraq(1, 2).div([1, 2]).toString() // -> "1"
fraq(1, 2).div(1.5).toString() // -> "1/3"
fraq(1, 2).div(0).toString() // throws Error
.eq(b: Fraq)
fraq(1, 2).eq(0.5) // -> true
fraq(1, 2).eq([1, 3]) // -> false
.lt(b: Fraq) -> boolean
.lte(b: Fraq) -> boolean
.gt(b: Fraq) -> boolean
.gte(b: Fraq) -> boolean
.toAscii(limit=16)
fraq(0.5).toUnicode() // -> "1/2"
fraq([1, 64]).toUnicode() // -> "0"
fraq([1, 64]).toUnicode(64) // -> "1/64"
.toUnicode()
fraq(0.5).toUnicode() // -> "½"
fraq([1, 64]).toUnicode() // -> "0"
fraq([1, 64]).toUnicode(64) // -> "¹⁄₆₄"
FAQs
Implementing fractions module from The Python Standard Library on TypeScript
The npm package fractions-math receives a total of 92 weekly downloads. As such, fractions-math popularity was classified as not popular.
We found that fractions-math demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.