1.0.2 • Published 6 years ago

text-drawing v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Text Drawing

A lightweight library contains some methods to create a string as your character drawing, you can also use it for more uses such as particles animation, carousel effects, etc.

Features

  • Converts one word, one line of words, or a paragraph of text to a character drawing.
  • Supports multiple languages and fonts, especially for Chinese and English characters.
  • You can config some options for style of drawing, includes font size, font family, font weight, word spacing, line spacing, text align.
  • Depends on the canvas capabilities supported by modern browsers.

Install

or

Methods & Usages

1. Word to drawing

Method:

wordToDrawing

Options:

OptionsCorresponds toDefault ValueType/Value
wordone word as input'W'string
fontSizefont-size40number
fontFamilyfont-family'Microsoft Yahei'string
fontWeightfont-weight'normal''normal', 'bold', 'lighter', number

Codes:

import { wordToDrawing } from 'text-drawing';

const drawing = wordToDrawing({ word: '你', fontSize: 30 });
console.log(drawing);

Outputs:

------++++----+++-------------
------+++++--+++++------------
------+++++--+++++------------
-----+++++---++++-------------
-----+++++--+++++-------------
-----++++---++++++++++++++++++
----+++++--+++++++++++++++++++
----+++++--+++++++++++++++++++
---+++++--+++++----------+++++
---+++++--+++++---++++---+++++
--++++++-+++++---+++++--+++++-
--++++++-++++----+++++--+++++-
-+++++++--+++----+++++--++++--
++++++++-----+---+++++--++++--
++++++++----+++++++++++++++---
++++++++----+++++++++++++++---
++++++++---+++++-+++++-+++++--
+++-++++---+++++-+++++-+++++--
-+--++++---++++--+++++--+++++-
----++++--+++++--+++++--+++++-
----++++--++++---+++++---++++-
----++++-+++++---+++++---+++++
----++++-+++++---+++++---+++++
----+++++++++----+++++----++++
----+++++++++----+++++----++++
----++++--++-----+++++--------
----++++----++++++++++--------
----++++----+++++++++---------
----++++----+++++++++---------
----++++----++++++++----------

2. One line of text to drawing

Method:

textToDrawing

Options:

OptionsCorresponds toDefault ValueType/Value
textone line of text as input'Hello World!'string
fontSizefont-size40number
fontFamilyfont-family'Microsoft Yahei'string
fontWeightfont-weight'normal''normal', 'bold', 'lighter', number
wordSpacingword-spacing4number

Codes:

import { textToDrawing } from 'text-drawing';

const drawing = textToDrawing({ text: '你好, Mike!', fontSize: 30 });
console.log(drawing);

