forked from folio-org/ui-users
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
34 lines (27 loc) · 1.09 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import _ from 'lodash';
import React from 'react';
import { FormattedDate, FormattedTime } from 'react-intl';
export function formatDate(dateStr) {
if (!dateStr) return dateStr;
return (<FormattedDate value={dateStr} />);
}
export function formatDateTime(dateStr) {
if (!dateStr) return dateStr;
return (<span><FormattedDate value={dateStr} /> <FormattedTime value={dateStr} /></span>);
}
export function getFullName(user) {
const lastName = _.get(user, ['personal', 'lastName'], '');
const firstName = _.get(user, ['personal', 'firstName'], '');
const middleName = _.get(user, ['personal', 'middleName'], '');
return `${lastName}${firstName ? ', ' : ' '}${firstName} ${middleName}`;
}
export function getRowURL(user) {
return `/users/view/${user.id}`;
}
export function isSubstringsInString(listSubStrings, testString) {
return new RegExp(listSubStrings.join('|')).test(testString);
}
export function eachPromise(arr, fn) {
if (!Array.isArray(arr)) return Promise.reject(new Error('Array not found'));
return arr.reduce((prev, cur) => (prev.then(() => fn(cur))), Promise.resolve());
}