-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
33 lines (28 loc) · 909 Bytes
/
utils.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
const _ = require('lodash')
function compareStrings (searchingStr, property) {
return function (str) {
const listName = _.get(str, property)
return _(searchingStr).toLower().replace(/ /g, '-') === _(listName).toLower().replace(/ /g, '-')
}
}
function stripPropertyFromResponse (property = 'body') {
return function _stripPropertyFromResponse (response) {
return _.get(response, property)
}
}
function findSpecificList (lists, listName, status) {
const compareFn = compareStrings(listName, 'name')
return _.find(lists, function (list) {
let isStatusOk = status ? status === list.state : true
return compareFn(list) && isStatusOk
})
}
function findSpecificListItem (listItems, listItemName) {
return _.find(listItems, compareStrings(listItemName, 'value'))
}
module.exports = {
compareStrings,
findSpecificList,
findSpecificListItem,
stripPropertyFromResponse
}