EverSharp Quick Reference¶
Two-column landscape cheat sheet for quick syntax reference
Left Column¶
Data Types¶
| Type | Literal Example | Description |
|---|---|---|
decimal |
42, 3.14, -10.5 |
128-bit decimal numbers |
string |
"hello", "John" |
Text in double quotes |
boolean |
true, false |
Boolean values |
null |
null |
Null/empty value |
DateTime |
$ToDate("2024-01-15") |
Date and time |
DateOnly |
$Today() |
Date without time |
Instance |
{ name: "John" } |
Object/dictionary |
InstanceArray |
[1, 2, 3] |
Array/list |
Variables¶
// No declaration keyword - just assign
count = 10;
name = "Alice";
isActive = true;
// Auto-initialized to null
uninitializedVar; // null
Operators¶
Arithmetic: + - * / %
Comparison: < <= > >= == !=
Logical: && || !
Assignment: = += -= *= /= %=
Postfix: ++ --
Ternary: condition ? valueIfTrue : valueIfFalse
Control Flow¶
If Statement:
While Loop:
Exit Statement:
Throw Statement:
No for, break, continue, switch
Functions¶
Declaration:
Call:
Lambda:
// Single parameter
square = (n) => n * n;
// Multiple parameters
add = (a, b) => a + b;
// Block body
process = (x) => {
result = x * 2;
return result;
};
Objects¶
Create:
Access:
Dynamic:
// Get property by name
value = $GetValue(obj, "propertyName");
// Set property by name
$SetValue(obj, "propertyName", value);
// Add new property
obj.AddProperty("newProp", value);
Right Column¶
Arrays¶
Create:
Access:
Common Methods:
| Method | Description | Example |
|---|---|---|
.Filter(lambda) |
Select matching items | nums.Filter((n) => n > 5) |
.Map(lambda) |
Transform items | nums.Map((n) => n * 2) |
.Find(lambda) |
Find first match | arr.Find((x) => x.id == 5) |
.Any(lambda) |
Check if any match | nums.Any((n) => n > 10) |
.All(lambda) |
Check if all match | nums.All((n) => n > 0) |
.ReduceToNum(lambda, init) |
Sum/aggregate to number | nums.ReduceToNum((s,n) => s+n, 0) |
.OrderBy(lambda) |
Sort ascending | arr.OrderBy((x) => x.value) |
.OrderByDescending(lambda) |
Sort descending | arr.OrderByDescending((x) => x) |
.Take(n) |
First n items | nums.Take(3) |
.Skip(n) |
Skip n items | nums.Skip(2) |
.Push(item) |
Add to end | arr.Push(10) |
.Distinct() |
Remove duplicates | nums.Distinct() |
.Join(separator) |
Join to string | words.Join(" ") |
String Methods¶
| Method | Description | Example |
|---|---|---|
.ToUpper() |
Uppercase | "hello".ToUpper() → "HELLO" |
.ToLower() |
Lowercase | "HELLO".ToLower() → "hello" |
.Trim() |
Remove whitespace | " hi ".Trim() → "hi" |
.Split(sep) |
Split to array | "a,b,c".Split(",") → ["a","b","c"] |
.Contains(str) |
Check contains | "hello".Contains("ell") → true |
.StartsWith(str) |
Check starts | "hello".StartsWith("hel") → true |
.EndsWith(str) |
Check ends | "hello".EndsWith("lo") → true |
.Replace(old,new) |
Replace text | "hi".Replace("i","ello") → "hello" |
.ToString(fmt) |
Format | num.ToString("N2") → "1,234.56" |
Math Functions¶
| Function | Description | Example |
|---|---|---|
$Max(a, b, ...) |
Maximum value | $Max(5, 10, 3) → 10 |
$Min(a, b, ...) |
Minimum value | $Min(5, 10, 3) → 3 |
$Abs(n) |
Absolute value | $Abs(-5) → 5 |
$Round(n) |
Round to integer | $Round(3.7) → 4 |
$Sum(arr) |
Sum array | $Sum([1,2,3]) → 6 |
Date/Time Functions¶
| Function | Description | Example |
|---|---|---|
$Now() |
Current date/time | $Now() |
$Today() |
Current date | $Today() |
$ToDate(str) |
Parse date | $ToDate("2024-01-15") |
$AddDays(date, n) |
Add days | $AddDays(date, 7) |
$AddMonths(date, n) |
Add months | $AddMonths(date, 1) |
$AddYears(date, n) |
Add years | $AddYears(date, 1) |
$DifferenceInDays(d1, d2) |
Days between | $DifferenceInDays(start, end) |
$DifferenceInYears(d1, d2) |
Years between | $DifferenceInYears(birth, today) |
$Year(date) |
Extract year | $Year(date) → 2024 |
$Month(date) |
Extract month | $Month(date) → 1 |
$Day(date) |
Extract day | $Day(date) → 15 |
Conversion Functions¶
| Function | Description | Example |
|---|---|---|
$ToNumber(str) |
String to number | $ToNumber("42") → 42 |
.ToNumber() |
Instance method | "42".ToNumber() → 42 |
$ToString(val) |
Value to string | $ToString(42) → "42" |
.ToString(fmt) |
Format string | num.ToString("N2") |
$ToDate(str) |
String to DateTime | $ToDate("2024-01-15") |
$ToDateOnly(dt) |
DateTime to DateOnly | $ToDateOnly(dateTime) |
.ToArray() |
JSON string to array | "[1,2,3]".ToArray() → [1,2,3] |
.ToDictionary() |
JSON string to object | jsonStr.ToDictionary() → object |
Utility Functions¶
| Function | Description | Example |
|---|---|---|
$Log(msg) |
Log to output | $Log("Debug info") |
$GetValue(obj, prop) |
Get property | $GetValue(obj, "name") |
$SetValue(obj, prop, val) |
Set property | $SetValue(obj, "age", 30) |
$IsInRange(min, max, val) |
Range check | $IsInRange(0, 100, val) |
$Fetch(url) |
HTTP GET | $Fetch("https://api.example.com") |
$Stringify(obj) |
To JSON | $Stringify(obj) |
Common Patterns¶
Sum Array:
Find Max:
Count Matching:
Calculate Average:
Check Age:
Format Currency:
Filter and Map:
Important Rules¶
No Implicit Coercion:
- Explicit comparisons required:
count > 0, notcount - No truthiness: use
flag == true - Exception:
+with strings concatenates
No Type Coercion:
- Numbers don't auto-convert
- Use
$ToNumber(),$ToString(), etc.
Strict Boolean:
- Only
trueandfalseare boolean - Comparisons return boolean
- Use explicit checks:
value != null
Comments:
Semicolons:
- Required for statements
- Not for block endings
EverSharp v1 | Quick Reference | © 2024