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

interpolation-builder

v2.1.0

Published

Using interpolation-builder you can build interpolation functions for objects and arrays

Downloads

167

Readme

interpolation-builder

experimental

Using interpolation-builder you can build interpolation functions for objects and arrays. By default lerp is used but you can drop in custom interpolation functions also.

Usage

NPM

Example

var builder = require( 'interpolation-builder' );

var lerper = build( {
  
  x: null, // will use linear interpolation
  sub: {

    x: function( percentage, start, end ) {

      return 'value is: ' + ( ( end - start ) * percentage + start );
    }
  } 
});

var start = {
    
  x: 0,
  sub: {
    x: 0
  }
};

var end = {
    
  x: 100,
  sub: {
    x: 100
  }
};

console.log( lerper( 0.5, start, end ) ); // { x: 50, sub: { x: 'value is: 50' } }

Example with Objects using sub and map functions

var builder = require( 'interpolation-builder' );

var lerper = builder();

lerper.map( [ 'x', 'y' ] ) // <- use default lerp for these properties
      .map( 'z', customInterpolation1 ) // <- custom interpolation for one prop
      .map( [ 'u', 'v' ], customInterpolation2 ); // <- custom for two props

var start = { x: 0, y: 0, z: 0, u: 0, v: 0 };
var end = { x: 100, y: 150, z: 100, u: 100, v: 200 };

console.log( lerper( 0.5, start, end ) ); // { x: 50, y: 75, z: 'c1 50', u: 'c2 50', v: 'c2 100' }

function customInterpolation1( time, start, end ) {

  return 'c1 ' + ( ( end - start ) * time + start );
}

function customInterpolation1( time, start, end ) {

  return 'c2 ' + ( ( end - start ) * time + start );
}

Example with Arrays

var builder = require( 'interpolation-builder' );

var lerper = builder();

lerper.map( [ 0, 1, 2 ] ); // <- use default lerp for these properties

var start = [ 0, 0, 0 ];
var end = [ 100, 200, 300 ];

console.log( lerper( 0.5, start, end ) ); // [ 50, 100, 150 ]

Example with sub/child objects

var start = {

  inner: {
    x: 0,
    y: 0
  }
};

var end = {

  inner: {
    x: 104,
    y: 100
  }
};

var animator = interpolator();

animator.sub( 'inner' )
        .map( [ 'x', 'y' ] );

animator( 0, start, end ); // { inner: { x: 52, y: 50 } }

License

MIT, see LICENSE.md for details.