lodash APIs
- cloneDeep
- get
- isEqual
- isEmpty
- debounce
- merge
- uniq
- omit
- isString
- isArray
- pick
- sortBy
- groupBy
- flatten
- set
- find
- orderBy
- mapValues
- isObject
- last
- isNil
- isNumber
- range
- chunk
- throttle
- filter
- uniqBy
- difference
- pickBy
- noop
- capitalize
- uniqueId
- has
- isUndefined
- map
- camelCase
- isFunction
- kebabCase
- intersection
- random
- includes
- isPlainObject
- compact
- Dictionary
- findIndex
- keyBy
- forEach
- trim
- clamp
- identity
- remove
- keys
- isNull
- times
- startCase
- first
- values
- mapKeys
- sumBy
- max
- reduce
- some
- zip
- every
- memoize
- clone
- countBy
- concat
- snakeCase
- assign
- isBoolean
- uniqWith
- omitBy
- without
- minBy
- head
- maxBy
- min
- upperFirst
- escapeRegExp
- reverse
- sample
- shuffle
- defaults
- inRange
- flattenDeep
- take
- union
- sum
- mergeWith
- castArray
- replace
- flatMap
- reject
- zipObject
- template
- isNaN
- mean
- size
- findLast
- unset
- partition
- round
- fromPairs
- floor
- toPairs
- indexOf
- toString
- sampleSize
- differenceBy
- update
- chain
- startsWith
- xor
- pull
- DebouncedFunc
- defaultsDeep
- split
- findKey
- unescape
- partial
- toNumber
- invert
- each
- differenceWith
- endsWith
- slice
- isDate
- unionBy
- findLastIndex
- join
- isInteger
- delay
- isObjectLike
- padStart
- result
- isError
- extend
- cloneDeepWith
- upperCase
- trimStart
- constant
- matches
- lowerCase
- forIn
- lowerFirst
- once
- transform
- isMatch
- escape
- isEqualWith
- zipWith
- isRegExp
- entries
- sortedIndexBy
- dropWhile
- takeWhile
- isElement
- forEachRight
- ReplaceFunction
- TemplateExecutor
- keysIn
- IsEqualCustomizer
- isTypedArray
- cond
- stubTrue
- toUpper
- isMap
- isSet
- meanBy
- rangeRight
- repeat
- trimEnd
- now
- nth
- pullAt
- toPath
- eq
- lt
- lte
- gt
- gte
- pullAllBy
- pullAll
- toLower
- fill
- ceil
- flatMapDeep
- CloneDeepWithCustomizer
- negate
- takeRightWhile
- invoke
- tap
- intersectionWith
- truncate
- Collection
- bind
- curry
- partialRight
- sortedUniq
- sortedIndexOf
- Object
- drop
- _
lodash#bind TypeScript Examples
The following examples show how to use
lodash#bind.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: curry.spec.ts From s-libs with MIT License | 4 votes |
/* eslint-disable max-params */
describe('curry()', () => {
//
// stolen from https://github.com/lodash/lodash
//
it('should curry based on the number of arguments given', () => {
function fn(_a: number, _b: number, _c: number, _d: number): any {
return Array.prototype.slice.call(arguments);
}
const curried = curry(fn);
expect(curried(1)(2)(3)(4)).toEqual([1, 2, 3, 4]);
expect(curried(1, 2)(3, 4)).toEqual([1, 2, 3, 4]);
expect(curried(1, 2, 3, 4)).toEqual([1, 2, 3, 4]);
});
it('should allow specifying `arity`', () => {
function fn(_a: number, _b: number, _c: number, _d: number): any {
return Array.prototype.slice.call(arguments);
}
const curried = curry(fn, 3);
expect(curried(1)(2, 3)).toEqual([1, 2, 3]);
expect(curried(1, 2)(3)).toEqual([1, 2, 3]);
expect(curried(1, 2, 3)).toEqual([1, 2, 3]);
});
it('should provide additional arguments after reaching arity', () => {
function fn(_a: number, _b: number, _c: number, _d: number): any {
return Array.prototype.slice.call(arguments);
}
const curried: any = curry(fn, 3);
expect(curried(1)(2, 3, 4)).toEqual([1, 2, 3, 4]);
expect(curried(1, 2)(3, 4, 5)).toEqual([1, 2, 3, 4, 5]);
expect(curried(1, 2, 3, 4, 5, 6)).toEqual([1, 2, 3, 4, 5, 6]);
});
it('should create a function with a `length` of `0`', () => {
function fn(_a: number, _b: number, _c: number, _d: number): any {
return Array.prototype.slice.call(arguments);
}
const curried = curry(fn);
expect(curried.length).toEqual(0);
expect(curried(1).length).toEqual(0);
expect(curried(1, 2).length).toEqual(0);
});
it('should use `this` binding of function', () => {
const object = { a: 1, b: 2, c: 3 };
const expected = [1, 2, 3];
type Fn = (a: string, b: string, c: string) => number[];
function fn(
this: ObjectWith<number> | undefined,
a: string,
b: string,
c: string,
): number[] {
const value = this ?? {};
return [value[a], value[b], value[c]];
}
expect(curry(bind(fn, object) as Fn, 3)('a')('b')('c')).toEqual(expected);
expect(curry(bind(fn, object) as Fn, 3)('a', 'b')('c')).toEqual(expected);
expect(curry(bind(fn, object) as Fn, 3)('a', 'b', 'c')).toEqual(expected);
expect(bind(curry(fn), object)('a')('b')('c')).toEqual(Array(3));
expect(bind(curry(fn), object)('a', 'b')('c')).toEqual(Array(3));
expect(bind(curry(fn), object)('a', 'b', 'c')).toEqual(expected);
});
it('should work for names that shadow `Object.prototype`', () => {
const curried = curry((a: number, b: number, c: number): number[] => [
a,
b,
c,
]);
expect(curried(1)(2)(3)).toEqual([1, 2, 3]);
});
});