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 🙏

© 2025 – Pkg Stats / Ryan Hefner

cubic-bezier-timing-function

v0.3.1

Published

cubic bezier timing function generator

Readme

cubic-bezier-timing-function

三次贝塞尔计时函数

Usage

创建一条三次贝塞尔曲线,需要提供4个点P0、P1、P2、P3。计时函数所对应的贝塞尔曲线的P0和P3是确定的,分别为P0(0, 0)和P3(1, 1),我们只需提供P1(x1, y1)和P2(x2, y2)。
We need 4 points to create a bezier curve. The bezier curve corresponding to the timing function has established P0(0, 0) and P3(1, 1). We need to provide the other 2 points P1(x1, y1) and P2(x2, y2).

// @param {number} x1  
// @param {number} y1  
// @param {number} x2  
// @param {number} y2  
// @param {number} precision 近似解的精度,默认值为 0.00001。
// The precision of the calculation. It is not necessary and has a default value 0.00001.  
cubicBezierTimingFunction(x1, y1, x2, y2, precision)

// cubicBezierTimingFunction(0.4, 0.3, 0.9, 1.2)  
// cubicBezierTimingFunction(0.4, 0.3, 0.9, 1.2, 0.0001)    



// @param {string} presetName 预设方案名称。  
// 'linear': [0, 0, 1, 1],  
// 'ease': [0.25, 0.1, 0.25, 1],  
// 'ease-in': [0.42, 0, 1, 1],  
// 'ease-out': [0, 0, 0.58, 1],  
// 'ease-in-out': [0.42, 0, 0.58, 1]  
// @param {number} precision 近似解的精度,默认值为 0.00001。
// The precision of the calculation. It is not necessary and has a default value 0.00001.  
cubicBezierTimingFunction(presetName, precision)

// cubicBezierTimingFunction('linear')  
// cubicBezierTimingFunction('linear', 0.000001)  
import cubicBezierTimingFunction from 'cubic-bezier-timing-function'

let timingFn = cubicBezierTimingFunction('ease')

let duration = 2000   // 动画时长,单位ms。 animation duration in milliseconds.
let startTime

function update() {
  if (!startTime) {
    startTime = Date.now()
  }

  let x = (Date.now() - startTime) / duration
  let y = timingFn(x)

  // 使用 y 值去更新其他值或视图
  // update something with y

  if (x < 1) {
    requestAnimationFrame(update)
  }
}

update()