-
Notifications
You must be signed in to change notification settings - Fork 1
String
runtoolkit edited this page Apr 13, 2026
·
1 revision
Pure stateless string utilities. All functions are named exports.
import * as str from './src/string.js';
// or selectively:
import { progressBar, formatTicks } from './src/string.js';str.concat('a', 'b', 'c') // → 'abc'
str.repeat('ab', 3) // → 'ababab'
str.truncate('hello world', 5) // → 'hello'
str.padLeft('7', 3, '0') // → '007'
str.insert('hello', 3, 'XY') // → 'helXYlo'
str.find('hello', 'ell') // → 1 (index, -1 if not found)
str.replace('a b a', 'a', 'x') // → 'x b x' (all occurrences)
str.split('a,b,c', ',') // → ['a', 'b', 'c']
str.toLowercase('HELLO') // → 'hello'
str.toUppercase('hello') // → 'HELLO'str.toNumber('42') // → 42
str.toNumber('abc') // → null
str.toString(42) // → '42'str.formatNumber(1234567) // → '1,234,567'
str.formatNumber(1234567, 'tr-TR') // locale-aware
str.formatTicks(1200) // → '1m 0s' (at 20 TPS)
str.formatTicks(1200, 20) // same, explicit TPS
str.ordinal(1) // → '1st'
str.ordinal(2) // → '2nd'
str.ordinal(3) // → '3rd'
str.ordinal(11) // → '11th'
str.pluralize(1, 'item') // → '1 item'
str.pluralize(3, 'item') // → '3 items'
str.pluralize(3, 'ox', 'oxen') // → '3 oxen' (custom plural)
str.progressBar(7, 10, 20)
// → '██████████████░░░░░░'
// progressBar(value, max, width, filledChar, emptyChar)
// defaults: width=20, filled='█', empty='░'
str.separator(40) // → '────────────────────────────────────────'
str.separator(20, '=') // → '===================='