From ac8e4a1a28be350fec1c3948fad95e03e06e8295 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 20 May 2019 04:46:26 -0400 Subject: [PATCH] (docs): add API and Usage docs for new optional arguments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b2ba64d..04b3b0d 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@
[![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 @@ -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 ... @@ -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).