k.utils.string
String and HTML text processing (
KText)
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, Page / View server scripts | None | Stripping rich-text HTML tags, generating summaries, and case-insensitive edits |
The script path is k.utils.string (KText type), providing HTML stripping, substring extraction, and case-insensitive replacement or removal.
Quick Start
js
k.api.get("cleanText", () => {
const plain = k.utils.string.removeHtml("<p>Hello <b>Kooboo</b> World</p>")
const summary = k.utils.string.sementicSubString(plain, 0, 14)
return { plain, summary }
})Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
removeHtml(input) | Remove HTML tags from a string | string |
subString(input, start, count) | Extract a substring (throws if start + count exceeds length) | string |
sementicSubString(input, start, count) | Extract a substring along word or semantic boundaries (returns null if start is past the end or only whitespace remains) | string | null |
replace(input, oldValue, newValue) | Perform case-insensitive substring replacement | string |
remove(input, valueToRemove) | Remove matching substrings case-insensitively | string |
Methods
All five k.utils.string methods take a source string and return the transformed result (sementicSubString() may return null).
| Method | Description |
|---|---|
removeHtml(input) | Remove HTML tags |
subString(input, start, count) | Extract substring (throws if start + count exceeds string length) |
sementicSubString(input, start, count) | Extract substring along word/semantic boundaries (returns null if start is past the end or remaining characters are whitespace) |
replace(input, oldValue, newValue) | Case-insensitive replace |
remove(input, valueToRemove) | Case-insensitive substring removal |
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string | Yes | Source string |
start | number | Yes | Start index; values below 0 are treated as 0 |
count | number | Yes | Length to take |
oldValue | string | Yes | Old value to replace, case-insensitive |
newValue | string | Yes | New value |
valueToRemove | string | Yes | Value to remove, case-insensitive |
Returns: string; sementicSubString() returns string | null (null when start is beyond the string length—including empty strings—or when the remaining slice is all whitespace).
js
const plain = k.utils.string.removeHtml("<p>Hi</p>")
const part = k.utils.string.subString("hello world", 0, 5)
const semantic = k.utils.string.sementicSubString("Kooboo builds websites", 0, 12)
const normalized = k.utils.string.replace("Hello KOOboo", "kooboo", "Kooboo")
const removed = k.utils.string.remove("SKU-001-draft", "-draft")TypeScript Definitions
ts
interface KText {
removeHtml(input: string): string;
sementicSubString(input: string, start: number, count: number): string | null;
subString(input: string, start: number, count: number): string;
replace(input: string, oldValue: string, newValue: string): string;
remove(input: string, ValueToRemove: string): string;
}Related Docs
- k.utils.dom — HTML document parsing