Underscore.js _.map() to native Array.map() (optional with Object.entries/values)

This commit is contained in:
djmaze 2020-07-22 20:09:31 +02:00
parent 032fa8c736
commit a82575a830
27 changed files with 68 additions and 78 deletions

View file

@ -187,7 +187,7 @@ export const staticCombinedIconClass = (data) => {
if (isNonEmptyArray(data)) {
result = 'icon-attachment';
types = _.uniq(_.compact(_.map(data, (item) => (item ? staticFileType(getFileExtension(item[0]), item[1]) : ''))));
types = _.uniq(_.compact(data.map(item => (item ? staticFileType(getFileExtension(item[0]), item[1]) : ''))));
if (types && 1 === types.length && types[0]) {
switch (types[0]) {

View file

@ -185,7 +185,7 @@ class EmailModel {
const parsedResult = addressparser(line);
if (isNonEmptyArray(parsedResult)) {
return _.compact(
_.map(parsedResult, (item) =>
parsedResult.map(item =>
item.address ? new EmailModel(item.address.replace(/^[<]+(.*)[>]+$/g, '$1'), item.name || '') : null
)
);

View file

@ -190,7 +190,7 @@ class FilterModel extends AbstractModel {
Enabled: this.enabled() ? '1' : '0',
Name: this.name(),
ConditionsType: this.conditionsType(),
Conditions: _.map(this.conditions(), (item) => item.toJson()),
Conditions: this.conditions().map(item => item.toJson()),
ActionValue: this.actionValue(),
ActionValueSecond: this.actionValueSecond(),
@ -231,7 +231,7 @@ class FilterModel extends AbstractModel {
if (isNonEmptyArray(json.Conditions)) {
this.conditions(
_.compact(
_.map(json.Conditions, (aData) => {
json.Conditions.map(aData => {
const filterCondition = new FilterConditionModel();
return filterCondition && filterCondition.parse(aData) ? filterCondition : null;
})
@ -282,7 +282,7 @@ class FilterModel extends AbstractModel {
filter.actionKeep(this.actionKeep());
filter.actionNoStop(this.actionNoStop());
filter.conditions(_.map(this.conditions(), (item) => item.cloneSelf()));
filter.conditions(this.conditions().map(item => item.cloneSelf()));
return filter;
}

View file

@ -202,8 +202,7 @@ class MessageModel extends AbstractModel {
getEmails(properties) {
return _.compact(
_.uniq(
_.map(
_.reduce(properties, (carry, property) => carry.concat(this[property]), []),
_.reduce(properties, (carry, property) => carry.concat(this[property]), []).map(
(oItem) => (oItem ? oItem.email : '')
)
)
@ -628,7 +627,7 @@ class MessageModel extends AbstractModel {
* @returns {string}
*/
attachmentsToStringLine() {
const attachLines = _.map(this.attachments(), (item) => item.fileName + ' (' + item.friendlySize + ')');
const attachLines = this.attachments().map(item => item.fileName + ' (' + item.friendlySize + ')');
return attachLines && 0 < attachLines.length ? attachLines.join(', ') : '';
}