Skip to content

Commit d717f4c

Browse files
committed
(docs): add API and Usage docs for new optional arguments
- show how to clone in Usage and specify that it's v0.2+ - add full API docs - slightly larger than 100 LoC now 😢 - use const instead of let in docs too
1 parent 7cb4e0e commit d717f4c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<br>
1616
[![NPM](https://nodei.co/npm/trim-canvas.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/package/trim-canvas)
1717

18-
A tiny (< 100 LoC) library for trimming whitespace from a `canvas` element with no dependencies.
18+
A tiny (~100 LoC) library for trimming whitespace from a `canvas` element with no dependencies.
1919

2020
## Installation
2121

@@ -35,9 +35,29 @@ trimCanvas(canvas)
3535
```
3636

3737
If you don't want to mess with your existing canvas, then simply clone the canvas element beforehand.
38+
`trim-canvas` v0.2+ has built-in support for cloning:
39+
40+
```javascript
41+
const newTrimmedCanvas = trimCanvas(canvas, {clone: true})
42+
```
43+
44+
Can view the [full list of options](#API) below.
3845

3946
`trim-canvas` returns the canvas element for easy chaining.
4047

48+
### API
49+
50+
#### `trimCanvas(canvas, options)`
51+
52+
- arguments
53+
- **canvas** *Canvas object* The canvas to be trimmed.
54+
- **options** *object* Optional arguments.
55+
- **clone** *bool* Whether to clone the canvas before trimming (default: `false`).
56+
- **createCanvas** *function* A custom function to create a Canvas (defaults to DOM implementation).
57+
Supports [`node-canvas`'s `createCanvas`](https://github.com/Automattic/node-canvas#createcanvas).
58+
59+
- returns the trimmed canvas (original or cloned)
60+
4161
## Example
4262

4363
Can see how `trim-canvas` is used inside of `react-signature-canvas` [here](https://github.com/agilgur5/react-signature-canvas/blob/310bff81813509a4035bedfe50d76e7045a880cb/src/index.js#L53-L64).

0 commit comments

Comments
 (0)