Ramda Adjunct 5.1.0

flattenProp.js

  1. import { of, curry } from 'ramda';
  2. import flattenPath from './flattenPath.js';
  3. /**
  4. * Flattens a property so that its fields are spread out into the provided object.
  5. * It's like {@link RA.spreadProp|spreadProp}, but preserves object under the property path.
  6. *
  7. * @func flattenProp
  8. * @memberOf RA
  9. * @since {@link https://char0n.github.io/ramda-adjunct/1.19.0|v1.19.0}
  10. * @category Object
  11. * @typedef Idx = String | Int
  12. * @sig [Idx] -> {k: v} -> {k: v}
  13. * @param {!string|number} prop The property to flatten
  14. * @param {!Object} obj The provided object
  15. * @return {!Object} The flattened object
  16. * @see {@link RA.flattenPath|flattenPath}, {@link RA.spreadProp|spreadProp}
  17. * @example
  18. *
  19. * RA.flattenProp(
  20. * 'b',
  21. * { a: 1, b: { c: 3, d: 4 } }
  22. * ); // => { a: 1, c: 3, d: 4, b: { c: 3, d: 4 } };
  23. */
  24. const flattenProp = curry((prop, obj) => flattenPath(of(Array, prop), obj));
  25. export default flattenProp;