Numeric values contexts

These snippets are frequently encountered in different contexts, such as formatting data, calculating averages, working with timestamps, and more. Each snippet is followed by a clear explanation to help you understand its purpose and functionality. Whether you're a developer looking to understand these snippets or someone seeking to document their usage, this article offers concise explanations to aid your understanding.

Dynamic Email Count Calculation with Conditional Handling

Calculates the total count of emails by summing the count property of each object in the EmailConnector array within the result object. If the array is missing, the count defaults to 0.

{{result["EmailConnector"] ? result["EmailConnector"].reduce((acc, connector) => acc + connector.count, 0) : 0}}


Numeric Value Formatting and Uppercase Conversion with formatNumber Function

Formats the numeric value self.value using the formatNumber function with an optional mantissa and converts the result to uppercase.

{{formatNumber(self.value, {optionalMantissa: true}).toUpperCase()}}


Flexible Numeric Value Formatting with formatNumber Function and Uppercase Conversion

Formats the numeric value self.value (or 0 if not available) using the formatNumber function, allowing an optional mantissa, and converts the result to uppercase.

{{formatNumber(self.value || 0, {optionalMantissa: true}).toUpperCase()}}


Formatted Binary-Based Byte Size with formatBytes Function and Clarity Enhancement

Formats the given byte size (self.value or 0) using binary-based units with an optional mantissa, then removes the 'i' character for clarity.

{{formatBytes(self.value || 0,{base:'binary' ,optionalMantissa:true}).replace('i','')}}


Dynamic Average Processing Time Calculation for API Results

Computes the average processing time per item by dividing the total processing time (in milliseconds) by the total count of items. This snippet can change depending on the API structure.

{{result.total.totalProcessingTime_ms / 1000 / result.total.count}}


Numeric Value Formatting with a letter Representation

Formats the numeric value self.value and appends 's' to indicate seconds.

{{formatNumber(self.value)}} s


Localized Date and Time Formatting with the moment Library

Formats the timestamp, in this case the variable item.dateMs, into a human-readable localized date and time format using the moment library.

{{moment(item.dateMs).tz(timezone).format('lll')}}


Calculating and Formatting Future Date with the moment Library

Calculates a new date by adding one day, in this case to the variable app.startDate, then formats it as 'YYYY-MM-DD' using the moment library.

{{moment(app.startDate, 'YYYY-MM-DD').add(1, 'day').format('YYYY-MM-DD')}}


Formatting Process Start Time with moment Library for Localized Date and Time

Formats the variable processStartTime timestamp from sanitizedItem.details into a readable localized date and time format using the moment library.

{{moment(result.sanitizedItem.details.processStartTime) .tz(timezone).format('lll')}}


Conditional Display: Handling 'undefined' or 'null' Values

Checks if value is 'undefined' or 'null', displaying a hyphen ('-') if true, otherwise showing the actual value.

{{value === 'undefined' || value === 'null' ? '-' : value}}


Conditional Color Display

Checks if item.severity is 2. If true, displays color '#22c55e', otherwise, displays '#fbbf24'.

{{item.severity === 2 ? '#22c55e' : '#fbbf24'}}


Dynamic Count Display

Displays the count of detected threats in item. If no threats are detected, it shows '0 Suspicious Objects Detected'.

{{item.threats.length || 0}} Suspicious Objects Detected


Calculation and Formatting with numbro Library

Calculates the duration between item.processStartTime and item.processEndTime, converts it to seconds, and formats it with a single decimal digit using the numbro library. Adds 'sec Sanitization Time'.

{{numbro(moment.duration(moment(item.processEndTime) .diff(item.processStartTime)).asSeconds()).format({trimMantissa: true, mantissa: 1 })}} sec Sanitization Time


Status-Based Display

Displays 'Blocked' if item.status is not 'OK', otherwise displays an empty string.

{{item.status !== 'OK' ? 'Blocked' : ''}}

Displays 'Suspicious' if item.hasThreats is true, otherwise shows an empty string.

{{item.hasThreats ? 'Suspicious' : ''}}


Mapping Widget Selected Values for URL Query

Maps the widget selected values as an array for the url query.

/url?{{ widget['id']?.value.map(e => 'ArrayMap='+e).join('&') }}