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

tween-base

v2.2.2

Published

a basic tween object for others to build on

Downloads

591

Readme

tween-base

unstable

This is a base class for tween types, built alongside tweenr and tween-ticker. It is not inherently tied to those modules, and may prove useful outside of those environments.

Usually you won't require tween-base itself, but the modules that build on top of it. Example:

var array = require('tween-array')
var ticker = require('tween-ticker')

var start = [25, 15],
    end = [10, 10]

ticker.push(array(start, end, { duration: 2 }))
    .on('complete', function(ev) {
        console.log("result:", ev.target)
    })

Usage

NPM

This describes the public (user-facing) API for tweens.

tween = BaseTween(opt)

Where options usually describes the following:

  • delay in time units, default 0
  • duration in time units, default 0
  • ease is an easing function -- tween engines may want to allow strings for user friendliness

methods

cancel()

Cancels a tween. Returns this for chaining. Next time this tween is ticked, it will:

  • emit a "cancelling" event
  • become inactive and stop updating the target
  • emit a "complete" event

A ticker engine might then choose to remove the tween from the queue.

members

tween.on(event, func)

A tween is an event emitter with the following events:

  • start triggered when the tween is first started
  • cancelling triggered before the tween completes, initiating from a call to cancel()
  • complete triggered when the tween is completed
  • update triggered after the tween updates its values

--

inheriting

See test/array.js for an example of a custom array interpolation.

Implementors might subclass like so:

var Base = require('tween-base')
var inherits = require('inherits')

function MyTween(target, opt) {
    Base.call(this, opt)
    this.target = target
}

inherits(MyTween, Base)

//called before 'start' event 
MyTween.prototype.ready = function() {
    //this is where you might store the current
    //state of "target" so that you can interpolate
    //from start to end
}

MyTween.prototype.lerp = function(alpha) {
    //interpolate "target" from start to end using alpha
}

License

MIT, see LICENSE.md for details.