New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easing-coordinates

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easing-coordinates - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

23

dist/index.js

@@ -1,14 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cubic_coordinates_1 = require("./lib/cubic-coordinates");
exports.cubicCoordinates = cubic_coordinates_1.cubicCoordinates;
const easing_map_1 = require("./lib/easing-map");
const shared = require("./lib/shared");
const steps_coordinates_1 = require("./lib/steps-coordinates");
exports.stepsCoordinates = steps_coordinates_1.stepsCoordinates;
import { cubicCoordinates } from './lib/cubic-coordinates';
import easingShorthandMap from './lib/easing-map';
import * as shared from './lib/shared';
import { stepsCoordinates } from './lib/steps-coordinates';
function easingCoordinates(easingFunction, hypotSize, incrementSize) {
const errorMsgStart = `Error parsing "${easingFunction}".`;
// If a shorthand like "ease-in" is provided then convert to equivalent cubic-bezier
if (easing_map_1.default[easingFunction]) {
easingFunction = easing_map_1.default[easingFunction];
if (easingShorthandMap[easingFunction]) {
easingFunction = easingShorthandMap[easingFunction];
}

@@ -29,3 +25,3 @@ // If we think it's a steps function

}
return steps_coordinates_1.stepsCoordinates(stepCount, stepSkip);
return stepsCoordinates(stepCount, stepSkip);
}

@@ -46,3 +42,3 @@ // If we think it's a cubic-bezier function

});
return cubic_coordinates_1.cubicCoordinates(x1, y1, x2, y2, hypotSize, incrementSize);
return cubicCoordinates(x1, y1, x2, y2, hypotSize, incrementSize);
}

@@ -55,3 +51,2 @@ // If it's not cubic bezier or steps it's not an easing function

}
exports.easingCoordinates = easingCoordinates;
exports.default = easingCoordinates;
export { stepsCoordinates, cubicCoordinates, easingCoordinates, easingCoordinates as default, };

