Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
curve-store
Advanced tools
A store for dealing with continuous values. Useful for complex animations. Continue reading for background and example usage. Click here for a demo.
The idea for this module came from discussions with @mikolalysenko. Credit largely goes to him. See filtered-vector for prior art.
Curve store is a state container that intelligently deals with mapping discrete values to a continuous curve. Its primary intended use case is for dealing with complex animations over time, though there may be other applications.
The idea is that animation can be defined as a series of positions over time:
given an object at position x, y
at time t
, we should be able to define an
animation by promising that the object will be at some other position x', y'
at
some future time t'
, and infer the points along the path.
This is what curve-store
gives you, a way to define state at a given time:
store.set(currentTime, { x: x, y: y});
store.set(currentTime + 1000, { x: xprime, y: yprime});
and a way to sample points in between:
store.sample(currentTime + 500);
// give { x: xval, y: yval } interpolated based on the points set above
Users can define how they want the interpolation to be handled. There are a few built in helpers, for example:
import { createStore } from 'curve-store';
import { linear } from 'curve-store/samplers';
const store = createStore({
x: linear('x'),
y: linear('y')
})
defines basic linear interpolation. There are also calculus functions to help build out more complicated curves:
import { createStore } from 'curve-store';
import { linear, derivative, integral } from 'curve-store/samplers';
const store = createStore({
position: {
x: linear('x'),
y: linear('y')
},
velocity: {
x: derivative('x'),
y: derivative('y')
},
acceleration: {
x: derivative(derivative('x')),
y: derivative(derivative('y'))
},
distance: {
x: integral('x'),
y: integral('y')
}
});
You can also provide custom sampling functions, to get e.g. different easing curves (see below for more details).
$ npm install --save curve-store
import { createStore } from 'curve-store';
import { linear, derivative } from 'curve-store/samplers';
const store = createStore({
x: linear('x'),
dx: derivative('x')
});
store.set(0, { x: 0 });
store.set(1, { x: 1 });
store.sample(0.25);
// --> { x: 0.25, dx: 1.0 }
createStore(samplers)
Creates a new curve-store
that maps discrete input values onto a set
of continuous output values. The samplers object defines this mapping and defines
how to interpolate between points.
Basic usage:
const store = createStore({
outputX: linear('inputX')
});
store.set(time, values)
Set values at a particular point in time.
Example:
store.set(0, { inputX: 0 });
store.set(1, { inputX: 0 });
Sample points at a particular time.
Example:
store.sample(0.5);
// -> outputs { outputX: 0.5 }
The way that sampling occurs is defined based on the samplers object passed
to createStore
.
import { createStore } from 'create-store';
import { getPointBefore, getPointAfter } from 'create-store/utils';
const store = createStore({
myKey: (t, state) => {
const before = getPointBefore(state.myKey, t);
// { time: 0, value: 0 }
const after = getPointAfter(state.myKey, t);
// { time: 1, value: 1}
// Insert custom sampling code here
return customVal;
}
});
store.set(0, { myKey: 0 });
store.set(1, { myKey: 1 });
store.sample(0.25);
// { myKey: customVal }
// Empties the store.
store.clear();
// Removes all values before time t
store.clearBefore(t);
// Removes all values after time t
stores.clearAfter(t);
MIT
FAQs
Redux-inspired store for dealing with continuous values
We found that curve-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.