apps-script-utils 2.1.1 Help

requireValidSlug

function requireValidSlug( value: string | null | undefined, message: string = "Expected a valid slug." ): string;

Starts with a letter, then letters, digits, hyphens and underscores — the shape a URL segment or a key can take. Spaces, leading digits and an empty string are rejected.

isX and nonX answer a question and never interrupt control flow; requireX and requireNonX hand the value back or throw. The scheme is explained in Validation conventions.

Parameters

Parameter

Type

Description

value

string \| null \| undefined

The value to validate.

message (optional) = "Expected a valid slug."

string

The message of the exception. A default is used when omitted.

Returns

string — the same value, typed as a slug.

Throws

Exception

Condition

IllegalArgumentException

the value is not a slug.

Examples

What passes and what does not

requireValidSlug("my-page"); // => "my-page" requireValidSlug("a_1"); // => "a_1" requireValidSlug("1-page"); // throws IllegalArgumentException requireValidSlug("my page"); // throws IllegalArgumentException

See also

Source

src/lang/string/requireValidSlug.ts

23 September 2026

This documentation was generated with AI (Claude) from the library's source code.