HareScript utility functions
Algorithms and structures
- VARIANT FUNCTION ArrayDelete(VARIANT list, VARIANT toremove)
Returns an array with all elements in 'toremove' deleted from 'list'
- VARIANT FUNCTION ArrayIntersection(VARIANT first, VARIANT second)
Returns an array containing all elements present in both arrays
- BOOLEAN FUNCTION ArrayIsSetEqual(VARIANT match, VARIANT input)
Checks if two arrays are equal, if treated as a set (ignore duplicates and ordering)
- BOOLEAN FUNCTION ArrayIsSubsetOf(VARIANT subset, VARIANT fullset)
Checks if the 'subset' array is a subset of the 'fullset' array
- BOOLEAN FUNCTION ArraysIntersect(VARIANT first, VARIANT second)
Returns TRUE if any value in either supplied array is present in both arrays.
- VARIANT FUNCTION ArrayUnion(VARIANT first, VARIANT second)
Combines the unique values from two arrays into one array
- INTEGER FUNCTION BinaryFind(VARIANT list, VARIANT element, FUNCTION PTR comparefunction)
Does a (case sensitive) binary search within a list
- VARIANT FUNCTION GetRandomElement(VARIANT input)
Returns a random element from the given input array of values.
- VARIANT FUNCTION GetShuffledElements(VARIANT input)
Shuffles the given array randomly, using the Durstenfeld algorithm for Fisher Yates shuffling.
- VARIANT FUNCTION GetSortedSet(VARIANT input)
Sorts an array of comparable values
- RECORD ARRAY FUNCTION JoinArrays(RECORD ARRAY lhs, STRING joincellname, RECORD ARRAY rhs, RECORD baserecord, RECORD options)
Join two record arrays
- RECORD FUNCTION LowerBound(VARIANT list, VARIANT element, FUNCTION PTR comparefunction)
Does a (case sensitive) binary search within a list
- INTEGER FUNCTION RecordBinaryFind(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)
Does a (case sensitive) binary search within a sorted record array
- RECORD FUNCTION RecordLowerBound(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)
Does a (case sensitive) binary search within a sorted record array
- RECORD ARRAY FUNCTION RecordRange(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)
Does a (case sensitive) binary search within a sorted record array, returns all matching records
- INTEGER FUNCTION RecordUpperBound(RECORD ARRAY list, RECORD element, STRING ARRAY cellnames)
Does a (case sensitive) binary search within a sorted record array, returns the position of the first element that is greater than the searched-for element
- INTEGER FUNCTION UpperBound(VARIANT list, VARIANT element, FUNCTION PTR comparefunction)
Does a (case sensitive) binary search within a list, returns of the position of the element that is greater than the searched-for element.
- OBJECTTYPE ValueMapper
A dictionary/map to look up values by key
String parser
- OBJECTTYPE StringParser
String parser class, has some useful functions for string parsing
eof and current can both be calculated from data and position, but they are used very often, so it would be inefficient to write wrapper functions for them.
The position is leading, but eof MAY be used for shortcuts (but MAY be ignored)
String/text comparisons and diffs
- INTEGER FUNCTION CalculateLevenshteinDistance(STRING sourcestr, STRING targetstr)
Calculates the edit distance between two strings
- RECORD FUNCTION DecodeSemanticVersion(STRING version)
Decode a semantic version string
- RECORD FUNCTION Diff(STRING ARRAY m, STRING ARRAY n)
- STRING FUNCTION EncodeSemanticVersion(RECORD version)
Encode a semantic version string from its components
- STRING FUNCTION GetBestMatch(STRING name, STRING ARRAY alternatives, RECORD options)
Find the best match for a string fiven a list of alternatives. Defaults to case insensitive match.
- STRING FUNCTION IncrementVersionMajor(STRING version)
Increments the major version of a semantic version string (resets minor version and patch level)
- STRING FUNCTION IncrementVersionMinor(STRING version)
Increments the minor version of a semantic version string (resets patch level)
- STRING FUNCTION IncrementVersionPatch(STRING version)
Increments the patch level of a semantic version string
- BOOLEAN FUNCTION IsSemanticVersionNewer(STRING fromversion, STRING toversion)
Compares two semantic version strings, returns it the second version string is newer than the first
- BOOLEAN FUNCTION IsValidSemanticVersion(STRING version)
Tests if a string is a valid semantic version string
- OBJECT FUNCTION MakeTextDiffGenerator()
- STRING FUNCTION SimpleTextDiff(STRING leftfile, STRING rightfile, RECORD options)
Gives a simple text diff between the lines of the texts
- BOOLEAN FUNCTION VersionSatisfiesRange(STRING version, STRING semverrange)
Check if a semantic version matches the specified range
Latitude/longitude calculations
- RECORD FUNCTION ConvertFromLatLng(RECORD latlng, STRING type)
Convert a latitude/longitude coordinate to another coordinates system
- RECORD FUNCTION ConvertToLatLng(RECORD coordinates, STRING type)
Convert a coordinates record from another coordinates system to latitude/longitude
- RECORD FUNCTION GetLatLngBoundingCoordinates(RECORD centerpoint, FLOAT distance, RECORD options)
Get bounding coordinates of a given distance box around a point
- FLOAT FUNCTION GetLatLngDistance(RECORD latlng1, RECORD latlng2, RECORD options)
Get the distance between two lat/long coordinates
- RECORD FUNCTION GetLatLngsBoundingCoordinates(RECORD ARRAY points)
Get bounding coordinates for a list of points
- BOOLEAN FUNCTION IsValidLatLng(RECORD latlng)
- STRING FUNCTION LatLngToString(RECORD latlng)
- RECORD FUNCTION MoveLatLng(RECORD latlng, FLOAT direction, FLOAT distance, FLOAT radius)
Move a lat/long coordinate
- RECORD FUNCTION StringTolatLng(STRING coordinates)
Localization and internationalization (i18n)
- OBJECTTYPE Collator
- OBJECTTYPE DateTimeFormat
- STRING ARRAY FUNCTION GetAvailableTimeZoneNames(STRING locale)
Get a list of available time zones names for time zone conversion
- RECORD ARRAY FUNCTION GetAvailableTimeZones(STRING locale)
List all available country-specific and general time zones
- STRING FUNCTION GetCanonicalTimeZoneID(STRING timezone)
Get the canonical time zone name for a given time zone
- RECORD ARRAY FUNCTION GetCountryList(VARIANT locale)
Get a list of country names in one or more locales or languages
- RECORD ARRAY FUNCTION GetLanguageList(VARIANT locale)
Get a list of language names in one or more locales or languages
- STRING FUNCTION GetLocaleForLangTag(STRING langtag)
- STRING FUNCTION GetLocalizedDatetimeStrings(STRING locale)
Get a string with date and time formatting components for use with FormatDateTime
- STRING FUNCTION GetLocalizeFormatString(STRING formatstring)
Convert a FormatDateTime formatting string to ICU format for use with LocalizeDateTime
- STRING FUNCTION GetSafeName(STRING value, RECORD options)
Generate a safe name for a string
- STRING FUNCTION GetSystemTimeZoneID()
Get the time zone name that is currently in use by the system
- STRING FUNCTION GetTimeZoneDisplay(STRING timezone, BOOLEAN dst, STRING style, STRING locale)
Get the display name of a timezone
- STRING FUNCTION GetTimeZoneIDForWindowsID(STRING timezone, STRING region)
Convert a Windows time zone name to a localization time zone name
- INTEGER FUNCTION GetUTCOffset(DATETIME date, STRING timezone)
Get the offset from UTC for the given time zone on a given local time
- RECORD FUNCTION GetVTimeZone(STRING timezone, DATETIME time)
Get the iCalendar time zone information for a given time zone
- BOOLEAN FUNCTION IsLocalTimeDST(DATETIME date, STRING timezone)
Check if daylight saving time is applied to the given local time in the given time zone
- BOOLEAN FUNCTION IsWeekend(DATETIME date, STRING locale)
Check if the given time is in a weekend for the given locale
- STRING FUNCTION LocalizeCurrency(VARIANT value, INTEGER decimals, BOOLEAN grouping, STRING currency, STRING locale)
Format a currency value
- STRING FUNCTION LocalizeDateTime(STRING formatstring, DATETIME date, STRING locale, STRING timezone, BOOLEAN useexact)
Returns a string containing a formatted date and time.
- STRING FUNCTION LocalizedNormalizeText(STRING value)
Normalize text for a given language
- STRING FUNCTION LocalizedToLowercase(STRING value)
Converts a string to lowercase.
- STRING FUNCTION LocalizedToUppercase(STRING value)
Converts a string to uppercase.
- STRING FUNCTION LocalizeNumber(VARIANT value, INTEGER decimals, BOOLEAN grouping, BOOLEAN round, STRING locale)
Format a numerical value
- STRING FUNCTION LocalizeOrdinal(INTEGER64 value, STRING locale)
Get the ordinal value of a numerical value
- STRING FUNCTION LocalizePercentage(FLOAT value, INTEGER decimals, BOOLEAN grouping, STRING locale)
Format a fractional value as percentage
- STRING FUNCTION LocalizeSpellout(INTEGER64 value, STRING locale)
Format a numerical value as spelled out text
- STRING FUNCTION LocalizeTimeStamp(STRING formatstring, INTEGER timestamp, STRING locale, BOOLEAN useexact)
Returns a string containing a formatted time.
- DATETIME FUNCTION LocalToUTC(DATETIME date, STRING timezone)
Convert local time to UTC time
- FUNCTION PTR FUNCTION MakeCompareFunction(STRING locale, STRING sensitivity, BOOLEAN ignorepunctuation, BOOLEAN numeric, STRING casefirst)
Get a function to compare strings
- BOOLEAN FUNCTION MatchLanguage(STRING setlanguagecode, VARIANT matchlanguages)
Check if a languagecode matches a list of languages
- STRING FUNCTION NormalizeText(STRING text, STRING langcode)
Normalize text for a given language
- OBJECTTYPE NumberFormat
- STRING FUNCTION StemWord(STRING word, STRING langcode)
Stem a word in a given language
- OBJECTTYPE TokenStream
Split text into tokens
- CONSTANT INTEGER TokenTypeControl
(Non-printable) control character
- CONSTANT INTEGER TokenTypePunct
Punctuation character
- CONSTANT INTEGER TokenTypeWhitespace
Whitespace
- CONSTANT INTEGER TokenTypeWord
A single word or number
- STRING FUNCTION TransliterateTextLocalized(STRING value)
Transliterate a string to latin characters
- DATETIME FUNCTION UTCtoLocal(DATETIME date, STRING timezone)
Convert UTC time to local time
OTP functions
- STRING FUNCTION GenerateOTPSecret(RECORD options)
Create a new HOTP/TOTP secret
- STRING FUNCTION GetHOTPCode(STRING secret, INTEGER64 counter, RECORD options)
Generate an HMAC-based one-time password
- STRING FUNCTION GetHOTPUrl(STRING secret, STRING account, STRING issuer, INTEGER64 counter, RECORD options)
Create a url which encodes the HOTP secret for use in external applications
- STRING FUNCTION GetTOTPCode(STRING secret, RECORD options)
Generate a time-based one-time password
- STRING FUNCTION GetTOTPUrl(STRING secret, STRING account, STRING issuer, RECORD options)
Create a url which encodes the TOTP secret for use in external applications
- RECORD FUNCTION TestTOTPCode(STRING secret, STRING code, RECORD options)
Test if a TOTP code matches the expected value
- RECORD FUNCTION UnpackOTPUrl(STRING url)
Unpacks an OTP url