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");

// Check whether a property exists
exists = $HasProperty(obj, "propertyName");
exists2 = obj.HasProperty("propertyName");

// Set property by name
$SetValue(obj, "propertyName", value);

// Add new property (returns a new object)
obj = 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)
.ReduceToNum(lambda) Aggregate to number nums.ReduceToNum((s, n) => s + n)
.ReduceToStr(lambda) Aggregate to string words.ReduceToStr((s, w) => s + w)
.ReduceToObj(lambda) Aggregate to object arr.ReduceToObj((o, x) => o.AddProperty(x.k, x.v))
.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)
.Slice(start, end) Sub-array nums.Slice(1, 3)
.IndexOf(item) Position of item nums.IndexOf(5)
.ForEach(lambda) Run for each item arr.ForEach((x) => $Log(x))
.Push(item) Add to end arr.Push(10)
.AddRange(arr) Append items arr.AddRange(other)
.Insert(i, item) Insert at index arr.Insert(0, 10)
.Remove(item) Remove item arr.Remove(10)
.RemoveAt(i) Remove at index arr.RemoveAt(0)
.Clear() Remove all items arr.Clear()
.Distinct() Remove duplicates nums.Distinct()
.Reverse() Reverse order nums.Reverse()
.Join(separator) Join to string words.Join(" ")
$AddToArray(arr, item) Add and return array arr = $AddToArray(arr, 10)
$Sort(arr, prop?) Sort ascending $Sort(items, "Value")
$Map(arr, prop) Pluck property $Map(items, "Value")
$Length(arr) Length $Length(items)

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"]
.Substring(start, len?) Extract text "hello".Substring(1, 3) → "ell"
.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"
.RemoveNonAlpha() Keep letters/digits "a1-b2".RemoveNonAlpha() → "a1b2"
.ToStringSafe() Safe stringify value.ToStringSafe() → "" for null
.GetCountryNameFromISOCode() Country lookup "UK".GetCountryNameFromISOCode() → "United Kingdom"
.ToString(fmt) Format num.ToString("N2") → "1,234.56"
.GetOptionName() Option name part "Gold##G".GetOptionName() → "Gold"
.GetOptionValue() Option value part "Gold##G".GetOptionValue() → "G"
.GetOptionInfoText() Option info part "Gold##G##Info".GetOptionInfoText() → "Info"
$Length(str) Length $Length("hello") → 5

Math Functions

Function Description Example
$Max(a, b) Maximum value $Max(5, 10) → 10
$Min(a, b) Minimum value $Min(5, 10) → 5
$Abs(n) Absolute value $Abs(-5) → 5
$Round(n, decimals) Round $Round(3.756, 2) → 3.76
$Pow(base, exp) Raise to a power $Pow(2, 8) → 256
$Ln(n) Natural logarithm $Ln(2.71828) → 1
$Sum(arr, prop?) 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")
.ToDateUTC(tz?) To UTC "2024-01-15".ToDateUTC("ES")
.ToDateOnly() To DateOnly $Now().ToDateOnly()
.ToDateLocalTime(tz) UTC to local utc.ToDateLocalTime("Europe/London")
.ToShortDateString() Short date text $Today().ToShortDateString()
.GetTimeZoneAbbreviation(tz) Timezone short local.GetTimeZoneAbbreviation("Eastern Standard Time")
$ConvertTimeFromUtc(d, tz) UTC to timezone $ConvertTimeFromUtc($Now(), "Eastern Standard Time")
$ConvertTimeToUtc(d, tz) Timezone to UTC $ConvertTimeToUtc(local, "Eastern Standard Time")
$AddSeconds(date, n) Add seconds $AddSeconds(date, 30)
$AddMinutes(date, n) Add minutes $AddMinutes(date, 15)
$AddHours(date, n) Add hours $AddHours(date, 2)
$AddDays(date, n) Add days $AddDays(date, 7)
$AddMonths(date, n) Add months $AddMonths(date, 1)
$AddYears(date, n) Add years $AddYears(date, 1)
$DifferenceInSeconds(d1, d2) Seconds between $DifferenceInSeconds(start, end)
$DifferenceInMinutes(d1, d2) Minutes between $DifferenceInMinutes(start, end)
$DifferenceInHours(d1, d2) Hours between $DifferenceInHours(start, end)
$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
$StartOfDay(date) Day start $StartOfDay(date) → 00:00:00
$EndOfDay(date) Day end $EndOfDay(date) → 23:59:59.999

Conversion Functions

Function Description Example
.ToNumber() String to number "42".ToNumber() → 42
.ToString(fmt?) Value to string num.ToString("N2")
.ToStringSafe() Null-safe string value.ToStringSafe()
$ToDate(str) String to DateTime $ToDate("2024-01-15")
.ToDateUTC(tz?) String to UTC DateTime "2024-01-15".ToDateUTC()
.ToDateOnly() DateTime to DateOnly dateTime.ToDateOnly()
.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, args...) Log to output $Log("Total: {0}", total)
$GetValue(obj, prop) Get property $GetValue(obj, "name")
$HasProperty(obj, prop) Check property $HasProperty(obj, "name")
$SetValue(obj, prop, val) Set property $SetValue(obj, "age", 30)
$IsInRange(min, max, val) Range check $IsInRange(0, 100, val)
$IsNumber(val) Check numeric $IsNumber("42.5")
.HasProperty(prop) Check property obj.HasProperty("name")
.AddProperty(name, val) Copy with property obj.AddProperty("age", 30)
.IsNullOrEmpty() Null/empty check value.IsNullOrEmpty()
$Fetch(url, options?) HTTP request $Fetch("https://api.example.com")
$Stringify(obj) To JSON $Stringify(obj)

Lookup Functions

Function Description Example
$FindEquals(arr, prop?, val) Equal to $FindEquals(items, "Type", "A")
$FindNotEquals(arr, prop?, val) Not equal to $FindNotEquals(items, "Type", "A")
$FindGreaterThan(arr, prop?, val) Greater than $FindGreaterThan(items, "Value", 10)
$FindGreaterThanOrEqual(arr, prop?, val) Greater or equal $FindGreaterThanOrEqual(nums, 10)
$FindLessThan(arr, prop?, val) Less than $FindLessThan(items, "Value", 10)
$FindLessThanOrEqual(arr, prop?, val) Less or equal $FindLessThanOrEqual(nums, 10)

Testing Functions

Function Description Example
$AssertTrue(cond) Assert true $AssertTrue(x > 0)
$AssertFalse(cond) Assert false $AssertFalse(x < 0)
$AssertAreEqual(expected, actual) Assert equal $AssertAreEqual(6, $Sum([1,2,3]))

Common Patterns

Sum Array:

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

Find Max:

max = nums.ReduceToNum((m, n, i) => (i == 0 || n > m ? n : m));

Count Matching:

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

Calculate Average:

sum = nums.ReduceToNum((s, n) => s + n);
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