Skip to content

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: + - * / %

sum = a + b;
product = a * b;
diff = a - b;
quotient = a / b;
remainder = a % b;

Comparison: < <= > >= == !=

isGreater = a > b;
isEqual = a == b;
isLessEqual = a <= b;
notEqual = a != b;

Logical: && || !

bothTrue = a && b; // AND
eitherTrue = a || b; // OR
notTrue = !a; // NOT

Assignment: = += -= *= /= %=

x = 5;
x += 3;
x -= 2;
x *= 4;
x /= 2;
x %= 3;

Postfix: ++ --

count++;
index--;

Ternary: condition ? valueIfTrue : valueIfFalse

status = age >= 18 ? "Adult" : "Minor";

Control Flow

If Statement:

if (condition) {
  // code
} else if (otherCondition) {
  // code
} else {
  // code
}

While Loop:

i = 0;
while (i < 10) {
  // code
  i = i + 1;
}

Exit Statement:

exit; // Terminates script normally

Throw Statement:

throw "Error message"; // Terminates with error
throw; // Throws "Runtime error"

No for, break, continue, switch

Functions

Declaration:

function name(param1, param2) {
  // code
  return result;
}

Call:

result = name(arg1, arg2);

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:

person = {
  name: "John",
  age: 30,
  email: "john@example.com",
};

Access:

personName = person.name;
personAge = person.age;

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:

numbers = [1, 2, 3, 4, 5];
names = ["Alice", "Bob"];
empty = [];
arr = $Array(10, 20, 30);

Access:

first = numbers[0];
count = numbers.Length;

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:

total = nums.ReduceToNum((sum, n) => sum + n, 0);

Find Max:

max = nums.ReduceToNum((m, n) => (n > m ? n : m), nums[0]);

Count Matching:

count = items.Filter((x) => x.status == "Active").Length;

Calculate Average:

sum = nums.ReduceToNum((s, n) => s + n, 0);
avg = sum / nums.Length;

Check Age:

age = $DifferenceInYears(birthDate, $Today());
isAdult = age >= 18;

Format Currency:

display = amount.ToString("C2"); // $1,234.56

Filter and Map:

result = items.Filter((x) => x.active).Map((x) => x.value);

Important Rules

No Implicit Coercion:

  • Explicit comparisons required: count > 0, not count
  • No truthiness: use flag == true
  • Exception: + with strings concatenates

No Type Coercion:

  • Numbers don't auto-convert
  • Use $ToNumber(), $ToString(), etc.

Strict Boolean:

  • Only true and false are boolean
  • Comparisons return boolean
  • Use explicit checks: value != null

Comments:

// Single-line comments only
x = 10; // End of line comment

Semicolons:

  • Required for statements
  • Not for block endings

EverSharp v1 | Quick Reference | © 2024