Skip to content

Commit c2ccea9

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 2c54039 commit c2ccea9

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
@@ -11,7 +11,7 @@
1111

1212
[![NPM](https://nodei.co/npm/trim-canvas.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/package/trim-canvas)
1313

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

1616
## Installation
1717

@@ -22,7 +22,7 @@ A tiny (< 100 LoC) library for trimming whitespace from a `canvas` element with
2222
```javascript
2323
import trimCanvas from 'trim-canvas'
2424

25-
let canvas = document.createElement('canvas')
25+
const canvas = document.createElement('canvas')
2626

2727
// do some drawing on it ...
2828

@@ -31,9 +31,29 @@ trimCanvas(canvas)
3131
```
3232

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

3542
`trim-canvas` returns the canvas element for easy chaining.
3643

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

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