Add count() and clamp() functions#29
Merged
Sander-Toonen merged 2 commits intomasterfrom Jan 23, 2026
Merged
Conversation
Co-authored-by: Sander-Toonen <5106372+Sander-Toonen@users.noreply.github.com>
Sander-Toonen
requested changes
Jan 23, 2026
Sander-Toonen
left a comment
There was a problem hiding this comment.
Rearrange all functions in docs/syntax.md. Create sections for numeric functions, string functions, array functions and object functions.
Copilot
AI
changed the title
[WIP] Add count and clamp functions with updated documentation
Add count() and clamp() functions
Jan 23, 2026
Copilot stopped work on behalf of
Sander-Toonen due to an error
January 23, 2026 15:48
There was a problem hiding this comment.
Pull request overview
This PR introduces two new built-in functions, count() for array length and clamp() for numeric range bounding, and wires them through the parser, docs, and language service. It also adds targeted test coverage to ensure behavior matches existing conventions, especially around undefined handling.
Changes:
- Added
count(array)function in the array operations module, with tests and documentation describing its behavior andundefinedhandling. - Added
clamp(value, min, max)function in the math/advanced module, with tests covering ranges, edge values, decimals, andundefinedarguments. - Updated parser wiring, language service IntelliSense documentation, and syntax documentation to expose and describe the new functions.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
test/functions/functions-array-string.ts |
Adds unit tests validating count() behavior on empty, single, multi-element, and undefined-containing arrays, plus undefined arguments. |
test/functions/functions-advanced.ts |
Adds unit tests validating clamp() behavior for in-range, below-min, above-max, negative ranges, decimals, and undefined arguments. |
src/parsing/parser.ts |
Wires count and clamp into the parser’s built-in function map and re-exports, making them available in expressions. |
src/language-service/language-service.documentation.ts |
Extends built-in function documentation to describe count and clamp for language service/IntelliSense consumers. |
src/functions/math/advanced.ts |
Implements clamp() with undefined-aware handling and min/max bounding. |
src/functions/array/operations.ts |
Implements count() with undefined passthrough and runtime type checks consistent with other array helpers (e.g., sum). |
docs/syntax.md |
Updates syntax reference to include clamp and count in the pre-defined functions table with descriptions matching their implementations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two new built-in functions:
count()for array length andclamp()for bounding values.Changes
count(array)- Returns number of items in an arrayclamp(value, min, max)- Constrains value to [min, max] rangeUsage
Both functions return
undefinedwhen passedundefinedarguments, consistent with existing function behavior.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.