Socket
Socket
Sign inDemoInstall

array-to-sentence

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-to-sentence - npm Package Compare versions

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc