Product documentation and training for Shipcode.
Pipes Reference: Numeric Pipes
Pipes designed for mathematical operations and numeric comparisons.

This section defines Pipes designed for mathematical operations and numeric comparisons. These include:

isEqualTo

  • Usage Syntax: {{ inputValue | isEqualTo: value: 'path': 'optional': 'keys' }}
  • Evaluates to: boolean
  • Description: The isEqualTo pipe compares the input to a specified value. It returns true if the values are equal, and false otherwise. This pipe supports optional path traversal to compare nested values within objects.
    • Useful for:
      • Comparing strings, numbers, or booleans.
      • Accessing nested properties for comparison.
  • Parameters:
    • value:
      • Type: any
      • Required: Yes
      • Description: Value to compare input against.
    • ...path:
      • Type: string[]
      • Required: No
      • Description: One or more keys to access a nested value within the input object.
  • Returns:
    • boolean: Returns true if the input equals the specified value (after traversing the path, if provided); otherwise returns false.
  • Example 1: Direct numeric comparison
    • {{ aNumber | isEqualTo: 15 }}
    • Output: true (if aNumber = 15)
  • Example 2: Comparing nested value
    • {{ priceObject | isEqualTo: 15: 'path': 'amount' }}
    • Output: false (if priceObject = { amount: 30 })
  • Notes:
    • Path values should correspond to keys in the input object.
    • If the path does not resolve to a valid value, the pipe returns false.

isNotEqualTo

    • Usage Syntax: {{ inputValue | isNotEqualTo: value: 'path': 'optional': 'keys' }}
    • Evaluates to: boolean
    • Description: The isNotEqualTo pipe checks whether the input value is not equal to a specified value. It returns true if the input and the target value are different, and false if they are the same. This pipe supports optional path traversal to compare values inside nested objects.
      • Useful for:
        • Validating that a property does not match a given value.
        • Accessing nested properties for comparison.
    • Parameters:
      • value:
        • Type: any
        • Required: Yes
        • Description: The value to compare the input against.
      • ...path:
        • Type: string[]
        • Required: No
        • Description: One or more keys to access a nested value within the input object.
    • Returns:
      • boolean: Returns true if the input value does not equal the specified value (after applying the optional path, if provided); otherwise returns false.
    • Example 1: Simple inequality comparison
      • {{ userAge | isNotEqualTo: 21 }}
      • Output: true (if userAge = 17)
    • Example 2: Comparing nested value
      • {{ user | isNotEqualTo: 21: 'path': 'profile': 'age' }}
      • Output: true (if user = { profile: { age: 25 } })
    • Notes:
      • Path values should match existing keys in the input object.
      • If the path does not resolve to a valid value, the pipe will return true (as the values do not match).
      • This pipe behaves as the logical inverse of isEqualTo.

isGreaterThan

  • Usage Syntax: {{ inputValue | isGreaterThan: value: 'path': 'optional': 'keys' }}
  • Evaluates to: boolean
  • Description: The isGreaterThan pipe evaluates whether the input value is greater than a specified number. It returns true if the input is greater, and false otherwise. This pipe supports optional path traversal for comparing nested numeric values inside objects.
    • Useful for:
      • Filtering values above a threshold.
      • Validating minimum amounts or limits.
      • Comparing nested numeric properties.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The numeric value to compare the input against.
    • ...path:
      • Type: string[]
      • Required: No
      • Description: One or more keys to access a nested numeric value within the input object.
  • Returns:
    • boolean: Returns true if the input is numerically greater than the specified value (after resolving the path, if provided); otherwise returns false.
  • Example 1: Simple numeric comparison
    • {{ score | isGreaterThan: 75 }}
    • Output: true (if score > 75)
  • Example 2: Comparing nested numeric value
    • {{ product | isGreaterThan: 5: 'path': 'details': 'weight' }}
    • Output: true (if product = { details: { weight: 10.5 } })
  • Notes:
    • Path keys should reference valid numeric values within the input object.
    • If the path does not resolve or the value is not a number, the pipe will return !error.

isLessThan

  • Usage Syntax: {{ inputValue | isLessThan: value: 'path': 'optional': 'keys' }}
  • Evaluates to: boolean
  • Description: The isLessThan pipe evaluates whether the input value is less than a specified number. It returns true if the input is numerically less than the given value, and false otherwise. This pipe supports optional path traversal when working with nested numeric values inside objects.
    • Useful for:
      • Filtering values below a threshold.
      • Validating maximum limits or caps.
      • Comparing nested numeric fields.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The numeric value to compare the input against.
    • ...path:
      • Type: string[]
      • Required: No
      • Description: One or more keys to access a nested numeric value within the input object.
  • Returns:
    • boolean: Returns true if the input is numerically less than the specified value (after resolving the path, if provided); otherwise returns false.
  • Example 1: Basic numeric comparison
    • {{ temperature | isLessThan: 32 }}
    • Output: true (if temperature = 20)
  • Example 2: Comparing nested numeric property
    • {{ item | isLessThan: 5: 'path': 'stats': 'weight' }}
    • Output: true (if item = { stats: { weight: 2.5 } })
  • Notes:
    • Path keys must follow the 'path': prefix to activate nested access.
    • If the path does not resolve or the value is not a number, the pipe will return !error.

isGreaterThanOrEqualTo

  • Usage Syntax: {{ inputValue | isGreaterThanOrEqualTo: value: 'path': 'optional': 'keys' }}
  • Evaluates to: boolean
  • Description: The isGreaterThanOrEqualTo pipe evaluates whether the input value is greater than or equal to a specified number. It returns true if the input is greater than or equal to the value, and false otherwise. This pipe supports optional path traversal for comparing deeply nested numeric values.
    • Useful for:
      • Threshold-based validations (e.g., "must be at least").
      • Sorting or filtering based on minimum values.
      • Comparing nested properties in structured data.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The numeric value to compare the input against.
    • ...path:
      • Type: string[]
      • Required: No
      • Description: One or more keys to access a nested numeric value within the input object.
  • Returns:
    • boolean: Returns true if the input is numerically greater than or equal to the specified value (after resolving the path, if provided); otherwise returns false.
  • Example 1: Direct numeric comparison
    • {{ totalScore | isGreaterThanOrEqualTo: 100 }}
    • Output: true (if totalScore = 100)
  • Example 2: Comparing nested numeric field
    • {{ order | isGreaterThanOrEqualTo: 100: 'path': 'totals': 'amount' }}
    • Output: true (if order = { totals: { amount: 120 } })
  • Notes:
    • Path keys must follow the 'path': keyword to enable nested access.
    • If the path is invalid or the resolved value is not a number, the pipe will return !error.

isLessThanOrEqualTo

  • Usage Syntax: {{ inputValue | isLessThanOrEqualTo: value: 'path': 'optional': 'keys' }}
  • Evaluates to: boolean
  • Description: The isLessThanOrEqualTo pipe evaluates whether the input value is less than or equal to a specified number. It returns true if the input is less than or equal to the value, and false otherwise. It supports optional path traversal to access and compare nested numeric values.
    • Useful for:
      • Validating that input does not exceed a maximum.
      • Filtering items below or at a specific threshold.
      • Comparing nested numeric fields in structured objects.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The numeric value to compare the input against.
    • ...path:
      • Type: string[]
      • Required: No
      • Description: One or more keys to access a nested numeric value within the input object.
  • Returns:
    • boolean: Returns true if the input is numerically less than or equal to the specified value (after resolving the path, if provided); otherwise returns false.
  • Example 1: Basic numeric comparison
    • {{ quantity | isLessThanOrEqualTo: 50 }}
    • Output: true (if quantity <= 50)
  • Example 2: Comparing nested numeric property
    • {{ item | isLessThanOrEqualTo: 50: 'path': 'specs': 'size' }}
    • Output: true (if item = { specs: { size: 42 } })
  • Notes:
    • Use the 'path': keyword before any nested keys for path-based comparisons.
    • If the resolved value is not numeric or the path is invalid, the pipe returns !error.

add

  • Usage Syntax: {{ inputValue | add: value }}
  • Evaluates to: number
  • Description: The add pipe adds a numeric value to the input. It returns the result of the addition if both the input and the parameter are valid numbers. If either value is not a number, the pipe returns !error.
    • Useful for:
      • Performing simple inline math in templates.
      • Adjusting values dynamically based on a known offset.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The number to add to the input.
  • Returns:
    • number: The result of input + value, or !error if either is not a valid number.
  • Example 1: Adding a constant value
    • {{ subtotal | add: 5.5 }}
    • Output: 105.5 (if subtotal = 100)
  • Example 2: Invalid input
    • {{ 'abc' | add: 5 }}
    • Output: !error
  • Notes:
    • Both the input and the value parameter must be valid numbers.
    • This pipe is not path-aware; it only works on the direct numeric input.
    • Use with other math or comparison pipes for more complex expressions.

subtract

  • Usage Syntax: {{ inputValue | subtract: value }}
  • Evaluates to: number
  • Description: The subtract pipe subtracts a numeric value from the input. It returns the result of the subtraction if both the input and the parameter are valid numbers. If either value is not a number, the pipe returns !error.
    • Useful for:
      • Inline mathematical operations in templates.
      • Calculating remaining balances, differences, or reductions.
      • Dynamic value adjustments during rendering.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The number to subtract from the input.
  • Returns:
    • number: The result of input - value, or !error if either the input or the parameter is not a valid number.
  • Example 1: Basic subtraction
    • {{ total | subtract: 10 }}
    • Output: 90 (if total = 100)
  • Example 2: Invalid input
    • {{ 'abc' | subtract: 5 }}
    • Output: !error
  • Notes:
    • Both the input and the value parameter must be valid numbers.
    • This pipe operates on the direct input only (no path-based access).
    • Can be chained with other math or comparison pipes for calculated expressions.

multiply

  • Usage Syntax: {{ inputValue | multiply: value }}
  • Evaluates to: number
  • Description: The multiply pipe multiplies the input by a given numeric value. It returns the result of the multiplication if both the input and the parameter are valid numbers. If either value is not numeric, the pipe returns !error.
    • Useful for:
      • Calculating totals or scaled values.
      • Applying percentage-based transformations.
      • Combining with other pipes for chained math operations.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The number to multiply the input by.
  • Returns:
    • number: The result of input * value, or !error if either the input or value is not a valid number.
  • Example 1: Basic multiplication
    • {{ price | multiply: 1.2 }}
    • Output: 120 (if price = 100)
  • Example 2: Invalid multiplication
    • {{ 'abc' | multiply: 5 }}
    • Output: !error
  • Notes:
    • Both the input and the value parameter must be valid numbers.
    • This pipe does not support path-based input—only direct numeric values.
    • Useful for calculating tax, totals, discounts, and scaling values.

divideBy

  • Usage Syntax: {{ inputValue | divideBy: value }}
  • Evaluates to: number
  • Description: The divideBy pipe divides the input by a given numeric value. It returns the result of the division if both the input and the parameter are valid numbers and the divisor is not zero. If the input is not numeric or the divisor is zero, the pipe returns !error.
    • Useful for:
      • Calculating ratios or averages.
      • Normalizing values.
      • Breaking down totals into equal parts.
  • Parameters:
    • value:
      • Type: number
      • Required: Yes
      • Description: The number to divide the input by. Must not be 0.
  • Returns:
    • number: The result of input / value, or !error if the input is not numeric or the value is zero.
  • Example 1: Basic division
    • {{ total | divideBy: 2 }}
    • Output: 50 (if total = 100)
  • Example 2: Division by zero
    • {{ subtotal | divideBy: 0 }}
    • Output: !error
  • Notes:
    • Both the input and the value parameter must be valid numbers.
    • Division by zero will always return !error.
    • This pipe does not support path-based access—input must be a direct number.

modulo

  • Usage Syntax: {{ inputValue | modulo: modulus }}
  • Evaluates to: number
  • Description: The modulo pipe returns the remainder when the input is divided by the given modulus. It performs a modular division (input % modulus) and returns the result. If either the input or the modulus is not numeric, the pipe returns !error. If the modulus is zero, the pipe returns NaN.
    • Useful for:
      • Checking even/odd values.
      • Looping logic (e.g., grouping every N elements).
      • Mod-based constraints or partitioning.
  • Parameters:
    • modulus:
      • Type: number
      • Required: Yes
      • Description: The number to divide the input by (must not be 0).
  • Returns:
    • number: The result of input % modulus, or !error if the input is not numeric. Returns NaN if the modulus is zero.
  • Example 1: Basic modulo operation
    • {{ index | modulo: 3 }}
    • Output: 1 (if index = 10)
  • Example 2: Zero modulus
    • {{ index | modulo: 0 }}
    • Output: NaN
  • Example 3: Invalid input
    • {{ 'abc' | modulo: 3 }}
    • Output: !error
  • Notes:
    • Both the input and modulus must be valid numbers.
    • The pipe returns NaN if the modulus is zero.
    • Useful for conditional styling, grouping, or pattern matching based on index.

floor

  • Usage Syntax: {{ inputValue | floor }}
  • Evaluates to: number
  • Description: The floor pipe rounds a decimal input value downward to the nearest whole number (integer). For example, both 5.9 and 5.3 will evaluate to 5.
    • Useful for:
      • Truncating decimal precision.
      • Pagination, quantity rounding, or whole-unit logic.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • number: The nearest lower integer value of the numeric input. Returns !error if the input is not a valid number.
  • Example 1: Rounding down a float
    • {{ total | floor }}
    • Output: 8 (if total = 8.9)
  • Example 2: Rounding down a negative float
    • {{ value | floor }}
    • Output: -4 (if value = -3.1)
  • Notes:
    • This pipe only works with numeric input values.
    • Always rounds toward negative infinity (i.e., floor(-1.5) = -2).

ceiling

  • Usage Syntax: {{ inputValue | ceiling }}
  • Evaluates to: number
  • Description: The ceiling pipe rounds a decimal input value upward to the nearest whole number (integer). For example, both 5.3 and 5.9 will evaluate to 6.
    • Useful for:
      • Ensuring values meet minimum integer requirements.
      • Pricing, count-based logic, and pagination.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • number: The smallest integer greater than or equal to the numeric input. Returns !error if the input is not a valid number.
  • Example 1: Rounding up from a decimal
    • {{ price | ceiling }}
    • Output: 6 (if price = 5.1)
  • Example 2: Rounding up a negative number
    • {{ temperature | ceiling }}
    • Output: -3 (if temperature = -3.9)
  • Notes:
    • Only valid with numeric inputs.
    • Always rounds toward positive infinity (e.g., ceiling(-1.5) = -1).

absoluteValue

  • Usage Syntax: {{ inputValue | absoluteValue }}
  • Evaluates to: number
  • Description: The absoluteValue pipe returns the absolute value of a given numeric input. It removes any negative sign and returns the non-negative magnitude of the number.
    • Useful for:
      • Distance, magnitude, or difference calculations.
      • Ensuring a value is always positive.
      • Financial, statistical, and geometry-related logic.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • number: The non-negative absolute value of the numeric input. Returns !error if the input is not a valid number.
  • Example 1: Converting a negative number
    • {{ difference | absoluteValue }}
    • Output: 15 (if difference = -15)
  • Example 2: Using a positive number
    • {{ points | absoluteValue }}
    • Output: 42 (if points = 42)
  • Notes:
    • Input must be a valid number.
    • Returns the same number if input is already positive or zero.

negate

  • Usage Syntax: {{ inputValue | negate }}
  • Evaluates to: number
  • Description: The negate pipe flips the sign of a numeric input. If the input is positive, it becomes negative. If the input is negative, it becomes positive.
    • Useful for:
      • Reversing numeric values.
      • Scorekeeping, accounting, or differential logic.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • number: The input multiplied by -1. Returns !error if the input is not a valid number.
  • Example 1: Negating a positive number
    • {{ score | negate }}
    • Output: -50 (if score = 50)
  • Example 2: Negating a negative number
    • {{ loss | negate }}
    • Output: 30 (if loss = -30)
  • Notes:
    • This pipe only works with numeric input.
    • 0 as an input will return 0.
    • This is a simple sign-flip; it does not check for magnitude.

toNumber

  • Usage Syntax: {{ inputValue | toNumber }}
  • Evaluates to: number
  • Description: The toNumber pipe attempts to convert the input into a number. It parses strings into a numeric format.
    • Useful for:
      • Converting form input, string-based values, or dynamic content into numbers.
      • Preparing data before applying math or comparison pipes.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • number: The numeric form of the input if successfully parsed. Returns !error if the conversion fails.
  • Example 1: Parsing a numeric string
    • {{ '123' | toNumber }}
    • Output: 123
  • Example 2: Attempting to parse a non-numeric string
    • {{ 'abc' | toNumber }}
    • Output: !error
  • Notes:
    • Returns a float or integer based on the input string.
    • Fails if the input cannot be coerced into a valid number.
    • Useful before applying other math or comparison pipes.

currency

  • Usage Syntax: {{ inputValue | currency: 'USD' }} {{ currencyObject | currency }}
  • Evaluates to: string
  • Description: The currency pipe formats a numeric input or a currency object into a properly formatted currency string, such as $40.00.
    • If the input is a number, a currencyCode must be provided as a parameter.
    • If the input is an object, the object must include both amount and currencyCode properties.
    • Returns !error if the currency code is missing or the input cannot be interpreted correctly.
    • Useful for:
      • Displaying localized currency values in templates.
      • Formatting price, cost, or billing fields.
  • Parameters:
    • currencyCode:
      • Type: string
      • Required: Yes (for numeric input)
      • Description: A 3-letter ISO 4217 currency code (e.g., "USD").
  • Returns:
    • string: A currency-formatted string (e.g., $115.00). Returns !error if the input or currency code is invalid.
  • Example 1: Number with explicit currency code
    • {{ 40 | currency: 'USD' }}
    • Output: $40.00
  • Example 2: Currency object with embedded code
    • {{ obj | currency }}
    • Output: $115.00 (if obj = { amount: '115.0', currencyCode: 'USD' })
  • Example 3: Object missing currencyCode
    • {{ object | currency }}
    • Output: !error (if object = { amount: '115.0' })
  • Notes:
    • For numeric inputs, the currencyCode parameter is required.
    • For object inputs, the object must contain both amount and currencyCode keys.
    • Fails if formatting rules can't be applied or if required fields are missing.
    • Currency symbols and formatting may vary based on locale and implementation.

toFixed

  • Usage Syntax: {{ inputValue | toFixed: digits }}
  • Evaluates to: string
  • Description: The toFixed pipe formats a numeric input to a string, keeping a fixed number of digits after the decimal point, as specified by the digits parameter.
    • Useful for:
      • Currency-like formatting, precision control, or UI display.
      • Ensuring consistent decimal places in output.
  • Parameters:
    • digits:
      • Type: number
      • Required: Yes
      • Description: The number of decimal places to retain in the output string.
  • Returns:
    • string: A string representation of the number with exactly digits decimal places. Returns !error if the input is not a valid number or if digits is invalid.
  • Example 1: Formatting a float to 2 decimal places
    • {{ price | toFixed: 2 }}
    • Output: '3.14' (if price = 3.14159)
  • Example 2: Rounding and padding
    • {{ taxRate | toFixed: 4 }}
    • Output: '0.0500' (if taxRate = 0.05)
  • Example 3: Invalid digits parameter
    • {{ taxRate | toFixed: -4 }}
    • Output: !error
  • Notes:
    • Output is a string, not a number.
    • digits must be a non-negative integer between 0 and 100.
    • Pads with trailing zeros if needed.
    • Useful when chaining with other formatting pipes like currency.
Did this answer your question?