Skip to content

Commit

Permalink
[Robustness] remove has; call-bind all prototype methods
Browse files Browse the repository at this point in the history
This module has always required ES5; so there's no need for `function-bind` via `has`.

See #9 (comment)
  • Loading branch information
ljharb committed May 3, 2020
1 parent 984acd1 commit 303d9cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 12 additions & 8 deletions index.js
@@ -1,9 +1,15 @@
'use strict';

var has = require('has');
var has = Function.call.bind(Object.prototype.hasOwnProperty);
var join = Function.call.bind(Array.prototype.join);
var trim = Function.call.bind(String.prototype.trim);
var isArray = Array.isArray;
var filter = Function.call.bind(Array.prototype.filter);
var slice = Function.call.bind(Array.prototype.slice);
var concat = Function.call.bind(Array.prototype.concat);

module.exports = function listify(list) {
if (!Array.isArray(list)) {
if (!isArray(list)) {
throw new TypeError('requires an array');
}

Expand All @@ -17,16 +23,14 @@ module.exports = function listify(list) {
finalWord += ' ';
}

var trimmed = list.filter(function (item) {
return String(item).trim();
});
var trimmed = filter(list, trim);
var str;
if (trimmed.length === 2 && finalWord.length > 0) {
str = trimmed.join(' ' + finalWord);
str = join(trimmed, ' ' + finalWord);
} else if (trimmed.length < 3) {
str = trimmed.join(separator);
str = join(trimmed, separator);
} else {
str = trimmed.slice(0, -1).concat(finalWord + trimmed[trimmed.length - 1]).join(separator);
str = join(concat(slice(trimmed, 0, -1), finalWord + trimmed[trimmed.length - 1]), separator);
}
return str;
};
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -36,7 +36,6 @@
"url": "https://github.com/ljharb/listify/issues"
},
"dependencies": {
"has": "^1.0.3"
},
"devDependencies": {
"@ljharb/eslint-config": "^16.0.0",
Expand Down

0 comments on commit 303d9cd

Please sign in to comment.