From d2bdc152ac6c35f0273cb3893f8079a0630ecd4c Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Fri, 17 Jul 2015 07:19:39 +0500 Subject: [PATCH] lodash: added set() method --- lodash/lodash-tests.ts | 3 +++ lodash/lodash.d.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 9b4548502..804c8cc36 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1080,6 +1080,9 @@ result = _.pick({ 'name': 'moe', '_userid': 'moe1' }, function (value, return key.charAt(0) != '_'; }); + +result = <{ a: { b: { c: number; }}[]}>_.set({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c', 4); + result = _.transform([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], function (r: number[], num: number) { num *= num; if (num % 2) { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index f02a4aa97..efefed277 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6235,6 +6235,20 @@ declare module _ { thisArg?: any): Picked; } + //_.set + interface LoDashStatic { + /** + * Sets the property value of path on object. If a portion of path does not exist it is created. + * @param object The object to augment. + * @param path The path of the property to set. + * @param value The value to set. + * @return Returns object. + **/ + set(object: T, + path: string|string[], + value: any): T; + } + //_.transform interface LoDashStatic { /**