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-0 to 2.0.0-1

index.mjs

70

index.js

@@ -0,1 +1,3 @@

'use strict';
/*!

@@ -5,42 +7,44 @@ * array-to-sentence | MIT (c) Shinnosuke Watanabe

*/
module.exports = function arrayToSentence(arr, options) {
'use strict';
function arrayToSentence(arr, options) {
if (!Array.isArray(arr)) {
throw new TypeError('Expected an array, but got a non-array value ' + arr + '.');
}
if (!Array.isArray(arr)) {
throw new TypeError(String(arr) + ' is not an array. Expected an array.');
}
options = options || {};
options = options || {};
function validateOption(optionName) {
if (typeof options[optionName] !== 'string') {
throw new TypeError(
'Expected `' +
optionName +
'` option to be a string, but got a non-string value ' +
options[optionName] +
'.'
);
}
}
function validateOption(optionName) {
if (typeof options[optionName] !== 'string') {
throw new TypeError(
String(options[optionName]) +
' is not a string. ' +
'`' + optionName + '` option must be a string.'
);
}
}
if (options.separator === undefined) {
options.separator = ', ';
} else {
validateOption('separator');
}
if (options.separator === undefined) {
options.separator = ', ';
} else {
validateOption('separator');
}
if (options.lastSeparator === undefined) {
options.lastSeparator = ' and ';
} else {
validateOption('lastSeparator');
}
if (options.lastSeparator === undefined) {
options.lastSeparator = ' and ';
} else {
validateOption('lastSeparator');
}
if (arr.length === 0) {
return '';
}
if (arr.length === 0) {
return '';
}
if (arr.length === 1) {
return arr[0];
}
if (arr.length === 1) {
return arr[0];
}
return arr.slice(0, -1).join(options.separator) + options.lastSeparator + arr[arr.length - 1];
}
return arr.slice(0, -1).join(options.separator) + options.lastSeparator + arr[arr.length - 1];
};
module.exports = arrayToSentence;
{
"name": "array-to-sentence",
"version": "2.0.0-0",
"description": "Join all elements of an array and create a human-readable string",
"repository": "shinnn/array-to-sentence",
"scripts": {
"pretest": "eslint --fix --format=codeframe --ignore-path .gitignore .",
"test": "node --throw-deprecation --track-heap-objects test.js",
"coverage": "istanbul cover test.js"
},
"license": "MIT",
"jsnext:main": "index.jsnext.js",
"files": [
"index.js",
"index.jsnext.js"
],
"keywords": [
"to-sentence",
"sentence",
"array",
"join",
"human",
"readable",
"string",
"separator",
"comma",
"and",
"browser",
"client-side"
],
"devDependencies": {
"@shinnn/eslint-config": "^3.3.6",
"eslint": "^3.13.1",
"istanbul": "^0.4.5",
"require-from-string": "^1.2.1",
"rollup": "^0.41.4",
"tape": "^4.6.3"
},
"eslintConfig": {
"extends": "@shinnn"
}
"name": "array-to-sentence",
"version": "2.0.0-1",
"description": "Join all elements of an array and create a human-readable string",
"repository": "shinnn/array-to-sentence",
"scripts": {
"prebuild": "eslint --fix --format=codeframe module.mjs test.js",
"build": "rollup --config=node:module",
"pretest": "npm run-script build",
"test": "nyc --reporter=html --reporter=text node test.js"
},
"license": "MIT",
"module": "index.mjs",
"files": [
"index.js",
"index.mjs"
],
"keywords": [
"to-sentence",
"sentence",
"array",
"join",
"human",
"readable",
"string",
"separator",
"comma",
"and",
"browser",
"client-side"
],
"devDependencies": {
"@shinnn/eslint-config": "^5.4.0",
"eslint": "^4.18.1",
"nyc": "^11.5.0",
"rollup": "^0.56.3",
"rollup-config-module": "^2.0.0",
"tape": "^4.9.0"
},
"eslintConfig": {
"extends": "@shinnn"
}
}

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