数据转换函数是辅助函数,用于简化表达式中的数据转换操作。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript 代码。更多信息请参考表达式文档。

各数据类型可用的函数列表请参阅对应页面:

使用方法#

数据转换函数可在表达式编辑器中使用。

语法格式为:

{{ dataItem.function() }}

例如,检查字符串是否为电子邮件地址:

{{ "example@example.com".isEmail() }}

// 返回 true

数组#

本文档列出了内置的便捷函数,用于支持在表达式中对数组进行数据转换。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript。更多信息请参考表达式

average(): Number #

Returns the value of elements in an array


chunk(size: Number): Array #

Splits arrays into chunks with a length of size

Function parameters#

sizeRequiredNumber

The size of each chunk.


compact(): Array #

Removes empty values from the array.


difference(arr: Array): Array #

Compares two arrays. Returns all elements in the base array that aren't present in arr.

Function parameters#

arrRequiredArray

The array to compare to the base array.


intersection(arr: Array): Array #

Compares two arrays. Returns all elements in the base array that are present in arr.

Function parameters#

arrRequiredArray

The array to compare to the base array.


first(): Array item #

Returns the first element of the array.


isEmpty(): Boolean #

Checks if the array doesn't have any elements.


isNotEmpty(): Boolean #

Checks if the array has elements.


last(): Array item #

Returns the last element of the array.


max(): Number #

Returns the highest value in an array.


merge(arr: Array): Array #

Merges two Object-arrays into one array by merging the key-value pairs of each element.

Function parameters#

arrRequiredArray

The array to merge into the base array.


min(): Number #

Gets the minimum value from a number-only array.


pluck(fieldName?: String): Array #

Returns an array of Objects where keys equal the given field names.

Function parameters#

fieldNameOptionalString

The key(s) you want to retrieve. You can enter as many keys as you want, as comma-separated strings.


randomItem(): Array item #

Returns a random element from an array.


removeDuplicates(key?: String): Array #

Removes duplicates from an array.

Function parameters#

keyOptionalString

A key, or comma-separated list of keys, to check for duplicates.


renameKeys(from: String, to: String): Array #

Renames all matching keys in the array. You can rename more than one key by entering a series of comma separated strings, in the pattern oldKeyName, newKeyName.

Function parameters#

fromRequiredString

The key you want to rename.

toRequiredString

The new name.


smartJoin(keyField: String, nameField: String): Array #

Operates on an array of objects where each object contains key-value pairs. Creates a new object containing key-value pairs, where the key is the value of the first pair, and the value is the value of the second pair. Removes non-matching and empty values and trims any whitespace before joining.

Function parameters#

keyFieldRequiredString

The key to join.

nameFieldRequiredString

The value to join.

Example
Basic usage
// 输入
{{ [{"type":"fruit", "name":"apple"},{"type":"vegetable", "name":"carrot"} ].smartJoin("type","name") }}
// 输出
[Object: {"fruit":"apple","vegetable":"carrot"}]

sum(): Number #

Returns the total sum all the values in an array of parsable numbers.


toJsonString(): String #

Convert an array to a JSON string. Equivalent of JSON.stringify.


union(arr: Array): Array #

Concatenates two arrays and then removes duplicate.

Function parameters#

arrRequiredArray

The array to compare to the base array.


unique(key?: String): Array #

Remove duplicates from an array.

Function parameters#

keyOptionalString

A key, or comma-separated list of keys, to check for duplicates.

布尔值#

本文档列出了内置的便捷函数,用于支持在表达式中对数组进行数据转换。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript。更多信息请参考表达式

toInt(): Number #

Convert a boolean to a number. false converts to 0true converts to 1.

日期处理#

本文档列出了内置的便捷函数,用于支持在表达式中进行日期数据转换。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript 代码。更多信息请参考表达式

beginningOf(unit?: DurationUnit): Date #

Transforms a Date to the start of the given time period. Returns either a JavaScript Date or Luxon Date, depending on input.

Function parameters#

unitOptionalString enum

A valid string specifying the time unit.

Default: week

One of: secondminutehourdayweekmonthyear


endOfMonth(): Date #

Transforms a Date to the end of the month.


extract(datePart?: DurationUnit): Number #

