The high-level goal of @openinf/util-text
is to serve as a Node.js package
containing essential cross-platform text utilities that degrade gracefully
when used in terminals lacking feature support. We are constantly working to
improve this repository, so please feel free to contribute if
you notice any omissions or errors.
Thanks!
Supported Node.js Environments
- v4:Argon (Ar)
- v6:Boron (B)
- v8:Carbon (C)
- v10:Dubnium (Db)
- v12:Erbium (Er)
- v14:Fermium (Fm)
- v16:Gallium (Ga)
- v18:Hydrogen (H)
@openinf/util-text
runs on
supported versions of Node.js and is available via
npm
, pnpm
, or yarn
.
Using the npm CLI
See the official documentation for this command for more information.
npm i @openinf/util-text
Using the pnpm CLI
See the official documentation for this command for more information.
pnpm add @openinf/util-text
Using the Yarn 1 CLI (Classic)
See the official documentation for this command for more information.
yarn add @openinf/util-text
To get started using the text utils provided by @openinf/util-text
, all
that needs to be done is either import/require (depending on the module format)
the default export of the module or destructure the individual named helper
functions exported.
import { blueify, ellipsify } from '@openinf/util-text';
console.log(blueify(ellipsify('Deserializing database tables')));
The “supplied string” should be supplied by app developer (not arbitrarily) because anything beyond that (e.g., in publicly-facing apps) may need be pre-processed. The next release may perform preprocessing to follow Web Platform Design Principles.
Notice that these APIs were not built for (and are potentially not good for) language models:
-
Speak with a diverse mix of prospective users of your application within your target population about its intended purpose to gain a wider perspective on potential risks and have your app be adapted to those circumstances.
ⓘ This tip was paraphrased from Google AI safety guidance; however, further reading on the topic of AI safety guidance may be available elsewhere.
- blueify(text) ⇒
string
Returns the supplied string as blue colored if ANSI escapes are supported.
- curlyQuote(text) ⇒
string
Returns the supplied string as curly quoted if Unicode is supported.
- ellipsify(text) ⇒
string
Returns the supplied string as ellipsified if Unicode is supported.
- italicize(text) ⇒
string
Returns the supplied string as italicized if ANSI escapes are supported.
- mdCodeSpans2html(text) ⇒
string
Processes the supplied string by transforming any Markdown backtick code spans (beginning and ending with a single backtick) into HTML code elements.
- redden(text) ⇒
string
Returns the supplied string as red colored if ANSI escapes are supported.
- underline(text) ⇒
string
Returns the supplied string as underlined if ANSI escapes are supported.
- yellow(text) ⇒
string
Returns the supplied string as yellow colored if ANSI escapes are supported.
Kind: global enum
Properties
Name | Type | Default |
---|---|---|
infoSymbol | string |
"ⓘ" |
midlineEllipsis | string |
"⋯" |
ellipsis | string |
"…" |
errorSymbol | string |
"ⓧ" |
leftDoubleQuotes | string |
"“" |
rightDoubleQuotes | string |
"”" |
warningSymbol | string |
"⚠" |
Returns the supplied string as blue colored if ANSI escapes are supported.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as curly quoted if Unicode is supported.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as ellipsified if Unicode is supported.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as italicized if ANSI escapes are supported.
Kind: global function
Param | Type |
---|---|
text | string |
This API will be deprecated in the next release in favor of one that follows Web Platform Design Principles.
Processes the supplied string by transforming any Markdown backtick code spans (beginning and ending with a single backtick) into HTML code elements.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as red colored if ANSI escapes are supported.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as underlined if ANSI escapes are supported.
Kind: global function
Param | Type |
---|---|
text | string |
Returns the supplied string as yellow colored if ANSI escapes are supported.
Kind: global function
Param | Type |
---|---|
text | string |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If for whatever reason you spot something to fix but cannot patch it yourself, please open an issue.
This project is licensed under either of
at your option.
The SPDX license identifier for this project is
MIT OR Apache-2.0
.
If you like the project (or want to bookmark it) —
— give it a star ⭐️ — it will greatly encourage
us.