array-to-sentence
Advanced tools
Comparing version 2.0.0-2 to 2.0.0
27
index.js
@@ -7,2 +7,4 @@ 'use strict'; | ||
*/ | ||
var OPTION_NAMES = ['separator', 'lastSeparator']; | ||
function arrayToSentence(arr, options) { | ||
@@ -13,11 +15,14 @@ if (!Array.isArray(arr)) { | ||
options = options || {}; | ||
options = Object.assign({ | ||
separator: ', ', | ||
lastSeparator: ' and ', | ||
}, options); | ||
function validateOption(optionName) { | ||
if (typeof options[optionName] !== 'string') { | ||
for (var i = 0; i < 2; i++) { | ||
if (typeof options[OPTION_NAMES[i]] !== 'string') { | ||
throw new TypeError( | ||
'Expected `' + | ||
optionName + | ||
OPTION_NAMES[i] + | ||
'` option to be a string, but got a non-string value ' + | ||
options[optionName] + | ||
options[OPTION_NAMES[i]] + | ||
'.' | ||
@@ -28,14 +33,2 @@ ); | ||
if (options.separator === undefined) { | ||
options.separator = ', '; | ||
} else { | ||
validateOption('separator'); | ||
} | ||
if (options.lastSeparator === undefined) { | ||
options.lastSeparator = ' and '; | ||
} else { | ||
validateOption('lastSeparator'); | ||
} | ||
if (arr.length === 0) { | ||
@@ -42,0 +35,0 @@ return ''; |
{ | ||
"name": "array-to-sentence", | ||
"version": "2.0.0-2", | ||
"version": "2.0.0", | ||
"description": "Join all elements of an array and create a human-readable string", | ||
@@ -5,0 +5,0 @@ "repository": "shinnn/array-to-sentence", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
5403
66