https://github.com/openinf/openinf-util-text
Cross-platform terminal-friendly text utilities
https://github.com/openinf/openinf-util-text
color commonjs commonjs-module commonjs-package cross-platform functional helpers helpers-library javascript javascript-library nodejs nodejs-module npm-package predicate text typescript typescript-library typescript-package utilities
Last synced: about 1 month ago
JSON representation
Cross-platform terminal-friendly text utilities
- Host: GitHub
- URL: https://github.com/openinf/openinf-util-text
- Owner: OpenINF
- License: other
- Created: 2021-01-28T08:27:19.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-05T01:41:45.000Z (about 2 months ago)
- Last Synced: 2025-04-05T02:28:38.195Z (about 2 months ago)
- Topics: color, commonjs, commonjs-module, commonjs-package, cross-platform, functional, helpers, helpers-library, javascript, javascript-library, nodejs, nodejs-module, npm-package, predicate, text, typescript, typescript-library, typescript-package, utilities
- Language: JavaScript
- Homepage: https://github.com/OpenINF/openinf-util-text#readme
- Size: 379 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
## `@openinf/util-text`
> Essential cross-platform terminal-friendly text utilities
[!['View on npm'][npm-badge--shields]][npm-badge-url]
[!['License: MIT/Apache-2.0'][license-badge--shields]][license-badge-url]
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](#contributing) 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)
- [x] v14:Fermium (Fm)
- [x] v16:Gallium (Ga)
- [x] v18:Hydrogen (H)
[![Code Style: Prettier][prettier-badge]][prettier-url]
[![Commit Style: Conventional Commits][conventional-commits-badge]][conventional-commits-url]
[![Chat on Matrix][matrix-badge--shields]][matrix-url]
---
### Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [Contributing](#contributing)
- [License](#license)
---
Installation
![]()
`@openinf/util-text` runs on
[supported versions of Node.js](#platform--node-js-lts) and is available via
**`npm`**, **`pnpm`**, or **`yarn`**.**Using the npm CLI**
See the
[official documentation for this command](https://docs.npmjs.com/cli/commands/npm-install)
for more information.```shell
npm i @openinf/util-text
```**Using the pnpm CLI**
See the [official documentation for this command](https://pnpm.io/cli/add)
for more information.```shell
pnpm add @openinf/util-text
```**Using the Yarn 1 CLI (Classic)**
See the
[official documentation for this command](https://classic.yarnpkg.com/en/docs/cli/add)
for more information.```shell
yarn add @openinf/util-text
```
### Usage
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.```ts
import { blueify, ellipsify } from '@openinf/util-text';console.log(blueify(ellipsify('Deserializing database tables')));
```
### API
![]()
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.
#### UnicodeEscapes : enum
**Kind**: global enum
**Properties**
| Name | Type | Default |
| --- | --- | --- |
| infoSymbol | string
| "ⓘ"
|
| midlineEllipsis | string
| "⋯"
|
| ellipsis | string
| "…"
|
| errorSymbol | string
| "ⓧ"
|
| leftDoubleQuotes | string
| "“"
|
| rightDoubleQuotes | string
| "”"
|
| warningSymbol | string
| "⚠"
|
#### blueify(text) ⇒ string
Returns the supplied string as blue colored if ANSI escapes are supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### curlyQuote(text) ⇒ string
Returns the supplied string as curly quoted if Unicode is supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### ellipsify(text) ⇒ string
Returns the supplied string as ellipsified if Unicode is supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### italicize(text) ⇒ string
Returns the supplied string as italicized if ANSI escapes are supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### mdCodeSpans2html(text) ⇒ string
This API will be deprecated in the next release in favor of one that follows
[Web Platform Design Principles](https://github.com/OpenINF/openinf-util-text/issues/169).
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
|
#### redden(text) ⇒ string
Returns the supplied string as red colored if ANSI escapes are supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### underline(text) ⇒ string
Returns the supplied string as underlined if ANSI escapes are supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
#### yellow(text) ⇒ string
Returns the supplied string as yellow colored if ANSI escapes are supported.
**Kind**: global function
| Param | Type |
| --- | --- |
| text | string
|
---
### Contributing
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][].
### License
This project is licensed under either of
- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
- [MIT license](https://opensource.org/licenses/MIT)
at your option.
The [SPDX](https://spdx.dev) license identifier for this project is
`MIT OR Apache-2.0`.
---
### Show Your Support
If you like the project (or want to bookmark it) —
— [give it a star ⭐️][] — it will greatly encourage
us.
[conventional-commits-badge]: https://img.shields.io/badge/commit%20style-Conventional-%23fa6673?logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMCAzMCI+PHBhdGggc3R5bGU9ImZpbGw6ICNGRkYiIGQ9Ik0xNSwyQTEzLDEzLDAsMSwxLDIsMTUsMTMsMTMsMCwwLDEsMTUsMm0wLTJBMTUsMTUsMCwxLDAsMzAsMTUsMTUsMTUsMCwwLDAsMTUsMFoiLz48L3N2Zz4K 'Commit Style: Conventional Commits'
[conventional-commits-url]: https://www.conventionalcommits.org 'Commit Style: Conventional Commits'
[give it a star ⭐️]: https://github.com/OpenINF/openinf-util-text/stargazers
[license-badge--shields]: https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg?logo=github 'License: MIT/Apache 2.0'
[license-badge-url]: #license 'License: MIT/Apache 2.0'
[matrix-badge--shields]: https://img.shields.io/badge/matrix-join%20chat-%2346BC99?logo=matrix 'Chat on Matrix'
[matrix-url]: https://matrix.to/#/#openinf-space:matrix.org 'You're invited to talk on Matrix'
[npm-badge--shields]: https://img.shields.io/npm/v/@openinf/util-text/latest.svg?logo=npm&color=fe7d37 'View on npm'
[npm-badge-url]: https://www.npmjs.com/package/@openinf/util-text#top 'View on npm'
[open an issue]: https://github.com/OpenINF/openinf-util-text/issues
[prettier-badge]: https://img.shields.io/badge/code_style-Prettier-ff69b4.svg?logo=prettier 'Code Style: Prettier'
[prettier-url]: https://prettier.io/playground 'Code Style: Prettier'
[project-status-badge]: https://img.shields.io/badge/project%20status-under%20construction-orange 'Project Status: Under construction badge'
[Google AI safety guidance]:
https://developers.generativeai.google/guide/safety_guidance
"Safety Guidance for Developers of Generative AI Applications"