-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (21 loc) · 782 Bytes
/
index.js
File metadata and controls
28 lines (21 loc) · 782 Bytes
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
'use-strict';
var defaultOptions = {
word: 'and'
}
module.exports = function (inputArray, options) {
if (!Array.isArray(inputArray)) {
console.warn(`Wrong argument in function arraySemanticJoin. Expect Array instead of ${typeof inputArray}`);
return '';
}
if (options && typeof options.word !== 'string') {
console.warn(`Wrong options argument used. Expected Object with property 'word' as string instead of ${typeof options.word}`);
return '';
}
options = options || defaultOptions
if (inputArray.length === 0) {
return '';
} else if (inputArray.length === 1) {
return inputArray[0];
}
return inputArray.slice(0, -1).join(', ') + ' ' + options.word + '\u00A0' + inputArray.slice(-1);
}