Product documentation and training for Shipcode.
Pipes Reference: Boolean Pipes
Pipes used for logical operations and explicit boolean coercion.

This section defines Pipes used for logical operations and explicit boolean coercion. This includes:

and

  • Usage Syntax: {{ inputValue | and: other }}
  • Evaluates to: boolean
  • Description: The and pipe performs a logical AND operation between the input and the provided argument.
    • Both the input and other are coerced to booleans using standard JavaScript truthiness.
    • Returns true only if both values are truthy.
  • Useful for:
    • Conditional logic chaining in templates or expressions.
  • Parameters:
    • other:
      • Type: boolean
      • Required: Yes
      • Description: The second value to compare using logical AND.
  • Returns:
    • boolean: true if both the input and other are truthy; otherwise false.
  • Example 1: Two truthy values
    • {{ true | and: true }}
    • Output: true
  • Example 2: Mixed types
    • {{ null | and: true }}
    • Output: false (null is falsy)
  • Notes:
    • This pipe uses JavaScript truthiness rules to evaluate values.
    • Combine with pipes like or, not, or conditional filters for logical control flows.

or

  • Usage Syntax: {{ inputValue | or: other }}
  • Evaluates to: boolean
  • Description: The or pipe performs a logical OR operation between the input and the provided argument.
    • Both the input and other are coerced to booleans using standard JavaScript truthiness rules.
    • Returns true if either value is truthy.
    • Useful for:
      • Fallback logic, conditions, or composing optional evaluations.
  • Parameters:
    • other:
      • Type: boolean
      • Required: Yes
      • Description: The second value to evaluate with logical OR.
  • Returns:
    • boolean: true if either the input or other is truthy; otherwise false.
  • Example 1: One truthy value
    • {{ false | or: true }}
    • Output: true
  • Example 2: Both values falsy
    • {{ null | or: 0 }}
    • Output: false
  • Notes:
    • Operates using JavaScript's truthiness model.
    • Works well in templates for providing default values or conditions.

xor

  • Usage Syntax: {{ inputValue | xor: other }}
  • Evaluates to: boolean
  • Description: The xor pipe performs a logical exclusive OR (XOR) between the input and the provided argument.
    • Both input and other are coerced to booleans using JavaScript truthiness rules.
    • Returns true if exactly one of the two values is truthy.
    • Returns false if both are truthy or both are falsy.
    • Useful for:
      • Mutual exclusivity checks or toggle logic.
  • Parameters:
    • other:
      • Type: boolean
      • Required: Yes
      • Description: The value to compare against using logical XOR.
  • Returns:
    • boolean: true if one (and only one) of the input or other is truthy; otherwise false.
  • Example 1: One truthy, one falsy
    • {{ true | xor: false }}
    • Output: true
  • Example 2: Both truthy
    • {{ 'text' | xor: 1 }}
    • Output: false
  • Notes:
    • Coerces both input and parameter using JavaScript truthiness.
    • Can be helpful for toggles or conditions where only one option should be active.

not

  • Usage Syntax: {{ inputValue | not }}
  • Evaluates to: boolean
  • Description: The not pipe performs a logical NOT operation on the input value.
    • The input is coerced to a boolean using JavaScript's standard truthiness semantics.
    • Returns true if the input is falsy, and false if the input is truthy.
    • Useful for:
      • Negating conditions directly in templates or expressions.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • boolean: true if the input is falsy; otherwise false.
  • Example 1: Negate a falsy value
    • {{ 0 | not }}
    • Output: true
  • Example 2: Negate a non-empty string
    • {{ 'hello' | not }}
    • Output: false
  • Notes:
    • Falsy values include: false, 0, '', null, undefined, NaN.
    • Truthy values include: everything else.

toBoolean

  • Usage Syntax: {{ inputValue | toBoolean }}
  • Evaluates to: boolean
  • Description: The toBoolean pipe explicitly coerces the input to a boolean using standard JavaScript truthiness semantics.
    • Equivalent to using !!input in JavaScript.
    • Useful for:
      • Normalizing mixed types to true or false.
  • Parameters: This pipe does not accept additional parameters.
  • Returns:
    • boolean: true if the input is truthy; false if the input is falsy.
  • Example 1: Coerce empty string
    • {{ '' | toBoolean }}
    • Output: false
  • Example 2: Coerce object
    • {{ {} | toBoolean }}
    • Output: true
  • Notes:
    • Falsy values include: false, 0, '', null, undefined, NaN.

