parseUrl
Generic URL parser. Extracts standard URL parts (domain, path, query) plus Prisme.ai-specific fields (workspaceId, file id/filename).
Returns an object with the following fields:
How id / filename splitting works
The last path segment is parsed based on the number of dots:
- 2+ dots (
{id}.{name}.{ext}):idis everything before the first dot,filenameis the rest. - 1 dot (
{name}.{ext}): the whole segment is thefilename, noid. - 0 dots: the whole segment is the
filename, noid.
Examples
Extract a file ID from a native upload URL:splitText
Split text into chunks using a recursive character splitting strategy. The splitter tries separators in order, splits on the first one found, merges small pieces back up tochunkSize, maintains chunkOverlap between consecutive chunks, and recurses with finer separators for pieces still too large.
Returns an array of
{ content, size } objects:
Split with custom separators (e.g. Markdown headings)
Iterate over chunks
search
grep-like line search over a text content. Returns the matching lines with their 1-based line numbers, so an automation can act on positions without re-parsing the text.
Returns
{ matches: [{ line, text, context? }], count } where count is the number of matching lines (context lines excluded).
substitute
sed-like regex substitution. Use this instead of thereplace() expression helper when you need a regular expression (the expression helper is literal-only). Returns the new content and the number of replacements made, so you can detect no-ops.
Returns
{ content, count }.
diff
Produces a unified diff between two texts, the complement ofapplyPatch. Feed the result to applyPatch to reapply the change: applyPatch(a, diff(a, b).patch) yields b.
Returns
{ patch, changed, additions, deletions }.
applyPatch
Applies a unified diff to a text content. Designed for LLM-generated patches: hunks are located by matching their context lines, not by trusting the@@ line numbers (models are unreliable at line arithmetic), so a patch still applies even when its line numbers are off.
Returns
{ content, hunksTotal, hunksApplied, hunksFailed }. A hunk that fails never corrupts the content, its reason is actionable so a model can regenerate just that hunk.
encodeUriComponent
Percent-encodes a single URI component, exactly like JavaScript’sencodeURIComponent.
URLSearchParams(...).asString already encodes, but only as key=value pairs and with + for spaces. A lone path segment has no other native way through — a namespaced project path such as group/sub/repo that must travel as group%2Fsub%2Frepo, for instance.
Returns the encoded string. Everything outside
A-Z a-z 0-9 - _ . ! ~ * ' ( ) is escaped, and a space becomes %20, not +.
removeDiacritics
Strips diacritical marks from text, leaving the base letters. Case is preserved, and text with nothing to fold comes back unchanged.
Two passes, because neither alone suffices. Unicode decomposition splits a precomposed letter into base + combining mark and every non-spacing mark is dropped, which covers Latin, Greek and Cyrillic without enumerating anything. A small table then handles the letters that have no decomposition — a stroke or a bar is part of the glyph, not a combining mark, so
ø, đ, ł, ħ survive the first pass untouched; ligatures that are letters in their own right (æ, œ, ß) are expanded here too.
A typical use is normalising a filename before upload: macOS stores filenames in NFD, and services that store an upload under one normalisation but reference it under another will 404 on accented names.