punktde/eel-arrayhelper

Last activity on 1 January 2021
  • 3
  • 3256
composer require punktde/eel-arrayhelper

The package provides an eel-helper with additional methods to work with arrays.

1.8.0

The package provides an eel-helper with additional methods to work with arrays.

Version
1.8.0
Type
neos-package
Release Date
19.01.2021 17:12:12
Source
git
Distribution
zip
Requires
Requires (dev)
None
Suggest
None
Provides
None
Conflicts
None
Replaces
None
MIT 201d9b3be9f083fd45b101b1fb7b389dac3e6028

Neos Eel helper for array handling

Latest Stable Version Total Downloads License

Installation

composer require punktde/eel-arrayhelper

Usage

This packages provides the methods:

Sort by Key (ksort)

attributes = Neos.Fusion:RawArray
attributes.@process.ksort = ${PunktDe.Array.ksort(value)}

Sort by sub value

  arrayToSort = [
   ['subValueKey' => "bb"]
   ['subValueKey' => "aa"]
  ]
 
  sorted = [
   ['subValueKey' => "aa"]
   ['subValueKey' => "bb"]
  ]

attributes.@process.sortBySubValue = ${PunktDe.Array.sortBySubValue(value, 'subValueKey')}

Filter arrays (array_filter)

attributes.@process.arrayFilter = ${PunktDe.Array.arrayFilter(value)}

Array values (array_values)

attributes.@process.arrayValues = ${PunktDe.Array.arrayValues(value)}

Array flip (array_flip)

attributes.@process.arrayFlip = ${PunktDe.Array.arrayFlip(value)}

Add a key/value pair to an array:

Can be used to add a value with a dynamic key

attributes = Neos.Fusion:RawArray
attributes.@process.addKV = ${PunktDe.Array.setKeyValue(value, 'key', 'value')}

Extract Sub Elements

This method extracts sub elements to the parent level.

@process.extractSubElements = ${PunktDe.Array.extractSubElements(value)}

An input array of type:

[
element1 => [
    0 => 'value1'
],
element2 => [
    0 => 'value2'
    1 => 'value3'
],

will be converted to:

[
    0 => 'value1'
    1 => 'value2'
    2 => 'value3'
]

Count elements (length)

The method counts elements of a given array or a countable object.

count = ${PunktDe.Array.length(this.rawCollection)}

hasKey(array, key)

bool = ${PunktDe.Array.hasKey(array, key)}

hasValue(array, key)

bool = ${PunktDe.Array.hasValue(array, key)}

getValueByPath(array, path)

Returns the value of a nested array by following the specified path.

result = ${PunktDe.Array.getValueByPath(array, path)}

setValueByPath(subject, path, value)

Sets the given value in a nested array or object by following the specified path.

array = ${PunktDe.Array.setValueByPath(subject, path, value)}

unsetValue(key, array)

Unset the value for the given key

array = ${PunktDe.Array.unsetValue(key, array)}

Sponsors & Contributors

The development of this package is sponsored by punkt.de GmbH.

The content of the readme is provided by Github
The same vendor provides 30 package(s).