1 | import _ = require("../index");
|
2 | // eslint-disable-next-line @definitelytyped/strict-export-declare-modifiers
|
3 | type GlobalPartial<T> = Partial<T>;
|
4 | export const uniqueSymbol: unique symbol;
|
5 | declare module "../index" {
|
6 | type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
7 | type PartialObject<T> = GlobalPartial<T>;
|
8 | type Many<T> = T | readonly T[];
|
9 | type ImpChain<T> =
|
10 | T extends { __trapAny: any } ? Collection<any> & Function<any> & Object<any> & Primitive<any> & String :
|
11 | T extends null | undefined ? never :
|
12 | T extends string ? String<T> :
|
13 | T extends (...args: any) => any ? Function<T> :
|
14 | T extends List<infer U> | null | undefined ? Collection<U> :
|
15 | T extends object | null | undefined ? Object<T> :
|
16 | Primitive<T>;
|
17 | type ExpChain<T> =
|
18 | T extends { __trapAny: any } ? CollectionChain<any> & FunctionChain<any> & ObjectChain<any> & PrimitiveChain<any> & StringChain :
|
19 | T extends null | undefined ? never :
|
20 | T extends string ? StringChain<T> :
|
21 | T extends (...args: any) => any ? FunctionChain<T> :
|
22 | T extends List<infer U> | null | undefined ? CollectionChain<U> :
|
23 | T extends object | null | undefined ? ObjectChain<T> :
|
24 | PrimitiveChain<T>;
|
25 | interface LoDashStatic {
|
26 | /**
|
27 | * Creates a lodash object which wraps value to enable implicit method chain sequences.
|
28 | * Methods that operate on and return arrays, collections, and functions can be chained together.
|
29 | * Methods that retrieve a single value or may return a primitive value will automatically end the
|
30 | * chain sequence and return the unwrapped value. Otherwise, the value must be unwrapped with value().
|
31 | *
|
32 | * Explicit chain sequences, which must be unwrapped with value(), may be enabled using _.chain.
|
33 | *
|
34 | * The execution of chained methods is lazy, that is, it's deferred until value() is
|
35 | * implicitly or explicitly called.
|
36 | *
|
37 | * Lazy evaluation allows several methods to support shortcut fusion. Shortcut fusion
|
38 | * is an optimization to merge iteratee calls; this avoids the creation of intermediate
|
39 | * arrays and can greatly reduce the number of iteratee executions. Sections of a chain
|
40 | * sequence qualify for shortcut fusion if the section is applied to an array and iteratees
|
41 | * accept only one argument. The heuristic for whether a section qualifies for shortcut
|
42 | * fusion is subject to change.
|
43 | *
|
44 | * Chaining is supported in custom builds as long as the value() method is directly or
|
45 | * indirectly included in the build.
|
46 | *
|
47 | * In addition to lodash methods, wrappers have Array and String methods.
|
48 | * The wrapper Array methods are:
|
49 | * concat, join, pop, push, shift, sort, splice, and unshift.
|
50 | * The wrapper String methods are:
|
51 | * replace and split.
|
52 | *
|
53 | * The wrapper methods that support shortcut fusion are:
|
54 | * at, compact, drop, dropRight, dropWhile, filter, find, findLast, head, initial, last,
|
55 | * map, reject, reverse, slice, tail, take, takeRight, takeRightWhile, takeWhile, and toArray
|
56 | *
|
57 | * The chainable wrapper methods are:
|
58 | * after, ary, assign, assignIn, assignInWith, assignWith, at, before, bind, bindAll, bindKey,
|
59 | * castArray, chain, chunk, commit, compact, concat, conforms, constant, countBy, create,
|
60 | * curry, debounce, defaults, defaultsDeep, defer, delay, difference, differenceBy, differenceWith,
|
61 | * drop, dropRight, dropRightWhile, dropWhile, extend, extendWith, fill, filter, flatMap,
|
62 | * flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, flip, flow, flowRight,
|
63 | * fromPairs, functions, functionsIn, groupBy, initial, intersection, intersectionBy, intersectionWith,
|
64 | * invert, invertBy, invokeMap, iteratee, keyBy, keys, keysIn, map, mapKeys, mapValues,
|
65 | * matches, matchesProperty, memoize, merge, mergeWith, method, methodOf, mixin, negate,
|
66 | * nthArg, omit, omitBy, once, orderBy, over, overArgs, overEvery, overSome, partial, partialRight,
|
67 | * partition, pick, pickBy, plant, property, propertyOf, pull, pullAll, pullAllBy, pullAllWith, pullAt,
|
68 | * push, range, rangeRight, rearg, reject, remove, rest, reverse, sampleSize, set, setWith,
|
69 | * shuffle, slice, sort, sortBy, sortedUniq, sortedUniqBy, splice, spread, tail, take,
|
70 | * takeRight, takeRightWhile, takeWhile, tap, throttle, thru, toArray, toPairs, toPairsIn,
|
71 | * toPath, toPlainObject, transform, unary, union, unionBy, unionWith, uniq, uniqBy, uniqWith,
|
72 | * unset, unshift, unzip, unzipWith, update, updateWith, values, valuesIn, without, wrap,
|
73 | * xor, xorBy, xorWith, zip, zipObject, zipObjectDeep, and zipWith.
|
74 | *
|
75 | * The wrapper methods that are not chainable by default are:
|
76 | * add, attempt, camelCase, capitalize, ceil, clamp, clone, cloneDeep, cloneDeepWith, cloneWith,
|
77 | * conformsTo, deburr, defaultTo, divide, each, eachRight, endsWith, eq, escape, escapeRegExp,
|
78 | * every, find, findIndex, findKey, findLast, findLastIndex, findLastKey, first, floor, forEach,
|
79 | * forEachRight, forIn, forInRight, forOwn, forOwnRight, get, gt, gte, has, hasIn, head,
|
80 | * identity, includes, indexOf, inRange, invoke, isArguments, isArray, isArrayBuffer,
|
81 | * isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith,
|
82 | * isError, isFinite, isFunction, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN,
|
83 | * isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp,
|
84 | * isSafeInteger, isSet, isString, isUndefined, isTypedArray, isWeakMap, isWeakSet, join,
|
85 | * kebabCase, last, lastIndexOf, lowerCase, lowerFirst, lt, lte, max, maxBy, mean, meanBy,
|
86 | * min, minBy, multiply, noConflict, noop, now, nth, pad, padEnd, padStart, parseInt, pop,
|
87 | * random, reduce, reduceRight, repeat, result, round, runInContext, sample, shift, size,
|
88 | * snakeCase, some, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, startCase,
|
89 | * startsWith, stubArray, stubFalse, stubObject, stubString, stubTrue, subtract, sum, sumBy,
|
90 | * template, times, toFinite, toInteger, toJSON, toLength, toLower, toNumber, toSafeInteger,
|
91 | * toString, toUpper, trim, trimEnd, trimStart, truncate, unescape, uniqueId, upperCase,
|
92 | * upperFirst, value, and words.
|
93 | **/
|
94 | <TrapAny extends { __trapAny: any }>(value: TrapAny): Collection<any> & Function<any> & Object<any> & Primitive<any> & String;
|
95 | <T extends string>(value: T): String<T>;
|
96 | <T extends null | undefined>(value: T): Primitive<T>;
|
97 | (value: string | null | undefined): String;
|
98 | <T extends (...args: any) => any>(value: T): Function<T>;
|
99 | <T = any>(value: List<T> | null | undefined): Collection<T>;
|
100 | <T extends object>(value: T | null | undefined): Object<T>;
|
101 | <T>(value: T): Primitive<T>;
|
102 | /**
|
103 | * The semantic version number.
|
104 | **/
|
105 | VERSION: string;
|
106 | /**
|
107 | * By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby
|
108 | * (ERB). Change the following template settings to use alternative delimiters.
|
109 | **/
|
110 | templateSettings: TemplateSettings;
|
111 | }
|
112 | /**
|
113 | * By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby
|
114 | * (ERB). Change the following template settings to use alternative delimiters.
|
115 | **/
|
116 | interface TemplateSettings {
|
117 | /**
|
118 | * The "escape" delimiter.
|
119 | **/
|
120 | escape?: RegExp | undefined;
|
121 | /**
|
122 | * The "evaluate" delimiter.
|
123 | **/
|
124 | evaluate?: RegExp | undefined;
|
125 | /**
|
126 | * An object to import into the template as local variables.
|
127 | */
|
128 | imports?: Dictionary<any> | undefined;
|
129 | /**
|
130 | * The "interpolate" delimiter.
|
131 | */
|
132 | interpolate?: RegExp | undefined;
|
133 | /**
|
134 | * Used to reference the data object in the template text.
|
135 | */
|
136 | variable?: string | undefined;
|
137 | }
|
138 | /**
|
139 | * Creates a cache object to store key/value pairs.
|
140 | */
|
141 | interface MapCache {
|
142 | /**
|
143 | * Removes `key` and its value from the cache.
|
144 | * @param key The key of the value to remove.
|
145 | * @return Returns `true` if the entry was removed successfully, else `false`.
|
146 | */
|
147 | delete(key: any): boolean;
|
148 | /**
|
149 | * Gets the cached value for `key`.
|
150 | * @param key The key of the value to get.
|
151 | * @return Returns the cached value.
|
152 | */
|
153 | get(key: any): any;
|
154 | /**
|
155 | * Checks if a cached value for `key` exists.
|
156 | * @param key The key of the entry to check.
|
157 | * @return Returns `true` if an entry for `key` exists, else `false`.
|
158 | */
|
159 | has(key: any): boolean;
|
160 | /**
|
161 | * Sets `value` to `key` of the cache.
|
162 | * @param key The key of the value to cache.
|
163 | * @param value The value to cache.
|
164 | * @return Returns the cache object.
|
165 | */
|
166 | set(key: any, value: any): this;
|
167 | /**
|
168 | * Removes all key-value entries from the map.
|
169 | */
|
170 | clear?: (() => void) | undefined;
|
171 | }
|
172 | interface MapCacheConstructor {
|
173 | new (): MapCache;
|
174 | }
|
175 | interface Collection<T> {
|
176 | pop(): T | undefined;
|
177 | push(...items: T[]): this;
|
178 | shift(): T | undefined;
|
179 | sort(compareFn?: (a: T, b: T) => number): this;
|
180 | splice(start: number, deleteCount?: number, ...items: T[]): this;
|
181 | unshift(...items: T[]): this;
|
182 | }
|
183 | interface CollectionChain<T> {
|
184 | pop(): ExpChain<T | undefined>;
|
185 | push(...items: T[]): this;
|
186 | shift(): ExpChain<T | undefined>;
|
187 | sort(compareFn?: (a: T, b: T) => number): this;
|
188 | splice(start: number, deleteCount?: number, ...items: T[]): this;
|
189 | unshift(...items: T[]): this;
|
190 | }
|
191 | interface Function<T extends (...args: any) => any> extends LoDashImplicitWrapper<T> {
|
192 | }
|
193 | interface String<T extends string = string> extends LoDashImplicitWrapper<T> {
|
194 | }
|
195 | interface Object<T> extends LoDashImplicitWrapper<T> {
|
196 | }
|
197 | interface Collection<T> extends LoDashImplicitWrapper<T[]> {
|
198 | }
|
199 | interface Primitive<T> extends LoDashImplicitWrapper<T> {
|
200 | }
|
201 | interface FunctionChain<T extends (...args: any) => any> extends LoDashExplicitWrapper<T> {
|
202 | }
|
203 | interface StringChain<T extends string = string> extends LoDashExplicitWrapper<T> {
|
204 | }
|
205 | interface StringNullableChain extends LoDashExplicitWrapper<string | undefined> {
|
206 | }
|
207 | interface ObjectChain<T> extends LoDashExplicitWrapper<T> {
|
208 | }
|
209 | interface CollectionChain<T> extends LoDashExplicitWrapper<T[]> {
|
210 | }
|
211 | interface PrimitiveChain<T> extends LoDashExplicitWrapper<T> {
|
212 | }
|
213 | type NotVoid = unknown;
|
214 | type IterateeShorthand<T> = PropertyName | [PropertyName, any] | PartialShallow<T>;
|
215 | type ArrayIterator<T, TResult> = (value: T, index: number, collection: T[]) => TResult;
|
216 | type TupleIterator<T extends readonly unknown[], TResult> = (value: T[number], index: StringToNumber<keyof T>, collection: T) => TResult;
|
217 | type ListIterator<T, TResult> = (value: T, index: number, collection: List<T>) => TResult;
|
218 | type ListIteratee<T> = ListIterator<T, NotVoid> | IterateeShorthand<T>;
|
219 | type ListIterateeCustom<T, TResult> = ListIterator<T, TResult> | IterateeShorthand<T>;
|
220 | type ListIteratorTypeGuard<T, S extends T> = (value: T, index: number, collection: List<T>) => value is S;
|
221 | // Note: key should be string, not keyof T, because the actual object may contain extra properties that were not specified in the type.
|
222 | type ObjectIterator<TObject, TResult> = (value: TObject[keyof TObject], key: string, collection: TObject) => TResult;
|
223 | type ObjectIteratee<TObject> = ObjectIterator<TObject, NotVoid> | IterateeShorthand<TObject[keyof TObject]>;
|
224 | type ObjectIterateeCustom<TObject, TResult> = ObjectIterator<TObject, TResult> | IterateeShorthand<TObject[keyof TObject]>;
|
225 | type ObjectIteratorTypeGuard<TObject, S extends TObject[keyof TObject]> = (value: TObject[keyof TObject], key: string, collection: TObject) => value is S;
|
226 | type StringIterator<TResult> = (char: string, index: number, string: string) => TResult;
|
227 | /** @deprecated Use MemoVoidArrayIterator or MemoVoidDictionaryIterator instead. */
|
228 | type MemoVoidIterator<T, TResult> = (prev: TResult, curr: T, indexOrKey: any, list: T[]) => void;
|
229 | /** @deprecated Use MemoListIterator or MemoObjectIterator instead. */
|
230 | type MemoIterator<T, TResult> = (prev: TResult, curr: T, indexOrKey: any, list: T[]) => TResult;
|
231 | type MemoListIterator<T, TResult, TList> = (prev: TResult, curr: T, index: number, list: TList) => TResult;
|
232 | type MemoObjectIterator<T, TResult, TList> = (prev: TResult, curr: T, key: string, list: TList) => TResult;
|
233 | type MemoIteratorCapped<T, TResult> = (prev: TResult, curr: T) => TResult;
|
234 | type MemoIteratorCappedRight<T, TResult> = (curr: T, prev: TResult) => TResult;
|
235 | type MemoVoidArrayIterator<T, TResult> = (acc: TResult, curr: T, index: number, arr: T[]) => void;
|
236 | type MemoVoidDictionaryIterator<T, K extends string | number | symbol, TResult> = (acc: TResult, curr: T, key: K, dict: Record<K, T>) => void;
|
237 | type MemoVoidIteratorCapped<T, TResult> = (acc: TResult, curr: T) => void;
|
238 | type ValueIteratee<T> = ((value: T) => NotVoid) | IterateeShorthand<T>;
|
239 | type ValueIterateeCustom<T, TResult> = ((value: T) => TResult) | IterateeShorthand<T>;
|
240 | type ValueIteratorTypeGuard<T, S extends T> = (value: T) => value is S;
|
241 | type ValueKeyIteratee<T> = ((value: T, key: string) => NotVoid) | IterateeShorthand<T>;
|
242 | type ValueKeyIterateeTypeGuard<T, S extends T> = (value: T, key: string) => value is S;
|
243 | type Comparator<T> = (a: T, b: T) => boolean;
|
244 | type Comparator2<T1, T2> = (a: T1, b: T2) => boolean;
|
245 | type PropertyName = string | number | symbol;
|
246 | type PropertyPath = Many<PropertyName>;
|
247 | /** Common interface between Arrays and jQuery objects */
|
248 | type List<T> = ArrayLike<T>;
|
249 | interface Dictionary<T> {
|
250 | [index: string]: T;
|
251 | }
|
252 | interface NumericDictionary<T> {
|
253 | [index: number]: T;
|
254 | }
|
255 | // Crazy typedef needed get _.omit to work properly with Dictionary and NumericDictionary
|
256 | type AnyKindOfDictionary =
|
257 | | Dictionary<unknown>
|
258 | | NumericDictionary<unknown>;
|
259 | type PartialShallow<T> = {
|
260 | [P in keyof T]?: T[P] extends object ? object : T[P]
|
261 | };
|
262 | type StringToNumber<T> = T extends `${infer N extends number}` ? N : never;
|
263 | // For backwards compatibility
|
264 | type LoDashImplicitArrayWrapper<T> = LoDashImplicitWrapper<T[]>;
|
265 | type LoDashImplicitNillableArrayWrapper<T> = LoDashImplicitWrapper<T[] | null | undefined>;
|
266 | type LoDashImplicitObjectWrapper<T> = LoDashImplicitWrapper<T>;
|
267 | type LoDashImplicitNillableObjectWrapper<T> = LoDashImplicitWrapper<T | null | undefined>;
|
268 | type LoDashImplicitNumberArrayWrapper = LoDashImplicitWrapper<number[]>;
|
269 | type LoDashImplicitStringWrapper = LoDashImplicitWrapper<string>;
|
270 | type LoDashExplicitArrayWrapper<T> = LoDashExplicitWrapper<T[]>;
|
271 | type LoDashExplicitNillableArrayWrapper<T> = LoDashExplicitWrapper<T[] | null | undefined>;
|
272 | type LoDashExplicitObjectWrapper<T> = LoDashExplicitWrapper<T>;
|
273 | type LoDashExplicitNillableObjectWrapper<T> = LoDashExplicitWrapper<T | null | undefined>;
|
274 | type LoDashExplicitNumberArrayWrapper = LoDashExplicitWrapper<number[]>;
|
275 | type LoDashExplicitStringWrapper = LoDashExplicitWrapper<string>;
|
276 | type DictionaryIterator<T, TResult> = ObjectIterator<Dictionary<T>, TResult>;
|
277 | type DictionaryIteratee<T> = ObjectIteratee<Dictionary<T>>;
|
278 | type DictionaryIteratorTypeGuard<T, S extends T> = ObjectIteratorTypeGuard<Dictionary<T>, S>;
|
279 | // NOTE: keys of objects at run time are always strings, even when a NumericDictionary is being iterated.
|
280 | type NumericDictionaryIterator<T, TResult> = (value: T, key: string, collection: NumericDictionary<T>) => TResult;
|
281 | type NumericDictionaryIteratee<T> = NumericDictionaryIterator<T, NotVoid> | IterateeShorthand<T>;
|
282 | type NumericDictionaryIterateeCustom<T, TResult> = NumericDictionaryIterator<T, TResult> | IterateeShorthand<T>;
|
283 | }
|