Releases · halil/string-builder · GitHub
Skip to content

Releases: halil/string-builder

v1.0.0

27 Jun 12:53

Choose a tag to compare

v1.0.0 Release Notes

First major release — modernized architecture, new methods, ESM + TypeScript support, and 57 tests.
No breaking changes to existing require("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 automatically

appendJoin(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   // → 0

Modernization

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

  • appendFormat now returns this — method chaining was silently broken in v0.1.8 (sb.appendFormat(...).append(...) threw a TypeError)
  • exports wildcard — added "./src/*": "./src/*" to prevent deep import breakage when the exports field is present
  • TypeScript exports resolution — added "types" condition inside exports so TypeScript resolves types correctly under moduleResolution: bundler and node16

Package improvements

Field Change
engines Added "node": ">=12.0.0"
files Explicit allowlist — only src/ and index.d.ts ship
sideEffects Set to false for bundler tree-shaking
repository.url Updated to git+https:// format
homepage Points to the npm package page
keywords Expanded from 8 to 19 entries for better npm discoverability

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())