Skip to content

Commit

Permalink
Simplify API (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Mar 15, 2024
1 parent f2f2f8c commit a6de35c
Show file tree
Hide file tree
Showing 12 changed files with 3,474 additions and 2,670 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
package-lock.json -diff
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use NodeJS v${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install
run: npm ci
- name: Test
run: npm test
- name: Coverage
uses: coverallsapp/github-action@v1.1.2
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./tests/coverage/lcov.info
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use NodeJS v16
uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Use NodeJS v20
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- name: Install
run: npm ci
- name: Lint
Expand All @@ -54,19 +54,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Use NodeJS v16
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 20.x
- name: Install dependencies
run: npm ci
- name: Sanity check
run: |
npm run lint
npm test
- name: Deploy to NPM
uses: JS-DevTools/npm-publish@v1.4.3
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}

Expand All @@ -90,11 +90,10 @@ jobs:
TAG_BODY="${TAG_BODY//$'\r'/'%0D'}"
echo ::set-output name=body::$TAG_BODY
- name: Create Release
uses: actions/create-release@v1.1.4
id: create-release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag.outputs.title }}
release_name: ${{ steps.tag.outputs.title }}
name: ${{ steps.tag.outputs.title }}
body: ${{ steps.tag.outputs.body }}
draft: false
prerelease: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-copyright-years-in-license-file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
action-update-license-year:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: FantasticFiasco/action-update-license-year@v2
- uses: FantasticFiasco/action-update-license-year@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
77 changes: 27 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,48 +33,30 @@ console.log(JSON.stringify(segments, null, 2));
{
"start": 0,
"end": 4,
"params": [
"M",
5,
6
],
"abs": true,
"chained": true,
"chainStart": 0,
"chainEnd": 8
"params": ["M", 5, 6],
"chain": {
"start": 0,
"end": 8
},
},
{
"start": 5,
"end": 8,
"params": [
"M",
7,
8
],
"abs": true,
"chained": true,
"chainStart": 0,
"chainEnd": 8
"params": ["M", 7, 8],
"chain": {
"start": 0,
"end": 8
},
},
{
"start": 8,
"end": 12,
"params": [
"l",
3,
4
],
"abs": false,
"chained": false
"params": ["l", 3, 4],
},
{
"start": 12,
"end": 13,
"params": [
"z"
],
"abs": false,
"chained": false
"params": ["z"],
}
]
```
Expand All @@ -87,30 +69,25 @@ svg-path-segments --pretty "M5 6 7 8l3 4z"

### Reference

<a name="svgPathParse" href="#svgPathParse">#</a> <b>svgPathParse</b>(<i>d</i>)
`Array`

- **d** (string) SVG path.
<a name="svgPathParse" href="#svgPathParse">#</a> **svgPathParse**(d: _string_)
_Segment[]_

Returns the segments of the SVG path. The result is an array of objects, one
per segment, which contain next properties:

- **`start`** (*Integer*): Index of the first character of the segment.
- **`end`** (*Integer*): Index of the first character after the segment. Note
- **`start`** (_number_): Index of the first character of the segment.
- **`end`** (_number_): Index of the first character after the segment. Note
that you can use `d.substring(result.start, result.end)` to get the raw string
representation of the segment.
- **`params`** (*Array*): Parameters of the segment. The first parameter always
- **`params`** (_number[]_): Parameters of the segment. The first parameter always
is the command that draws the segment.
- **`abs`** (*Boolean*): Indicates that the coordinates of the segment are
absolute.
- **`chained`** (*Boolean*): Indicates that the segment is part of a chained
set of segments. If this property is `true`, the object will also contain the
properties `chainStart` and `chainEnd`.
- **`chainStart`** (optional, *Integer*): Index of the first character of the
chained set of segments to which the segment belongs.
- **`chainEnd`** (optional, *Integer*): Index of the first character after the
chained set of segments to which the segment belongs. Note that you can use
`d.substring(result.chainStart, result.chainEnd)` to get the raw string
- **`chain`** (_object?_): If present, indicates that the segment is part of a
chained set of segments.
- **`start`** (_number_): Index of the first character of the chained set of
segments to which the segment belongs.
- **`end`** (_number_): Index of the first character after the chained set of
segments to which the segment belongs. Note that you can use
`d.substring(result.chain.start, result.chain.end)` to get the raw string
representation of the chained set of segments to which the segment belongs.

### Comparison against other implementations
Expand All @@ -134,8 +111,8 @@ per segment, which contain next properties:
| Check invalid float exponents | NO | YES |
| Unicode support | NO | PARTIAL |

> \* Benchmarks are orientative, if you want to perform your own, run the script
[scripts/simple-icons-benchmark.js][si-benchmark-link].
> \* Benchmarks are orientative, if you want to perform your own, see
[scripts/\*-benchmark.js][scripts-link].

### Usage with [fontello/svgpath](https://github.com/fontello/svgpath)

Expand All @@ -156,5 +133,5 @@ SVGPath.segments = segments.map(segment => segment.params);
[coverage-link]: https://coveralls.io/github/mondeja/svg-path-segments?branch=master
[license-image]: https://img.shields.io/npm/l/svg-path-segments?color=blue
[license-link]: https://github.com/mondeja/svg-path-segments/blob/master/LICENSE
[si-benchmark-link]: https://github.com/mondeja/svg-path-segments/blob/master/scripts/simple-icons-benchmark.js
[scripts-link]: https://github.com/mondeja/svg-path-segments/tree/master/scripts
[svg11-spec-link]: https://www.w3.org/TR/SVG11/paths.html

0 comments on commit a6de35c

Please sign in to comment.