
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@okiba/math
Advanced tools
Collection of math functions
__
npm i --save @okiba/math
Or import it directly in the browser
<script type="module" src="https://unpkg.com/@okiba/math/index.js"></script>
import math from '@okiba/math'
Okiba Core packages are not transpiled, so don't forget to transpile them with your favourite bundler. For example, using Babel with Webpack, you should prevent imports from okiba to be excluded from transpilation, like follows:
{
test: /\.js$/,
exclude: /node_modules\/(?!(@okiba)\/).*/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
Linear interpolation between a two values
import {lerp} from '@okiba/math'
const xPosition = lerp(0, 100, 0.5)
console.log(xPosition) // 50
min
: Number
Minimum possible value
max
: Number
Maximum possible value
fraction
: Number
Current position
Number
The interpolated value
Maps a value between two ranges
import {map} from '@okiba/math'
const x = map(0.5, 0, 1, 0, 1000)
console.log(x) // 500
const y = map(0, -1, 1, -1000, 1000)
console.log(y) // 0
n
: Number
Value to map
min1
: Number
Source range minimum
max1
: Number
Source range maximum
min2
: Number
Target range minimum
max2
: Number
Target range maximum
Number
Mapped value
Limit a value between a min and a max (inclusive)
import {cap} from '@okiba/math'
let progress = 1.1
progress = cap(0, 1, progress)
console.log(progress) // 1
n
: Number
Value to cap
min
: Number
Minimum possible value
max
: Number
Maximum possible value
Number
Capped value
Distance between two numbers
import {distance} from '@okiba/math'
const x1 = -100, x2 = 100
const d = distance(x1, x2)
console.log(d) // 200
x1
: Number
First number
x2
: Number
Second number
Number
Distance between the values
Round a number with given precision, with memoized powers
import {round} from '@okiba/math'
const rounded = distance(1.111111, 3)
console.log(rounded) // 1.111
n
: Number
Number to round
p
: Number
| optional - default: 3
Precision of digits to leave
Number
Rounded number
FAQs
Math functions used in okiba.js
We found that @okiba/math demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.