Pipe Reference: Object Pipes
Pipes used for deconstructing or constructing JavaScript objects.
Pipe Reference: Object Pipes
Pipes used for deconstructing or constructing JavaScript objects.
This section defines Pipes used for deconstructing or constructing JavaScript objects. These include:
values
- Usage Syntax:
{{ inputObject | values }} - Evaluates to: any[]
- Description: The values pipe returns an array of an object's own enumerable property values. It behaves like Object.values(input) in JavaScript, extracting only the values and discarding the keys.
- Useful for:
- Iteration, transformation, or formatting in loops.
- Ignores inherited properties and non-enumerable keys.
- Parameters: This pipe does not accept additional parameters.
- Returns:
- any[]: An array of values from the input object's own enumerable properties. Returns !error if the input is not a valid object.
- Example 1: Extracting values from a flat object
{{ myObject | values }}- Output: [1, 2, 3] (if myObject = { a: 1, b: 2, c: 3 })
- Example 2: Invalid input
{{ 'not-an-object' | values }}- Output: !error
- Notes:
- Only works with plain objects.
- Input must be a plain object; returns !error otherwise.
- Does not include keys or inherited properties.
keys
- Usage Syntax: {
{ inputObject | keys }} - Evaluates to: string[]
- Description: The keys pipe returns an array of the object's own enumerable property names (keys). It behaves like Object.keys(input) in JavaScript and ignores inherited or non-enumerable properties.
- Useful for:
- Building dynamic UIs, creating lists of fields, or iterating over object structure.
- Parameters: This pipe does not accept additional parameters.
- Returns:
- string[]: An array of keys (property names) from the input object. Returns !error if the input is not a valid object.
- Example 1: Extracting keys from a simple object
{{ user | keys }}- Output: ['name', 'age'] (if user = { name: 'Alice', age: 30 })
- Example 2: Invalid input (non-object)
{{ 123 | keys }}- Output: !error
- Notes:
- Input must be a plain object.
- Only enumerable own properties are returned.
keyValue
- Usage Syntax:
{{ inputObject | keyValue }} - Evaluates to: { key: string, value: any }[]
- Description: The keyValue pipe returns an array of objects, each with a key and value property representing the enumerable properties of the input object. It is similar to Object.entries(), but instead of returning tuples, it structures each pair into a consistent object shape.
- Useful for:
- Iterating key-value pairs in templates.
- Preserving the original order of the object's keys.
- Parameters: This pipe does not accept additional parameters.
- Returns:
- { key: string, value: any }[]: An array of objects containing the key and value for each property in the input. Returns !error if the input is not a valid object.
- Example 1: Basic usage with a simple object
{{ data | keyValue }}- Output: [{ key: 'color', value: 'pink' }] (if data = { color: 'pink' })
- Example 2: Object with multiple properties
{{ user | keyValue }}- Output: [{ key: 'name', value: 'Alice' }, { key: 'age', value: 30 }] (if user = { name: 'Alice', age: 30 })
- Notes:
- Input must be a plain object. Returns !error otherwise.
- Each returned object contains two keys: key and value.
- Does not include inherited or non-enumerable properties.
createObject
- Usage Syntax:
{{ inputValue | createObject: 'desiredKey' }} - Evaluates to: object
- Description: The createObject pipe creates a new object using the piped input as the value and the first argument (provided after the colon) as the key.
- If the input is a primitive (e.g., number, string), the result is a single-key object: { key: value }.
- If the input is already an object, it is nested under the given key: { key: { ...originalObject } }.
- Useful for:
- Transforming loose values into structured objects.
- Wrapping existing objects under a new property name.
- Parameters:
- key:
- Type: string
- Required: Yes
- Description: The key to use as the property name in the resulting object.
- Returns:
- object: A newly constructed object with the input as the value and the argument as the key. Returns !error if the key is not provided.
- Example 1: Wrapping a primitive
{{ 42 | createObject: 'count' }}- Output: { count: 42 }
- Example 2: Wrapping a string
{{ 'blue' | createObject: 'color' }}- Output: { color: 'blue' }
- Example 3: Nesting an object
{{ coordinates | createObject: 'position' }}- Output: { position: { x: 10, y: 20 } } (if coordinates = { x: 10, y: 20 })
- Notes:
- The key argument must be a string and is required.
- If the input is already an object, it will be nested as-is.
- Any additional arguments after the first is ignored.
- Useful for shaping data before merging, sending to APIs, or transforming pipeline results.
modifyObject
- Usage Syntax:
{{ inputObject | modifyObject: 'key': value }} - Evaluates to: object
- Description: The modifyObject pipe adds a key-value pair to an object, returning a new object with the added property.
- Returns a copy of the original object (immutable operation).
- If the key already exists, it will be overwritten with the new value.
- Useful for:
- Dynamically adding properties to objects.
- Building objects incrementally in templates.
- Extending object structures without mutation.
- Parameters:
- key:
- Type: string
- Required: Yes
- Description: The property name to add to the object.
- value:
- Type: any
- Required: Yes
- Description: The value to assign to the new property.
- Returns:
- object: A copy of the input object with the new key-value pair added.
- Example 1: Adding a property to an object
{{ testObject | modifyObject: 'testKey': 'testValue' }}- Output: { key1: 10, testKey: 'testValue' } (if testObject = { key1: 10 })
- Example 2: Adding a number property
{{ user | modifyObject: 'age': 30 }}- Output: { name: 'Alice', age: 30 } (if user = { name: 'Alice' })
- Example 3: Overwriting existing property
{{ data | modifyObject: 'status': 'active' }}- Output: { status: 'active', count: 5 } (if data = { status: 'inactive', count: 5 })
- Notes:
- Returns a new object; does not mutate the original.
- If the key already exists, its value will be replaced.
- Both parameters are required.
omit
- Usage Syntax:
{{ inputObject | omit: 'key1': 'key2': ... }} - Evaluates to: object
- Description: The omit pipe removes specified keys from an object, returning a new object without those properties.
- Accepts one or more keys to remove.
- Returns a new object (immutable operation).
- Keys that don't exist in the original object are ignored (no error).
- Useful for:
- Filtering out sensitive data before display or API calls.
- Creating subsets of objects.
- Removing unwanted properties from data structures.
- Parameters:
- ...keys:
- Type: string[]
- Required: Yes
- Description: One or more property names to remove from the object.
- Returns:
- object: A new object with the specified keys removed.
- Example 1: Remove single property
{{ user | omit: 'email' }}- Output: { name: 'Alice', age: 30 } (if user = { name: 'Alice', age: 30, email: '[email protected]' })
- Example 2: Remove multiple properties
{{ user | omit: 'email': 'age' }}- Output: { name: 'Alice' } (if user = { name: 'Alice', age: 30, email: '[email protected]' })
- Example 3: Remove non-existent key
{{ data | omit: 'missing' }}- Output: { key1: 'value1' } (if data = { key1: 'value1' })
- Notes:
- Returns a new object; does not mutate the original.
- Non-existent keys are silently ignored.
- Only removes top-level properties (does not work with nested paths).
- At least one key parameter is required.
initializeObjectArray
- Usage Syntax:
{{ count | initializeObjectArray }} - Evaluates to: object[]
- Description: The initializeObjectArray pipe creates an array of empty objects. The input number determines how many empty objects are created.
- Useful for:
- Creating placeholder structures for data.
- Pairing with insertEvery pipe to construct arrays of objects with identical key-value pairs.
- Initializing data structures before population.
- Parameters: This pipe does not accept additional parameters.
- Returns:
- object[]: An array containing the specified number of empty objects.
- Example 1: Create three empty objects
{{ 3 | initializeObjectArray }}- Output: [{}, {}, {}]
- Example 2: Create single empty object
{{ 1 | initializeObjectArray }}- Output: [{}]
- Example 3: Create five empty objects
{{ 5 | initializeObjectArray }}- Output: [{}, {}, {}, {}, {}]
- Notes:
- Input must be a number representing the count of objects to create.
- All objects in the resulting array are empty.
- Commonly used with insertEvery pipe to populate the objects with data.
- Returns an array, not a single object.
Did this answer your question?
