[英]“stringValues” is defined but never used no-unused-vars
I'm new to JS and I am trying to call a function inside another function. 我是JS的新手,正在尝试在另一个函数内调用一个函数。 When I try it I am getting the lint error.
尝试时,出现棉绒错误。 - stringValues inserts comma in between numbers to display correct formats, for 1000 it displays as 1,000 and for 10000 it displays as 10,000
-stringValues在数字之间插入逗号以显示正确的格式,对于1000,它显示为1,000;对于10000,它显示为10,000。
return Number(unitsOfNumbers.join('')).stringValues();
ERROR: 错误:
"stringValues" is defined but never used no-unused-vars
CODE: 码:
import {differentCountriesCurrency} from 'sports-input-utils/lib/formatting';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.appleBrowser = appleBrowser;
exports.appleBrowserWithDecimals = appleBrowserWithDecimals;
function stringValues(x, sep, grp) {
var sx = (''+x).split('.'), s = '', i, j;
sep || (sep = ','); // default seperator
grp || grp === 0 || (grp = 3); // default grouping
i = sx[0].length;
while (i > grp) {
j = i - grp;
s = sep + sx[0].slice(j, i) + s;
i = j;
}
s = sx[0].slice(0, i) + s;
sx[0] = s;
return sx.join('.');
}
function appleBrowser(value, parm) {
var unitsOfNumbers;
if (!value) {
return value;
}
// extract unitsOfNumbers. if no unitsOfNumbers, fill in a zero.
unitsOfNumbers = value.match(/\d/g) || ['0'];
return Number(unitsOfNumbers.join('')).stringValues();
}
function appleBrowserWithDecimals(value, parm) {
var unitsOfNumbers;
if (!value) {
return value;
}
// extract unitsOfNumbers. if no unitsOfNumbers, fill in a zero.
unitsOfNumbers = value.match(/\d/g) || ['0'];
// zero-pad a one-digit input
if (unitsOfNumbers.length === 1) {
unitsOfNumbers.unshift('0');
}
// add a decimal point
unitsOfNumbers.splice(unitsOfNumbers.length - 2, 0, '.');
return Number(unitsOfNumbers.join('')).stringValues();
}
//# sourceMappingURL=formatting.js.map
exports.limitMaximumLength = limitMaximumLength;
function limitMaximumLength(value, parm) {
if (value.length < parm) {
return value;
} else {
return value.substring(0, parm);
}
}
exports.differentCountriesCurrencyWithMaxLen = differentCountriesCurrencyWithMaxLen;
function differentCountriesCurrencyWithMaxLen (value) {
var isSafari;
return differentCountriesCurrency(limitMaximumLength(value, 7));
isSafari = navigator.userAgent.indexOf("Safari") > -1;
if (isSafari) {
return appleBrowser(limitMaximumLength(value, 7));
}
}
Not worrying about other linting errors or checking anything about the logic (haven't checked if it does what you want or not), I can remove the no-unused-vars
error like this: 不用担心其他掉毛错误或检查逻辑上的任何内容(不必检查它是否满足您的要求),我可以像这样删除
no-unused-vars
错误:
import {differentCountriesCurrency} from 'sports-input-utils/lib/formatting';
Object.defineProperty(exports, '__esModule', {
value: true
});
function stringValues(x, sep, grp) {
var sx = (''+x).split('.'), s = '', i, j;
sep || (sep = ','); // default seperator
grp || grp === 0 || (grp = 3); // default grouping
i = sx[0].length;
while (i > grp) {
j = i - grp;
s = sep + sx[0].slice(j, i) + s;
i = j;
}
s = sx[0].slice(0, i) + s;
sx[0] = s;
return sx.join('.');
};
exports.appleBrowser = function (value, parm) {
var unitsOfNumbers;
if (!value) {
return value;
}
// extract unitsOfNumbers. if no unitsOfNumbers, fill in a zero.
unitsOfNumbers = value.match(/\d/g) || ['0'];
return stringValues(Number(unitsOfNumbers.join('')));
};
exports.appleBrowserWithDecimals = function (value, parm) {
var unitsOfNumbers;
if (!value) {
return value;
}
// extract unitsOfNumbers. if no unitsOfNumbers, fill in a zero.
unitsOfNumbers = value.match(/\d/g) || ['0'];
// zero-pad a one-digit input
if (unitsOfNumbers.length === 1) {
unitsOfNumbers.unshift('0');
}
// add a decimal point
unitsOfNumbers.splice(unitsOfNumbers.length - 2, 0, '.');
return stringValues(Number(unitsOfNumbers.join('')));
};
exports.limitMaximumLength = function (value, parm) {
if (value.length < parm) {
return value;
} else {
return value.substring(0, parm);
}
};
exports.differentCountriesCurrencyWithMaxLen = function (value) {
var isSafari;
return differentCountriesCurrency(limitMaximumLength(value, 7));
// ^^^ There's no way this ^^^ is what you want.
// The rest of the function is always ignored. You've already returned.
isSafari = navigator.userAgent.indexOf("Safari") > -1;
if (isSafari) {
return appleBrowser(limitMaximumLength(value, 7));
}
};
To remove the error, I did exactly what @JosephYoung says. 为了消除该错误,我完全按照@JosephYoung的说明进行操作。 You haven't added
stringValues
to whatever Number returns. 您还没有将
stringValues
添加到任何Number返回。 You declared it globally. 您在全球范围内对其进行了声明。
So don't do this: 所以不要这样做:
return Number(unitsOfNumbers.join('')).stringValues();
That pretends there's another stringValues
as a function-property on Number
's return value. 这就假装在
Number
的返回值上还有另一个stringValues
作为函数属性。 Your function stringValues
exists at global scope, and is never called. 您的函数
stringValues
存在于全局范围内,并且永远不会被调用。
To call what you declared, you do this: 要调用您声明的内容,请执行以下操作:
return stringValues(Number(unitsOfNumbers.join('')));
One important readability issue to notice: Instead of the lines you have like this... 需要注意的一个重要的可读性问题:您不是这样的行...
exports.limitMaximumLength = limitMaximumLength;
function limitMaximumLength(value, parm) {
... go ahead and put the assignment on a single line like this... ...继续将作业放在这样的一行上...
exports.limitMaximumLength = function (value, parm) {
Makes it easier to tell what you're exporting and what's a "private" utility function. 使您更容易知道要导出的内容以及什么是“私有”实用程序功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.