Releases: halil/string-builder
v1.0.0
v1.0.0 Release Notes
First major release — modernized architecture, new methods, ESM + TypeScript support, and 57 tests.
No breaking changes to existingrequire("string-builder")usage.
What's New
Format specifiers in appendFormat
appendFormat now supports :U, :L, and :n specifiers for inline value transformation.
sb.appendFormat("{0:U}", "hello") // → "HELLO"
sb.appendFormat("{0:L}", "WORLD") // → "world"
sb.appendFormat("{0:n}", 1234567.89) // → "1,234,567.89"
sb.appendFormat("{name:U} earned {amount:n}", { name: "alice", amount: 95000 })
// → "ALICE earned 95,000"prepend(value)
Adds a value to the beginning of the buffer.
new StringBuilder("world").prepend("hello ").toString() // → "hello world"replace(search, replacement) and replaceAll(search, replacement)
In-place string or RegExp replacement within the buffer. replaceAll automatically adds the g flag to non-global RegExp patterns.
sb.append("foo foo foo")
.replace("foo", "bar") // → "bar foo foo"
.replaceAll("foo", "baz") // → "bar baz baz"
sb.replaceAll(/\s+/, "-") // global flag added automaticallyappendJoin(arr, sep?)
Appends array elements joined by a separator. Default separator is "".
sb.appendJoin(["id", "name", "email"], ", ") // → "id, name, email"
sb.appendJoin([1, 2, 3], " + ") // → "1 + 2 + 3"length and isEmpty
Query the buffer state without calling toString().
const sb = new StringBuilder("hello world")
sb.length // → 11
sb.isEmpty // → false
sb.clear()
sb.isEmpty // → true
sb.length // → 0Modernization
ESM support
import StringBuilder from "string-builder"Both CJS and ESM are exposed via the exports field. Deep imports (require("string-builder/src/stringbuilder")) continue to work.
TypeScript support
Full type definitions ship in index.d.ts — all methods typed, including overloads for appendFormat.
import StringBuilder from "string-builder"
const sb = new StringBuilder()
sb.append("hello").appendFormat("{0:U}", "world")ES6 class syntax
Replaced the Stream.call(this) constructor pattern with class StringBuilder extends Stream. instanceof Stream and pipe() now work correctly.
Jest test suite
57 tests covering all methods, edge cases, chaining behavior, and type coercion.
Bug Fixes
appendFormatnow returnsthis— method chaining was silently broken in v0.1.8 (sb.appendFormat(...).append(...)threw a TypeError)exportswildcard — added"./src/*": "./src/*"to prevent deep import breakage when theexportsfield is present- TypeScript
exportsresolution — added"types"condition insideexportsso TypeScript resolves types correctly undermoduleResolution: bundlerandnode16
Package improvements
Compatibility
No breaking changes. All existing code using require("string-builder") continues to work without modification.
// still works exactly as before
const StringBuilder = require("string-builder")
const sb = new StringBuilder()
sb.append("hello")
sb.appendLine()
sb.appendFormat("{0}", "world")
console.log(sb.toString())