From 6969dc0304f5e55d8408db7b8bc108d84da4f4c0 Mon Sep 17 00:00:00 2001 From: rzymek Date: Wed, 1 Mar 2017 22:57:24 +0100 Subject: [PATCH] lodash - Add _.nth --- lodash/index.d.ts | 51 ++++++++++++++++++++++++++++++++++++++++++ lodash/lodash-tests.ts | 31 +++++++++++++++++++++++++ lodash/nth/index.d.ts | 2 ++ lodash/tsconfig.json | 3 ++- 4 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 lodash/nth/index.d.ts diff --git a/lodash/index.d.ts b/lodash/index.d.ts index da5710a7de..0acf1d8726 100644 --- a/lodash/index.d.ts +++ b/lodash/index.d.ts @@ -2679,6 +2679,57 @@ declare namespace _ { ): LoDashExplicitWrapper; } + //_.nth + interface LoDashStatic { + /** + * Gets the element at index `n` of `array`. If `n` is negative, the nth element from the end is returned. + * + * @param array array The array to query. + * @param value The index of the element to return. + * @return Returns the nth element of `array`. + */ + nth( + array: List, + n?: number + ): T; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.nth + */ + nth( + n?: number + ): T; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.nth + */ + nth( + n?:number + ): TResult; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.nth + */ + nth( + n?:number + ): LoDashExplicitWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.nth + */ + nth( + n?:number + ): LoDashExplicitWrapper; + } + //_.pull interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 8accba65c0..2f5cf2ac57 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1289,6 +1289,37 @@ namespace TestLastIndexOf { } } +// _.nth +namespace TestNth { + let array: TResult[]; + let list: _.List; + let value: number; + + { + let result: TResult; + + result = _.nth(array); + + result = _.nth(array, 42); + + result = _(array).nth(); + result = _(array).nth(42); + + result = _(list).nth(); + result = _(list).nth(42); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(array).chain().nth(); + result = _(array).chain().nth(42); + + result = _(list).chain().nth(); + result = _(list).chain().nth(42); + } +} + // _.pull namespace TestPull { let array: TResult[]; diff --git a/lodash/nth/index.d.ts b/lodash/nth/index.d.ts new file mode 100644 index 0000000000..afbe952398 --- /dev/null +++ b/lodash/nth/index.d.ts @@ -0,0 +1,2 @@ +import { nth } from "../index"; +export = nth; \ No newline at end of file diff --git a/lodash/tsconfig.json b/lodash/tsconfig.json index 3a760cfd1a..419b6142b1 100644 --- a/lodash/tsconfig.json +++ b/lodash/tsconfig.json @@ -171,6 +171,7 @@ "noConflict/index.d.ts", "noop/index.d.ts", "now/index.d.ts", + "nth/index.d.ts", "nthArg/index.d.ts", "omit/index.d.ts", "omitBy/index.d.ts", @@ -306,4 +307,4 @@ "noEmit": true, "forceConsistentCasingInFileNames": true } -} \ No newline at end of file +}