ifElse

  • Usage Syntax: {{ inputValue | ifElse: ifTrue: ifFalse }}
  • Evaluates to: any
  • Description: The ifElse pipe evaluates whether the input is truthy and returns one of two results:
    • If the input is truthy, the ifTrue value or expression is returned.
    • If the input is falsy, the ifFalse value or expression is returned.
    • Both ifTrue and ifFalse may be literal values or nested pipe expressions (FQL).
    • Useful for:
      • Conditional logic and value selection directly within template expressions.
  • Parameters:
    • ifTrue:
      • Type: any | FQL
      • Required: Yes
      • Description: The value or FQL expression returned if the input is truthy.
    • ifFalse:
      • Type: any | FQL
      • Required: Yes
      • Description: The value or FQL expression returned if the input is falsy.
  • Returns:
    • any: Returns the ifTrue or ifFalse result depending on the truthiness of the input.
  • Example 1: Simple condition
    • {{ true | ifElse: 'Load more products': 'No more results' }}
    • Output: 'Load more products'
  • Example 2: Using pipe in the ifTrue branch
    • {{ hasNextPage | ifElse: (products | arrayLength): 'No more results' }}
    • Output: 2 (if hasNextPage is true)
  • Notes:
    • Input is evaluated using JavaScript's truthiness model.
    • You can pass pipe expressions like (array | length) into either branch.

onFalsy

  • Usage Syntax: {{ inputValue | onFalsy: fallbackValue }}
  • Evaluates to: any
  • Description: The onFalsy pipe acts as a catch mechanism for falsy values: if the input is falsy, it replaces it with the provided fallback value.
    • If the input is falsy, returns the fallbackValue.
    • If the input is truthy, passes through the input value normally.
    • Falsy values include: false, 0, '' (empty string), null, undefined, and NaN.
    • Useful for:
      • Providing guaranteed non-falsy values in expression chains.
      • Building fault-tolerant pipelines that handle missing or empty data.
  • Parameters:
    • value:
      • Type: any
      • Required: Yes
      • Description: The value to substitute if the input is falsy.
  • Returns:
    • any: The input value if truthy; otherwise, the provided fallback value.
  • Example 1: Catch empty string
    • {{ '' | onFalsy: 'Default Text' }}
    • Output: 'Default Text'
  • Example 2: Truthy value passes through
    • {{ 'Hello' | onFalsy: 'Fallback' }}
    • Output: 'Hello'
  • Example 3: Catch zero
    • {{ 0 | onFalsy: 1 }}
    • Output: 1
  • Example 4: Chain with other operations
    • {{ userName | trim | onFalsy: 'Anonymous' }}
    • Output: 'Anonymous' (if userName is empty after trimming)
  • Notes:
    • Uses JavaScript's truthiness rules to evaluate the input.
    • All falsy values (false, 0, '', null, undefined, NaN) trigger the fallback.
    • For more selective handling of only null/undefined, use onNullish instead.
    • Similar to defaultIfFalsy in Utility Pipes but positioned as a conditional catch mechanism.

onNullish

  • Usage Syntax: {{ inputValue | onNullish: fallbackValue }}
  • Evaluates to: any
  • Description: The onNullish pipe acts as a catch mechanism for nullish values: if the input is null or undefined, it replaces it with the provided fallback value.
    • If the input is null or undefined, returns the fallbackValue.
    • If the input has any other value (including falsy values like 0, false, or ''), passes through the input normally.
    • Only null and undefined are considered "nullish".
    • Useful for:
      • Providing defaults without overwriting valid falsy inputs like 0 or empty strings.
      • Handling missing or uninitialized data gracefully.
  • Parameters:
    • value:
      • Type: any
      • Required: Yes
      • Description: The value to substitute if the input is null or undefined.
  • Returns:
    • any: The input value if non-nullish; otherwise, the provided fallback value.
  • Example 1: Catch null
    • {{ null | onNullish: 'Default Value' }}
    • Output: 'Default Value'
  • Example 2: Catch undefined
    • {{ undefined | onNullish: 'Not Set' }}
    • Output: 'Not Set'
  • Example 3: Zero passes through (not nullish)
    • {{ 0 | onNullish: 100 }}
    • Output: 0
  • Example 4: Empty string passes through (not nullish)
    • {{ '' | onNullish: 'Fallback' }}
    • Output: ''
  • Example 5: Chain with object property access
  • Notes:
    • Only null and undefined trigger the fallback.
    • Other falsy values (0, false, '', NaN) are kept intact.
    • For handling all falsy values, use onFalsy instead.
    • Similar to defaultIfNull in Utility Pipes but positioned as a conditional catch mechanism.
    • Follows JavaScript's nullish coalescing semantics.
Did this answer your question?