Outputs:

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
------++++----+++---------------------++++-----------------------------------------------------------------------------------------------------------------------------
------+++++--+++++--------------------++++-----------------------------------------------------------------------+++-----++++------------------------------------------
------+++++--+++++--------------------++++----+++++++++++++++++-------------------++++++--------------+++++----++++++----++++-------------------------------------++++-
-----+++++---++++--------------------+++++----+++++++++++++++++-------------------++++++-------------++++++----++++++----++++------------------------------------+++++-
-----+++++--+++++--------------------+++++----+++++++++++++++++-------------------+++++++------------++++++----++++++----++++------------------------------------+++++-
-----++++---++++++++++++++++++-------+++++----+++++++++++++++++-------------------+++++++-----------+++++++-----++++-----++++------------------------------------+++++-
----+++++--+++++++++++++++++++----+++++++++++++---------++++++--------------------++++++++----------+++++++--------------++++------------------------------------+++++-
----+++++--+++++++++++++++++++----+++++++++++++--------++++++---------------------++++++++---------++++++++--------------++++------------------------------------+++++-
---+++++--+++++----------+++++----+++++++++++++------+++++++----------------------++++++++---------++++++++--------------++++----------------------++++----------+++++-
---+++++--+++++---++++---+++++----+++++++++++++------++++++-----------------------+++++++++--------++++++++-----++++-----++++-----++++++---------++++++++--------+++++-
--++++++-+++++---+++++--+++++-------+++++--++++------+++++------------------------+++++++++-------+++++++++----+++++-----++++----++++++--------++++++++++++------+++++-
--++++++-++++----+++++--+++++-------+++++-+++++------++++-------------------------++++++++++------+++++++++----+++++-----++++---++++++--------++++++++++++++-----+++++-
-+++++++--+++----+++++--++++--------++++--++++-------++++-------------------------++++++++++-----++++++++++----+++++-----++++--++++++---------++++++--++++++-----+++++-
++++++++-----+---+++++--++++--------++++--++++++++++++++++++++++------------------+++++++++++----++++++++++----+++++-----++++-++++++---------++++++----++++++----+++++-
++++++++----+++++++++++++++--------+++++--++++++++++++++++++++++------------------+++++-+++++---+++++++++++----+++++-----++++++++++----------+++++------+++++----+++++-
++++++++----+++++++++++++++--------+++++--++++++++++++++++++++++------------------+++++-+++++---+++++-+++++----+++++-----++++++++++----------++++++++++++++++----+++++-
++++++++---+++++-+++++-+++++-------++++--+++++++++++++++++++++++------------------+++++--+++++--+++++-+++++----+++++-----+++++++++-----------++++++++++++++++----+++++-
+++-++++---+++++-+++++-+++++-------+++++-++++--------++++-------------------------+++++--+++++-+++++--+++++----+++++-----++++++++-----------+++++++++++++++++----+++++-
-+--++++---++++--+++++--+++++------++++++++++--------++++-------------------------+++++---++++++++++--+++++----+++++-----+++++++++----------+++++++++++++++++----+++++-
----++++--+++++--+++++--+++++-------+++++++++--------++++-------------------------+++++---+++++++++---+++++----+++++-----++++++++++----------+++++---------------+++++-
----++++--++++---+++++---++++--------+++++++---------++++-------------------------+++++---+++++++++---+++++----+++++-----++++-++++++---------+++++---------------------
----++++-+++++---+++++---+++++---------++++++--------++++-------------++++--------+++++----+++++++----+++++----+++++-----++++-+++++++--------+++++--------+------------
----++++-+++++---+++++---+++++--------++++++++-------++++------------+++++--------+++++----+++++++----+++++----+++++-----++++--+++++++-------+++++++----++++-----+++++-
----+++++++++----+++++----++++-------+++++++++++-----++++------------+++++--------+++++-----++++++----+++++----+++++-----++++---+++++++-------++++++++++++++-----++++++
----+++++++++----+++++----++++------++++++++++++-----++++------------+++++--------+++++-----+++++-----+++++----+++++-----++++----+++++++-------+++++++++++++-----++++++
----++++--++-----+++++-------------++++++--++++------++++------------++++---------+++++------++++-----+++++----+++++-----++++-----++++++--------+++++++++++------+++++-
----++++----++++++++++------------++++++----++-++++++++++-----------+++++-------------------------------------------------------------------------+++++++---------+++--
----++++----+++++++++-------------+++++--------++++++++++-----------+++++----------------------------------------------------------------------------------------------
----++++----+++++++++-------------++++---------+++++++++------------++++-----------------------------------------------------------------------------------------------
----++++----++++++++---------------++-----------+++++++-------------++++-----------------------------------------------------------------------------------------------
--------------------------------------------------------------------++++-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

3. One paragraph of text to drawing

Method:

paragraphToDrawing

Options:

OptionsCorresponds toDefault ValueType/Value
paragraphmultiple lines of text as input'Hello,\nWorld!'string
fontSizefont-size40number
fontFamilyfont-family'Microsoft Yahei'string
fontWeightfont-weight'normal''normal', 'bold', 'lighter', number
wordSpacingword-spacing4number
lineSpacingline-spacing0number
textAligntext-align'left''left', 'center', 'right'

Codes:

import { paragraphToDrawing } from 'text-drawing';

const drawing = paragraphToDrawing({
  paragraph: '你好, Mike!\n我是 Parksben',
  fontSize: 30,
  textAlign: 'center',
});
console.log(drawing);

Outputs:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------++++----+++---------------------++++------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------+++++--+++++--------------------++++-----------------------------------------------------------------------+++-----++++-------------------------------------------------------------------
--------------------------------+++++--+++++--------------------++++----+++++++++++++++++-------------------++++++--------------+++++----++++++----++++-------------------------------------++++--------------------------
-------------------------------+++++---++++--------------------+++++----+++++++++++++++++-------------------++++++-------------++++++----++++++----++++------------------------------------+++++--------------------------
-------------------------------+++++--+++++--------------------+++++----+++++++++++++++++-------------------+++++++------------++++++----++++++----++++------------------------------------+++++--------------------------
-------------------------------++++---++++++++++++++++++-------+++++----+++++++++++++++++-------------------+++++++-----------+++++++-----++++-----++++------------------------------------+++++--------------------------
------------------------------+++++--+++++++++++++++++++----+++++++++++++---------++++++--------------------++++++++----------+++++++--------------++++------------------------------------+++++--------------------------
------------------------------+++++--+++++++++++++++++++----+++++++++++++--------++++++---------------------++++++++---------++++++++--------------++++------------------------------------+++++--------------------------
-----------------------------+++++--+++++----------+++++----+++++++++++++------+++++++----------------------++++++++---------++++++++--------------++++----------------------++++----------+++++--------------------------
-----------------------------+++++--+++++---++++---+++++----+++++++++++++------++++++-----------------------+++++++++--------++++++++-----++++-----++++-----++++++---------++++++++--------+++++--------------------------
----------------------------++++++-+++++---+++++--+++++-------+++++--++++------+++++------------------------+++++++++-------+++++++++----+++++-----++++----++++++--------++++++++++++------+++++--------------------------
----------------------------++++++-++++----+++++--+++++-------+++++-+++++------++++-------------------------++++++++++------+++++++++----+++++-----++++---++++++--------++++++++++++++-----+++++--------------------------
---------------------------+++++++--+++----+++++--++++--------++++--++++-------++++-------------------------++++++++++-----++++++++++----+++++-----++++--++++++---------++++++--++++++-----+++++--------------------------
--------------------------++++++++-----+---+++++--++++--------++++--++++++++++++++++++++++------------------+++++++++++----++++++++++----+++++-----++++-++++++---------++++++----++++++----+++++--------------------------
--------------------------++++++++----+++++++++++++++--------+++++--++++++++++++++++++++++------------------+++++-+++++---+++++++++++----+++++-----++++++++++----------+++++------+++++----+++++--------------------------
--------------------------++++++++----+++++++++++++++--------+++++--++++++++++++++++++++++------------------+++++-+++++---+++++-+++++----+++++-----++++++++++----------++++++++++++++++----+++++--------------------------
--------------------------++++++++---+++++-+++++-+++++-------++++--+++++++++++++++++++++++------------------+++++--+++++--+++++-+++++----+++++-----+++++++++-----------++++++++++++++++----+++++--------------------------
--------------------------+++-++++---+++++-+++++-+++++-------+++++-++++--------++++-------------------------+++++--+++++-+++++--+++++----+++++-----++++++++-----------+++++++++++++++++----+++++--------------------------
---------------------------+--++++---++++--+++++--+++++------++++++++++--------++++-------------------------+++++---++++++++++--+++++----+++++-----+++++++++----------+++++++++++++++++----+++++--------------------------
------------------------------++++--+++++--+++++--+++++-------+++++++++--------++++-------------------------+++++---+++++++++---+++++----+++++-----++++++++++----------+++++---------------+++++--------------------------
------------------------------++++--++++---+++++---++++--------+++++++---------++++-------------------------+++++---+++++++++---+++++----+++++-----++++-++++++---------+++++----------------------------------------------
------------------------------++++-+++++---+++++---+++++---------++++++--------++++-------------++++--------+++++----+++++++----+++++----+++++-----++++-+++++++--------+++++--------+-------------------------------------
------------------------------++++-+++++---+++++---+++++--------++++++++-------++++------------+++++--------+++++----+++++++----+++++----+++++-----++++--+++++++-------+++++++----++++-----+++++--------------------------
------------------------------+++++++++----+++++----++++-------+++++++++++-----++++------------+++++--------+++++-----++++++----+++++----+++++-----++++---+++++++-------++++++++++++++-----++++++-------------------------
------------------------------+++++++++----+++++----++++------++++++++++++-----++++------------+++++--------+++++-----+++++-----+++++----+++++-----++++----+++++++-------+++++++++++++-----++++++-------------------------
------------------------------++++--++-----+++++-------------++++++--++++------++++------------++++---------+++++------++++-----+++++----+++++-----++++-----++++++--------+++++++++++------+++++--------------------------
------------------------------++++----++++++++++------------++++++----++-++++++++++-----------+++++-------------------------------------------------------------------------+++++++---------+++---------------------------
------------------------------++++----+++++++++-------------+++++--------++++++++++-----------+++++-----------------------------------------------------------------------------------------------------------------------
------------------------------++++----+++++++++-------------++++---------+++++++++------------++++------------------------------------------------------------------------------------------------------------------------
------------------------------++++----++++++++---------------++-----------+++++++-------------++++------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------++++------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
---------------+++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------++++++++++--++--------------++++++++++++++++++++++-----------------------------------------------------------------++++--------------------------------++++-----------------------------------------------------
--++++++++++++++++++-++++-------------++++++++++++++++++++++------------+++++++++++------------------------------------------++++--------------------------------++++-----------------------------------------------------
++++++++++++++++++++++++++------------++++++++++++++++++++++------------+++++++++++++----------------------------------------++++--------------------------------++++-----------------------------------------------------
++++++++++++++++++++-++++++-----------++++++++++++++++++++++------------++++++++++++++---------------------------------------++++--------------------------------++++-----------------------------------------------------
-+++++++++-----+++++--++++++----------++++--------------++++------------+++++++++++++++--------------------------------------++++--------------------------------++++-----------------------------------------------------
--+---++++-----+++++---++++++---------++++++++++++++++++++++------------+++++---++++++++-------------------------------------++++--------------------------------++++-----------------------------------------------------
------++++-----+++++----++++----------++++++++++++++++++++++------------+++++-----++++++-------------------------------------++++--------------------------------++++-----------------------------------------------------
------++++------++++-----++-----------++++++++++++++++++++++------------+++++------+++++----------+++++---------------++-----++++--------------------++++--------++++---++++-----------------++++-----------------++++----
++++++++++++++++++++++++++++++--------++++--------------++++------------+++++------+++++-------++++++++++------++++++++++----++++-----++++++------++++++++++-----++++-++++++++-------------++++++++--------++++-++++++++--
++++++++++++++++++++++++++++++--------++++++++++++++++++++++------------+++++------+++++------++++++++++++-----++++++++++----++++----++++++------+++++++++++-----+++++++++++++++---------++++++++++++------++++++++++++++-
++++++++++++++++++++++++++++++--------++++++++++++++++++++++------------+++++------+++++------+++++++++++++----++++++++++----++++---++++++------++++++++++++-----+++++++++++++++--------++++++++++++++-----+++++++++++++++
-++++-++++-++++-++++-++++++-++--------++++++++++++++++++++++------------+++++-----++++++------+++++--++++++----++++++++++----++++--++++++-------++++++--++++-----+++++++--+++++++-------++++++--++++++-----+++++++--++++++
------++++------++++----++++----------++++++++++++++++++++++------------+++++----++++++-------+++-----+++++----++++++--------++++-++++++--------+++++------------++++++-----+++++------++++++----++++++----+++++-----+++++
------++++------++++----+++++---------++++--------------++++------------+++++++++++++++----------------++++----+++++---------++++++++++---------+++++------------+++++------++++++-----+++++------+++++----+++++-----+++++
------++++-++++++++++--++++++-----++++++++++++++++++++++++++++++--------++++++++++++++-----------++++++++++----+++++---------++++++++++---------+++++++----------+++++-------+++++-----++++++++++++++++----+++++-----+++++
-----++++++++++++++++-++++++------++++++++++++++++++++++++++++++--------+++++++++++++----------++++++++++++----+++++---------+++++++++----------+++++++++--------+++++-------+++++-----++++++++++++++++----+++++-----+++++
+++++++++++++++++++++++++++-------++++++++++++++++++++++++++++++--------+++++++++++-----------+++++++++++++----+++++---------++++++++------------++++++++++------++++--------+++++----+++++++++++++++++----++++------+++++
++++++++++++++++++++++++++--------------+++----+++++--------------------+++++----------------++++++++++++++----++++----------+++++++++-------------+++++++++-----++++--------+++++----+++++++++++++++++----++++------+++++
+++++++++++------++++++++--------------+++++---+++++--------------------+++++---------------++++++----+++++----++++----------++++++++++--------------+++++++-----+++++------++++++-----+++++---------------++++------+++++
++++++++++-------+++++++---+-----------++++----+++++++++++++++----------+++++---------------+++++-----+++++----++++----------++++-++++++---------------++++++----+++++------+++++------+++++---------------++++------+++++
------++++------+++++++---++++--------+++++----+++++++++++++++----------+++++---------------+++++-----+++++----++++----------++++-+++++++---------------+++++----+++++------+++++------+++++--------+------++++------+++++
------++++-----+++++++----++++--------+++++----+++++++++++++++----------+++++---------------++++++---++++++----++++----------++++--+++++++------+++----++++++----+++++++--+++++++------+++++++----++++-----++++------+++++
------++++---++++++++++---++++-------+++++++---+++++--------------------+++++----------------++++++++++++++----++++----------++++---+++++++-----++++++++++++-----+++++++++++++++--------++++++++++++++-----++++------+++++
------++++-+++++++++++++--++++-------+++++++++-+++++--------------------+++++----------------++++++++++++++----++++----------++++----+++++++----++++++++++++-----++++++++++++++----------+++++++++++++-----++++------+++++
------++++++++++++-++++++-++++------++++++++++++++++--------------------+++++-----------------+++++++++++++----++++----------++++-----++++++----++++++++++-------+++++++++++++------------+++++++++++------++++------+++++
-+++++++++++++++----++++++++++-----+++++-+++++++++++++++++++++++--------------------------------+++++---------------------------------------------++++++---------------+++++----------------+++++++-----------------------
-+++++++++-+++------++++++++++----++++++---+++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------
-+++++++++-----------++++++++-----+++++------+++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------
-+++++++---------------+++++------++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

License

MIT License