📚 Proxies
The hbh-proxies package ships with utility libraries exposed via Proxies:
1import { Proxies } from "hbh-proxies";2const { HBHChalk, HBHString, DataConverter } = Proxies;
1️⃣ DataConverter
Purpose: Convert between common data types (strings, numbers, arrays, booleans, JSON).
Key Methods:
| Method | Description |
|---|---|
strToArray(str) |
Converts string to array of characters. |
strToArrayByComma(str) |
Splits a string by commas into an array. |
arrayToStr(arr) |
Joins an array into a string. |
arrayToStrWithSpace(arr) |
Joins an array into a string with spaces. |
strToNum(str) |
Converts string to Number. |
strToInt(str) |
Converts string to integer using parseInt. |
numToStr(num) |
Converts number to string. |
intToFloat(n) |
Converts integer to float using parseFloat. |
parseJSON(str) |
Parses JSON string, returns null on error. |
stringifyJSON(obj) |
Converts object to JSON string. |
boolToStr(b) |
Converts boolean to string. |
strToBool(str) |
Converts string to boolean (true, 1, yes, on → true). |
Usage Example:
1DataConverter.strToArray("hello");2// → ['h','e','l','l','o']4DataConverter.strToBool("Yes");5// → true7DataConverter.parseJSON('{"a":1}');8// → { a: 1 }
2️⃣ HBHChalk
Purpose: Terminal string styling (colors, backgrounds, styles, RGB/Hex).
Features:
| Method / Property | Description |
|---|---|
red, green, blue… |
Standard ANSI colors |
brightRed, brightGreen… |
Bright text colors |
bgRed, bgGreen… |
Background colors |
hex(colorHex) |
24-bit color by hex (text) |
bgHex(colorHex) |
24-bit color by hex (background) |
rgb(r,g,b) |
Text color using RGB |
bgRgb(r,g,b) |
Background RGB color |
color256(code) |
256-color text |
bgColor256(code) |
256-color background |
bold, italic, underline, dim, inverse, strikethrough |
Text styles |
error(str) |
Shortcut: red.bold(str) |
strip(str) |
Removes all ANSI codes |
preview(str) |
Prints styled string to console |
Usage Example:
1HBHChalk.red.bold("Error!");2HBHChalk.hex("#ff8800")("Warning");3HBHChalk.bgRgb(0,128,255)("Hello Background");4HBHChalk.strip("\x1b[31mRed\x1b[0m");5// → "Red"
3️⃣ HBHString
Purpose: Chainable string utilities for case conversion, trimming, formatting, encoding, and more.
Key Features:
| Category | Examples |
|---|---|
| Trimming / Whitespace | trim, ltrim, rtrim, collapse |
| Case Conversion | toUpper, toLower, capitalize, uncapitalize, title, swapCase, alternatingCase |
| Casing / Naming | toCamelCase, toPascalCase, toSnakeCase, toKebabCase, slugify |
| Reversing / Padding | reverse, padStart, padEnd, padBoth, mirror, center |
| Filtering / Stripping | removeVowels, removeConsonants, onlyAlpha, onlyNumeric, onlyAlphaNumeric, stripHTML, stripSymbols, stripNonAlpha, stripNonASCII, stripPunctuation |
| Encoding / Decoding | base64, unbase64, uriEncode, uriDecode |
| Quotes / Wrapping | quote, singleQuote, parens, brackets, braces, wrap, wrapWith, encloseDouble, encloseSingle |
| Number / Digit | extractDigits, removeDigits, hasNumbers, isNumeric, toNumber |
| Fun / Creative | shout, mockingSponge, emojiWrap, binary, hex |
| String Info / Checks | length, wordCount, lineCount, isUpper, isLower, isBlank, startsWithA, endsWithZ, isSlugSafe |
| Custom Suffix / Prefix | addPrefix, addSuffix, wrapSlug |
| Markdown / HTML | markdownBold, markdownItalic, htmlBold, htmlItalic |
Usage Example:
1HBHString.toUpper("hello"); 2// → "HELLO"4HBHString.toCamelCase("hello world"); 5// → "helloWorld"7HBHString.removeVowels("beautiful"); 8// → "btfl"10HBHString.slugify("Héllö Wörld!"); 11// → "hello-world"13HBHString.shout("hey"); 14// → "HEY!!!"16HBHString.binary("AB"); 17// → "1000001 1000010"
These libraries are fully chainable thanks to ProxyBuilder. Each method can be called directly, or combined in a pipeline:
1HBHString.toUpper.removeVowels("hello world");2// → "HLL WRLD"4DataConverter.strToArrayByComma.strToInt(["1","2","3"]);5// → [1, 2, 3]