Extracts the part defined in datePart from a Date. Returns either a JavaScript Date or Luxon Date, depending on input.

Function parameters#

datePartOptionalString enum

A valid string specifying the time unit.

Default: week

One of: secondminutehourdayweekmonthyear


format(fmt: TimeFormat): String #

Formats a Date in the given structure

Function parameters#

fmtRequiredString enum

A valid string specifying the time format. Refer to Luxon | Table of tokens for formats.


isBetween(date1: Date | DateTime, date2: Date | DateTime): Boolean #

Checks if a Date is between two given dates.

Function parameters#

date1RequiredDate or DateTime

The first date in the range.

date2RequiredDate or DateTime

The last date in the range.


isDst(): Boolean #

Checks if a Date is within Daylight Savings Time.


isInLast(n?: Number, unit?: DurationUnit): Boolean #

Checks if a Date is within a given time period.

Function parameters#

nOptionalNumber

The number of units. For example, to check if the date is in the last nine weeks, enter 9.

Default: 0

unitOptionalString enum

A valid string specifying the time unit.

Default: minutes

One of: secondminutehourdayweekmonthyear


isWeekend(): Boolean #

Checks if the Date falls on a Saturday or Sunday.


minus(n: Number, unit?: DurationUnit): Date #

Subtracts a given time period from a Date. Returns either a JavaScript Date or Luxon Date, depending on input.

Function parameters#

nRequiredNumber

The number of units. For example, to subtract nine seconds, enter 9 here.

unitOptionalString enum

A valid string specifying the time unit.

Default: milliseconds

One of: secondminutehourdayweekmonthyear


plus(n: Number, unit?: DurationUnit): Date #

Adds a given time period to a Date. Returns either a JavaScript Date or Luxon Date, depending on input.

Function parameters#

nRequiredNumber

The number of units. For example, to add nine seconds, enter 9 here.

unitOptionalString enum

A valid string specifying the time unit.

Default: milliseconds

One of: secondminutehourdayweekmonthyear


toDateTime(): Date #

Converts a JavaScript date to a Luxon date object.

数字处理#

本文档列出了内置的便捷函数,用于支持在表达式中对数字进行数据转换。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript。更多信息请参考表达式

ceil(): Number #

Rounds up a number to a whole number.


floor(): Number #

Rounds down a number to a whole number.


format(locales?: LanguageCode, options?: FormatOptions): String #

This is a wrapper around Intl.NumberFormat(). Returns a formatted string of a number based on the given LanguageCode and FormatOptions. When no arguments are given, transforms the number in a like format 1.234.

Function parameters#

localesOptionalString

An IETF BCP 47 language tag.

Default: en-US

optionsOptionalObject

Configure options for number formatting. Refer to MDN | Intl.NumberFormat() for more information.


isEven(): Boolean #

Returns true if the number is even. Only works on whole numbers.


isOdd(): Boolean #

Returns true if the number is odd. Only works on whole numbers.


round(decimalPlaces?: Number): Number #

Returns the value of a number rounded to the nearest whole number, unless a decimal place is specified.

Function parameters#

decimalPlacesOptionalNumber

How many decimal places to round to.

Default: 0


toBoolean(): Boolean #

Converts a number to a boolean. 0 converts to false. All other values convert to true.


toDateTime(format?: String): Date #

Converts a number to a Luxon date object.

Function parameters#

formatOptionalString enum

Can be ms (milliseconds), s (seconds), or excel (Excel 1900). Defaults to milliseconds.

对象#

本文档列出了内置的便捷函数,用于支持在表达式中对对象进行数据转换。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript。更多信息请参考表达式

isEmpty(): Boolean #

Checks if the Object has no key-value pairs.


merge(object: Object): Object #

Merges two Objects into a single Object using the first as the base Object. If a key exists in both Objects, the key in the base Object takes precedence.

Function parameters#

objectRequiredObject

The Object to merge with the base Object.


hasField(fieldName: String): Boolean #

Checks if the Object has a given field. Only top-level keys are supported.

Function parameters#

fieldNameRequiredString

The field to search for.


removeField(key: String): Object #

Removes a given field from the Object

Function parameters#

keyRequiredString

The field key of the field to remove.


removeFieldsContaining(value: String): Object #

