# jw-canvas-ascii

> A text react component which renders the ascii text converted from a canvas image data.

Latest version **0.1.5** (published 2019-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install jw-canvas-ascii
pnpm add jw-canvas-ascii
yarn add jw-canvas-ascii
bun add jw-canvas-ascii
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2019-02-15 |
| First published | 2018-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 2.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | john wong |
| Maintainers | johnwong |
| Keywords | react, canvas, ascii |

## Links

- npm: https://www.npmjs.com/package/jw-canvas-ascii
- Repository: https://github.com/WaiChungWong/jw-canvas-ascii
- Homepage: https://waichungwong.github.io/jw-canvas-ascii/build
- Issues: https://github.com/WaiChungWong/jw-canvas-ascii/issues
- npm.io page: https://npm.io/package/jw-canvas-ascii

## Dependencies (1)

- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.5 (latest) — 2019-02-15
- 0.1.4 — 2018-08-17
- 0.1.3 — 2018-07-16
- 0.1.2 — 2018-07-12
- 0.1.1 — 2018-07-12
- 0.1.0 — 2018-06-15

## README

# jw-canvas-ascii

A text react component which renders the ascii text converted from a canvas image data.

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![node version][node-image]][node-url]
[![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/jw-canvas-ascii.svg
[npm-url]: http://npmjs.org/package/jw-canvas-ascii
[travis-image]: https://img.shields.io/travis/WaiChungWong/jw-canvas-ascii.svg
[travis-url]: https://travis-ci.org/WaiChungWong/jw-canvas-ascii
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/jw-canvas-ascii.svg
[download-url]: https://npmjs.org/package/jw-canvas-ascii

[Demo](http://waichungwong.github.io/jw-canvas-ascii/build)

## Install

[![NPM](https://nodei.co/npm/jw-canvas-ascii.png)](https://nodei.co/npm/jw-canvas-ascii)

## Methods

| Method              | Parameters            | Description                                                     |
| ------------------- | --------------------- | --------------------------------------------------------------- |
| `setCanvas`         | `canvas`: DOM element | set a target canvas component to convert image data from        |
| `getTextElement`    |                       | retrieve the ascii text element                                 |
| `generateAsciiCode` |                       | returns a newly generated ascii text from the canvas image data |
| `update`            |                       | re-render ascii text onto the text element                      |

## Props

| Prop                  | Description                                                                                                                                                                         |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `asciiData`(optional) | an array of character to present the ascii with.<br>Ordered from brightest (white) to darkest (black).<br>Default: `[" ", ".", ",", ";", "\|", "\*", "%", "@", "X", "#", "W", "M"]` |
| `invert`(optional)    | whether to reverse the `asciiData` ordering<br>Default: `false`                                                                                                                     |

## Usage

```javascript
import React, { Component } from "react";
import { render } from "react-dom";
import CanvasASCII from "jw-canvas-ascii";

class Example extends Component {
  constructor(props) {
    super(props);

    this._resizeHandler = this._resizeHandler.bind(this);
  }

  componentDidMount() {
    const { canvas, ascii } = this;

    let context = canvas.getContext("2d");

    /**** Start drawing on the canvas here. *****/

    ascii.setCanvas(canvas);

    /** Handle auto update when the canvas size changes. */
    window.addEventListener("resize", this._resizeHandler, false);
    canvas.addEventListener("resize", this._resizeHandler, false);
  }

  componentWillUnmount() {
    const { canvas } = this;

    window.removeEventListener("resize", this._resizeHandler);
    canvas.removeEventListener("resize", this._resizeHandler);
  }

  _resizeHandler() {
    this.ascii.update();
  }

  render() {
    return (
      <div id="example">
        <canvas ref={c => (this.canvas = c)} />
        <CanvasASCII ref={a => (this.ascii = a)} invert={false} />
      </div>
    );
  }
}

render(<Example />, document.getElementById("root"));
```

---
_Source: https://npm.io/package/jw-canvas-ascii · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
