Giter VIP home page Giter VIP logo

eel-arrayhelper's Introduction

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
[email protected] = ${PunktDe.Array.ksort(value)}

Sort by sub value

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

[email protected] = ${PunktDe.Array.sortBySubValue(value, 'subValueKey')}

Filter arrays (array_filter)

[email protected] = ${PunktDe.Array.arrayFilter(value)}

Array values (array_values)

[email protected] = ${PunktDe.Array.arrayValues(value)}

Array flip (array_flip)

[email protected] = ${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
[email protected] = ${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'
]

Group Elements

@process.groupByKey = ${PunktDe.Array.groupByKey(value, 'group')}

Method can be used to convert an array of type

 [
     'element1' => [
          'name' => 'theName1',
          'group' => 'theGroup1',
     ],
     'element2' => [
          'name' => 'theName2',
          'group' => 'theGroup2',
     ],
     'element3' => [
          'name' => 'theName2',
          'group' => 'theGroup2',
     ],
]

into

[
  'theGroup1' => [
     'element1' => [
          'name' => 'theName1',
          'group' => 'theGroup1',
     ],
 ],

 'theGroup2' => [
     'element2' => [
          'name' => 'theName2',
          'group' => 'theGroup2',
     ],
     'element3' => [
          'name' => 'theName2',
          'group' => 'theGroup2',
     ],
   ]
]

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.

eel-arrayhelper's People

Contributors

andrehoffmann30 avatar daniellienert avatar fnkr avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.