Skip to content

Commit

Permalink
Include native support for Typescript (#87)
Browse files Browse the repository at this point in the history
* Include native support for Typescript

* Remove uneeded dependency

* Fix typo

* Add CHANGELOG entry

* Add formatting for all files

* Check formatting in CI

* Minor change

* Drop dependency

* Node 18.x works?

* Use ESM import in README example
  • Loading branch information
mondeja authored May 6, 2022
1 parent 4051f28 commit b2d3732
Show file tree
Hide file tree
Showing 26 changed files with 8,472 additions and 2,047 deletions.
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"requireConfigFile": false
},
"plugins": ["@typescript-eslint", "prettier"],
"extends": [
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
]
}
72 changes: 38 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,42 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x]
node-version: [14.x, 16.x, 18.x]
steps:
- uses: actions/checkout@v2
- name: Use NodeJS v${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Test
run: npm test
- name: Coverage
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./tests/coverage/lcov.info
- uses: actions/checkout@v3
- name: Use NodeJS v${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Run examples
run: npm run examples
- name: Test
run: npm test
- name: Coverage
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./tests/coverage/lcov.info

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use NodeJS v16
uses: actions/setup-node@v2.2.0
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install
run: npm ci
- name: Lint
run: npm run lint
- name: Check format
run: npm run format:check

npm:
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -54,29 +60,27 @@ jobs:
name: NPM Package
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use NodeJS v16
uses: actions/[email protected]
with:
node-version: 16.x
- name: Install dependencies
run: npm ci
- name: Sanity check
run: |
npm run lint
npm test
- name: Deploy to NPM
uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_TOKEN }}
- name: Checkout
uses: actions/checkout@v3
- name: Use NodeJS v16
uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install dependencies
run: npm ci
- name: Sanity check
run: run-s build examples test
- name: Deploy to NPM
uses: JS-DevTools/[email protected]
with:
token: ${{ secrets.NPM_TOKEN }}

release:
name: Release
needs: npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Get tag metadata
id: tag
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
action-update-license-year:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: FantasticFiasco/action-update-license-year@v2
Expand Down
5 changes: 3 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env sh
. "$(dirname $0)/_/husky.sh"

npm run lintfix
npm test
set -e

run-s build examples test
git add .
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*
!LICENSE
!src/
!dist/
!package.json
!CHANGELOG.md
!README.md
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tests/coverage
dist/
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
# CHANGELOG

## [1.0.1] - 2021-06-021
## [1.1.0] - 2022-05-06

- Add support for Typescript.

## [1.0.2] - 2022-01-11

- Add basic options `--version` and `--help` to CLI.

## [1.0.1] - 2021-06-21

- Fixed error computing limits for cubic Bèzier curves of length 0.

## [1.0.0] - 2021-06-03

- Testing with 100% coverage.
- Make `svgPathBbox` function the default export.

## [0.2.0] - 2020-12-22

- Removed almost all public API functions (only keep `svgPathBbox` function).
- Removed `polf` dependency.
- Optimized quadratic Bézier curves minimum and maximum values computation.
- Optimized cubic Bézier curves minimum and maximum values computation.
- Optimized lineal segments minimum and maximum values computation.

## [0.1.5] - 2020-11-26

- Documentation improved.
- Switch CI to Github Actions.

## [0.1.4] - 2020-11-23

- Document and export `quadraticBezierCurveBbox` function.
- Remove development file from NPM package.
- Update acknowledgments.

## [0.1.1] - 2020-11-19

- Fix error computing bounding boxes for Q, T and some C commands.

## [0.0.47] - 2020-07-23

- Separate point on line functions in another package.
- Replaced svg-path-parser dependency with svgpath to optimize parsing time.
- Removed dregrees to radians converter function.
Expand All @@ -35,21 +50,25 @@
- Add tests for utilities and command line client.

## [0.0.28] - 2020-05-22

- Update LICENSE.
- Fix error converting quaratic to Bézier coordinates.
- Add tests for some bounding boxes functions.

## [0.0.26] - 2020-05-21

- Removed `quadraticBezierCurveBbox` function.
- Optimized quadratic Bézier curve bounding box computation.
- Optimized cubic Bézier curve bounding box algorithm.
- Fixed error on V and H commands computing SVG path bbox.

## [0.0.20] - 2020-05-17

- Add function to obtain an array of numbers from SVG path.
- Multiple paths as arguments for command line script.

## [0.0.13] - 2020-05-17

- Add command line interface.
- Add linting.
- Released to NPM.
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ npm install svg-path-bbox
### Usage

```javascript
> const svgPathBbox = require("svg-path-bbox")
> import svgPathBbox from "svg-path-bbox";
> svgPathBbox("M5 10l2 3z")
[ 5, 10, 7, 13 ]
> svgPathBbox("M5 10c3 0 3 3 0 3z")
Expand All @@ -46,15 +46,28 @@ $ svg-path-bbox "M5 10c3 0 3 3 0 3z" "M2 8m5 5z"
2 8 7 13
```

### Typescript usage

```typescript
import svgPathBbox from "svg-path-bbox";
import type { BBox } from "svg-path-bbox";

type CasesTuple = Array<[string, BBox]>;

const cases: CasesTuple = [["M0 0H3V6Z", [0, 0, 3, 6]]];
console.log(svgPathBbox(cases[0]));
```

### Reference

<a name="svgPathBbox" href="#svgPathBbox">#</a> <b>svgPathBbox</b>(<i>d</i>) ⇒ `Array`
<a name="svgPathBbox" href="#svgPathBbox">#</a> <b>svgPathBbox</b>(d : <em>string</em>) ⇒ [minX: <em>number</em>, maxX: <em>number</em>, minY: <em>number</em>, maxY: <em>number</em>]

Computes the bounding box of SVG path following the [SVG 1.1 specification](https://www.w3.org/TR/SVG/paths.html).

- **d** (string) SVG path.
- **d** (_string_) SVG path.

## Thanks to

- [simple-icons/simple-icons](https://github.com/simple-icons/simple-icons) for reference dataset.
- [kpym/SVGPathy](https://github.com/kpym/SVGPathy) for reference implementation.
- [icons8/svg-path-bounding-box](https://github.com/icons8/svg-path-bounding-box) because [their bug](https://github.com/icons8/svg-path-bounding-box/issues/3) has been the source of this library.
Expand Down
Loading

0 comments on commit b2d3732

Please sign in to comment.