add new data transformation functions

This commit is contained in:
Deborah Barnard 2024-03-21 11:47:13 +00:00
parent c766eed049
commit 7df8588b25
3 changed files with 61 additions and 2 deletions

View File

@ -8,6 +8,12 @@ df_types:
- month
- year
df_string:
- funcName: base64Encode
returns: A base64 encoded string.
description: Encode a string as base64.
- funcName: base64Decode
returns: A plain string.
description: Convert a base64 encoded string to a normal string.
- funcName: extractDomain
returns: String
description: Extracts a domain from a string containing a valid URL. Returns undefined if none is found.
@ -17,6 +23,9 @@ df_string:
- funcName: extractUrl
returns: String
description: Extracts a URL from a string. Returns undefined if none is found.
- funcName: extractUrlPath
returns: String
description: Extract the path but not the root domain from a URL. For example, <code>"https://example.com/orders/1/details".extractUrlPath()</code> returns <code>"/orders/1/details/"</code>.
- funcName: hash
args:
- argName: algo
@ -55,6 +64,9 @@ df_string:
- funcName: isUrl
returns: Boolean
description: Checks if a string is a valid URL.
- funcName: parseJson
returns: Object
description: Equivalent of <code>JSON.parse()</code>. Parses a string as a JSON object.
- funcName: quote
args:
- argName: mark
@ -75,9 +87,12 @@ df_string:
- funcName: removeTags
returns: String
description: Remove tags, such as HTML or XML, from a string.
- funcName: toDate
- funcName: toBoolean
returns: Boolean
description: Convert a string to a boolean. <code>"false"</code>, <code>"0"</code>, <code>""</code>, and <code>"no"</code> convert to <code>false</code>.
- funcName: toDateTime
returns: Date
description: Converts a string to a date.
description: Converts a string to a <a href="https://docs.n8n.io/code/cookbook/luxon/">Luxon date object</a>.
- funcName: toDecimalNumber
returns: Number
description: See <a href="#string-toFloat">toFloat</a>
@ -171,6 +186,9 @@ df_object:
- funcName: compact
returns: Object
description: Removes empty values from an Object.
- funcName: toJsonString
returns: String
description: Convert an object to a JSON string. Equivalent of <code>JSON.stringify</code>.
- funcName: urlEncode
returns: String
description: Transforms an Object into a URL parameter list. Only top-level keys are supported.
@ -212,6 +230,15 @@ df_number:
description: How many decimal places to round to.
returns: Number
description: Returns the value of a number rounded to the nearest whole number, unless a decimal place is specified.
- funcName: toBoolean
returns: Boolean
description: Converts a number to a boolean. <code>0</code> converts to <code>false</code>. All other values convert to <code>true</code>.
- funcName: toDateTime
returns: Date
description: Converts a number to a <a href="https://docs.n8n.io/code/cookbook/luxon/">Luxon date object</a>.
- funcName: toInt
returns: Integer
description: Convert a number to an integer by rounding up or down. <code>.5</code> and above rounds up.
df_date:
- funcName: beginningOf
args:
@ -316,6 +343,12 @@ df_date:
options: *df_durationUnit
returns: Date
description: Adds a given time period to a Date. Returns either a JavaScript Date or Luxon Date, depending on input.
- funcName: toDateTime
returns: Date
description: Converts a JavaScript date to a <a href="https://docs.n8n.io/code/cookbook/luxon/">Luxon date object</a>.
- funcName: toInt
returns: Number
description: Gets the milliseconds for the current DateTime and returns it as a number. For example, <code>DateTime.fromISO('2024-01-01T00:00:00.000Z').toInt()</code> returns <code>1704067200000</code>
df_array:
- funcName: average
returns: Number
@ -432,6 +465,9 @@ df_array:
- funcName: sum
returns: Number
description: Returns the total sum all the values in an array of parsable numbers.
- funcName: toJsonString
returns: String
description: Convert an array to a JSON string. Equivalent of <code>JSON.stringify</code>.
- funcName: union
args:
- argName: arr
@ -450,3 +486,7 @@ df_array:
description: A key, or comma-separated list of keys, to check for duplicates.
returns: Array
description: Remove duplicates from an array.
df_boolean:
- funcName: toInt
returns: Number
description: Convert a boolean to a number. <code>false</code> converts to <code>0</code>, <code>true</code> converts to <code>1</code>.

View File

@ -0,0 +1,18 @@
---
title: Data transformation functions for booleans
description: A reference document listing built-in convenience functions to support data transformation in expressions for booleans.
contentType: reference
---
# Booleans
A reference document listing built-in convenience functions to support data transformation in expressions for arrays.
/// note | JavaScript in expressions
You can use any JavaScript in expressions. Refer to [Expressions](/code/expressions/) for more information.
///
[[% import "_macros/data-functions.html" as dataFunctions %]]
[[% for func in df_boolean %]]
[[ dataFunctions.dataFunctions("boolean", func.funcName, func.returns, func.description, func.args, func.examples ) ]]
[[% endfor %]]

View File

@ -1166,6 +1166,7 @@ nav:
- Data transformation functions:
- code/builtin/data-transformation-functions/index.md
- Arrays: code/builtin/data-transformation-functions/arrays.md
- Booleans: code/builtin/data-transformation-functions/booleans.md
- Dates: code/builtin/data-transformation-functions/dates.md
- Numbers: code/builtin/data-transformation-functions/numbers.md
- Objects: code/builtin/data-transformation-functions/objects.md