数据转换函数参考
所有数据转换函数,按类别分组
这是数据转换函数的完整目录。大多数用户可以通过任意文本输入框中的 / 斜杠触发来使用它们——详细介绍请参阅数据转换。
语法
function_name(arg1; arg2; arg3)
- 参数之间使用分号(;) 分隔,而非逗号。
- 参数类型在编辑时会进行检查;类型不匹配会在输入框下方的预览面板中显示。
- 函数可以自由嵌套——任何参数都可以是另一个函数。
- 文本参数周围的引号是可选的(
combine(John; Smith)和combine("John"; "Smith")都有效),但空值或仅含空白的值除外——空字符串使用"",单个空格分隔符使用" "。
文本
处理字符串的函数。
| 函数 | 签名 | 描述 | 示例 |
|---|---|---|---|
combine | combine(text1; text2; separator) | 将两个或多个值连接成一段文本。 | combine(John; Smith; " ") → John Smith |
uppercase | uppercase(text) | 将所有字符转换为大写。 | uppercase(acme inc) → ACME INC |
lowercase | lowercase(text) | 将所有字符转换为小写。 | lowercase(John@ACME.com) → john@acme.com |
titlecase | titlecase(text) | 将每个单词的首字母大写。 | titlecase(john smith) → John Smith |
trim | trim(text) | 移除开头和结尾的空格字符。 | trim( Hello World ) → Hello World |
prefix | prefix(text; value) | 在值之前添加文本。 | prefix(10042; ORD-) → ORD-10042 |
suffix | suffix(text; value) | 在值之后添加文本。 | suffix(Acme; " Ltd.") → Acme Ltd. |
replace | replace(text; find; with) | 查找某个单词或字符并将其替换为另一个。 | replace(first_name; "_"; " ") → first name |
remove | remove(text; value) | 删除某个字符或单词的所有出现。 | remove(004-420-712; "-") → 004420712 |
first_n | first_n(text; n) | 仅返回前 N 个字符。 | first_n(Jonathan; 3) → Jon |
last_n | last_n(text; n) | 仅返回后 N 个字符。 | last_n(ACC-7890; 4) → 7890 |
truncate | truncate(text; n) | 将文本截断为 N 个字符并在末尾添加 ...。 | truncate(Annual Revenue Report; 14) → Annual Revenue... |
split | split(text; separator; index) | 将文本分割成多个部分并返回其中一个。 | split(John Smith; " "; 0) → John |
extract_between | extract_between(text; start; end) | 返回两个标记之间的文本。 | extract_between(Status [urgent]; "["; "]") → urgent |
extract_email | extract_email(text) | 查找并返回文本中的第一个电子邮件地址。 | extract_email(Contact john@acme.com for help) → john@acme.com |
extract_url | extract_url(text) | 查找并返回文本中的第一个 URL。 | extract_url(Visit https://acme.com today) → https://acme.com |
length | length(text) | 计算文本中的字符数。 | length(Hello World) → 11 |
contains | contains(text; value) | 检查文本中是否包含特定单词或字符。 | contains(bug, urgent, backend; urgent) → TRUE |
starts_with | starts_with(text; value) | 检查文本是否以特定值开头。 | starts_with(support@acme.com; info@) → FALSE |
ends_with | ends_with(text; value) | 检查文本是否以特定值结尾。 | ends_with(report.pdf; .pdf) → TRUE |
remove_spaces | remove_spaces(text) | 移除文本中所有多余的空格和换行符。 | remove_spaces(hello world) → hello world |
word_count | word_count(text) | 计算文本中的单词数。 | word_count(The quick brown fox) → 4 |
数字
用于算术运算和格式化数值的函数。
| 函数 | 签名 | 描述 | 示例 |
|---|---|---|---|
add | add(num1; num2) | 将两个数字相加。 | add(49.99; 5.00) → 54.99 |
subtract | subtract(num1; num2) | 从第一个数字中减去第二个数字。 | subtract(100.00; 10.50) → 89.5 |
multiply | multiply(num1; num2) | 将两个数字相乘。 | multiply(3; 49.99) → 149.97 |
divide | divide(num1; num2) | 将第一个数字除以第二个数字。 | divide(4999; 100) → 49.99 |
round | round(number; decimals) | 将数字四舍五入到指定的小数位数。 | round(49.9871; 2) → 49.99 |
round_up | round_up(number) | 始终向上取整为下一个整数。 | round_up(7.1) → 8 |
round_down | round_down(number) | 始终向下取整为前一个整数。 | round_down(7.9) → 7 |
absolute | absolute(number) | 返回数字的正数版本,去除负号。 | absolute(-42.00) → 42 |
percentage | percentage(value; total) | 计算该值占总数的百分比。 | percentage(75; 100) → 75% |
format_number | format_number(number; decimals) | 添加千位分隔符,使大数字更易读。 | format_number(1250000; 2) → 1,250,000.00 |
format_currency | format_currency(number; symbol) | 添加货币符号并格式化数字。 | format_currency(49.99; "$") → $49.99 |
cents_to_dollars | cents_to_dollars(number) | 将以美分存储的值转换为美元。 | cents_to_dollars(4999) → $49.99 |
min | min(num1; num2) | 返回两个数字中较小的一个。 | min(87; 100) → 87 |
max | max(num1; num2) | 返回两个数字中较大的一个。 | max(-5; 0) → 0 |
to_number | to_number(text) | 将文本值转换为可用于计算的数字。 | to_number(1990) → 1990 |
日期
处理日期和时间的函数。
| 函数 | 签名 | 描述 | 示例 |
|---|---|---|---|
format_date | format_date(date; format) | 使用您选择的格式更改日期的显示方式。 | format_date(2025-01-15; MMM DD, YYYY) → Jan 15, 2025 |
format_date_long | format_date_long(date) | 以通俗语言完整显示日期。 | format_date_long(2025-01-15) → 2025年1月15日 星期五 |
format_time | format_time(date; format) | 从日期中提取时间并格式化。 | format_time(2025-01-15T14:30:00Z; h:mm A) → 2:30 PM |
relative_time | relative_time(date) | 显示日期距今或未来有多久。 | relative_time(2025-01-12) → 3 天前 |
add_days | add_days(date; n) | 为日期增加指定天数。 | add_days(2025-01-15; 30) → Feb 14, 2025 |
subtract_days | subtract_days(date; n) | 从日期减去指定天数。 | subtract_days(2025-01-15; 7) → Jan 08, 2025 |
add_hours | add_hours(date; n) | 为日期时间增加指定小时数。 | add_hours(2025-01-15T14:30:00Z; 2) → 2025-01-15T16:30:00Z |
days_between | days_between(date1; date2) | 计算两个日期之间的天数。 | days_between(2025-01-01; 2025-01-15) → 14 |
get_day | get_day(date) | 从日期中返回天数(1–31)。 | get_day(2025-01-15) → 15 |
get_month | get_month(date) | 从日期中返回月份。 | get_month(2025-01-15) → January |
get_year | get_year(date) | 从日期中返回年份。 | get_year(2025-01-15) → 2025 |
get_day_of_week | get_day_of_week(date) | 返回星期几的名称。 | get_day_of_week(2025-01-15) → 星期三 |
start_of_month | start_of_month(date) | 返回同月的第一天。 | start_of_month(2025-01-15) → Jan 01, 2025 |
end_of_month | end_of_month(date) | 返回同月的最后一天。 | end_of_month(2025-01-15) → Jan 31, 2025 |
convert_timezone | convert_timezone(date; timezone) | 将日期时间从一个时区转换到另一个时区。 | convert_timezone(2025-01-15T14:30:00Z; America/New_York) → Jan 15, 9:30 AM EST |
now | now() | 返回工作流运行时刻的当前日期和时间。 | now() → 2025-01-15T14:30:00Z |
today | today() | 返回今天的日期,不包含时间。 | today() → 2025-01-15 |
to_date | to_date(text) | 将文本值转换为工作流可以处理的日期格式。 | to_date(January 15, 2025) → 2025-01-15T00:00:00Z |
列表
处理集合(项目数组)的函数。
| 函数 | 签名 | 描述 | 示例 |
|---|---|---|---|
filter_list | filter_list(list; field; value) | 仅保留指定字段值匹配的项目。 | filter_list(tickets; status; open) → [共10项中的3项] |
sort_list | sort_list(list; field; order) | 按指定字段对列表从高到低或从 A 到 Z 排序。 | sort_list(orders; amount; desc) → [排序后: 500, 200, 50] |
pluck | pluck(list; field) | 从列表的每个项目中提取指定字段。 | pluck(users; email) → [ana@x.com, bob@x.com] |
join_list | join_list(list; separator) | 使用分隔符将列表转换为一段文本。 | join_list([bug;urgent;backend]; ", ") → bug, urgent, backend |
first_item | first_item(list) | 返回列表中的第一项。 | first_item([apple;banana;cherry]) → apple |
last_item | last_item(list) | 返回列表中的最后一项。 | last_item([apple;banana;cherry]) → cherry |
item_at | item_at(list; index) | 返回列表中指定位置的项目。 | item_at([apple;banana;cherry]; 1) → banana |
count | count(list) | 计算列表中有多少个项目。 | count([bug;urgent;backend]) → 3 |
sum | sum(list; field) | 对列表中所有项目的某个数字字段求和。 | sum(orders; amount) → 4820.5 |
average | average(list; field) | 计算列表中所有项目某个数字字段的平均值。 | average(scores; value) → 82.4 |
max_in_list | max_in_list(list; field) | 查找列表中所有项目某个字段的最高值。 | max_in_list(orders; amount) → 1200 |
min_in_list | min_in_list(list; field) | 查找列表中所有项目某个字段的最低值。 | min_in_list(orders; amount) → 9.99 |
deduplicate | deduplicate(list; field) | 移除指定字段值重复的项目。 | deduplicate(leads; email) → [共10项中的7项] |
flatten | flatten(list) | 将列表的列表展平为一个列表。 | flatten([[a;b];[c;d]]) → [a,b,c,d] |
split_text_to_list | split_text_to_list(text; separator) | 将逗号分隔的文本转换为项目列表。 | split_text_to_list(bug,urgent,backend; ",") → [bug,urgent,backend] |
逻辑
用于条件判断、比较和回退的函数。
| 函数 | 签名 | 描述 | 示例 |
|---|---|---|---|
if | if(condition; true_value; false_value) | 如果条件为真返回一个值,否则返回另一个值。 | if(1500 > 1000; 高价值; 标准) → 高价值 |
if_empty | if_empty(value; fallback) | 如果字段为空则使用回退值。 | if_empty(""; 无名称) → 无名称 |
if_null | if_null(value; fallback) | 如果字段没有任何值则使用回退值。 | if_null(null; N/A) → N/A |
switch | switch(value; key1; result1; key2; result2; ...) | 将值映射为另一个值——类似内联查找表。 | switch(US; US; 北美; DE; 欧洲) → 北美 |
is_empty | is_empty(value) | 检查字段是否有值。 | is_empty("") → TRUE |
is_not_empty | is_not_empty(value) | 检查字段是否有任何值。 | is_not_empty(john@acme.com) → TRUE |
is_equal | is_equal(value1; value2) | 检查两个值是否完全相同。 | is_equal(active; active) → TRUE |
and | and(condition1; condition2) | 仅当两个条件同时为真时返回真。 | and(25 >= 18; US = US) → TRUE |
or | or(condition1; condition2) | 如果至少有一个条件为真则返回真。 | or(standard = vip; 600 > 500) → TRUE |
not | not(condition) | 将真值翻转为假值,或将假值翻转为真值。 | not(is_empty(john@acme.com)) → TRUE |
coalesce | coalesce(value1; value2; value3; ...) | 返回第一个有值的字段,跳过任何空值。 | coalesce(""; John; User) → John |
已弃用的函数
目前没有函数处于弃用状态。当某个函数被替换或计划移除时,它会出现在这里,并附带推荐的替代函数及其将被移除的版本。使用已弃用函数的已保存工作流会继续运行——编辑器仅通过显示带删除线的标签来标记问题。