UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

1 lines 2.8 kB
{"version":3,"file":"merge.cjs","names":["purry"],"sources":["../src/merge.ts"],"sourcesContent":["import type { Merge } from \"type-fest\";\nimport { purry } from \"./purry\";\n\n/**\n * Merges two objects into one by combining their properties, effectively\n * creating a new object that incorporates elements from both. The merge\n * operation prioritizes the second object's properties, allowing them to\n * overwrite those from the first object with the same names.\n *\n * Equivalent to `{ ...data, ...source }`.\n *\n * @param data - The destination object, serving as the basis for the merge.\n * Properties from this object are included in the new object, but will be\n * overwritten by properties from the source object with matching keys.\n * @param source - The source object, whose properties will be included in the\n * new object. If properties in this object share keys with properties in the\n * destination object, the values from the source object will be used in the\n * new object.\n * @returns An object fully containing `source`, and any properties from `data`\n * that don't share a name with any property in `source`.\n * @signature\n * R.merge(data, source)\n * @example\n * R.merge({ x: 1, y: 2 }, { y: 10, z: 2 }) // => { x: 1, y: 10, z: 2 }\n * @dataFirst\n * @category Object\n */\nexport function merge<T, Source>(data: T, source: Source): Merge<T, Source>;\n\n/**\n * Merges two objects into one by combining their properties, effectively\n * creating a new object that incorporates elements from both. The merge\n * operation prioritizes the second object's properties, allowing them to\n * overwrite those from the first object with the same names.\n *\n * Equivalent to `{ ...data, ...source }`.\n *\n * @param source - The source object, whose properties will be included in the\n * new object. If properties in this object share keys with properties in the\n * destination object, the values from the source object will be used in the\n * new object.\n * @returns An object fully containing `source`, and any properties from `data`\n * that don't share a name with any property in `source`.\n * @signature\n * R.merge(source)(data)\n * @example\n * R.pipe(\n * { x: 1, y: 2 },\n * R.merge({ y: 10, z: 2 }),\n * ); // => { x: 1, y: 10, z: 2 }\n * @dataLast\n * @category Object\n */\nexport function merge<Source>(source: Source): <T>(data: T) => Merge<T, Source>;\n\nexport function merge(...args: ReadonlyArray<unknown>): unknown {\n return purry(mergeImplementation, args);\n}\n\nconst mergeImplementation = <T, Source>(\n data: T,\n source: Source,\n): Merge<T, Source> => ({ ...data, ...source });\n"],"mappings":"wCAuDA,SAAgB,EAAM,GAAG,EAAuC,CAC9D,OAAOA,EAAAA,EAAM,EAAqB,EAAK,CAGzC,MAAM,GACJ,EACA,KACsB,CAAE,GAAG,EAAM,GAAG,EAAQ"}