diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json index 17f26604a3..ca7c7485cd 100644 --- a/packages/string-templates/package.json +++ b/packages/string-templates/package.json @@ -26,7 +26,7 @@ "manifest": "ts-node ./scripts/gen-collection-info.ts" }, "dependencies": { - "@budibase/handlebars-helpers": "^0.13.2", + "@budibase/handlebars-helpers": "^0.13.1", "dayjs": "^1.10.8", "handlebars": "^4.7.8", "lodash.clonedeep": "^4.5.0" diff --git a/packages/string-templates/src/manifest.json b/packages/string-templates/src/manifest.json index 5387f1e746..dce4af8665 100644 --- a/packages/string-templates/src/manifest.json +++ b/packages/string-templates/src/manifest.json @@ -1,105 +1,144 @@ { "math": { "abs": { - "args": ["a"], + "args": [ + "a" + ], "numArgs": 1, "example": "{{ abs 12012.1000 }} -> 12012.1", "description": "
Return the magnitude of a
.
Return the sum of a
plus b
.
Returns the average of all numbers in the given array.
\n", "requiresBlock": false }, "ceil": { - "args": ["value"], + "args": [ + "value" + ], "numArgs": 1, "example": "{{ ceil 1.2 }} -> 2", "description": "Get the Math.ceil()
of the given value.
Divide a
by b
Get the Math.floor()
of the given value.
Return the product of a
minus b
.
Get the remainder of a division operation.
\n", "requiresBlock": false }, "multiply": { - "args": ["a", "b"], + "args": [ + "a", + "b" + ], "numArgs": 2, "example": "{{ multiply 10 5 }} -> 50", "description": "Multiply number a
by number b
.
Add a
by b
.
Generate a random number between two values
\n", "requiresBlock": false }, "remainder": { - "args": ["a", "b"], + "args": [ + "a", + "b" + ], "numArgs": 2, "example": "{{ remainder 10 6 }} -> 4", "description": "Get the remainder when a
is divided by b
.
Round the given number.
\n", "requiresBlock": false }, "subtract": { - "args": ["a", "b"], + "args": [ + "a", + "b" + ], "numArgs": 2, "example": "{{ subtract 10 5 }} -> 5", "description": "Return the product of a
minus b
.
Returns the sum of all numbers in the given array.
\n", @@ -108,196 +147,285 @@ }, "array": { "after": { - "args": ["array", "n"], + "args": [ + "array", + "n" + ], "numArgs": 2, "example": "{{ after ['a', 'b', 'c', 'd'] 2}} -> ['c', 'd']", "description": "Returns all of the items in an array after the specified index. Opposite of before.
\n", "requiresBlock": false }, "arrayify": { - "args": ["value"], + "args": [ + "value" + ], "numArgs": 1, "example": "{{ arrayify 'foo' }} -> ['foo']", "description": "Cast the given value
to an array.
Return all of the items in the collection before the specified count. Opposite of after.
\n", "requiresBlock": false }, "eachIndex": { - "args": ["array", "options"], + "args": [ + "array", + "options" + ], "numArgs": 2, "example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}} -> ' 1 is 0 2 is 1 3 is 2 '", "description": "Iterates the array, listing an item and the index of it.
\n", "requiresBlock": true }, "filter": { - "args": ["array", "value", "options"], + "args": [ + "array", + "value", + "options" + ], "numArgs": 3, "example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}} -> 2 Found", "description": "Block helper that filters the given array and renders the block for values that evaluate to true
, otherwise the inverse block is returned.
Returns the first item, or first n
items of an array.
Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - index
- total
- isFirst
- isLast
Also, @index
is exposed as a private variable, and additional private variables may be defined as hash arguments.
Block helper that renders the block if an array has the given value
. Optionally specify an inverse block to render when the array does not have the given value.
Returns true if value
is an es5 array.
Returns the item from array
at index idx
.
Join all elements of array into a string, optionally using a given separator.
\n", "requiresBlock": false }, "equalsLength": { - "args": ["value", "length"], + "args": [ + "value", + "length" + ], "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "Returns true if the the length of the given value
is equal to the given length
. Can be used as a block or inline helper.
Returns the last item, or last n
items of an array or string. Opposite of first.
Returns the length of the given string or array.
\n", "requiresBlock": false }, "lengthEqual": { - "args": ["value", "length"], + "args": [ + "value", + "length" + ], "numArgs": 2, "example": "{{equalsLength [1, 2, 3] 3}} -> true", "description": "Returns true if the the length of the given value
is equal to the given length
. Can be used as a block or inline helper.
Returns a new array, created by calling function
on each element of the given array
. For example,
Map over the given object or array or objects and create an array of values from the given prop
. Dot-notation may be used (as a string) to get nested properties.
Reverse the elements in an array, or the characters in a string.
\n", "requiresBlock": false }, "some": { - "args": ["array", "iter", "provided"], + "args": [ + "array", + "iter", + "provided" + ], "numArgs": 3, "example": "{{#some [1, \"b\", 3] isString}} string found {{else}} No string found {{/some}} -> ' string found '", "description": "Block helper that returns the block if the callback returns true for some value in the given array.
\n", "requiresBlock": true }, "sort": { - "args": ["array", "key"], + "args": [ + "array", + "key" + ], "numArgs": 2, "example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']", "description": "Sort the given array
. If an array of objects is passed, you may optionally pass a key
to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
Sort an array
. If an array of objects is passed, you may optionally pass a key
to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
Use the items in the array after the specified index as context inside a block. Opposite of withBefore.
\n", "requiresBlock": true }, "withBefore": { - "args": ["array", "idx", "options"], + "args": [ + "array", + "idx", + "options" + ], "numArgs": 3, "example": "{{#withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}} -> ' 1 '", "description": "Use the items in the array before the specified index as context inside a block. Opposite of withAfter.
\n", "requiresBlock": true }, "withFirst": { - "args": ["array", "idx", "options"], + "args": [ + "array", + "idx", + "options" + ], "numArgs": 3, "example": "{{#withFirst [1, 2, 3] }}{{this}}{{/withFirst}} -> 1", "description": "Use the first item in a collection inside a handlebars block expression. Opposite of withLast.
\n", "requiresBlock": true }, "withGroup": { - "args": ["array", "size", "options"], + "args": [ + "array", + "size", + "options" + ], "numArgs": 3, "example": "{{#withGroup [1, 2, 3, 4] 2}}{{#each this}}{{.}}{{/each}}Block helper that groups array elements by given group size
.
Use the last item or n
items in an array as context inside a block. Opposite of withFirst.
Block helper that sorts a collection and exposes the sorted collection as context inside the block.
\n", "requiresBlock": true }, "unique": { - "args": ["array", "options"], + "args": [ + "array", + "options" + ], "numArgs": 2, "example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }}{{.}}{{/each}} -> acbe", "description": "Block helper that return an array with all duplicate values removed. Best used along with a each helper.
\n", @@ -306,61 +434,83 @@ }, "number": { "bytes": { - "args": ["number"], + "args": [ + "number" + ], "numArgs": 1, "example": "{{ bytes 1386 1 }} -> 1.4 kB", "description": "Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. Examples: - 'foo' => 3 B
- 13661855 => 13.66 MB
- 825399 => 825.39 kB
- 1396 => 1.4 kB
Add commas to numbers
\n", "requiresBlock": false }, "phoneNumber": { - "args": ["num"], + "args": [ + "num" + ], "numArgs": 1, "example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212", "description": "Convert a string or number to a formatted phone number.
\n", "requiresBlock": false }, "toAbbr": { - "args": ["number", "precision"], + "args": [ + "number", + "precision" + ], "numArgs": 2, "example": "{{ toAbbr 10123 2 }} -> 10.12k", "description": "Abbreviate numbers to the given number of precision
. This for general numbers, not size in bytes.
Returns a string representing the given number in exponential notation.
\n", "requiresBlock": false }, "toFixed": { - "args": ["number", "digits"], + "args": [ + "number", + "digits" + ], "numArgs": 2, "example": "{{ toFixed 1.1234 2 }} -> 1.12", "description": "Formats the given number using fixed-point notation.
\n", "requiresBlock": false }, "toFloat": { - "args": ["number"], + "args": [ + "number" + ], "numArgs": 1, "description": "Convert input to a float.
\n", "requiresBlock": false }, "toInt": { - "args": ["number"], + "args": [ + "number" + ], "numArgs": 1, "description": "Convert input to an integer.
\n", "requiresBlock": false }, "toPrecision": { - "args": ["number", "precision"], + "args": [ + "number", + "precision" + ], "numArgs": 2, "example": "{{toPrecision '1.1234' 2}} -> 1.1", "description": "Returns a string representing the Number
object to the specified precision.
Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.
\n", "requiresBlock": false }, "escape": { - "args": ["str"], + "args": [ + "str" + ], "numArgs": 1, "example": "{{ escape 'https://myurl?Hello+There' }} -> https%3A%2F%2Fmyurl%3FHello%2BThere", "description": "Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.
\n", "requiresBlock": false }, "decodeURI": { - "args": ["str"], + "args": [ + "str" + ], "numArgs": 1, "example": "{{ decodeURI 'https://myurl?Hello%20There' }} -> https://myurl?Hello There", "description": "Decode a Uniform Resource Identifier (URI) component.
\n", "requiresBlock": false }, "urlResolve": { - "args": ["base", "href"], + "args": [ + "base", + "href" + ], "numArgs": 2, "example": "{{ urlResolve 'https://myurl' '/api/test' }} -> https://myurl/api/test", "description": "Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
\n", "requiresBlock": false }, "urlParse": { - "args": ["str"], + "args": [ + "str" + ], "numArgs": 1, "example": "{{ urlParse 'https://myurl/api/test' }}", "description": "Parses a url
string into an object.
Strip the query string from the given url
.
Strip protocol from a url
. Useful for displaying media that may have an 'http' protocol on secure connections.
Append the specified suffix
to the given string.
camelCase the characters in the given string
.
Capitalize the first word in a sentence.
\n", "requiresBlock": false }, "capitalizeAll": { - "args": ["str"], + "args": [ + "str" + ], "numArgs": 1, "example": "{{ capitalizeAll 'foo bar baz'}} -> Foo Bar Baz", "description": "Capitalize all words in a string.
\n", "requiresBlock": false }, "center": { - "args": ["str", "spaces"], + "args": [ + "str", + "spaces" + ], "numArgs": 2, "example": "{{ center 'test' 1}} -> ' test '", "description": "Center a string using non-breaking spaces
\n", "requiresBlock": false }, "chop": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{ chop ' ABC '}} -> ABC", "description": "Like trim, but removes both extraneous whitespace and non-word characters from the beginning and end of a string.
\n", "requiresBlock": false }, "dashcase": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{dashcase 'a-b-c d_e'}} -> a-b-c-d-e", "description": "dash-case the characters in string
. Replaces non-word characters and periods with hyphens.
dot.case the characters in string
.
Lowercase all of the characters in the given string. Alias for lowercase.
\n", "requiresBlock": false }, "ellipsis": { - "args": ["str", "length"], + "args": [ + "str", + "length" + ], "numArgs": 2, "example": "{{ellipsis 'foo bar baz' 7}} -> foo bar…", "description": "Truncates a string to the specified length
, and appends it with an elipsis, …
.
Replace spaces in a string with hyphens.
\n", "requiresBlock": false }, "isString": { - "args": ["value"], + "args": [ + "value" + ], "numArgs": 1, "example": "{{isString 'foo'}} -> true", "description": "Return true if value
is a string.
Lowercase all characters in the given string.
\n", "requiresBlock": false }, "occurrences": { - "args": ["str", "substring"], + "args": [ + "str", + "substring" + ], "numArgs": 2, "example": "{{occurrences 'foo bar foo bar baz' 'foo'}} -> 2", "description": "Return the number of occurrences of substring
within the given string
.
PascalCase the characters in string
.
path/case the characters in string
.
Replace spaces in the given string with pluses.
\n", "requiresBlock": false }, "prepend": { - "args": ["str", "prefix"], + "args": [ + "str", + "prefix" + ], "numArgs": 2, "example": "{{prepend 'bar' 'foo-'}} -> foo-bar", "description": "Prepends the given string
with the specified prefix
.
Remove all occurrences of substring
from the given str
.
Remove the first occurrence of substring
from the given str
.
Replace all occurrences of substring a
with substring b
.
Replace the first occurrence of substring a
with substring b
.
Sentence case the given string
\n", "requiresBlock": false }, "snakecase": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{snakecase 'a-b-c d_e'}} -> a_b_c_d_e", "description": "snake_case the characters in the given string
.
Split string
by the given character
.
Tests whether a string begins with the given prefix.
\n", "requiresBlock": true }, "titleize": { - "args": ["str"], + "args": [ + "str" + ], "numArgs": 1, "example": "{{titleize 'this is title case' }} -> This Is Title Case", "description": "Title case the given string.
\n", "requiresBlock": false }, "trim": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{trim ' ABC ' }} -> ABC", "description": "Removes extraneous whitespace from the beginning and end of a string.
\n", "requiresBlock": false }, "trimLeft": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{trimLeft ' ABC ' }} -> 'ABC '", "description": "Removes extraneous whitespace from the beginning of a string.
\n", "requiresBlock": false }, "trimRight": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{trimRight ' ABC ' }} -> ' ABC'", "description": "Removes extraneous whitespace from the end of a string.
\n", "requiresBlock": false }, "truncate": { - "args": ["str", "limit", "suffix"], + "args": [ + "str", + "limit", + "suffix" + ], "numArgs": 3, "example": "{{truncate 'foo bar baz' 7 }} -> foo bar", "description": "Truncate a string to the specified length
. Also see ellipsis.
Truncate a string to have the specified number of words. Also see truncate.
\n", "requiresBlock": false }, "upcase": { - "args": ["string"], + "args": [ + "string" + ], "numArgs": 1, "example": "{{upcase 'aBcDef'}} -> ABCDEF", "description": "Uppercase all of the characters in the given string. Alias for uppercase.
\n", "requiresBlock": false }, "uppercase": { - "args": ["str", "options"], + "args": [ + "str", + "options" + ], "numArgs": 2, "example": "{{uppercase 'aBcDef'}} -> ABCDEF", "description": "Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.
\n", "requiresBlock": false - }, - "lorem": { - "args": ["num"], - "numArgs": 1, - "example": "{{lorem 11}} -> Lorem ipsum", - "description": "Takes a number and returns that many charaters of Lorem Ipsum
\n", - "requiresBlock": false } }, "comparison": { "and": { - "args": ["a", "b", "options"], + "args": [ + "a", + "b", + "options" + ], "numArgs": 3, "example": "{{#and great magnificent}}both{{else}}no{{/and}} -> no", "description": "Helper that renders the block if both of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.
\n", "requiresBlock": true }, "compare": { - "args": ["a", "operator", "b", "options"], + "args": [ + "a", + "operator", + "b", + "options" + ], "numArgs": 4, "example": "{{compare 10 '<' 5 }} -> false", "description": "Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.
\n", "requiresBlock": false }, "contains": { - "args": ["collection", "value", "[startIndex=0]", "options"], + "args": [ + "collection", + "value", + "[startIndex=0]", + "options" + ], "numArgs": 4, "example": "{{#contains ['a', 'b', 'c'] 'd'}} This will not be rendered. {{else}} This will be rendered. {{/contains}} -> ' This will be rendered. '", "description": "Block helper that renders the block if collection
has the given value
, using strict equality (===
) for comparison, otherwise the inverse block is rendered (if specified). If a startIndex
is specified and is negative, it is used as the offset from the end of the collection.
Returns the first value that is not undefined, otherwise the 'default' value is returned.
\n", "requiresBlock": false }, "eq": { - "args": ["a", "b", "options"], + "args": [ + "a", + "b", + "options" + ], "numArgs": 3, "example": "{{#eq 3 3}}equal{{else}}not equal{{/eq}} -> equal", "description": "Block helper that renders a block if a
is equal to b
. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare=''
hash argument for the second value.
Block helper that renders a block if a
is greater than b
. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare=''
hash argument for the second value.
Block helper that renders a block if a
is greater than or equal to b
. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare=''
hash argument for the second value.
Block helper that renders a block if value
has pattern
. If an inverse block is specified it will be rendered when falsy.
Returns true if the given value
is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.
Returns true if the given value
is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.
Return true if the given value is an even number.
\n", "requiresBlock": true }, "ifNth": { - "args": ["a", "b", "options"], + "args": [ + "a", + "b", + "options" + ], "numArgs": 3, "example": "{{#ifNth 2 10}}remainder{{else}}no remainder{{/ifNth}} -> remainder", "description": "Conditionally renders a block if the remainder is zero when b
operand is divided by a
. If an inverse block is specified it will be rendered when the remainder is not zero.
Block helper that renders a block if value
is an odd number. If an inverse block is specified it will be rendered when falsy.
Block helper that renders a block if a
is equal to b
. If an inverse block is specified it will be rendered when falsy. Similar to eq but does not do strict equality.
Block helper that renders a block if a
is not equal to b
. If an inverse block is specified it will be rendered when falsy. Similar to unlessEq but does not use strict equality for comparisons.
Block helper that renders a block if a
is less than b
. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare=''
hash argument for the second value.
Block helper that renders a block if a
is less than or equal to b
. If an inverse block is specified it will be rendered when falsy. You may optionally use the compare=''
hash argument for the second value.
Block helper that renders a block if neither of the given values are truthy. If an inverse block is specified it will be rendered when falsy.
\n", "requiresBlock": true }, "not": { - "args": ["val", "options"], + "args": [ + "val", + "options" + ], "numArgs": 2, "example": "{{#not undefined }}falsey{{else}}not falsey{{/not}} -> falsey", "description": "Returns true if val
is falsey. Works as a block or inline helper.
Block helper that renders a block if any of the given values is truthy. If an inverse block is specified it will be rendered when falsy.
\n", "requiresBlock": true }, "unlessEq": { - "args": ["a", "b", "options"], + "args": [ + "a", + "b", + "options" + ], "numArgs": 3, "example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> ' not equal '", "description": "Block helper that always renders the inverse block unless a
is equal to b
.
Block helper that always renders the inverse block unless a
is greater than b
.
Block helper that always renders the inverse block unless a
is less than b
.
Block helper that always renders the inverse block unless a
is greater than or equal to b
.
Block helper that always renders the inverse block unless a
is less than or equal to b
.
Extend the context with the properties of other objects. A shallow merge is performed to avoid mutating the context.
\n", "requiresBlock": false }, "forIn": { - "args": ["context", "options"], + "args": [ + "context", + "options" + ], "numArgs": 2, "description": "Block helper that iterates over the properties of an object, exposing each key and value on the context.
\n", "requiresBlock": true }, "forOwn": { - "args": ["obj", "options"], + "args": [ + "obj", + "options" + ], "numArgs": 2, "description": "Block helper that iterates over the own properties of an object, exposing each key and value on the context.
\n", "requiresBlock": true }, "toPath": { - "args": ["prop"], + "args": [ + "prop" + ], "numArgs": 1, "description": "Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
\n", "requiresBlock": false }, "get": { - "args": ["prop", "context", "options"], + "args": [ + "prop", + "context", + "options" + ], "numArgs": 3, "description": "Use property paths (a.b.c
) to get a value or nested value from the context. Works as a regular helper or block helper.
Use property paths (a.b.c
) to get an object from the context. Differs from the get
helper in that this helper will return the actual object, including the given property key. Also, this helper does not work as a block helper.
Return true if key
is an own, enumerable property of the given context
object.
Return true if value
is an object.
Parses the given string using JSON.parse
.
Stringify an object using JSON.stringify
.
Deeply merge the properties of the given objects
with the context object.
Parses the given string using JSON.parse
.
Pick properties from the context object.
\n", "requiresBlock": true }, "stringify": { - "args": ["obj"], + "args": [ + "obj" + ], "numArgs": 1, "description": "Stringify an object using JSON.stringify
.
Format a date using moment.js date formatting - the timezone is optional and uses the tz database.
\n" }, "duration": { - "args": ["time", "durationType"], + "args": [ + "time", + "durationType" + ], "numArgs": 2, "example": "{{duration 8 \"seconds\"}} -> a few seconds", "description": "Produce a humanized duration left/until given an amount of time and the type of time measurement.
\n" } } -} +} \ No newline at end of file