The snippet library.
Small, practical examples. Search by task or narrow things down below.
Build a URL query string from values
TypeScript: URLSearchParams handles query escaping and repeated parameter appends.
TypeScript✓ Tested
Decode a percent-encoded URL component
TypeScript: decodeURIComponent reverses percent encoding and throws for malformed sequences.
TypeScript✓ Tested
Extract all regex matches with their groups
TypeScript: matchAll requires a global regular expression and returns an iterator of matches.
TypeScript✓ Tested
Inspect the parsed pieces of a URL
TypeScript: Use URL properties rather than splitting a URL at punctuation.
TypeScript✓ Tested
Percent-encode one URL component
TypeScript: encodeURIComponent escapes a parameter value rather than a complete URL.
TypeScript✓ Tested
Read named regex capture groups
TypeScript: Named groups make a fixed input format easier to inspect than numeric group positions.
TypeScript✓ Tested
Reorder captured text in a replacement
TypeScript: Use numbered replacement groups to rearrange a known two-part name.
TypeScript✓ Tested
Resolve a relative URL against a base
TypeScript: A trailing slash makes the final base path component a directory.
TypeScript✓ Tested
Split text on several separator characters
TypeScript: A regex character class can recognize alternative simple delimiters.
TypeScript✓ Tested
Validate a whole ASCII identifier
TypeScript: Use an anchored expression without the multiline flag and reject a trailing line break explicitly.
TypeScript✓ Tested