diff --git a/docs/interpolation/common.rst b/docs/interpolation/common.rst new file mode 100644 index 0000000..4efc567 --- /dev/null +++ b/docs/interpolation/common.rst @@ -0,0 +1,37 @@ +Common +====== + +env +--- + +.. js:function:: env(key) + + :param string key: The environment key to get + :return: The value of the environment variable, or "" if it doesn't exist + +Example +^^^^^^^ + +.. code-block:: guess + + env("FOO") // foo + +length +------ + +.. js:function:: length(object) + + :param string/list/map object: The object to return the length of + :return: The length of the object. + If object is a string, it is the number of characters. + If object is a list, it is the number of items in the list. + If object is a map, it is the number of keys in the map. + +Example +^^^^^^^ + +.. code-block:: guess + + length("hello") // 5 + length(["foo", "bar"]) // 2 + length({"foo": "bar"}) // 1 \ No newline at end of file diff --git a/docs/interpolation/maps.rst b/docs/interpolation/maps.rst new file mode 100644 index 0000000..9fa2d64 --- /dev/null +++ b/docs/interpolation/maps.rst @@ -0,0 +1,65 @@ +Maps +==== + +has +--- + +.. js:function:: has(map, key) + + :param map map: The map to perform the lookup on + :param string key: The key to look for + :return: A bool as to whether or not the key exists + +Example +^^^^^^^ + +.. code-block:: guess + + has({"foo": "bar"}, "foo") // true + +map +--- + +.. js:function:: map(key, value, ...) + + :param string key: The key for the key/value pair + :param any value: The value for the key/value/pair + :return: A map object consisting of the provided key/value pairs + +Example +^^^^^^^ + +.. code-block:: guess + + map("foo", "bar") // {"foo": "bar"} + map("foo", list(1, 2, 3), "bar", list(3, 2, 1)) // {"foo": [1, 2, 3], "bar": [3, 2, 1]} + +keys +---- + +.. js:function:: keys(map) + + :param map map: The map to extract keys + :return: The list of keys from the map + +Example +^^^^^^^ + +.. code-block:: guess + + keys(map("foo", "bar")) // ["foo"] + +merge +----- + +.. js:function:: merge(map1, ...) + + :param map map1: One or many maps to merge + :return: The result of the merge + +Example +^^^^^^^ + +.. code-block:: guess + + merge(map("foo", "bar"), map("foo", "bar2", "hello", "there")) // {"foo": "bar2", "hello": "there"} \ No newline at end of file