Skip to content

Commit 92657e2

Browse files
committed
update to module and use new xo formatting.
1 parent 6af13a2 commit 92657e2

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

index.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,54 @@
1-
const fetch = require('isomorphic-unfetch')
1+
import fetch from 'isomorphic-unfetch'
22

33
function checkInputs(namespace, text, level, options) {
4-
if (options.url === undefined) options.url = 'https://pushnotice.chat/api/v1/chatnotice'
5-
if (options.debug === undefined) options.debug = false
6-
if (options.env === undefined) options.env = undefined
4+
if (options.url === undefined) {
5+
options.url = 'https://pushnotice.chat/api/v1/chatnotice'
6+
}
7+
8+
if (options.debug === undefined) {
9+
options.debug = false
10+
}
11+
12+
if (options.env === undefined) {
13+
options.env = undefined
14+
}
15+
716
if (options.disabled === true) {
817
return { error: { title: 'Disabled', message: 'disabled not sending the notification' } }
918
}
19+
1020
if (options.chat === undefined) {
1121
return { error: { title: 'MissingChatObject', message: 'chat object has to be provided' } }
1222
}
23+
1324
if (options.chat?.id === undefined) {
1425
return { error: { title: 'MissingChatId', message: 'chat id has to be provided' } }
1526
}
27+
1628
if (options.chat?.secret === undefined) {
1729
return { error: { title: 'MissingChatSecret', message: 'chat secret has to be provided' } }
1830
}
31+
1932
if (namespace === undefined) {
2033
return { error: { title: 'MissingNamespace', message: 'namespace has to be provided' } }
2134
}
35+
2236
if (typeof namespace !== 'string' && !(namespace instanceof String)) {
2337
return { error: { title: 'NamespaceMustBeString', message: 'namespace must be a String' } }
2438
}
39+
2540
if (text === undefined && text === '') {
2641
return { error: { title: 'MissingText', message: 'text has to be provided' } }
2742
}
43+
2844
if (typeof text !== 'string' && !(text instanceof String)) {
2945
return { error: { title: 'TextMustBeString', message: 'text must be a String' } }
3046
}
47+
3148
if (level === undefined) {
3249
return { error: { title: 'MissingLevel', message: 'level has to be provided' } }
3350
}
51+
3452
if (typeof level !== 'string' && !(level instanceof String)) {
3553
return { error: { title: 'LevelMustBeString', message: 'level must be a String' } }
3654
}
@@ -65,7 +83,7 @@ async function sendRequest(namespace, text, level = 'INFO', options = {}) {
6583
if (!body.ok && body.name !== 'notificationQueued') {
6684
return { error: { title: 'ApiRequestFailed', message: 'Error sending Notification to PushNotice API' } }
6785
}
68-
} catch (err) {
86+
} catch {
6987
return { error: { title: 'ApiRequestFailed', message: 'Error sending Notification to PushNotice API' } }
7088
}
7189

@@ -76,4 +94,4 @@ function pnotice(namespace, options = {}) {
7694
return (text, level = 'INFO') => sendRequest(namespace, text, level, options)
7795
}
7896

79-
module.exports = pnotice
97+
export default pnotice

0 commit comments

Comments
 (0)