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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ui-calc

v1.0.1

Published

A library of interface calculators.

Downloads

3

Readme

UI Calculators

A library of interface calculators.

Use

Install

npm install ui-calc --save

Import

import { angle } from 'ui-calc';

API

angle()

Calculate the angle between two 2D points, in radians

const a = { x: 0, y: 0 };
const b = { x: 45, y: 45 };

angle(a, b); // 0.7853981633974483

Radians can be converted to degrees using radiansToDegrees().

degreesToRadians()

Convert degrees to radians

degreesToRadians(45); // 0.7853981633974483 

dilate()

Dilate the difference between two sequential values.

(a, b, dilationFactor)

const a = 10;
const b = 20;

dilate(a, b, 1); // 20 (no change)
dilate(a, b, 0.5); // 15
dilate(a, b, 2); // 30

distance()

Calculate the difference between two n-dimensional points (max 3)

distance(100, -500); // 600
distance({ x: 0, y: 0}, { x: 45, y: 45 }); // 63.639
distance({ x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 10 }); // 10

hypotenuse()

Calculate the hypotenuse of a triangle, given the length of sides A and B

hypotenuse(30, 50); // 58.31

getProgressFromValue()

Return a progress given a value and a range

const value = 500;
const min = 0;
const max = 1000;

getProgressFromValue(value, min, max); // 0.5

getValueFromProgress()

Return a value given a progress (0-1) and a range

const progress = 0.25;
const min = 100;
const max = 500;

getValueFromProgress(progress, min, max); // 200

offset()

Calculate the offset between two objects of numerical properties

const a = { foo: 5 };
const b = { foo: 15, bar: 20 };

offset(a, b); // { foo: 10, bar: 0 }

pointFromAngleAndDistance()

Calculate new 2D point given an origin point, angle and distance

const origin = { x: 100, y: 200 };
const angle = 45;
const distance = 100;

pointFromAngleAndDistance(origin, angle, distance);
/*
    Returns:
        {
            x: 170.71067811865476,
            y: 270.71067811865476
        }
*/

radiansToDegrees()

Convert a value from radians to degrees

radiansToDegrees(0.7853981633974483); // 45

relativeValue()

Calculates a relative value (ie "+=50") as applied to a numerical value

Valid operators are +, -, / and *.

relativeValue(50, '+=5'); // 55
relativeValue(50, '*=2'); // 100

random()

Generates a random number, optionally within a range

random(); // Random number between 0 and 1
random(15, 30); // Random number between 15 and 30

restrict()

Restricts the provided value to within the provided range

const value = 2000;
const min = 0;
const max = 1000;

restrict(value, min, max); // 1000

smooth()

Smooth a value between its old and new values over a duration of time

const newValue = 100;
const oldValue = 50;
const frameDuration = 16.667;
const noSmoothing = 0;
const heavySmoothing = 100;

smooth(newValue, oldValue, frameDuration, noSmoothing); // 100
smooth(newValue, oldValue, frameDuration, heavySmoothing); // 60.41

speedPerFrame()

Calculate speed per frame given speed per second and frame duration

const speedPerSecond = 300;
const frameDuration = 16;

speedPerFrame(speedPerSecond, frameDuration); // 4.8

speedPerSecond()

Calculate speed per second given speed per frame and frame duration

const speedPerFrame = 10;
const frameDuration = 16;

speedPerSecond(speedPerFrame, frameDuration); // 625