Pen'script functions

Functions in pen-script are objects with the attributes starting with ":". When writing a function in pen-script, Penbox will evaluate the function in real-time and replace the object with the result of the function.

This manual will discuss the following topics: 

Operators 

:sum

Return the sum of a list of values:

Is undefined if an element of the list is a string or an object.
 :product

Returns the product of a list of values:

:max

Returns the max of a list of values:

Also works with date formats 

:min

Returns the min of a list of values:

Also works with date formats.
:increasing

Returns true if the second value is higher than the first value provided in the list:

Logic

 :if :then :else

Evaluate expression in :if. Return :then if expression returns a trurthy value (eg: a string not empty is a truthy value), return :else otherwise.

 
 
:case :when

Evaluate a value and return the block associated with the value (in most language it corresponds to a switch):

 
:defined

Returns true if the evaluated expression is defined (neither null nor undefined).

Example:

 :cmp

Compare a value with an other value using a function.

The list of possible functions:

  • :eq compares if the two elements are equal
  • :gt compares if the first element is greater than the second one
  • :ge compares if the first element is greater or equal to the second one
  • :lt compares if the first element is lower than the second one
  • :le compares if the first element is lower or equal to the second one
 :in

Evaluate if a value is present in a list:

 :includes

Evaluate if a list contains a value:

:intersects

Evaluate of some elements from a list can be found in some elements from an other list:

:not

Give the reverse boolean value of an expression:

:true

Evaluate if an expression is true.

:false

Evaluate if an expression is false.

:every

Evaluate if all the expressions in the list return a truthy value

 :some

Evaluate if at least one of the expressions in the list return a truthy value

:coalesce

Returns the first undefined value of an list:

List & loops 

 :range

Return a list of integer from index_start to index_end:

{":range": [4, 10]} will return a value of [4, 5, 6, 7, 8, 9].
:array :fill

Create an array with a specified length and optionally fill it using an expression.

The following variables are accessible in the :fill context:
  • @first: boolean, true if first item
  • @index: current index, starting counting at 0
  • @position: current position. Equals to index + 1
  • @last: boolean, true if last item
:map :to

Loop in a list and return an array evaluated for every element found.

It can also be:
The following variables are accessible in the :to context:
  • @item: the content of the current item
  • @first: boolean, true if first item
  • @index: current index, starting counting at 0
  • @position: current position. Equals to index + 1
  • @last: boolean, true if last item

Objects

:assign

Based on the list of objects provided, overwrite the keys of the current object with the later.

Example:

Result:
:object-entries

Transform an object into a list with the input evaluated in ::as. Optional argument ::order-bywith value keyor value.

Example:

Will return: