-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
39 lines (31 loc) · 1.02 KB
/
helpers.js
File metadata and controls
39 lines (31 loc) · 1.02 KB
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
35
36
37
38
39
const iU = require('lodash/isUndefined');
const iE = require('lodash/isEmpty');
const format = require('date-fns/format');
exports.isNotValid = x => iU(x) || iE(x);
exports.isValid = x => !(iU(x) || iE(x));
exports.iE = iE;
exports.iU = iU;
exports.isValidToSave = x => !(iU(x) || iE(x) || x === 'N/A');
exports.getFields = req => {
if (iU(req.query.fields) || iE(req.query.fields)) return '';
return req.query.fields
.split(',')
.map(f => f.trim())
.join(' ');
};
exports.getUsername = url => {
if (iU(url) || iE(url)) return '';
if (['/', '@'].includes(url.slice(-1))) return '';
const split = url.split('/');
return split[split.length - 1];
};
exports.dump = x => JSON.stringify(x, null, 2);
exports.fmtDate = date => format(date, 'MM/DD/YY @ hh:mma');
exports.BASE_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:8000'
: 'http://api.berkeleypse.org';
exports.BASE_RETURN_URL =
process.env.NODE_ENV === 'development'
? 'http://localhost:3000'
: 'http://www.berkeleypse.org';