Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1856 | Rev 1907 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
const jsonToParams = (data = {}) => {
2
  if (!data) {
3
    return false
4
  }
5
  const formBody = []
6
 
7
  for (const property in data) {
8
    const encodedKey = encodeURIComponent(property)
9
 
10
    // @ts-ignore
11
    const encodedValue = encodeURIComponent(data[property])
12
    formBody.push(encodedKey + '=' + encodedValue)
13
  }
14
 
15
  const _formBody = formBody.join('&')
16
 
17
  return _formBody
18
}
19
 
20
const filterItems = (query = '', items = []) => {
21
  if (!query) {
22
    return items
23
  }
24
 
25
  return items.filter((conversation) =>
26
    conversation.name.toLowerCase().includes(query.toLowerCase())
27
  )
28
}
29
 
30
const debounce = (func, timeout = 300) => {
31
  let timer
32
  return (...args) => {
33
    clearTimeout(timer)
34
    timer = setTimeout(() => {
35
      func.apply(this, args)
36
    }, timeout)
37
  }
38
}
39
 
40
const camalize = function camalize(str) {
41
  return str
42
    .toLowerCase()
43
    .replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase())
44
}
45
 
46
const scrollToBottom = (element) => {
47
  if (!element.current) {
48
    return false
49
  }
50
 
51
  element.scrollTop = element.scrollHeight * 9
52
}
53
 
1856 stevensc 54
const formatObjectToArray = (object) => {
55
  return Object.entries(object).map(([key, value]) => ({
56
    name: value,
57
    value: key
58
  }))
59
}
60
 
1904 stevensc 61
const isPromise = (obj) => {
62
  return (
63
    !!obj &&
64
    (typeof obj === 'object' || typeof obj === 'function') &&
65
    typeof obj.then === 'function'
66
  )
67
}
68
 
1856 stevensc 69
export {
70
  jsonToParams,
71
  debounce,
72
  scrollToBottom,
73
  filterItems,
74
  camalize,
1904 stevensc 75
  formatObjectToArray,
76
  isPromise
1856 stevensc 77
}