
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
number-unit
Advanced tools
A heavily tested JavaScript component to handle arbitrary precision numbers with units.
A number without context (unit) is meaningless. Even more so in the realm of computers. Computers rely on input, usually from humans, to be precise. Humans are prone to error. This library helps to remove that error.
Consider these two famous incidents...
From https://en.wikipedia.org/wiki/Mars_Climate_Orbiter:
However, on September 23, 1999, communication with the spacecraft was lost as the spacecraft went into orbital insertion, due to ground-based computer software which produced output in non-SI units of pound-seconds (lbf s) instead of the metric units of newton-seconds (N s) specified in the contract between NASA and Lockheed. The spacecraft encountered Mars on a trajectory that brought it too close to the planet, causing it to pass through the upper atmosphere and disintegrate.
From https://en.wikipedia.org/wiki/Gimli_Glider:
...ran out of fuel at an altitude of 12,500 metres (41,000 ft) MSL, about halfway through its flight originating in Montreal to Edmonton. The crew were able to glide the aircraft safely to an emergency landing at Gimli Industrial Park Airport, a former Royal Canadian Air Force base in Gimli, Manitoba.[1]
The subsequent investigation revealed a combination of company failures and a chain of human errors that defeated built-in safeguards. Fuel loading was miscalculated because of a misunderstanding of the recently adopted metric system which replaced the imperial system.
If you're writing software that handles people's money, you can't afford to be wrong. That's why this library was built.
npm i --save number-unit
Quick example:
// import { UnitType } from 'number-unit' // if using ES6 (ES2015)
var UnitType = require('number-unit').UnitType
// create a UnitType first
var bitcoin = UnitType.create('bitcoin', { satoshis: 1, bits: 1e2, BTC: 1e8 }, 'bits')
// now create a NumberUnit
var amount1 = bitcoin.BTC(1.53)
var amount2 = bitcoin.bits('1530000') // notice, can accept strings as well
console.log(amount1.toString()) // => 1.53 BTC
console.log(amount2.toString()) // => 1530000 bits
// compare numerical values
console.log(amount1.equals(amount2)) // => true
You must use UnitType.create() to create a UnitType() to start working with
NumberUnits.
UnitTypes can be a type of other UnitTypes. For example, you may create
a UnitType named distance, and then want to create another named distanceSI
representing your desire to model SI / Metric Units.
Now you may want to create another named distanceUS, modeling
United States customary units. Since both
have distance has a parent type, you can convert between the two. This is the value
of parent types. As it wouldn't make sense to convert from distance to currency or something
lie that. See for some examples: https://github.com/jprichardson/number-unit
UnitType.create(label, [parentUnitType], [definitions], [defaultUnit])
Creates an instance of UnitType and returns it.
label: The unit type label.parentUnitType: The parent unit type. Useful for converting between UnitType that have the same parent.definitions: Actual conversions.defaultUnit: Default unit. Used when defaultUnit is called.[instanceof UnitType].parse(string)
Method that parses the input string and returns an instance of NumberUnit with
a number value extracted from the string and a unitName from the string.
var amount = bitcoin.parse('1.53 BTC')
console.log(amount.toNumber()) // => 1.53
console.log(amount.unitName) // => BTC
[instanceof UnitType].ZERO
Property that creates and returns an instance of NumberUnit with a number value of 0 and a
the unit being the default unit.
var zero = bitcoin.ZERO
console.log(amount.toNumber()) // => 0
console.log(amount.unitName) // => bits
FAQs
Numbers with units.
We found that number-unit demonstrated a not healthy version release cadence and project activity because the last version was released 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
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.