String Utilities (str)
Optimized functions for string manipulation, generation, and formatting.
.randomString(length?)
Generates a random Alpha-Numeric string. Ideal for temporary identifiers or nonces.
const tempId = `tmp-${__sys__.utils.str.randomString(6)}`; // → "tmp-aB7x9z"crypto module..slugify(text)
Transforms an arbitrary string into a URL-safe slug by normalizing case and removing non-alphanumeric characters.
const slug = __sys__.utils.str.slugify("Implementing XyPriss Utilities!");
// → "implementing-xypriss-utilities-a-deep-dive".truncate(text, maxLength, suffix?)
Shortens a string to a specific length. The total length, including the suffix, will exactly equal maxLength.
const short = __sys__.utils.str.truncate("This is a very long description", 30);
// → "This is a very long descri...".toCamelCase(text)
Converts hyphenated, underscored, or space-separated strings into standard camelCase notation.
const key = __sys__.utils.str.toCamelCase("first_name"); // → "firstName".capitalize(text)
Ensures the first character of the input string is uppercase.
__sys__.utils.str.capitalize("john_doe"); // → "John_doe".pad(text, length, char?, position?)
Pads the input string to a target length using a specific character at the start or end.
__sys__.utils.str.pad("42", 5, "0"); // → "00042".countOccurrences(text, word, caseSensitive?)
Analyzes a text body to count how many times a specific substring appeared.
__sys__.utils.str.countOccurrences("ERROR: Failed. ERROR: Timeout.", "error"); // → 2.toQueryString(params)
Serializes a flat record into a URL-encoded query string format.
const qs = __sys__.utils.str.toQueryString({ search: "query string", page: 1 });
// → "search=query%20string&page=1"Learn about math operations and byte formatting in XyPriss.
