Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3692 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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