mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 08:05:29 +00:00

Update ESLint to 2.1.0. ESLint has a number of potentially-useful new features but this change attempts to be minimal in its changes. However, some things could not be avoided reasonably. ESLint 2.1.0 found a few lint issues that ESLing 1.x missed with template strings that did not take advantage of any features of template strings, and `let` declarations where `const` sufficed. Additionally, ESLint 2.1.0 removes some granularity around enabling ES6 features. Some features (e.g., spread operator) that had been turned off in our configuration for ESLint 1.x are now permitted. PR-URL: https://github.com/nodejs/node/pull/5214 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Myles Borins <myles.borins@gmail.com>
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
exports.repeat = function (str, num) {
|
|
var result = '';
|
|
for (var i = 0; i < num; i++) { result += str; }
|
|
return result;
|
|
};
|
|
|
|
exports.arrayEqual = function (a, b) {
|
|
if (a.length !== b.length) { return false; }
|
|
for (var i = 0; i < a.length; i++) {
|
|
if (a[i] !== b[i]) { return false; }
|
|
}
|
|
return true;
|
|
};
|
|
|
|
exports.trimChars = function (str, chars) {
|
|
var start = 0;
|
|
var end = str.length - 1;
|
|
while (chars.indexOf(str.charAt(start)) >= 0) { start++; }
|
|
while (chars.indexOf(str.charAt(end)) >= 0) { end--; }
|
|
return str.slice(start, end + 1);
|
|
};
|
|
|
|
exports.capitalize = function (str) {
|
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
};
|
|
|
|
exports.arrayUnion = function () {
|
|
var result = [];
|
|
for (var i = 0, values = {}; i < arguments.length; i++) {
|
|
var arr = arguments[i];
|
|
for (var j = 0; j < arr.length; j++) {
|
|
if (!values[arr[j]]) {
|
|
values[arr[j]] = true;
|
|
result.push(arr[j]);
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
|
|
function has(obj, key) {
|
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
}
|
|
|
|
exports.has = has;
|
|
|
|
exports.extend = function (dest, src) {
|
|
for (var i in src) {
|
|
if (has(src, i)) { dest[i] = src[i]; }
|
|
}
|
|
};
|
|
|
|
exports.trimEnd = function (str) {
|
|
return str.replace(/\s+$/g, '');
|
|
};
|