Skip to content

Commit ac8e4a1

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 078d684 commit ac8e4a1

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

README.md

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

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

1919
## Installation
2020

@@ -25,7 +25,7 @@ A tiny (< 100 LoC) library for trimming whitespace from a `canvas` element with
2525
```javascript
2626
import trimCanvas from 'trim-canvas'
2727

28-
let canvas = document.createElement('canvas')
28+
const canvas = document.createElement('canvas')
2929

3030
// do some drawing on it ...
3131

@@ -34,9 +34,29 @@ trimCanvas(canvas)
3434
```
3535

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

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

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

4262
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)