Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface LodashTool

Hierarchy

  • LodashTool

Index

Methods

_debounce

  • _debounce(func: Function, delay?: undefined | number, options?: undefined | object): Function
  • description

    防抖

    example

    utils._debounce(calculateLayout, 150)

    Parameters

    • func: Function
    • Optional delay: undefined | number
    • Optional options: undefined | object

    Returns Function

_findIndex

  • _findIndex(array: Array<any>, predicate: any, fromIndex?: undefined | number): number
  • description

    该方法类似find,区别是该方法返回第一个通过 predicate 判断为真值的元素的索引值(index),而不是元素本身。

    example
    • array = [
    • { 'user': 'barney', 'active': false },
    • { 'user': 'fred', 'active': false },
    • { 'user': 'pebbles', 'active': true }
    • ]
    • utils._findIndex(array, function(o) { return o.user == 'barney'; }) => 0
    • utils._findIndex(array, { 'user': 'fred', 'active': false }) => 1 (推荐使用)
    • utils._findIndex(array, ['active', false]) => 0 (推荐使用)
    • utils._findIndex(array, 'active') => 2 (推荐使用)

    Parameters

    • array: Array<any>
    • predicate: any
    • Optional fromIndex: undefined | number

    Returns number

    -1为没找到对应的值,其余为数组对应的index

_findLastIndex

  • _findLastIndex(array: Array<any>, predicate: Array<any> | Function | object | string, fromIndex?: undefined | number): number
  • description

    该方法类似find,区别是该方法返回第一个通过 predicate 判断为真值的元素的索引值(index),而不是元素本身。

    example
    • array = [
    • { 'user': 'barney', 'active': false },
    • { 'user': 'fred', 'active': false },
    • { 'user': 'pebbles', 'active': true }
    • ]
    • utils._findLastIndex(array, function(o) { return o.user == 'pebbles'; }) => 2
    • utils._findLastIndex(array, { 'user': 'barney', 'active': true }) => 0 (推荐使用)
    • utils._findLastIndex(array, ['active', false]) => 2 (推荐使用)
    • utils._findLastIndex(array, 'active') => 0 (推荐使用)

    Parameters

    • array: Array<any>
    • predicate: Array<any> | Function | object | string
    • Optional fromIndex: undefined | number

    Returns number

    -1为没找到对应的值,其余为数组对应的index

_get

  • _get(object: object, path: string, defaultVal?: any): any
  • description

    get方法,用于解决a.b.c.d出现undefined导致代码保存不继续向下执行

    Parameters

    • object: object
    • path: string
    • Optional defaultVal: any

    Returns any

    获取到的值

    var object = { 'a': [{ 'b': { 'c': 3 } }] };
    utils._get(object, 'a[0].b.c'); // => 3 (推荐使用)
    utils._get(object, ['a', '0', 'b', 'c']); // => 3
    utils._get(object, 'a.b.c', 'default'); // => 'default' (推荐使用)

_isEmpty

  • _isEmpty(val: any): boolean
  • description

    检测是否是空对象

    example

    utils._isEmpty(null) true utils._isEmpty([1, 2, 3]) true utils._isEmpty({ 'a': 1 }) false

    Parameters

    • val: any

    Returns boolean

_isEqual

  • _isEqual(value: any, other: any): boolean
  • description

    对比两值是否相等

    example

    const a = {a:1} const b = {a:1} utils._isEqual(a, b) // true a === b // false

    Parameters

    • value: any
    • other: any

    Returns boolean

_isNaN

  • _isNaN(value: any): boolean
  • description

    判断是否为NaN

    example
    • var a = +'str'
    • utils._isNaN(a) => true

    Parameters

    • value: any

    Returns boolean

    返回布尔值

_isUndefined

  • _isUndefined(value: any): boolean
  • description

    判断是否为undefined

    example
    • var a
    • utils._isUndefined(a) => true

    Parameters

    • value: any

    Returns boolean

    返回布尔值

_omit

  • _omit(object: object, props: string | string[]): object
  • description

    反向版 pick

    example
    • var object = { 'a': 1, 'b': '2', 'c': 3 }
    • utils._pick(object, ['a', 'c']) => { 'b': '2' }

    Parameters

    • object: object
    • props: string | string[]

    Returns object

_padEnd

  • _padEnd(str?: undefined | string, length?: undefined | number, chars?: undefined | string): string
  • description:

    字符串后填充字符

    Parameters

    • Optional str: undefined | string
    • Optional length: undefined | number
    • Optional chars: undefined | string

    Returns string

    utils._padEnd('GFG', 5) // 'GFG ' utils._padEnd('1234', 6, 'a') // '1234aa' utils._padEnd('1234', 3, '#') // '1234'

_padStart

  • _padStart(str?: undefined | string, length?: undefined | number, chars?: undefined | string): string
  • description:

    字符串前填充字符

    example

    utils._padStart('GFG', 5) // ' GFG' utils._padStart('1234', 6, 'a') // 'aa1234' utils._padStart('1234', 3, '#') // '1234'

    Parameters

    • Optional str: undefined | string
    • Optional length: undefined | number
    • Optional chars: undefined | string

    Returns string

_pick

  • _pick(object: object, props: string | string[]): object
  • description

    创建一个从 object 中选中的 key 的对象。

    example
    • var object = { 'a': 1, 'b': '2', 'c': 3 }
    • utils._pick(object, ['a', 'c']) => { 'a': 1, 'c': 3 }

    Parameters

    • object: object
    • props: string | string[]

    Returns object

_throttle

  • _throttle(func: Function, delay?: undefined | number, options?: undefined | object): Function
  • description

    节流

    example

    utils._throttle(() => {}, 100)

    Parameters

    • func: Function
    • Optional delay: undefined | number
    • Optional options: undefined | object

    Returns Function

_trim

  • _trim(str: string, chars?: undefined | string): string
  • description

    去除字符串首尾空格方法

    example
    • var a = ' 123 '
    • utils._Trim(a) = '123'

    Parameters

    • str: string
    • Optional chars: undefined | string

    Returns string

    返回去除后的字符串

_uniq

  • _uniq(array: Array<any>): Array<any>
  • description

    数组去重(纯数组)

    example
    • var a =[1, 2, 1, 5, 1, 9]
    • utils._uniq(a) => [1, 2, 5, 9]

    Parameters

    • array: Array<any>

    Returns Array<any>

Generated using TypeDoc