remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 1.77 kB
Source Map (JSON)
{"version":3,"file":"set.cjs","names":["purry"],"sources":["../src/set.ts"],"sourcesContent":["import type { UpsertProp } from \"./internal/types/UpsertProp\";\nimport { purry } from \"./purry\";\n\n/**\n * Sets the `value` at `prop` of `object`.\n *\n * To add a new property to an object, or to override its type, use `addProp`\n * instead, and to set a property within a nested object use `setPath`.\n *\n * @param obj - The target method.\n * @param prop - The property name.\n * @param value - The value to set.\n * @signature\n * R.set(obj, prop, value)\n * @example\n * R.set({ a: 1 }, 'a', 2) // => { a: 2 }\n * @dataFirst\n * @category Object\n */\nexport function set<T, K extends keyof T, V extends Required<T>[K]>(\n obj: T,\n prop: K,\n value: V,\n): UpsertProp<T, K, V>;\n\n/**\n * Sets the `value` at `prop` of `object`.\n *\n * To add a new property to an object, or to override it's type use `addProp`\n * instead.\n *\n * @param prop - The property name.\n * @param value - The value to set.\n * @signature\n * R.set(prop, value)(obj)\n * @example\n * R.pipe({ a: 1 }, R.set('a', 2)) // => { a: 2 }\n * @dataLast\n * @category Object\n */\nexport function set<T, K extends keyof T, V extends Required<T>[K]>(\n prop: K,\n value: V,\n): (obj: T) => UpsertProp<T, K, V>;\n\nexport function set(...args: ReadonlyArray<unknown>): unknown {\n return purry(setImplementation, args);\n}\n\nconst setImplementation = <T, K extends keyof T, V extends Required<T>[K]>(\n obj: T,\n prop: K,\n value: V,\n): UpsertProp<T, K, V> =>\n // @ts-expect-error [ts2322] - Hard to type\n ({ ...obj, [prop]: value });\n"],"mappings":"wCA6CA,SAAgB,EAAI,GAAG,EAAuC,CAC5D,OAAOA,EAAAA,EAAM,EAAmB,EAAK,CAGvC,MAAM,GACJ,EACA,EACA,KAGC,CAAE,GAAG,GAAM,GAAO,EAAO"}