Usage

Installation

npm install --save @thebespokepixel/string

Example

const bString = require('@thebespokepixel/string')

console.log(bString.subScript('String to print'))

.pad(string, char, length)

Pads string, using char to length characters. If length is negative, pads the right rather than the left of string. If length is less than string.length, it will crop string to fit.

.toSuperscript(string) | .toSubscript(string)

Prints the string using the alternative super/sub characters available in Unicode (Such as in DejaVu Sans Mono or Source Code Pro). Superscript support is much more complete that Subscript. Unavaiable subscript characters will be printed as . The character Q has to be approximated.

TODO: Use compound Unicode overlay characters to better approximate missing chars.

Unless the environment has TERM_FONT=full set (see Term-NG) and you have a Unicode terminal font that supports sub/super-script characters, then it will fall back to printing normal characters.

Character set (Github display is incomplete)
Class Numerals Symbols Lower case Upper case
Basic 0123456789 `+-=:()/ . ` abcdefghijklmnopqrstuvwxyz
Superscript ⁰¹²³⁴⁵⁶⁷⁸⁹ ⁺⁻⁼⁼⁽⁾╵╵⋅ ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖᵍʳˢᵗᵘᵛʷˣʸᶻ ᴬᴮᶜᴰᴱᶠᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾᴼᴿˢᵀᵁⱽᵂˣʸᶻ
Subscript ₀₁₂₃₄₅₆₇₈₉ ₊₋₌₌₍₎╷╷. ₐₓₓₓₑₓₓₕᵢⱼₖₗₘₙₒₚₓᵣₛₜᵤᵥₓₓₓₓ ᴀʙcᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀꜱᴛᴜᴠᴡxʏᴢ

API

constructor

src/index.js

Contruct a BespokeString instance.

constructor(content: String)
Parameters
content (String) The string content.

pad → BespokeString

src/index.js

Pad the contents.

pad(length: Number, char: String) → BespokeString
Parameters
length (Number = 8) [description]
char (String = ' ') [description]
Returns
BespokeString: A BespokeString instance.

toSub → BespokeString

src/index.js

Transform the contents to subscript characters.

toSub() → BespokeString
Returns
BespokeString: A BespokeString instance.

toSuper → BespokeString

src/index.js

Transform the contents to superscript characters.

toSuper() → BespokeString
Returns
BespokeString: A BespokeString instance.

asEmoji → BespokeString

src/index.js

Print Emoji characters.

Totally naïve implentation right now, just pad wide emoji chars with a space.

asEmoji() → BespokeString
Returns
BespokeString: A BespokeString instance.

inBox → BespokeString

src/index.js

Print the content as a graphic box.

inBox(options: Object) → BespokeString
Parameters
options (Object = {}) Boxen options.
Returns
BespokeString: A BespokeString instance.

bespokeString → BespokeString

src/index.js

Helper method for creating a BespokeString instance

bespokeString(content: String) → BespokeString
Parameters
content (String) String content.
Returns
BespokeString: A BespokeString instance.

Helper method for padding a string.

pad(content: String, length: Number, char: String) → String
Parameters
content (String) The string to pad.
length (Number) Target length.
char (String) Character to use for pad.
Returns
String: The padded string.

Helper method for creating a visual box (using boxen)

box(content: String, options: Object) → String
Parameters
content (String) Box content.
options (Object) Boxen options.
Returns
String: The contructed box.

toSubscript String

src/index.js

Helper method from creating a simple Unicode subscript representation.

toSubscript(content: String) → String
Parameters
content (String) The string to transform to subscript.
Returns
String: The subscript string.

toSuperscript String

src/index.js

Helper method from creating a simple Unicode superscript representation.

toSuperscript(content: String) → String
Parameters
content (String) The string to transform to superscript.
Returns
String: The superscript string.

Helper method from creating a wide Emoji character.

emoji(content: String) → String
Parameters
content (String) The emoji to print.
Returns
String: The Emoji string.