Removes fields with a given value from the Object.

Function parameters#

valueRequiredString

The field value of the field to remove.


keepFieldsContaining(value: String): Object #

Removes fields that do not match the given value from the Object.

Function parameters#

valueRequiredString

The field value of the field to keep.


compact(): Object #

Removes empty values from an Object.


toJsonString(): String #

Convert an object to a JSON string. Equivalent of JSON.stringify.


urlEncode(): String #

Transforms an Object into a URL parameter list. Only top-level keys are supported.

字符串处理函数#

本文档列出了内置的便捷函数,用于支持在 表达式 中对字符串数据进行转换处理。

表达式中的 JavaScript

您可以在表达式中使用任何 JavaScript 功能。更多信息请参考表达式文档。

base64Encode(): A base64 encoded string. #

Encode a string as base64.


base64Decode(): A plain string. #

Convert a base64 encoded string to a normal string.


extractDomain(): String #

Extracts a domain from a string containing a valid URL. Returns undefined if none is found.


extractEmail(): String #

Extracts an email from a string. Returns undefined if none is found.


extractUrl(): String #

Extracts a URL from a string. Returns undefined if none is found.


extractUrlPath(): String #

Extract the path but not the root domain from a URL. For example, "https://example.com/orders/1/details".extractUrlPath() returns "/orders/1/details/".


hash(algo?: Algorithm): String #

Returns a string hashed with the given algorithm.

Function parameters#

algoOptionalString enum

Which hashing algorithm to use.

Default: md5

One of: md5base64sha1sha224sha256sha384sha512sha3ripemd160


isDomain(): Boolean #

Checks if a string is a domain.


isEmail(): Boolean #

Checks if a string is an email.


isEmpty(): Boolean #

Checks if a string is empty.


isNotEmpty(): Boolean #

Checks if a string has content.


isNumeric(): Boolean #

Checks if a string only contains digits.


isUrl(): Boolean #

Checks if a string is a valid URL.


parseJson(): Object #

Equivalent of JSON.parse(). Parses a string as a JSON object.


quote(mark?: String): String #

Returns a string wrapped in the quotation marks. Default quotation is ".

Function parameters#

markOptionalString

Which quote mark style to use.

Default: "


removeMarkdown(): String #

Removes Markdown formatting from a string.


replaceSpecialChars(): String #

Replaces non-ASCII characters in a string with an ASCII representation.


removeTags(): String #

Remove tags, such as HTML or XML, from a string.


toBoolean(): Boolean #

Convert a string to a boolean. "false""0""", and "no" convert to false.


toDateTime(): Date #

Converts a string to a Luxon date object.


toDecimalNumber(): Number #

See toFloat


toFloat(): Number #

Converts a string to a decimal number.


toInt(): Number #

Converts a string to an integer.


toSentenceCase(): String #

Formats a string to sentence case.


toSnakeCase(): String #

Formats a string to snake case.


toTitleCase(): String #

Formats a string to title case. Will not change already uppercase letters to prevent losing information from acronyms and trademarks such as iPhone or FAANG.


toWholeNumber(): Number #

Converts a string to a whole number.


urlDecode(entireString?: Boolean): String #

Decodes a URL-encoded string. It decodes any percent-encoded characters in the input string, and replaces them with their original characters.

Function parameters#

entireStringOptionalBoolean

Whether to decode characters that are part of the URI syntax (true) or not (false).


urlEncode(entireString?: Boolean): String #

Encodes a string to be used/included in a URL.

Function parameters#

entireStringOptionalBoolean

Whether to encode characters that are part of the URI syntax (true) or not (false).

《DeepSeek高效数据分析:从数据清洗到行业案例》聚焦DeepSeek在数据分析领域的高效应用,是系统讲解其从数据处理到可视化全流程的实用指南。作者结合多年职场实战经验,不仅深入拆解DeepSeek数据分析的核心功能——涵盖数据采集、清洗、预处理、探索分析、建模(回归、聚类、时间序列等)及模型评估,更通过金融量化数据分析、电商平台数据分析等真实行业案例,搭配报告撰写技巧,提供独到见解与落地建议。助力职场人在激烈竞争中凭借先进技能突破瓶颈,实现职业进阶,开启发展新篇。

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