Skip to content

Conversation

Copy link

Copilot AI commented Jan 16, 2026

Adds five new expression functions as requested.

New Functions

  • slice(s, start, end?) — Extract portion of string or array; supports negative indices
  • urlEncode(str) — URL-encode via encodeURIComponent
  • base64Encode(str) — Base64-encode with proper UTF-8 handling using btoa
  • base64Decode(str) — Base64-decode with proper UTF-8 handling using atob
  • coalesce(a, b, ...) — Return first non-null, non-empty-string value

Usage

const parser = new Parser();

// slice - works with strings and arrays, supports negative indices
parser.evaluate('slice("hello world", 0, 5)');     // "hello"
parser.evaluate('slice("hello world", -5)');       // "world"
parser.evaluate('slice([1,2,3,4,5], -2)');         // [4, 5]

// urlEncode
parser.evaluate('urlEncode("foo=bar&baz")');       // "foo%3Dbar%26baz"

// base64Encode / base64Decode - handles UTF-8
parser.evaluate('base64Encode("hello")');          // "aGVsbG8="
parser.evaluate('base64Decode("aGVsbG8=")');       // "hello"
parser.evaluate('base64Encode("日本語")');          // "5pel5pys6Kqe"
parser.evaluate('base64Decode("5pel5pys6Kqe")');   // "日本語"

// coalesce - first non-null/non-empty value
parser.evaluate('coalesce("", null, "found")');    // "found"
parser.evaluate('coalesce(null, 0, 42)');          // 0 (0 is valid)

All functions follow existing patterns: return undefined for undefined inputs, throw descriptive errors for type mismatches.

Original prompt

Add support for the following functions:

  • slice(s, start, end?) (with support for negative indices) it should support strings and arrays
  • urlEncode
  • base64Encode
  • coalesce(a, b, ...) (first non-null/non-empty string)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 16, 2026 12:45
Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
…dling

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for slice, urlEncode, base64Encode, and coalesce functions Add slice, urlEncode, base64Encode, and coalesce functions Jan 16, 2026
Copilot AI requested a review from Sander-Toonen January 16, 2026 12:49
Copy link

@Sander-Toonen Sander-Toonen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation for the new functions, also make sure the language server knows about the new functions

padRight: padRight,
padBoth: padBoth
padBoth: padBoth,
// New functions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in b0fb3f9.

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 16, 2026

Add documentation for the new functions, also make sure the language server knows about the new functions

Added in b0fb3f9:

  • Documentation for the new functions (slice, urlEncode, base64Encode, coalesce) in docs/syntax.md
  • Language server documentation in src/language-service/language-service.documentation.ts with descriptions and parameter info for all four functions

* Handles UTF-8 encoding properly
*/
export function base64Encode(str: string | undefined): string | undefined {
if (str === undefined) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Simplify this function by using "btoa" instead. Also create and document a base64Decode function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified base64Encode to use btoa and added base64Decode function using atob in c537880. Also added documentation and language server support for both functions, plus 7 new tests for base64Decode.

Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Copilot AI changed the title Add slice, urlEncode, base64Encode, and coalesce functions Add slice, urlEncode, base64Encode, base64Decode, and coalesce functions Jan 16, 2026
Copilot AI requested a review from Sander-Toonen January 16, 2026 13:24
@Sander-Toonen Sander-Toonen marked this pull request as ready for review January 16, 2026 14:13
@Sander-Toonen Sander-Toonen merged commit 1976648 into master Jan 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants