Registry / testing / spannable-string-formatter

spannable-string-formatter

JSON →
library1.0.0jsnpmunverified

A JavaScript library (v1.0.0) for styling strings using a builder pattern inspired by Android's SpannableString. It allows chaining .text(), .property() methods to apply CSS-like styles (text-color, text-decoration) and outputs a HTML string. Ships TypeScript types. Last updated in 2020, likely stable but not actively maintained. Differentiated by its simple API mimicking Android's SpannableString, but limited in features compared to libraries like chalk or ansicolor.

npm install spannable-string-formatter
INSTALL
IMPORT
SIG · SPANNABLE-STRING-F
S
spannable-string-formatter
testingjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SpannableStringFormatter
import { SpannableStringFormatter } from 'spannable-string-formatter'
import SpannableStringFormatter from 'spannable-string-formatter'
This is a named export; default import does not exist.
SpannableStringFormatter
const { SpannableStringFormatter } = require('spannable-string-formatter')
const SpannableStringFormatter = require('spannable-string-formatter')
CommonJS requires destructuring due to named export.
SpannableStringFormatter
import type { SpannableStringFormatter } from 'spannable-string-formatter'
TypeScript type import for type-only usage.

Demonstrates the builder pattern: create formatted text by chaining .text() and .property() methods, then output as HTML string.

import { SpannableStringFormatter } from 'spannable-string-formatter'; const styledText = SpannableStringFormatter .text("Hello, World!") .property("font-weight", "bold") .property("color", "red") .toString(); console.log(styledText); // Output: <span style="font-weight:bold;color:red;">Hello, World!</span>
Debug
Known issues
deprecatedLibrary has not been updated since 2020; may not support modern JavaScript/TypeScript features.
fix
Consider actively maintained alternatives like 'chalk' or 'ansicolor'.
affects: >=1.0.0
gotchaThe .property() method accepts multiple arguments, but only the first becomes the CSS value; subsequent arguments are ignored silently.
fix
Use separate .property() calls for each CSS property-value pair.
affects: >=1.0.0
gotchaThe output is a plain HTML string without any escaping; user input may lead to XSS vulnerabilities.
fix
Sanitize user input before passing to .text() or escape HTML entities manually.
affects: >=1.0.0
gotchaOnly a limited set of CSS properties are supported; unsupported properties are silently ignored.
fix
Check supported properties in documentation; consider extending the parser if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: SpannableStringFormatter.text is not a function
Using default import instead of named import.
fix
Use `import { SpannableStringFormatter } from 'spannable-string-formatter'`
Cannot read property 'text' of undefined
Trying to call .text() on the result of .property() which returns a new instance, but if using wrong chaining order.
fix
Ensure start with .text() before .property() methods.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
Resources
spannable-string-formatter — npm install spannable-string-formatter · libregistry