@@ -1,4 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
import { cubicCoordinates, easingCoordinates, stepsCoordinates } from './index';
const cubicTest = [

@@ -115,37 +113,37 @@ { x: 0, y: 0 },

test('coordinates for "cubic-bezier(0.5, 0, 0.5, 1)"', () => {
expect(index_1.easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1)')).toEqual(cubicTest);
expect(easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1)')).toEqual(cubicTest);
});
test('coordinates for "cubic-bezier(0, 0, 0.5, 2)"', () => {
expect(index_1.easingCoordinates('cubic-bezier(0, 0, 0.5, 2)')).toEqual(cubicTest2);
expect(easingCoordinates('cubic-bezier(0, 0, 0.5, 2)')).toEqual(cubicTest2);
});
test('coordinates for "ease"', () => {
expect(index_1.easingCoordinates('ease')).toEqual(easeTest);
expect(easingCoordinates('ease')).toEqual(easeTest);
});
test('ease shorthand is the same as equivalent cubic-bezier', () => {
expect(index_1.easingCoordinates('ease-in-out')).toEqual(index_1.easingCoordinates('cubic-bezier(0.42, 0, 0.58, 1)'));
expect(easingCoordinates('ease-in-out')).toEqual(easingCoordinates('cubic-bezier(0.42, 0, 0.58, 1)'));
});
test('coordinates for "ease" with a bigger hypotSize shoul be fewer and further appart', () => {
expect(index_1.easingCoordinates('ease', 0.2)).toEqual(easeTestHypot);
expect(easingCoordinates('ease', 0.2)).toEqual(easeTestHypot);
});
test('easingCoordinates returns the same as cubicCoordinates', () => {
expect(index_1.easingCoordinates('cubic-bezier(0.42, 0, 0.58, 1)')).toEqual(index_1.cubicCoordinates(0.42, 0, 0.58, 1));
expect(easingCoordinates('cubic-bezier(0.42, 0, 0.58, 1)')).toEqual(cubicCoordinates(0.42, 0, 0.58, 1));
});
test('easingCoordinates returns the same as stepsCoordinates', () => {
expect(index_1.easingCoordinates('steps(4, skip-end)')).toEqual(index_1.stepsCoordinates(4, 'skip-end'));
expect(easingCoordinates('steps(4, skip-end)')).toEqual(stepsCoordinates(4, 'skip-end'));
});
test('coordinates for "steps(4, skip-end)"', () => {
expect(index_1.easingCoordinates('steps(4, skip-end)')).toEqual(stepTestEnd);
expect(easingCoordinates('steps(4, skip-end)')).toEqual(stepTestEnd);
});
test('coordinates for "steps(4)" - the default is "skip-end" as per spec', () => {
expect(index_1.easingCoordinates('steps(4)')).toEqual(stepTestEnd);
expect(easingCoordinates('steps(4)')).toEqual(stepTestEnd);
});
test('coordinates for "steps(4, skip-none)"', () => {
expect(index_1.easingCoordinates('steps(4, skip-none)')).toEqual(stepTestNone);
expect(easingCoordinates('steps(4, skip-none)')).toEqual(stepTestNone);
});
test('coordinates for "steps(4, skip-both)"', () => {
expect(index_1.easingCoordinates('steps(4, skip-both)')).toEqual(stepTestBoth);
expect(easingCoordinates('steps(4, skip-both)')).toEqual(stepTestBoth);
});
test('old and new steps syntax should yield the same', () => {
expect(index_1.easingCoordinates('steps(4, skip-end)')).toEqual(index_1.easingCoordinates('steps(4, end)'));
expect(index_1.easingCoordinates('steps(2, skip-start)')).toEqual(index_1.easingCoordinates('steps(2, start)'));
expect(easingCoordinates('steps(4, skip-end)')).toEqual(easingCoordinates('steps(4, end)'));
expect(easingCoordinates('steps(2, skip-start)')).toEqual(easingCoordinates('steps(2, start)'));
});

@@ -157,3 +155,3 @@ /*

function incorrectInput() {
index_1.easingCoordinates('steps()');
easingCoordinates('steps()');
}

@@ -164,3 +162,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('steps(4, skip-end, 3)');
easingCoordinates('steps(4, skip-end, 3)');
}

@@ -171,3 +169,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('steps(skip-end, 4)');
easingCoordinates('steps(skip-end, 4)');
}

@@ -178,3 +176,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('steps(4, 4)');
easingCoordinates('steps(4, 4)');
}

@@ -185,3 +183,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('steps(4, skip-forward)');
easingCoordinates('steps(4, skip-forward)');
}

@@ -192,3 +190,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('cubic-bezier(0.5, 0, 0.5)');
easingCoordinates('cubic-bezier(0.5, 0, 0.5)');
}

@@ -199,3 +197,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1, 1)');
easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1, 1)');
}

@@ -206,3 +204,3 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('cubic-bezier(0.5, hello, 0.5, 1)');
easingCoordinates('cubic-bezier(0.5, hello, 0.5, 1)');
}

@@ -213,5 +211,5 @@ expect(incorrectInput).toThrowError();

function incorrectInput() {
index_1.easingCoordinates('funky(0.5, 0.5, 0.5, 1, 1)');
easingCoordinates('funky(0.5, 0.5, 0.5, 1, 1)');
}
expect(incorrectInput).toThrowError();
});

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const BezierEasing = require("bezier-easing");
const shared = require("./shared");
function cubicCoordinates(x1, y1, x2, y2, hypotSize = 0.1, incrementSize = 0.001) {
import * as BezierEasing from 'bezier-easing';
import * as shared from './shared';
export function cubicCoordinates(x1, y1, x2, y2, hypotSize = 0.1, incrementSize = 0.001) {
const bezier = BezierEasing(x1, y1, x2, y2);

@@ -44,2 +42,1 @@ let x = 0;

}
exports.cubicCoordinates = cubicCoordinates;

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const easeMap = {

@@ -9,2 +7,2 @@ ease: 'cubic-bezier(0.25, 0.1, 0.25, 1)',

};
exports.default = easeMap;
export { easeMap as default };

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const getParenthesisContent = (str) => {

@@ -11,11 +9,11 @@ return str

const convertToNumberMaybe = (str) => Number.isNaN(Number(str)) ? str : Number(str);
exports.roundToMaxTenDecimals = (num) => Number(`${+num.toFixed(10)}`);
exports.getCoordinate = (x, y) => {
export const roundToMaxTenDecimals = (num) => Number(`${+num.toFixed(10)}`);
export const getCoordinate = (x, y) => {
return {
x: exports.roundToMaxTenDecimals(x),
y: exports.roundToMaxTenDecimals(y),
x: roundToMaxTenDecimals(x),
y: roundToMaxTenDecimals(y),
};
};
exports.getFunctionArguments = (functionAsString) => {
export const getFunctionArguments = (functionAsString) => {
return getParenthesisContent(functionAsString).map(arg => convertToNumberMaybe(arg));
};

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const shared = require("./shared");
function stepsCoordinates(steps, skip = 'skip-end') {
import * as shared from './shared';
export function stepsCoordinates(steps, skip = 'skip-end') {
const coordinates = [];

@@ -32,2 +30,1 @@ let n = 0;

}
exports.stepsCoordinates = stepsCoordinates;
{
"name": "easing-coordinates",
"version": "1.0.0",
"description": "Utility script that takes an easing function as input and outputs a coordinate set with adjustable precision/resolution.",
"version": "1.0.1",
"description":
"Utility script that takes an easing function as input and outputs a coordinate set with adjustable precision/resolution.",
"main": "dist/index.js",

@@ -9,6 +10,8 @@ "types": "dist/index.d.ts",

"test": "jest",
"test-ci": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test-ci":
"jest --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coverage": "jest --coverage",
"build": "tsc",
"dev": "tsc -w"
"dev": "tsc -w",
"precommit": "pretty-quick --staged"
},

@@ -19,6 +22,3 @@ "repository": {

},
"keywords": [
"easing-functions",
"javascript"
],
"keywords": ["easing-functions", "javascript"],
"author": "Andreas Larsen <andreas@larsenwork.com> (https://larsenwork.com)",

@@ -37,4 +37,6 @@ "license": "MIT",

"coveralls": "^3.0.0",
"husky": "^0.14.3",
"jest": "^22.4.2",
"prettier": "^1.11.1",
"pretty-quick": "^1.4.1",
"ts-jest": "^22.4.2",

@@ -41,0 +43,0 @@ "tslint": "^5.9.1",

@@ -5,15 +5,93 @@ <h1 align="center">Easing Coordinates</h1>

<a href="https://travis-ci.org/larsenwork/easing-coordinates">
<img alt="Travis" src="https://img.shields.io/travis/larsenwork/easing-coordinates.svg?style=flat-square">
<img alt="Travis" src="https://travis-ci.org/larsenwork/easing-coordinates.svg?branch=master">
</a><a href="https://coveralls.io/github/larsenwork/easing-coordinates?branch=master">
<img alt="Code coverage" src="https://coveralls.io/repos/github/larsenwork/easing-coordinates/badge.svg?branch=master">
</a><a href="https://www.npmjs.com/package/easing-coordinates">
<img alt="npm version" src="https://img.shields.io/npm/v/easing-coordinates.svg">
</a><a href="https://www.npmjs.com/package/easing-coordinates">
<img alt="monthly downloads" src="https://img.shields.io/npm/dm/easing-coordinates.svg">
</a><a href="https://github.com/larsenwork/easing-coordinates/blob/master/LICENSE">
<img alt="MIT License" src="https://img.shields.io/github/license/larsenwork/easing-coordinates.svg">
</a><a href="https://github.com/prettier/prettier">
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg">
</a><a href="https://twitter.com/larsenwork">
<img alt="Follow Larsenwork on Twitter" src="https://img.shields.io/twitter/follow/larsenwork.svg?label=follow+larsenwork">
</a>
<a href="https://coveralls.io/github/larsenwork/easing-coordinates?branch=master">
<img alt="Code coverage" src="https://img.shields.io/coveralls/github/larsenwork/easing-coordinates/master.svg?style=flat-square">
</a>
<a href="https://github.com/prettier/prettier">
<img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square">
</a>
<a href="https://twitter.com/larsenwork">
<img alt="Follow+Larsenwork+on+Twitter" src="https://img.shields.io/twitter/follow/larsenwork.svg?label=follow+larsenwork&style=flat-square">
</a>
</p>
Utility script that takes an easing function as input and outputs a coordinate set with adjustable precision/resolution.
## Usage
The easingCoordinates function takes steps and cubic-bezier [single-transition-timing-functions](https://developer.mozilla.org/en-US/docs/Web/CSS/single-transition-timing-function) as input and returns a set of "low-poly" xy-coordinates.
```js
import { easingCoordinates } from 'easing-coordinates'
easingCoordinates('cubic-bezier(0.5, 0, 0.5, 1)')
/* =>
[
{ x: 0, y: 0 },
{ x: 0.099, y: 0.0143172435 },
{ x: 0.189, y: 0.0569704145 },
{ x: 0.265, y: 0.1207430791 },
{ x: 0.329, y: 0.1976360165 },
{ x: 0.384, y: 0.281541323 },
{ x: 0.433, y: 0.3687643431 },
{ x: 0.479, y: 0.4580875338 },
{ x: 0.524, y: 0.547869462 },
{ x: 0.57, y: 0.6368561714 },
{ x: 0.619, y: 0.7234436574 },
{ x: 0.674, y: 0.8064697166 },
{ x: 0.738, y: 0.8823204807 },
{ x: 0.815, y: 0.9456314885 },
{ x: 0.906, y: 0.9871537401 },
{ x: 1, y: 1 },
]
*/
easingCoordinates('steps(4)')
/* =>
[
{ x: 0, y: 0 },
{ x: 0.25, y: 0 },
{ x: 0.25, y: 0.25 },
{ x: 0.5, y: 0.25 },
{ x: 0.5, y: 0.5 },
{ x: 0.75, y: 0.5 },
{ x: 0.75, y: 0.75 },
{ x: 1, y: 0.75 },
]
*/
```
Use `stepsCoordinates` and `cubicCoordinates` methods directly depending on your data:
```js
import { cubicCoordinates, easingCoordinates, stepsCoordinates } from './index'
easingCoordinates('cubic-bezier(0.42, 0, 0.58, 1)') == cubicCoordinates(0.42, 0, 0.58, 1)
easingCoordinates('steps(4, skip-end)') == stepsCoordinates(4, 'skip-end')
```
Increase hypotSize (default = 0.1) to get a "lower-poly" version of your cubic-bezier functions and make sure incrementSize is always smaller than hypotSize.
```ts
interface ICoordinate {
x: number
y: number
}
function easingCoordinates(easingFunction: string, hypotSize?: number, incrementSize?: number): ICoordinate[]
function stepsCoordinates(steps: number, skip = 'skip-end'): ICoordinate[]
function cubicCoordinates(x1: number, y1: number, x2: number, y2: number, hypotSize = 0.1, incrementSize = 0.001): ICoordinate[]
```
## Build
```bash
# Checkout and then
npm install
# Compile and watch the .ts files
npm run dev
# Run test
npm run test
```
## PRs, suggestions, etc.
Are very welcome 🤗
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc