@razomy/string
v0.0.1-alpha.5
Published
[](https://github.com/razomy/js/blob/main/LICENSE) [](https://github.com/razomy/js/actions) [: string
Insert a string into another string at a specific index.
Examples
addByIndexString('-text', 0, 'prefix'); // prefix-textaddByIndexString('hello ', 6, 'world'); // hello worldaddByIndexString('foo baz', 4, 'bar '); // foo bar bazcontains
contains(text: string, search: string): boolean
Checks if a string contains a specific substring.
Examples
contains('razomy', 'zo'); // truecontains('razomy', 'bar'); // falsecontains('hello world', 'hello'); // truecountOccurrences
countOccurrences(text: string, substring: string): number
Counts the number of occurrences of a substring within a text.
Examples
countOccurrences('hello world', 'l'); // 3countOccurrences('aaaa', 'aa'); // 2countOccurrences('apple', 'z'); // 0countSpaceMargin
countSpaceMargin(string: string): number
Count leading space margin of a string.
Counts the number of leading space characters before the first non-space character in a string.
Examples
countSpaceMargin('hello'); // 0countSpaceMargin(' hello'); // 3countSpaceMargin(' '); // 5countSpaceMarginByArray
countSpaceMarginByArray(): number[]
Examples
countString
countString(strings: string[], equalString: string, offset: number, maxOffset: number): number
Count occurrences of a string within a subarray of strings.
Counts how many times equalString appears in the strings array
between index offset (inclusive) and maxOffset (exclusive).
Examples
countString(['a', 'b', 'a', 'c'], 'a', 0, 4); // 2countString(['hello', 'world', 'hello'], 'hello', 1, 3); // 1countString(['x', 'y', 'z'], 'w', 0, 3); // 0create
create(value: unknown): string
Convert any value to a string.
Examples
string(100); // 100string(true); // truestring(null); // nullescapeByString
escapeByString(): string
Examples
getWords
getWords(value: string): string[]
Splits string into an array of its words.
Examples
getWords('fred, barney, & pebbles'); // [fred, barney, pebbles]getWords('camelCase'); // [camel, Case]getWords('nested_snake_case'); // [nested, snake, case]indentLines
indentLines(): string
Examples
isEndsWith
isEndsWith(text: string, target: string, position: number | undefined): boolean
Checks if string ends with the given target string.
Examples
isEndsWith('abc', 'c'); // trueisEndsWith('abc', 'b'); // falseisEndsWith('abc', 'b', 2); // trueisEndsWithAny
isEndsWithAny(text: string, targets: string[], position: number | undefined): boolean
Checks if string ends with any of the given target strings.
Examples
isEndsWithAny('image.jpg', ['.jpg', '.png']); // trueisEndsWithAny('image.gif', ['.jpg', '.png']); // falseisEndsWithAny('abc', ['a', 'b'], 2); // trueisNullOrEmpty
isNullOrEmpty(str: string | null | undefined): boolean
Check if the string is null, undefined, or empty (including whitespace).
Examples
isNullOrEmpty(null); // trueisNullOrEmpty(' '); // trueisNullOrEmpty('razomy'); // falseisStartsWith
isStartsWith(string: string, target: string, position: number): boolean
Checks if string starts with the given target string.
Examples
isStartsWith('razomy', 'r'); // trueisStartsWith('razomy', 'z'); // falseisStartsWith('razomy', 'z', 2); // trueisString
isString(value: unknown): boolean
Check if the value is a string.
Examples
isString('razomy'); // trueisString(123); // falseisString(null); // falsejoin
join(items: string[], separator: string): string
Joins an array of strings into a single string using a separator.
Examples
join(['a', 'b', 'c'], '-'); // a-b-cjoin(['hello', 'world'], ' '); // hello worldjoin(['one'], ','); // onelevenshteinDistance
levenshteinDistance(a: string, b: string): number
Calculates the Levenshtein distance between two strings using the iterative approach with memory optimization.
Examples
levenshteinDistance('kitten', 'sitting'); // 3levenshteinDistance('test', 'text'); // 1levenshteinDistance('razomy', 'razomy'); // 0merge
merge(): string
Examples
padEnd
padEnd(input: string, length: number, chars: string): string
Pads the end of a string with a given string (repeated, if needed) so that the resulting string reaches a given length.
Examples
padEnd('abc', 6); // abcpadEnd('abc', 6, '0'); // abc000padEnd('abc', 2); // abcpadStart
padStart(input: string, length: number, chars: string): string
Pads the start of a string with another string until it reaches the given length.
Examples
padStart('a', 3); // apadStart('a', 3, '0'); // 00apadStart('abc', 2); // abcprefixLines
prefixLines(text: string, prefix: string): string
Add margin to every line of the string.
Examples
prefixLines('Hello', ' '); // HelloprefixLines('Line 1\nLine 2', '> '); // > Line 1\n> Line 2prefixLines('Code', '\t'); // \tCoderemoveIndex
removeIndex(string: string, index: number, length: number): string
Remove characters from a string at a given index.
Removes a specified number of characters from a string starting at the given index, returning the resulting string.
Examples
removeIndex('hello', 1, 1); // hlloremoveIndex('abcdef', 2, 3); // abfremoveIndex('world', 0, 2); // rldrepeat
repeat(content: string, count: number): string
Repeats a string a specified number of times.
Examples
repeat('a', 3); // aaarepeat('razomy', 2); // razomyrazomyrepeat('test', 0); // replace
replace(): string
Examples
similarity
similarity(): number
Examples
split
split(text: string, splitter: string | RegExp, limit: number | undefined): string[]
Split string by splitter characters.
Examples
split('Line 1\nLine 2', '\n'); // [Line 1, Line 2]split('A\nB\nC', /[\n]/); // [A, B, C]split('One', ''); // [O,n,e]splitLines
splitLines(text: string): string[]
Split string by newline characters.
Examples
splitLines('Line 1\nLine 2'); // [Line 1, Line 2]splitLines('A\r\nB\nC'); // [A, B, C]splitLines('One'); // [One]stripTags
stripTags(content: string): string
Strip HTML tags from a string.
Examples
stripTags('<p>Hello world</p>'); // Hello worldstripTags('<a href="https://example.com">Link</a>'); // LinkstripTags('<div><span>content</span></div>'); // contenttakeAfter
takeAfter(text: string, separator: string): string
Get the substring after the first occurrence of a separator.
Examples
takeAfter('foo.bar', '.'); // bartakeAfter('foo.bar.baz', '.bar.'); // baztakeAfter('foo', ','); // footakeBefore
takeBefore(text: string, separator: string): string
Gets the substring before the first occurrence of a separator.
Examples
takeBefore('@razomy/string', '.'); // razomytakeBefore('[email protected]', '@'); // usertakeBefore('atomic', ' '); // atomictakeBetween
takeBetween(text: string, start: string, end: string): string
Extracts a substring found between a start string and an end string.
Examples
takeBetween('The quick brown fox', 'quick ', ' fox'); // browntakeBetween('key="value";', '"', '"'); // valuetakeBetween('<div>content</div>', '<div>', '</div>'); // contenttoBuffer
toBuffer(value: string, encoding: BufferEncoding): Buffer<ArrayBufferLike>
Convert string to buffer using specified encoding.
Examples
toBuffer('abc', 'utf8'); // <Buffer 61 62 63>toBuffer('YWJj', 'base64'); // <Buffer 61 62 63>toBuffer('616263', 'hex'); // <Buffer 61 62 63>trim
trim(text: string): string
Removes whitespace from both ends of the string.
Examples
trim(' foo '); // footrim('\nbar\t'); // bartrim(' '); // truncate
truncate(text: string, length: number, omission: string): string
Truncates string if it's longer than the given maximum string length.
Examples
truncate('hello world', 5); // he...truncate('hello', 10); // hellotruncate('hello world', 7, '...'); // hello...unescapeByString
unescapeByString(): string
Examples
🕊️ Vision
"Razomy" means Together—you and me.
We act as catalysts, turning natural chaos into clarity through open collaboration.
By building honest, reliable systems, we empower humanity and create a foundation for peace.
We foster a borderless environment driven by quality code and mutual support.
Join us to build this future—one commit at a time.
💖 Fuel Our Shared Future
We can't build this without you. If this library has saved you time or helped turn chaos into clarity in your own projects, please consider backing the developers behind it. Building reliable, open-source tools takes immense time and energy. Your sponsorship isn't just a donation; it’s the fuel that keeps this project actively maintained, bug-free, and thriving for everyone who relies on it.
Help us keep the momentum going. Choose how you want to light the way:
🤝 Contributing
Contributions, issues and feature requests are welcome! Feel free to check issues page.
📝 License
Copyright © 2026 Razomy. This project is MIT licensed.
🐛 Reporting Issues
We use GitHub Issues as the official bug tracker for this project.
Before opening a new issue, please check if your problem has already been reported. If it hasn't, please open a new issue here: GitHub Issues: razomy/js
When reporting a bug, please include:
- A brief description of the issue.
- Steps to reproduce the bug.
- Your current environment (Node version, OS, etc.).
