Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
num2fraction
Advanced tools
The num2fraction npm package is designed to convert decimal numbers to their simplest fractional representation. This can be particularly useful in applications that require displaying numbers in a more human-readable form, such as in cooking recipes or mathematical education tools.
Decimal to Fraction Conversion
This feature allows you to convert a decimal number to its simplest fractional form. The code sample demonstrates converting the decimal numbers 0.5 and 1.75 to their fractional representations, '1/2' and '7/4' respectively.
const num2fraction = require('num2fraction');
console.log(num2fraction(0.5)); // Outputs: '1/2'
console.log(num2fraction(1.75)); // Outputs: '7/4'
Fraction.js is a package that not only converts decimals to fractions but also provides a comprehensive set of operations for fractions, such as addition, subtraction, multiplication, and division. It offers more extensive functionality compared to num2fraction, which focuses solely on conversion.
Converting Number to Fraction with Node.js.
npm install num2fraction
var π = Math.PI
var n2f = require('num2fraction')
console.log(n2f(0)) // => 0
console.log(n2f(.2)) // => 1/5
console.log(n2f(1.1)) // => 11/10
console.log(n2f(1.2)) // => 6/5
console.log(n2f(1.3)) // => 13/10
console.log(n2f(1.4)) // => 7/5
console.log(n2f(1.5)) // => 3/2
console.log(n2f(2)) // => 2/1
console.log(n2f(2.1)) // => 21/10
console.log(n2f(3)) // => 3/1
console.log(n2f(2.555)) // => 511/200
console.log(n2f(8.36)) // => 209/25
console.log(n2f('3em')) // => 3/1
console.log(n2f('1.5px')) // => 3/2
console.log(num2fraction(7 / 9) // => 7/9
console.log(num2fraction(8 / 9) // => 8/9
console.log(num2fraction(512 / 999) // => 512/999
console.log(num2fraction((2 * π / 3) / π) // => 2/3
console.log(num2fraction((8 * 5) / (4 / 2)) // => 20/1
Opera old versions support the non-standard -o-min-device-pixel-ratio
or -o-max-device-pixel-ratio
in CSS media queries.
@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and ( min--moz-device-pixel-ratio: 2),
only screen and ( -o-min-device-pixel-ratio: 2/1), /* Opera */
only screen and ( min-device-pixel-ratio: 2),
only screen and ( min-resolution: 192dpi), /* fallback */
only screen and ( min-resolution: 2dppx) {
}
First release.
FAQs
Convert number to fraction
We found that num2fraction 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.