Skip to content

Commit

Permalink
migrates to babel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
chrvadala committed Apr 5, 2019
1 parent ad858eb commit 64fb187
Show file tree
Hide file tree
Showing 29 changed files with 2,881 additions and 1,996 deletions.
27 changes: 0 additions & 27 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ os:
- osx

node_js:
- "6"
- "8"
- "10"
- "lts/*"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ Warning: This should be considered BETA until it is released a stable version of
- **1.13**- Adds `compose` function, Upgrades deps, Exposes skew operation [#37](https://github.com/chrvadala/transformation-matrix/pull/37)
- **1.14**- Adds support for points defined as `Array` in the form `[x, y]` [#38](https://github.com/chrvadala/transformation-matrix/pull/38)
- **1.15**- Adds `fromTriangle` and `smoothMatrix` functions [#41](https://github.com/chrvadala/transformation-matrix/issues/41)
- **2.0**- Migrates to Babel 7 and updates dependencies

## Some projects using transformation-matrix
- [**React Planner**](https://github.com/cvdlab/react-planner)
Expand Down
1 change: 1 addition & 0 deletions README.template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ available at [http://chrvadala.github.io/transformation-matrix/](http://chrvadal
- **1.13**- Adds `compose` function, Upgrades deps, Exposes skew operation [#37](https://github.com/chrvadala/transformation-matrix/pull/37)
- **1.14**- Adds support for points defined as `Array` in the form `[x, y]` [#38](https://github.com/chrvadala/transformation-matrix/pull/38)
- **1.15**- Adds `fromTriangle` and `smoothMatrix` functions [#41](https://github.com/chrvadala/transformation-matrix/issues/41)
- **2.0**- Migrates to Babel 7 and updates dependencies

## Some projects using transformation-matrix
- [**React Planner**](https://github.com/cvdlab/react-planner)
Expand Down
17 changes: 17 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function (api) {
api.cache(true)

return {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 8
}
}
]
],
plugins: []
}
}
44 changes: 20 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,30 @@
"description": "2d transformation matrix functions written in ES6 syntax. Tree shaking ready!",
"main": "./build-commonjs/index.js",
"typings": "transformation-matrix.d.ts",
"module": "./build-es/index.js",
"jsnext:main": "./build-es/index.js",
"module": "./src/index.js",
"jsnext:main": "./src/index.js",
"unpkg": "./build-umd/transformation-matrix.min.js",
"files": [
"*.md",
"build-*",
"src",
"tests",
"transformation-matrix.d.ts",
".babelrc"
"babel.config.js"
],
"scripts": {
"coverage": "jest --coverage --coveragePathIgnorePatterns autogenerated",
"coveralls": "jest --coverage --coveragePathIgnorePatterns autogenerated --coverageReporters=text-lcov | coveralls",
"test:ci": "npm-run-all standard test build coveralls",
"test": "jest",
"build-commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir build-commonjs",
"build-es": "cross-env BABEL_ENV=es babel src --out-dir build-es",
"build-commonjs": "babel src --out-dir build-commonjs",
"build-docs": "jsdoc2md --partial disclaimer.hbs --template README.template.hbs src/*.js > README.md",
"build-umd-min": "cross-env BABEL_ENV=es webpack --config ./webpack-umd.config.js --env.minimize",
"build-umd": "cross-env BABEL_ENV=es webpack --config ./webpack-umd.config.js",
"build-umd-min": "webpack --config ./webpack-umd.config.js --env.minimize",
"build-umd": "webpack --config ./webpack-umd.config.js",
"build-parser": "pegjs -o src/fromTransformAttribute.autogenerated.js --format es src/fromTransformAttribute.pegjs",
"clean": "del build-*",
"version": "npm-run-all clean test build add-readme-to-vcs",
"build": "npm-run-all clean build-commonjs build-es build-docs build-umd build-umd-min build-parser",
"build": "npm-run-all clean build-commonjs build-docs build-umd build-umd-min build-parser",
"add-readme-to-vcs": "git add -A README.md",
"standard": "standard"
},
Expand All @@ -52,25 +51,22 @@
},
"homepage": "https://github.com/chrvadala/transformation-matrix#readme",
"devDependencies": {
"@types/jest": "^23.3.1",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-jest": "^23.4.2",
"babel-loader": "^7.1.5",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.22.0",
"babel-register": "^6.26.0",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/plugin-transform-runtime": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@types/jest": "^24.0.11",
"babel-loader": "^8.0.5",
"coveralls": "^3.0.3",
"del-cli": "^1.1.0",
"jest": "^23.5.0",
"jest": "^24.7.1",
"jsdoc-to-markdown": "^4.0.1",
"npm-run-all": "^4.1.3",
"npm-run-all": "^4.1.5",
"pegjs": "0.11.0-dev.273",
"standard": "^11.0.1",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0"
"standard": "^12.0.1",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
"standard": {
"ignore": [
Expand Down
16 changes: 8 additions & 8 deletions src/fromTransformAttribute.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {parse} from './fromTransformAttribute.autogenerated'
import {translate} from './translate'
import {rotateDEG} from './rotate'
import {fromObject} from './fromObject'
import {scale} from './scale'
import {skewDEG} from './skew'
import { parse } from './fromTransformAttribute.autogenerated'
import { translate } from './translate'
import { rotateDEG } from './rotate'
import { fromObject } from './fromObject'
import { scale } from './scale'
import { skewDEG } from './skew'

/**
* Parser for SVG Trasform Attribute http://www.w3.org/TR/SVG/coords.html#TransformAttribute <br/>
Expand All @@ -14,13 +14,13 @@ import {skewDEG} from './skew'
export function fromTransformAttribute (transformString) {
let descriptors = parse(transformString)
let matrices = descriptors.map(convertMatrixDescriptorToMatrix)
return {descriptors, matrices}
return { descriptors, matrices }
}

function convertMatrixDescriptorToMatrix (matrixDescriptor) {
let hasParam = key => matrixDescriptor.hasOwnProperty(key)

let {type, ...params} = matrixDescriptor
let { type, ...params } = matrixDescriptor
switch (type) {
case 'matrix':
return fromObject(params)
Expand Down
2 changes: 1 addition & 1 deletion src/inverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export function inverse (matrix) {
// http://www.wolframalpha.com/input/?i=Inverse+%5B%7B%7Ba,c,e%7D,%7Bb,d,f%7D,%7B0,0,1%7D%7D%5D

let {a, b, c, d, e, f} = matrix
let { a, b, c, d, e, f } = matrix

let denom = a * d - b * c

Expand Down
8 changes: 4 additions & 4 deletions src/rotate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {isUndefined} from './utils'
import {translate} from './translate'
import {transform} from './transform'
import { isUndefined } from './utils'
import { translate } from './translate'
import { transform } from './transform'

const {cos, sin, PI} = Math
const { cos, sin, PI } = Math
/**
* Calculate a rotation matrix
* @param angle Angle in radians
Expand Down
2 changes: 1 addition & 1 deletion src/scale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {isUndefined} from './utils'
import { isUndefined } from './utils'

/**
* Calculate a scaling matrix
Expand Down
2 changes: 1 addition & 1 deletion src/skew.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew
const {tan} = Math
const { tan } = Math

/**
* Calculate a skew matrix
Expand Down
16 changes: 8 additions & 8 deletions test/applyToPoint.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global describe, it, expect */
import {applyToPoint, applyToPoints} from '../src/applyToPoint'
import {identity} from '../src/identity'
import { applyToPoint, applyToPoints } from '../src/applyToPoint'
import { identity } from '../src/identity'

describe('applyToPoint', () => {
const m1 = { // trans(40,40) scale(2,2) trans(-40,-40)
Expand All @@ -12,9 +12,9 @@ describe('applyToPoint', () => {
f: -40
}
it('should return a transformed object point', () => {
expect(applyToPoint(identity(), {x: 0, y: 0})).toEqual({x: 0, y: 0})
expect(applyToPoint(m1, {x: 30, y: 30})).toEqual({x: 20, y: 20})
expect(applyToPoint(m1, {x: 50, y: 50})).toEqual({x: 60, y: 60})
expect(applyToPoint(identity(), { x: 0, y: 0 })).toEqual({ x: 0, y: 0 })
expect(applyToPoint(m1, { x: 30, y: 30 })).toEqual({ x: 20, y: 20 })
expect(applyToPoint(m1, { x: 50, y: 50 })).toEqual({ x: 60, y: 60 })
})
it('should return a transformed array point', () => {
expect(applyToPoint(identity(), [0, 0])).toEqual([0, 0])
Expand All @@ -32,10 +32,10 @@ describe('applyToPoints', () => {
d: 2,
f: -40
}
const points = [{x: 30, y: 30}, {x: 50, y: 50}]
const transPoints = [{x: 20, y: 20}, {x: 60, y: 60}]
const points = [{ x: 30, y: 30 }, { x: 50, y: 50 }]
const transPoints = [{ x: 20, y: 20 }, { x: 60, y: 60 }]
it('should return transformed points', () => {
expect(applyToPoints(identity(), [{x: 0, y: 0}])).toEqual([{x: 0, y: 0}])
expect(applyToPoints(identity(), [{ x: 0, y: 0 }])).toEqual([{ x: 0, y: 0 }])
expect(applyToPoints(m1, points)).toEqual(transPoints)
})
})
10 changes: 5 additions & 5 deletions test/fromObject.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* global describe, it, expect */
import {fromObject} from '../src/fromObject'
import { fromObject } from '../src/fromObject'

describe('fromObject', () => {
it('should return an affine matrix', () => {
let expected = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}
let o1 = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}
let o2 = {a: 1, b: 2, z: 500, c: 3, d: 4, e: 5, f: 6, x: 100, y: 200}
let o3 = {a: '1', b: '2', c: '3', d: '4', e: '5', f: '6'}
let expected = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
let o1 = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
let o2 = { a: 1, b: 2, z: 500, c: 3, d: 4, e: 5, f: 6, x: 100, y: 200 }
let o3 = { a: '1', b: '2', c: '3', d: '4', e: '5', f: '6' }
expect(fromObject(o1)).toEqual(expected)
expect(fromObject(o2)).toEqual(expected)
expect(fromObject(o3)).toEqual(expected)
Expand Down
20 changes: 10 additions & 10 deletions test/fromString.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* global describe, it, expect */
import {fromString} from '../src/fromString'
import { fromString } from '../src/fromString'

describe('fromString', () => {
it('should parse a matrix from string', () => {
expect(fromString('matrix(1,2,3,4,5,6)')).toEqual({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6})
expect(fromString('matrix(1 , 2 , 3 , 4 , 5 , 6 )')).toEqual({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6})
expect(fromString('MaTrIx(1,2,3,4,5,6)')).toEqual({a: 1, b: 2, c: 3, d: 4, e: 5, f: 6})
expect(fromString('matrix(1.1,2.2,3.3,4.4,5.5,6.6)')).toEqual({a: 1.1, b: 2.2, c: 3.3, d: 4.4, e: 5.5, f: 6.6})
expect(fromString('matrix(1.1 ,2.2 ,3.3 , 4.4, 5.5, 6.6 )')).toEqual({a: 1.1, b: 2.2, c: 3.3, d: 4.4, e: 5.5, f: 6.6})
expect(fromString('matrix(1,2.2 ,3.3,4.4,5, 6 )')).toEqual({a: 1, b: 2.2, c: 3.3, d: 4.4, e: 5, f: 6})
expect(fromString('matrix(1,2,3,4,5,6)')).toEqual({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 })
expect(fromString('matrix(1 , 2 , 3 , 4 , 5 , 6 )')).toEqual({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 })
expect(fromString('MaTrIx(1,2,3,4,5,6)')).toEqual({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 })
expect(fromString('matrix(1.1,2.2,3.3,4.4,5.5,6.6)')).toEqual({ a: 1.1, b: 2.2, c: 3.3, d: 4.4, e: 5.5, f: 6.6 })
expect(fromString('matrix(1.1 ,2.2 ,3.3 , 4.4, 5.5, 6.6 )')).toEqual({ a: 1.1, b: 2.2, c: 3.3, d: 4.4, e: 5.5, f: 6.6 })
expect(fromString('matrix(1,2.2 ,3.3,4.4,5, 6 )')).toEqual({ a: 1, b: 2.2, c: 3.3, d: 4.4, e: 5, f: 6 })

expect(fromString('matrix(-1.1,-2.2,-3.3,-4.4,-5.5,-6.6)')).toEqual({a: -1.1, b: -2.2, c: -3.3, d: -4.4, e: -5.5, f: -6.6})
expect(fromString('matrix(-1,-2,-3,-4,-5,-6)')).toEqual({a: -1, b: -2, c: -3, d: -4, e: -5, f: -6})
expect(fromString('matrix(-1.1,-2.2,-3.3,-4.4,-5.5,-6.6)')).toEqual({ a: -1.1, b: -2.2, c: -3.3, d: -4.4, e: -5.5, f: -6.6 })
expect(fromString('matrix(-1,-2,-3,-4,-5,-6)')).toEqual({ a: -1, b: -2, c: -3, d: -4, e: -5, f: -6 })

expect(fromString('matrix(+43e+21, -43e+21, +43e-21, -43e-21, 43e0, 0e0)')).toEqual({a: +43e+21, b: -43e+21, c: +43e-21, d: -43e-21, e: 43, f: 0})
expect(fromString('matrix(+43e+21, -43e+21, +43e-21, -43e-21, 43e0, 0e0)')).toEqual({ a: +43e+21, b: -43e+21, c: +43e-21, d: -43e-21, e: 43, f: 0 })

expect(fromString.bind(this, 'matrix()')).toThrow()
expect(fromString.bind(this, 'matrix(1,2,3,4,5)')).toThrow()
Expand Down
32 changes: 16 additions & 16 deletions test/fromTransformAttribute.pegjs.spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* global describe, it, expect */
import {parse} from '../src/fromTransformAttribute.autogenerated'
import { parse } from '../src/fromTransformAttribute.autogenerated'

// credits: github:nidu/svg-transform-parser

describe('fromTransformAttribute.pegjs', () => {
describe('atomic transformations', () => {
it('should parse single matrices', () => {
expect(parse('translate(1.6,65.44)')).toEqual([{type: 'translate', tx: 1.6, ty: 65.44}])
expect(parse('translate(1.6,65.44)')).toEqual([{ type: 'translate', tx: 1.6, ty: 65.44 }])

expect(parse('translate(777)')).toEqual([{type: 'translate', tx: 777}])
expect(parse('translate(777)')).toEqual([{ type: 'translate', tx: 777 }])

expect(parse('rotate(51)')).toEqual([{type: 'rotate', angle: 51}])
expect(parse('rotate(51)')).toEqual([{ type: 'rotate', angle: 51 }])

expect(parse('rotate(46 51, 18.57)')).toEqual([{type: 'rotate', angle: 46, cx: 51, cy: 18.57}])
expect(parse('rotate(46 51, 18.57)')).toEqual([{ type: 'rotate', angle: 46, cx: 51, cy: 18.57 }])

expect(parse('skewX(19.08)')).toEqual([{type: 'skewX', angle: 19.08}])
expect(parse('skewX(19.08)')).toEqual([{ type: 'skewX', angle: 19.08 }])

expect(parse('skewY(56.11)')).toEqual([{type: 'skewY', angle: 56.11}])
expect(parse('skewY(56.11)')).toEqual([{ type: 'skewY', angle: 56.11 }])

expect(parse('matrix(1 2 3,4,5 6)')).toEqual([{type: 'matrix', a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}])
expect(parse('matrix(1 2 3,4,5 6)')).toEqual([{ type: 'matrix', a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }])
})

it('should throw exception', () => {
Expand All @@ -31,21 +31,21 @@ describe('fromTransformAttribute.pegjs', () => {
describe('complex transformations', () => {
it('should parse in the right order', () => {
expect(parse('translate(1,2) translate(3,4) translate(5,6)')).toEqual([
{type: 'translate', tx: 1, ty: 2},
{type: 'translate', tx: 3, ty: 4},
{type: 'translate', tx: 5, ty: 6}
{ type: 'translate', tx: 1, ty: 2 },
{ type: 'translate', tx: 3, ty: 4 },
{ type: 'translate', tx: 5, ty: 6 }
])
})

it('should parse multiple matrices', () => {
expect(
parse('translate(1,-1),rotate(2 0.2 0.5) skewX(3.3) skewY(4),matrix(6,5,4,3,2,1)')
).toEqual([
{type: 'translate', tx: 1, ty: -1},
{type: 'rotate', angle: 2, cx: 0.2, cy: 0.5},
{type: 'skewX', angle: 3.3},
{type: 'skewY', angle: 4},
{type: 'matrix', a: 6, b: 5, c: 4, d: 3, e: 2, f: 1}
{ type: 'translate', tx: 1, ty: -1 },
{ type: 'rotate', angle: 2, cx: 0.2, cy: 0.5 },
{ type: 'skewX', angle: 3.3 },
{ type: 'skewY', angle: 4 },
{ type: 'matrix', a: 6, b: 5, c: 4, d: 3, e: 2, f: 1 }
])
})
})
Expand Down

0 comments on commit 64fb187

Please sign in to comment.