Skip to content

Commit

Permalink
(docs): add API and Usage docs for new optional arguments
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Dec 2, 2019
1 parent 078d684 commit ac8e4a1
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<br>
[![NPM](https://nodei.co/npm/trim-canvas.png?downloads=true&downloadRank=true&stars=true)](https://npmjs.org/package/trim-canvas)

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

## Installation

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

let canvas = document.createElement('canvas')
const canvas = document.createElement('canvas')

// do some drawing on it ...

Expand All @@ -34,9 +34,29 @@ trimCanvas(canvas)
```

If you don't want to mess with your existing canvas, then simply clone the canvas element beforehand.
`trim-canvas` v0.2+ has built-in support for cloning:

```javascript
const newTrimmedCanvas = trimCanvas(canvas, {clone: true})
```

Can view the [full list of options](#API) below.

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

### API

#### `trimCanvas(canvas, options)`

- arguments
- **canvas** *Canvas object* The canvas to be trimmed.
- **options** *object* Optional arguments.
- **clone** *bool* Whether to clone the canvas before trimming (default: `false`).
- **createCanvas** *function* A custom function to create a Canvas (defaults to DOM implementation).
Supports [`node-canvas`'s `createCanvas`](https://github.com/Automattic/node-canvas#createcanvas).

- returns the trimmed canvas (original or cloned)

## Example

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).
Expand Down

0 comments on commit ac8e4a1

Please sign in to comment.