Utilities Module

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.

typescript
const tempId = `tmp-${__sys__.utils.str.randomString(6)}`; // → "tmp-aB7x9z"
Non-Cryptographic
This implementation is not cryptographically secure. For security-critical tokens, use the crypto module.

.slugify(text)

Transforms an arbitrary string into a URL-safe slug by normalizing case and removing non-alphanumeric characters.

typescript
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.

typescript
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.

typescript
const key = __sys__.utils.str.toCamelCase("first_name"); // → "firstName"

.capitalize(text)

Ensures the first character of the input string is uppercase.

typescript
__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.

typescript
__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.

typescript
__sys__.utils.str.countOccurrences("ERROR: Failed. ERROR: Timeout.", "error"); // → 2

.toQueryString(params)

Serializes a flat record into a URL-encoded query string format.

typescript
const qs = __sys__.utils.str.toQueryString({ search: "query string", page: 1 });
// → "search=query%20string&page=1"
Number Utilities

Learn about math operations and byte formatting in XyPriss.