Functions
Functions are like ready-made tools that perform specific tasks. They take in data as input, process it, and return a result.
Here are a few examples of what functions can do:
Count the number of characters in a text.
Search for a specific word in a text.
Determine the smallest number between two numbers.
Functions in ProtoPie have a specific structure:
function(argument: TYPE)→ result: TYPEfunction(argument1: TYPE, argument2: TYPE)→ result: TYPEfunction(argument1: TYPE, argument2: TYPE, argument3: TYPE)→ result: TYPE
Functions usually use one or multiple arguments (data) as input—the values a function uses to perform a task. Arguments, as well as the result, are values that are always of a specific type. A type could be a text, number, or color.
There are various categories to choose from:
Text
concat(source1: TEXT, source2: TEXT)
➔
文本
将两段独立的文本合并为一段。
•
Example: concat("hello", "world")
➔
"helloworld"
indexOf(source: TEXT, searchValue: TEXT)
➔
数字
查找关键字在文本中的起始位置。如果文本中不存在该关键字,则返回值为 -1。
•
Example: indexOf("hello world", "world")
➔
6
•
Example: indexOf("hello world", "hello")
➔
0
•
Example: indexOf("hello world", "goodbye")
➔
-1
•
对于电子邮件验证等用例,请使用 indexOf。查看用例示例。
length(source: TEXT)
➔
数字
统计文本中的字符数。
•
Example: length("hello")
➔
5
•
Example: length("helloworld")
➔
10
•
Example: length("hello world")
➔
11
•
对于密码验证等用例,请使用长度。查看用例示例。
lowerCase(source: TEXT)
➔
文本
将任何文本从大写转换为小写
•
Example: lowerCase("Hello")
➔
"hello"
upperCase(source: TEXT)
➔
文本
将任何文本从小写转换为大写。
•
Example: upperCase("Hello")
➔
"HELLO"
left(source: TEXT, count: NUMBER)
➔
文本
根据指定的字符数,从左侧提取一部分文本。
•
Example: left("hello", 3)
➔
"hel"
right(source: TEXT, count: NUMBER)
➔
文本
根据指定的字符数,从左侧提取一部分文本。
•
Example: right("hello", 2)
➔
"lo"
lpad(source: TEXT, length: NUMBER, pad: TEXT)
➔
文本
使用另一个文本在左侧填充文本,使其达到指定长度。
•
Example: lpad("5", 2, "0")
➔
"05"
•
Example: lpad("5", 4, "0")
➔
"0005"
rpad(source: TEXT, length: NUMBER, pad: TEXT)
➔
文本
使用另一段文本对文本进行右侧填充,以达到指定长度。
•
Example: rpad("5", 2, "1")
➔
"51"
•
Example: rpad("5", 6, "1")
➔
"511111"
repeat(source: TEXT, count: NUMBER)
➔
文本
将文本重复指定次数。
•
Example: repeat("hello", 2)
➔
"hellohello"
•
Example: repeat("hello", 3)
➔
"hellohellohello"
replace(source: TEXT, from: TEXT, to: TEXT)
➔
文本
将文本的一部分替换为另一段文本。
•
Example: replace("helloworld", "world", "protopie")
➔
"helloprotopie"
•
Example: replace("goodbye, John", "goodbye", "thank you")
➔
"thank you, John"
trim(source: TEXT)
➔
文本
移除文本两侧的空白字符。
•
示例: trim(" helloworld")
➔
"helloworld"
•
示例: trim(" helloworld ")
➔
"helloworld"
ltrim(source: TEXT)
➔
文本
删除文本左侧的空白字符。
•
Example: ltrim(" helloworld ")
➔
"helloworld "
rtrim(source: TEXT)
➔
文本
删除文本右侧的空白字符。
•
Example: ltrim(" helloworld ")
➔
" helloworld"
regexextract(source: TEXT, regular expression: TEXT)
➔
文本
提取文本中与提供的正则表达式匹配的首个子字符串。
•
Example: regexextract("Google Doc 101", "[0-9]+")
➔
"101"
•
Example:
regexextract("The price today is $826.25", "[0-9]*\.[0-9]+[0-9]+")
➔
"826.25"
regexreplace(source: TEXT, regular expression: TEXT, replacement: TEXT)
➔
文本
使用正则表达式将文本字符串的一部分替换为不同的文本字符串。
•
Example: regexreplace("Google Doc 101", "[0-9]+", "777")
➔
"Google Doc 777"
•
Example:
regexreplace("The price today is $826.25", "[0-9]*\.[0-9]+[0-9]+", "315.75")
➔
"The price is $315.75"
parseJson(source: TEXT, key: TEXT)
➔
文本
解析有效的 JSON 字符串并返回相应的值。
•
Example:
parseJson("{\"name\":\"John\", \"age\":30, \"car\":null}", "age")
➔
"30"
•
Example:
parseJson("{\"name\":\"John\", \"age\":30, \"car\":null}", "name")
➔
"John"
concat(source1: TEXT, source2: TEXT)
➔
文本
将两段独立的文本合并为一段。
•
示例:
concat("你好", "世界")
➔
"helloworld"
indexOf(source: TEXT, searchValue: TEXT)
➔
数字
查找关键字在文本中的起始位置。如果文本中不存在该关键字,则返回值为 -1。
•
示例:
indexOf("hello world", "world")
➔
6
•
示例:
indexOf("你好,世界", "你好")
➔
0
•
示例:
indexOf("你好,世界", "再见")
➔
-1
•
对于电子邮件验证等用例,请使用 indexOf。查看用例示例。
length(source: TEXT)
➔
数字
统计文本中的字符数。
•
Example: length("hello")
➔
5
•
Example: length("helloworld")
➔
10
•
Example: length("hello world")
➔
11
•
对于密码验证等用例,请使用长度。查看用例示例。
lowerCase(source: TEXT)
➔
文本
将任何文本从大写转换为小写
•
Example: lowerCase("Hello")
➔
"hello"
upperCase(source: TEXT)
➔
文本
将任何文本从小写转换为大写。
•
Example: upperCase("Hello")
➔
"HELLO"
left(source: TEXT, count: NUMBER)
➔
文本
根据指定的字符数,从左侧提取一部分文本。
•
Example: left("hello", 3)
➔
"hel"
right(source: TEXT, count: NUMBER)
➔
文本
根据指定的字符数,从左侧提取一部分文本。
•
Example: right("hello", 2)
➔
"lo"
lpad(source: TEXT, length: NUMBER, pad: TEXT)
➔
文本
使用另一个文本在左侧填充文本,使其达到指定长度。
•
Example: lpad("5", 2, "0")
➔
"05"
•
Example: lpad("5", 4, "0")
➔
"0005"
rpad(source: TEXT, length: NUMBER, pad: TEXT)
➔
文本
使用另一段文本对文本进行右侧填充,以达到指定长度。
•
示例: rpad("5", 2, "1")
➔
"51"
•
Example: rpad("5", 6, "1")
➔
"511111"
repeat(source: TEXT, count: NUMBER)
➔
文本
将文本重复指定次数。
•
Example: repeat("hello", 2)
➔
"hellohello"
•
Example: repeat("hello", 3)
➔
"hellohellohello"
replace(source: TEXT, from: TEXT, to: TEXT)
➔
文本
将文本的一部分替换为另一段文本。
•
Example: replace("helloworld", "world", "protopie")
➔
"helloprotopie"
•
示例:
replace("再见,约翰", "再见", "谢谢你")
➔
"thank you, John"
trim(source: TEXT)
➔
文本
移除文本两侧的空白字符。
•
示例:
trim(" helloworld")
➔
"helloworld"
•
示例:
trim(" helloworld ")
➔
"helloworld"
ltrim(source: TEXT)
➔
文本
删除文本左侧的空白字符。
•
示例:
ltrim(" helloworld ")
➔
"helloworld "
rtrim(source: TEXT)
➔
文本
删除文本右侧的空白字符。
•
示例:
ltrim(" helloworld ")
➔
" helloworld"
regexextract(source: TEXT, regular expression: TEXT)
➔
文本
提取文本中与提供的正则表达式匹配的首个子字符串。
•
Example: regexextract("Google Doc 101", "[0-9]+")
➔
"101"
•
Example:
regexextract("The price today is $826.25", "[0-9]*\.[0-9]+[0-9]+")
➔
"826.25"
regexreplace(source: TEXT, regular expression: TEXT, replacement: TEXT)
➔
文本
使用正则表达式将文本字符串的一部分替换为不同的文本字符串。
•
Example: regexreplace("Google Doc 101", "[0-9]+", "777")
➔
"Google Doc 777"
•
Example:
regexreplace("The price today is $826.25", "[0-9]*\.[0-9]+[0-9]+", "315.75")
➔
"The price is $315.75"
parseJson(source: TEXT, key: TEXT)
➔
文本
解析有效的 JSON 字符串并返回相应的值。
•
Example:
parseJson("{\"name\":\"John\", \"age\":30, \"car\":null}", "age")
➔
"30"
•
Example:
parseJson("{\"name\":\"John\", \"age\":30, \"car\":null}", "name")
➔
"John"
For example, let's consider parseJson(var, "key"). Here, var is the text variable that stores the JSON string, and "key" is the key to parse. The latter supports nested key calling and simple references to array-like objects via the . (dot) notation.
The parseJson function greatly simplifies working with complex data structures in ProtoPie. Additionally, since most API responses are in JSON format, being able to use parseJson within Pies makes working with APIs much more straightforward.
You can use the parseJson function to:
send JSON string to pies via Bridge apps in ProtoPie Connect (e.g., message: “AutomobileSignal”, value: “json string”).
store a value inside a Pie variable via the Receive trigger.
use the data values inside the JSON string.
To learn more, take a look at this Pie example.
Math
pow(source: NUMBER, exponent: NUMBER)
➔
数字
计算第一个数字的值提升到第二个数字次方后的结果。
•
Example: pow(2,3)
➔
8
sqrt(source: NUMBER)
➔
数字
计算一个数的平方根。这不适用于负数。
•
Example: sqrt(9)
➔
3
•
Example: sqrt(2)
➔
1.41
min(source1: NUMBER, source2: NUMBER)
➔
数字
提取两个数字中较小的一个。
•
Example: min(0, 1)
➔
0
max(source1: NUMBER, source2: NUMBER)
➔
数字
取两个数字中较大的一个。
•
Example: max(0, 1)
➔
1
abs(value: NUMBER)
➔
数字
返回一个数字的绝对值。实际上,这就是去掉数字前面的负号。
•
Example: abs(-1)
➔
1
•
Example: abs(5 - 25)
➔
20
sign(value: NUMBER)
➔
数字
检查一个数字是正数还是负数。如果一个数字是正数,则返回 1。如果一个数字是负数,则返回 -1。如果一个数字是 0,则返回 0。
•
Example: sign(5)
➔
1
•
Example: sign(-10)
➔
-1
•
Example: sign(0)
➔
0
round(source: NUMBER)
➔
数字
返回一个数字的四舍五入值。
•
Example: round(3.49)
➔
3
•
Example: round(1.5)
➔
2
•
Example: round(6.79)
➔
7
floor(source: NUMBER)
➔
数字
向下返回最接近的整数。
•
Example: floor(1.5)
➔
1
•
Example: floor(2.99)
➔
2
ceil(source: NUMBER)
➔
数字
向上返回最接近的整数。
•
Example: ceil(1.5)
➔
2
•
Example: ceil(4.3)
➔
5
random()
➔
数字
0 到 1 之间的随机小数。
•
Example: random()
➔
0 到 1 之间的一个随机小数
random(min: NUMBER, max: NUMBER)
➔
数字
在两个给定数字之间随机返回一个十进制数。
•
Example: random(1, 5)
➔
1 到 5 之间的一个随机小数
randomInt(min: NUMBER, max: NUMBER)
➔
数字
随机返回两个给定数字之间的一个整数。
•
Example: randomInt(1, 5)
➔
1 到 5 之间的随机整数
radians(degrees: NUMBER)
➔
数字
将角度转换为弧度。
•
Example: radians(180)
➔
3.14 = π
•
Example: radians(90)
➔
1.57 = π / 2
degrees(radians: NUMBER)
➔
数字
将弧度转换为度数。
•
Example: degrees($pi)
➔
180
•
Example: degrees($pi / 2)
➔
90
sin(radians: NUMBER)
➔
数字
计算一个以弧度为单位的数字的正弦值。
•
Example: sin($pi / 2)
➔
1
•
Example: sin($pi / 6)
➔
0.5
cos(radians: NUMBER)
➔
数字
计算一个以弧度表示的数的余弦值。
•
Example: cos(0)
➔
1
•
Example: cos($pi / 2)
➔
0
tan(radians: NUMBER)
➔
数字
计算一个以弧度表示的数字的正切值。
•
Example: tan($pi / 4)
➔
1
•
Example: tan(0)
➔
0
asin(x: NUMBER)
➔
数字
计算 x 的反正弦(以弧度为单位)。
•
Example: asin(1)
➔
1.57 = π / 2
•
Example: asin(0.5)
➔
0.52 = π / 6
acos(x: NUMBER)
➔
数字
计算 x 的反余弦(以弧度为单位)。
•
Example: acos(1)
➔
0
•
Example: acos(0)
➔
1.57 = π / 2
atan(x: NUMBER)
➔
数字
计算 x 的反正切值(以弧度为单位)。
•
Example: atan(1)
➔
0.79 = π / 4
•
Example: atan(0)
➔
0
atan2(y: NUMBER, x: NUMBER)
➔
数字
计算 x 和 y 的反正切(以弧度为单位),也称为欧几里得平面中的角度。
•
Example: atan2(1, 0)
➔
1.57 = π / 2
•
Example: atan2(1, 1)
➔
0.79 = π / 4
pow(source: NUMBER, exponent: NUMBER)
➔
数字
计算第一个数字的值提升到第二个数字次方后的结果。
•
Example: pow(2,3)
➔
8
sqrt(source: NUMBER)
➔
数字
计算一个数的平方根。这不适用于负数。
•
Example: sqrt(9)
➔
3
•
Example: sqrt(2)
➔
1.41
min(source1: NUMBER, source2: NUMBER)
➔
数字
提取两个数字中较小的一个。
•
Example: min(0, 1)
➔
0
max(source1: NUMBER, source2: NUMBER)
➔
数字
取两个数字中较大的一个。
•
Example: max(0, 1)
➔
1
abs(value: NUMBER)
➔
数字
返回一个数字的绝对值。实际上,这就是去掉数字前面的负号。
•
Example: abs(-1)
➔
1
•
Example: abs(5 - 25)
➔
20
sign(value: NUMBER)
➔
数字
检查一个数字是正数还是负数。如果一个数字是正数,则返回 1。如果一个数字是负数,则返回 -1。如果一个数字是 0,则返回 0。
•
Example: sign(5)
➔
1
•
Example: sign(-10)
➔
-1
•
Example: sign(0)
➔
0
round(source: NUMBER)
➔
数字
返回一个数字的四舍五入值。
•
Example: round(3.49)
➔
3
•
Example: round(1.5)
➔
2
•
Example: round(6.79)
➔
7
floor(source: NUMBER)
➔
数字
向下返回最接近的整数。
•
Example: floor(1.5)
➔
1
•
Example: floor(2.99)
➔
2
ceil(source: NUMBER)
➔
数字
向上返回最接近的整数。
•
Example: ceil(1.5)
➔
2
•
Example: ceil(4.3)
➔
5
random()
➔
数字
0 到 1 之间的随机小数。
•
Example: random()
➔
0 到 1 之间的一个随机小数
random(min: NUMBER, max: NUMBER)
➔
数字
在两个给定数字之间随机返回一个十进制数。
•
Example: random(1, 5)
➔
1 到 5 之间的一个随机小数
randomInt(min: NUMBER, max: NUMBER)
➔
数字
随机返回两个给定数字之间的一个整数。
•
Example: randomInt(1, 5)
➔
1 到 5 之间的随机整数
radians(degrees: NUMBER)
➔
数字
将角度转换为弧度。
•
Example: radians(180)
➔
3.14 = π
•
Example: radians(90)
➔
1.57 = π / 2
degrees(radians: NUMBER)
➔
数字
将弧度转换为度数。
•
Example: degrees($pi)
➔
180
•
Example: degrees($pi / 2)
➔
90
sin(radians: NUMBER)
➔
数字
计算一个以弧度为单位的数字的正弦值。
•
Example: sin($pi / 2)
➔
1
•
Example: sin($pi / 6)
➔
0.5
cos(radians: NUMBER)
➔
数字
计算一个以弧度表示的数的余弦值。
•
Example: cos(0)
➔
1
•
Example: cos($pi / 2)
➔
0
tan(radians: NUMBER)
➔
数字
计算一个以弧度表示的数字的正切值。
•
Example: tan($pi / 4)
➔
1
•
Example: tan(0)
➔
0
asin(x: NUMBER)
➔
数字
计算 x 的反正弦(以弧度为单位)。
•
Example: asin(1)
➔
1.57 = π / 2
•
Example: asin(0.5)
➔
0.52 = π / 6
acos(x: NUMBER)
➔
数字
计算 x 的反余弦(以弧度为单位)。
•
Example: acos(1)
➔
0
•
Example: acos(0)
➔
1.57 = π / 2
atan(x: NUMBER)
➔
数字
计算 x 的反正切值(以弧度为单位)。
•
Example: atan(1)
➔
0.79 = π / 4
•
Example: atan(0)
➔
0
atan2(y: NUMBER, x: NUMBER)
➔
数字
计算 x 和 y 的反正切(以弧度为单位),也称为欧几里得平面中的角度。
•
Example: atan2(1, 0)
➔
1.57 = π / 2
•
Example: atan2(1, 1)
➔
0.79 = π / 4
Color
color(red: NUMBER, green: NUMBER, blue: NUMBER)
➔
颜色
根据 RGB 值返回颜色值(十六进制颜色代码)。
•
Example: color(255, 255, 255)
➔
#FFFFFF
•
Example: color(255, 102, 97)
➔
#FF6661
red(source: COLOR)
➔
数字
返回十六进制颜色代码中 RGB 的红色参数。
•
Example: red(#FF0000)
➔
255
•
Example: red(#008000)
➔
0
•
Example: red(#0000FF)
➔
0
green(source: COLOR)
➔
数字
返回十六进制颜色代码的绿色 RGB 参数。
•
Example: green(#FF0000)
➔
0
•
Example: green(#008000)
➔
128
•
Example: green(#0000FF)
➔
0
blue(source: COLOR)
➔
数字
返回十六进制颜色代码的蓝色 RGB 分量。
•
Example: blue(#FF0000)
➔
0
•
Example: blue(#008000)
➔
0
•
Example: blue(#0000FF)
➔
255
color(red: NUMBER, green: NUMBER, blue: NUMBER)
➔
颜色
根据 RGB 值返回颜色值(十六进制颜色代码)。
•
Example: color(255, 255, 255)
➔
#FFFFFF
•
Example: color(255, 102, 97)
➔
#FF6661
red(source: COLOR)
➔
数字
返回十六进制颜色代码中 RGB 的红色参数。
•
Example: red(#FF0000)
➔
255
•
Example: red(#008000)
➔
0
•
Example: red(#0000FF)
➔
0
green(source: COLOR)
➔
数字
返回十六进制颜色代码的绿色 RGB 参数。
•
Example: green(#FF0000)
➔
0
•
Example: green(#008000)
➔
128
•
Example: green(#0000FF)
➔
0
blue(source: COLOR)
➔
数字
返回十六进制颜色代码的蓝色 RGB 分量。
•
Example: blue(#FF0000)
➔
0
•
Example: blue(#008000)
➔
0
•
Example: blue(#0000FF)
➔
255
Type Conversion
number(source: TEXT)
➔
数字
将文本转换为数字。如果文本无法转换为数字,此操作将不起作用。
•
Example: number("1234")
➔
1234
•
Example: number("94.27")
➔
94.27
text(source: NUMBER)
➔
文本
将数字转换为文本。
•
Example: text(1234)
➔
"1234"
•
Example: text(94.27)
➔
"94.27"
•
Example: text(1 + 3)
➔
"4"
format(source: NUMBER, format: TEXT)
➔
文本
将数字按特定格式转换为文本。# 是整数部分的占位符,而 0 表示小数部分。
•
Example: format(1234.567, "#")
➔
"1235"
•
Example: format(1234.567, "#,###")
➔
"1,235"
•
Example: format(1234.567, "#.###,00")
➔
"1,234.57"
•
Example: format(1234.567, "#,##.00")
➔
"12,34.57"
•
Example: format(1234.567, "#,###.00")
➔
"1,234.57"
color(source: TEXT)
➔
颜色
将文本转换为颜色值(十六进制颜色代码)。如果文本不符合十六进制颜色代码的结构,则此功能无法使用。
•
Example: green("#FFFFFF")
➔
#FF0000
number(source: TEXT)
➔
数字
将文本转换为数字。如果文本无法转换为数字,此操作将不起作用。
•
Example: number("1234")
➔
1234
•
Example: number("94.27")
➔
94.27
text(source: NUMBER)
➔
文本
将数字转换为文本。
•
Example: text(1234)
➔
"1234"
•
Example: text(94.27)
➔
"94.27"
•
Example: text(1 + 3)
➔
"4"
format(source: NUMBER, format: TEXT)
➔
文本
将数字按特定格式转换为文本。# 是整数部分的占位符,而 0 表示小数部分。
•
示例:
format(1234.567, "#")
➔
"1235"
•
示例:
format(1234.567, "#,###")
➔
"1,235"
•
示例:
format(1234.567, "#.###,00")
➔
"1,234.57"
•
示例:
format(1234.567, "#,##.00")
➔
"12,34.57"
•
示例:
format(1234.567, "#,###.00")
➔
"1,234.57"
color(source: TEXT)
➔
颜色
将文本转换为颜色值(十六进制颜色代码)。如果文本不符合十六进制颜色代码的结构,则此功能无法使用。
•
Example: green("#FFFFFF")
➔
#FF0000
Layers
layer(source: TEXT)
➔
图层
参考某个图层。
•
将其用作公式或其他函数的一部分。
layer(source: TEXT).property
➔
文本或数值
请参阅图层的属性。了解更多有关图层属性的信息。
•
Example: layer("Rectangle 1").x
➔
名为“Rectangle 1”的图层的 x 坐标
•
Example: layer("Oval 1").opacity
➔
名为 Oval 1 的图层的不透明度
•
Example: layer("Input 1").text
➔
输入层中名为 Input 1 的文本
parent(layerName: LAYER)
➔
图层
请参考父层,例如容器或组件。
•
将其用作公式或其他函数的一部分。
parent(layerName: LAYER).property
➔
文本或数值
请参照父图层的属性。了解更多关于图层属性。
•
Example: layer("Rectangle 1").x
➔
矩形 1 在其父图层中的 x 坐标
•
Example: layer("Oval 1").opacity
➔
椭圆 1 及其父图层的不透明度
initial(layerName: LAYER, layerProperty: TEXT)
➔
文本或数字
返回特定图层属性的初始值(在任何交互之前)。了解更多有关图层属性的信息。
•
Example: initial("Rectangle 1").x
➔
矩形 1 的初始 x 坐标
•
Example: initial("Oval 1, opacity")
➔
椭圆 1 的初始不透明度
•
Example: initial("Input 1, text")
➔
输入 1 中的初始文本
layer(source: TEXT)
➔
图层
参考某个图层。
•
将其用作公式或其他函数的一部分。
layer(source: TEXT).property
➔
文本或数值
请参阅图层的属性。了解更多有关图层属性的信息。
•
Example: layer("Rectangle 1").x
➔
名为“Rectangle 1”的图层的 x 坐标
•
Example: layer("Oval 1").opacity
➔
名为 Oval 1 的图层的不透明度
•
Example: layer("Input 1").text
➔
输入层中名为 Input 1 的文本
parent(layerName: LAYER)
➔
图层
请参考父层,例如容器或组件。
•
将其用作公式或其他函数的一部分。
parent(layerName: LAYER).property
➔
文本或数值
请参照父图层的属性。了解更多关于图层属性。
•
Example: layer("Rectangle 1").x
➔
矩形 1 在其父图层中的 x 坐标
•
Example: layer("Oval 1").opacity
➔
椭圆 1 及其父图层的不透明度
initial(layerName: LAYER, layerProperty: TEXT)
➔
文本或数字
返回特定图层属性的初始值(在任何交互之前)。了解更多有关图层属性的信息。
•
示例:
initial("矩形 1").x
➔
矩形 1 的初始 x 坐标
•
示例:
initial("椭圆 1,不透明度")
➔
椭圆 1 的初始不透明度
•
示例:
initial("输入 1,文本")
➔
输入 1 中的初始文本
Relative Coordinates
toLayerX(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于屏幕的 x 坐标转换为相对于容器或组件的对应 x 坐标。容器或组件内各图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果您想根据相对于屏幕的位置(100, 200)获取相对于容器 `Container 1` 的 x 坐标,请使用以下函数:
•
toLayerX(`Container 1`, 100, 200)
➔
根据相对于屏幕的 x 坐标 `100`,返回相对于 `Container 1` 的 x 坐标。
toLayerY(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于屏幕的 y 坐标转换为相对于容器或组件的对应 y 坐标。容器或组件内各图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果你想根据相对于屏幕的位置 (100, 200) 获取相对于容器 `Container 1` 的 y 坐标,请使用以下函数:
•
toLayerY(`Container 1`, 100, 200)
➔
根据相对于屏幕的 x 坐标 `100`,返回相对于 `Container 1` 的 x 坐标。
toScreenX(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于容器或组件的 x 坐标转换为相对于屏幕的对应 x 坐标。容器或组件内图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果您想根据相对于容器 `Container 1` 的位置 (10, 20) 获取相对于屏幕的 x 坐标,请使用以下函数:
•
toScreenX(`Container 1`, 10, 20)
➔
根据相对于 `Container 1` 的 x 坐标 `10`,返回相对于屏幕的 x 坐标。
toScreenY(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于容器或组件的 y 坐标转换为相对于屏幕的对应 y 坐标。容器或组件内图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果你想根据相对于容器 `Container 1` 的位置 (10, 20) 获取相对于屏幕的 y 坐标,请使用以下函数:
•
toScreenY(`Container 1`, 10, 20)
➔
根据相对于 `Container 1` 的 y 坐标 `20`,返回相对于屏幕的 y 坐标。
toLayerX(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于屏幕的 x 坐标转换为相对于容器或组件的对应 x 坐标。容器或组件内各图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果您想根据相对于屏幕的位置(100, 200)获取相对于容器 `Container 1` 的 x 坐标,请使用以下函数:
•
示例:
initial("矩形 1").x
➔
根据相对于屏幕的 x 坐标 `100`,返回相对于 `Container 1` 的 x 坐标。
toLayerY(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于屏幕的 y 坐标转换为相对于容器或组件的对应 y 坐标。容器或组件内各图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果你想根据相对于屏幕的位置 (100, 200) 获取相对于容器 `Container 1` 的 y 坐标,请使用以下函数:
•
示例:
initial("矩形 1").x
➔
根据相对于屏幕的 x 坐标 `100`,返回相对于 `Container 1` 的 x 坐标。
toScreenX(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于容器或组件的 x 坐标转换为相对于屏幕的对应 x 坐标。容器或组件内图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果您想根据相对于容器 `Container 1` 的位置 (10, 20) 获取相对于屏幕的 x 坐标,请使用以下函数:
•
示例:
initial("矩形 1").x
➔
根据相对于 `Container 1` 的 x 坐标 `10`,返回相对于屏幕的 x 坐标。
toScreenY(containerName: LAYER, x: NUMBER, y: NUMBER)
➔
数字
将相对于容器或组件的 y 坐标转换为相对于屏幕的对应 y 坐标。容器或组件内图层的坐标默认是相对于其所在的容器或组件。
•
例如,如果你想根据相对于容器 `Container 1` 的位置 (10, 20) 获取相对于屏幕的 y 坐标,请使用以下函数:
•
示例:
initial("矩形 1").x
➔
根据相对于 `Container 1` 的 y 坐标 `20`,返回相对于屏幕的 y 坐标。
Time & Date
Note: the time & date functions follow the ISO8601 format.
timeNow()
➔
文本
检索当前时间信息。
•
Example: timeNow()
➔
17:44:50.123
time(hour: NUMBER, min: NUMBER, sec: NUMBER)
➔
文本
使用提供的小时、分钟和秒值构建一个时间对象,并以标准的“小时:分钟:秒”格式显示时间。
•
Example: time(14, 50, 23)
➔
14:50:23
hour()
➔
数字
以24小时制检索并返回给定时间中的小时部分。该函数以时间值作为输入,提取小时部分,并将其作为数值返回。
•
Example: hour("17:44:30")
➔
17
minute()
➔
数字
提取并返回给定时间(24 小时制)的分钟部分。
•
Example: minute("17:44:30")
➔
44
second()
➔
数字
提取并返回给定时间(24 小时制)的分钟部分。
•
Example: second("17:44:30")
➔
30
diffTime()
➔
数字
计算两个时间点之间的差值,并以小时、分钟和/或秒返回持续时间。
•
Example: diffTime("17:45:30", "18:45:30", "H")
➔
1
•
Example: diffTime("17:45:30", "18:45:30", "M")
➔
60
•
Example: diffTime("17:45:30", "18:45:30", "S")
➔
3600
formatTime()
➔
数字
将时间值转换为人类可读的字符串,并遵循指定的格式模式。
•
Example: formatTime("11:44:30", "HHa")
➔
11am
•
Example: formatTime("11:44:30", "HHam mm")
➔
11am 44
•
Example: formatTime("11:44:30", "hh:mm a")
➔
11:40 am
dateNow()
➔
数字
在执行时检索并返回当前日期。
•
Example: dateNow()
➔
2023-09-22
date(year: NUMBER, month: NUMBER, day: NUMBER)
➔
文本
使用提供的年、月、日值构造一个日期对象,并以“年-月-日”格式返回。
•
Example: date(2014, 12, 8)
➔
2014-12-08
year()
➔
数字
从“年-月-日”日期字符串中提取并返回年份部分。
•
Example: year("2014-12-08")
➔
2014
month()
➔
数字
从“年-月-日”格式的日期中提取并返回月份部分。
•
Example: month("2014-12-08")
➔
12
day()
➔
数字
从“年-月-日”格式的日期中提取并返回“日”部分。
•
Example: day("2014-12-08")
➔
8
DiffDate()
➔
数字
计算两个日期之间的差值,并根据指定的单位("Y"、"M"、"D"、"YD"、"YM"、"MD")以数值形式返回。注意:如果“to”日期早于“from”日期,结果将为 -1。
•
Example: diffDate("1973-02-24", "1969-05-16", "Y")
➔
-1
•
Example: diffDate("1973-02-24", "1969-05-16", "M")
➔
-1
•
Example: diffDate("1973-02-24", "1969-05-16", "D")
➔
-1
•
Example: diffDate("1969-05-16", "1973-02-24", "Y")
➔
3
•
Example: diffDate("1969-05-16", "1973-02-24", "M")
➔
45
•
Example: diffDate("1969-05-16", "1973-02-24", "D")
➔
1380
•
Example: diffDate("1969-05-16", "1973-02-24", "MD")
➔
8
•
Example: diffDate("2023-01-01", "2023-02-10", "MD")
➔
9
•
Example: diffDate("1969-05-16", "1973-02-24", "YM")
➔
9
•
Example: diffDate("1969-05-16", "1973-02-24", "YD")
➔
284
•
Example: diffDate("2023-01-01", "2023-02-10", "YD")
➔
40
formatDate()
➔
文本
根据提供的日期值和格式字符串返回格式化的日期字符串。
•
Example: formatDate("2023-06-01", "DD/MM/YYYY")
➔
01/06/2023
•
Example: formatDate("2023-06-01", "YYYY MMMM dddd")
➔
2023 June Thursday
•
Example: formatDate("2023-06-01", "MMM DD, YY")
➔
Jun 01, 23
epochtodate(timestamp: NUMBER)
➔
文本
将 Unix 纪元时间戳(毫秒)转换为 UTC 日期时间表示形式。
•
Example: epochtodate (0)
➔
1970-01-01T00:00:00Z
•
Example: epochtodate (-1)
➔
1969-12-31T23:59:59.999Z
•
Example: epochtodate (1)
➔
1970-01-01T00:00:00.001Z
•
Example: epochtodate (1655908429662)
➔
1970-01-01T00:00:00.001Z
epochtodate(timestamp: NUMBER, format: TEXT)
➔
文本
根据指定格式将 Unix 时间戳转换为可读的日期/时间字符串。
•
Example: epochtodate (1695316200000)
➔
2023年9月21日17:10:00(UTC)
•
Example: epochtodate (1695316200000, "hh:mm")
➔
17:10
timeNow()
➔
文本
检索当前时间信息。
•
Example: timeNow()
➔
17:44:50.123
time(hour: NUMBER, min: NUMBER, sec: NUMBER)
➔
文本
使用提供的小时、分钟和秒值构建一个时间对象,并以标准的“小时:分钟:秒”格式显示时间。
•
Example: time(14, 50, 23)
➔
14:50:23
hour()
➔
数字
以24小时制检索并返回给定时间中的小时部分。该函数以时间值作为输入,提取小时部分,并将其作为数值返回。
•
Example: hour("17:44:30")
➔
17
minute()
➔
数字
提取并返回给定时间(24 小时制)的分钟部分。
•
Example: minute("17:44:30")
➔
44
second()
➔
数字
提取并返回给定时间(24 小时制)的分钟部分。
•
Example: second("17:44:30")
➔
30
diffTime()
➔
数字
计算两个时间点之间的差值,并以小时、分钟和/或秒返回持续时间。
•
示例:
diffTime("17:45:30", "18:45:30", "H")
➔
1
•
示例:
diffTime("17:45:30", "18:45:30", "M")
➔
60
•
示例:
diffTime("17:45:30", "18:45:30", "S")
➔
3600
formatTime()
➔
数字
将时间值转换为人类可读的字符串,并遵循指定的格式模式。
•
示例:
formatTime("11:44:30", "HHa")
➔
11am
•
示例:
formatTime("11:44:30", "HHam mm")
➔
11am 44
•
示例:
formatTime("11:44:30", "hh:mm a")
➔
11:40 am
dateNow()
➔
数字
在执行时检索并返回当前日期。
•
Example: dateNow()
➔
2023-09-22
date(year: NUMBER, month: NUMBER, day: NUMBER)
➔
文本
使用提供的年、月、日值构造一个日期对象,并以“年-月-日”格式返回。
•
Example: date(2014, 12, 8)
➔
2014-12-08
year()
➔
数字
从“年-月-日”日期字符串中提取并返回年份部分。
•
Example: year("2014-12-08")
➔
2014
month()
➔
数字
从“年-月-日”格式的日期中提取并返回月份部分。
•
Example: month("2014-12-08")
➔
12
day()
➔
数字
从“年-月-日”格式的日期中提取并返回“日”部分。
•
Example: day("2014-12-08")
➔
8
DiffDate()
➔
数字
计算两个日期之间的差值,并根据指定的单位("Y"、"M"、"D"、"YD"、"YM"、"MD")以数值形式返回。注意:如果“to”日期早于“from”日期,结果将为 -1。
•
示例:
diffDate("1973-02-24", "1969-05-16", "Y")
➔
-1
•
示例:
diffDate("1973-02-24", "1969-05-16", "M")
➔
-1
•
示例:
diffDate("1973-02-24", "1969-05-16", "D")
➔
-1
•
示例:
diffDate("1969-05-16", "1973-02-24", "Y")
➔
3
•
示例:
diffDate("1969-05-16", "1973-02-24", "M")
➔
45
•
示例:
diffDate("1969-05-16", "1973-02-24", "D")
➔
1380
•
示例:
diffDate("1969-05-16", "1973-02-24", "MD")
➔
8
•
示例:
diffDate("2023-01-01", "2023-02-10", "MD")
➔
9
•
示例:
diffDate("1969-05-16", "1973-02-24", "YM")
➔
9
•
示例:
diffDate("1969-05-16", "1973-02-24", "YD")
➔
284
•
示例:
diffDate("2023-01-01", "2023-02-10", "YD")
➔
40
formatDate()
➔
文本
根据提供的日期值和格式字符串返回格式化的日期字符串。
•
示例:
formatDate("2023-06-01", "DD/MM/YYYY")
➔
01/06/2023
•
示例:
formatDate("2023-06-01", "YYYY MMMM dddd")
➔
2023 June Thursday
•
示例:
formatDate("2023-06-01", "MMM DD, YY")
➔
Jun 01, 23
epochtodate(timestamp: NUMBER)
➔
文本
将 Unix 纪元时间戳(毫秒)转换为 UTC 日期时间表示形式。
•
示例:
epochtodate (0)
➔
1970-01-01T00:00:00Z
•
示例:
epochtodate (-1)
➔
1969-12-31T23:59:59.999Z
•
示例:
epochtodate (1)
➔
1970-01-01T00:00:00.001Z
•
示例:
epochtodate (1655908429662)
➔
1970-01-01T00:00:00.001Z
epochtodate(timestamp: NUMBER, format: TEXT)
➔
文本
根据指定格式将 Unix 时间戳转换为可读的日期/时间字符串。
•
示例:
epochtodate (1695316200000)
➔
2023年9月21日17:10:00(UTC)
•
示例:
epochtodate (1695316200000, "hh:mm")
➔
17:10
Learn More in ProtoPie School's Masterclass
Looking to learn more about using functions in ProtoPie? Join ProtoPie’s Masterclass for detailed examples and guidance on using some of the functions listed in this documentation.