All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.lib.utils.mergeByName.js.flow Maven / Gradle / Ivy

There is a newer version: 2.11.8
Show newest version
// @flow
import type { Modifier } from '../types';

export default function mergeByName(
  modifiers: Array<$Shape>>
): Array<$Shape>> {
  const merged = modifiers.reduce((merged, current) => {
    const existing = merged[current.name];
    merged[current.name] = existing
      ? {
          ...existing,
          ...current,
          options: { ...existing.options, ...current.options },
          data: { ...existing.data, ...current.data },
        }
      : current;
    return merged;
  }, {});

  // IE11 does not support Object.values
  return Object.keys(merged).map(key => merged[key]);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy