diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8bc80cb68..7dbd58dd8 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1794,6 +1794,54 @@ result = _({ 'one': 1, 'two': 2, 'three': 3 }).keys().value(); result = _.keysIn({ 'one': 1, 'two': 2, 'three': 3 }); result = _({ 'one': 1, 'two': 2, 'three': 3 }).keysIn().value(); +// _.mapKeys +module TestMapKeys { + let array: TResult[]; + let list: _.List; + let dictionary: _.Dictionary; + + let listIterator: (value: TResult, index: number, collection: _.List) => string; + let dictionaryIterator: (value: TResult, key: string, collection: _.Dictionary) => string; + + let result: _.Dictionary; + + result = _.mapKeys(array); + result = _.mapKeys(array, listIterator); + result = _.mapKeys(array, listIterator, any); + result = _.mapKeys(array, ''); + result = _.mapKeys(array, {}); + + result = _.mapKeys(list); + result = _.mapKeys(list, listIterator); + result = _.mapKeys(list, listIterator, any); + result = _.mapKeys(list, ''); + result = _.mapKeys(list, {}); + + result = _.mapKeys(dictionary); + result = _.mapKeys(dictionary, dictionaryIterator); + result = _.mapKeys(dictionary, dictionaryIterator, any); + result = _.mapKeys(dictionary, ''); + result = _.mapKeys(dictionary, {}); + + result = _(array).mapKeys().value(); + result = _(array).mapKeys(listIterator).value(); + result = _(array).mapKeys(listIterator, any).value(); + result = _(array).mapKeys('').value(); + result = _(array).mapKeys<{}>({}).value(); + + result = _(list).mapKeys().value(); + result = _(list).mapKeys(listIterator).value(); + result = _(list).mapKeys(listIterator, any).value(); + result = _(list).mapKeys('').value(); + result = _(list).mapKeys({}).value(); + + result = _(dictionary).mapKeys().value(); + result = _(dictionary).mapKeys(dictionaryIterator).value(); + result = _(dictionary).mapKeys(dictionaryIterator, any).value(); + result = _(dictionary).mapKeys('').value(); + result = _(dictionary).mapKeys({}).value(); +} + var mergeNames = { 'stooges': [ { 'name': 'moe' }, diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 172a25050..99bf76714 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -7403,6 +7403,97 @@ declare module _ { keysIn(): LoDashArrayWrapper } + //_.mapKeys + interface LoDashStatic { + /** + * The opposite of _.mapValues; this method creates an object with the same values as object and keys generated + * by running each own enumerable property of object through iteratee. + * + * @param object The object to iterate over. + * @param iteratee The function invoked per iteration. + * @param thisArg The this binding of iteratee. + * @return Returns the new mapped object. + */ + mapKeys( + object: List, + iteratee?: ListIterator, + thisArg?: any + ): Dictionary; + + /** + * @see _.mapKeys + */ + mapKeys( + object: Dictionary, + iteratee?: DictionaryIterator, + thisArg?: any + ): Dictionary; + + /** + * @see _.mapKeys + */ + mapKeys( + object: List|Dictionary, + iteratee?: TObject + ): Dictionary; + + /** + * @see _.mapKeys + */ + mapKeys( + object: List|Dictionary, + iteratee?: string + ): Dictionary; + } + + interface LoDashArrayWrapper { + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: ListIterator, + thisArg?: any + ): LoDashObjectWrapper>; + + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: TObject + ): LoDashObjectWrapper>; + + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: string + ): LoDashObjectWrapper>; + } + + interface LoDashObjectWrapper { + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: ListIterator|DictionaryIterator, + thisArg?: any + ): LoDashObjectWrapper>; + + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: TObject + ): LoDashObjectWrapper>; + + /** + * @see _.mapKeys + */ + mapKeys( + iteratee?: string + ): LoDashObjectWrapper>; + } + //_.mapValues interface LoDashStatic { /**