3b. Functions - HafisCZ/sf-tools GitHub Wiki
Name | Arguments | Description | Example |
---|---|---|---|
trunc |
Number | Removes the floating part from a number |
trunc(1.15) = 1
|
round |
Number | Rounds number |
round(1.5) = 2
|
ceil |
Number | Rounds number up |
ceil(1.6) = 2
|
floor |
Number | Rounds number down |
floor(1.4) = 1
|
abs |
Number | Removes sign from a number |
abs(-4) = 4
|
exp |
Number | Returns the euler exponenial of arg |
exp(1) = 2.718281828459045
|
pow |
2 Numbers | Returns the power of <first> to the exponent <second> |
pow(3,2) = 9
|
sqrt |
Number | Returns the positive square root of a positive number |
sqrt(4) = 2
|
random |
Returns a random number between 0 and 1 |
random() = 0.477551
|
|
range |
3 Numbers | Maps third number onto the range |
range(2, 4, 0.5) = 3
|
fixed |
Number | Creates a string from a number with a fixed amount of decimal places |
fixed(1.3, 3) = '1.300'
|
fnumber |
Number | Creates a formatted string from a number with spacing |
fnumber(10000) = '10 000'
|
enumber |
Number, Number | Creates a exponential number string |
enumber(1100, 1) = '1.1e3'
|
nnumber |
Number | Creates a named number string |
nnumber(1000000) = '1 M'
|
datetime |
Number | Creates a datetime string from a timestamp |
datetime(1596045850000) = '29.07.2020 20:04'
|
duration |
Number | Returns a string with duration as DD:HH:MM |
duration(60000) = '00:00:01'
|
date |
Number | Creates a date string from a timestamp |
date(1596045850000) = '29.07.2020'
|
now |
Returns current timestamp |
now() = 1596046455998
|
|
min |
Array or Numbers | Returns minimum value |
min(1, 2, 3) = 1
|
max |
Array or Numbers | Returns maximum value |
min(1, 2, 3) = 3
|
sum |
Array or Numbers | Returns a sum of all values |
min(1, 2, 3) = 6
|
average |
Array or Numbers | Returns the average of all values |
average(1, [2, 3],4 ) = 2.5
|
indexof |
Array Number | Returns the index of the first match in the array |
indexof( [2,3,4,5,4] , 4 ) = 2
|
at |
Array Number | Returns the value at the specified index in the array |
at( [2,3,4,5,4] , 3 ) = 5
|
len |
Array or Object | Returns number of elements in the object |
len({ 1, 2, 3 }) = 3
|
sort |
Array Function | Returns the array sorted by the specified function |
sort( [2,3,4,5,4] , abs(this-4) ) = [2,3,5,4,4]
|
join |
Array Stringable | Returns a string with the concatenated values of the array with the specified separator |
join( [2,3,4,5,4] , '-' ) = 2-3-4-5-4
|
filter |
Array Condition | Returns an array purged of the elements that don't match the Condition |
filter( [1,2,2,3],this!=2 ) = [1,3]
|
distinct |
Array | Returns an array purged of duplicates |
distinct( [1,2,2,3] ) = [1,2,3]
|
flatten |
Array | Returns an array with just one level |
flatten( [1,[2,[3,[4,5]]]] ) = [1,2,3,4,5]
|
hsl |
4 Numbers | Converts HSL color into HEX format |
hsl(360, 100, 100,1) = '#ffffffff'
|
rgb |
3 Numbers | Converts RGB color into HEX format |
rgb(255, 255, 255) = '#ffffffff'
|
rgba |
4 Numbers | Converts RGBA color into HEX format |
rgba(255, 255, 255, 0.5) = '#ffffff7f'
|
gradient |
2 Colors, Number | Returns a color from a point between two specified colors |
gradient('000000', 'ffffff', 0.5) = #7f7f7fff
|
gradient |
Object, Number | Returns a color from a point between any amount of specified colors. You need to supply an array with values and colors. |
gradient({ 0: '000000', 1: 'ffffff' }, 0.5) = #7f7f7fff
|
dualcolor |
Number(%) , 2 Colors | Paints a cell with Color1 from the left until the specified % of width and the rest with Color2 if used in an expc
|
dualcolor( 23 , 'c33f36', 'E0F2F7') = linear-gradient(90deg, rgb(195, 63, 54) 23%, rgb(224, 242, 247) 23%)
|
lingradient |
Number(°) , Color, Number(%), Color, Number(%),... |
Paints a cell with N dual-color dégradé segments with tilted boundaries if used in an expc . Matching %'s of width impose a hard transition between colors |
lingradient( 45, 'green', 50, 'eb605e', 50, rgb(224, 242, 247), 80 ) = linear-gradient(45deg, rgb(0, 128, 0) 50%, rgb(235, 96, 94) 50%, rgb(224, 242, 247) 80%)
|
img |
source_url, width, height |
Inserts image via html string |
img('https://sftools.mar21.eu/res/class1.png',30,30) = <img src="https://sftools.mar21.eu/res/class1.png" width="30" height="30"/>
|
number |
Anything | Converts strings or objects to number. If conversion fails returns NaN |
number('123e-1') = 12.3
|
stringify |
Anything | Creates a string from argument |
stringify({}) = '[object Object]'
|
format |
String Anything | Creates a formatted string |
format('{0}: {1}', 1, 2) = '1: 2'
|
makesequence |
Integer, Integer | Creates an array with the sequence of integers in between |
makesequence(1,5) = [1,2,3,4,5]
|
makearray |
Integer[,Object] | Creates an array with specified length. Each position is initialized either with 0 or the Object if specified |
makearray(5,6) = [6,6,6,6,6]
|
expneeded |
Number | Returns the sum of all EXP needed to obtain the specified level |
expneeded(393) = 97350102860
|
statcost |
Number | Returns the cost of the next attribute upgrade when you have the specified number of purchases already |
statcost(3155) = 10000000
|
statsum |
Number | Returns the sum of all the gold spent up to the specified number of attribute purchases |
statsum(1000) = 5511218.5
|
log |
Anything | Returns its argument while also printing it to the browser console for debugging |
log(1000000) = 1000000
|
presence |
Anything | Returns false if null, 0, empty array, empty hash or empty string |
presence([]) = false
|
* Most common functions related to strings and numbers can also be available. Try your luck!<\p)