Skip to content

Commit

Permalink
refactor: remove the remaining underscore calls in plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
iparamonau committed Dec 18, 2024
1 parent d7b4082 commit b17982a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
10 changes: 3 additions & 7 deletions lib/plugins/validators/sync/06_autoplay.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as _ from 'underscore';

export default {

prepareLink: function(link) {


if (link.href && link.type && link.type.indexOf('video/') > -1 && link.rel.indexOf(CONFIG.R.autoplay) > -1) {
// Remove "autoplay" from html5 videos.
link.rel.splice(link.rel.indexOf(CONFIG.R.autoplay), 1);
Expand All @@ -29,11 +26,10 @@ export default {
var play = link.autoplay;
// don't need this field any longer
delete link.autoplay;


if (link.href.indexOf(play) > -1 || link.rel.indexOf(CONFIG.R.autoplay) == -1) {

var stop = play.replace (/\=(\w+)/, function (p1, p2) {
var stop = play.replace(/\=(\w+)/, function (p1, p2) {
var antonyms = {
'1': '0',
'0': '1',
Expand All @@ -45,8 +41,8 @@ export default {
return '=' + antonyms[p2];
});

var rels = _.clone(link.rel);
var new_link = _.extend({}, link);
var rels = [...link.rel];
var new_link = Object.assign({}, link);
new_link.rel = rels; // deep copy


Expand Down
6 changes: 2 additions & 4 deletions plugins/custom/og-image-rel-image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as _ from "underscore";

var rel = [CONFIG.R.image, CONFIG.R.og];
const rel = [CONFIG.R.image, CONFIG.R.og];

function getImageLinks(image) {
return [{
Expand All @@ -24,7 +22,7 @@ export default {

if (og.image instanceof Array) {

return _.flatten(og.image.map(getImageLinks));
return og.image.map(getImageLinks).flat();

} else if (og.image) {

Expand Down
3 changes: 1 addition & 2 deletions plugins/domains/itunes.apple.com/apple.music.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as URL from 'url';
import * as _ from 'underscore';

export default {

Expand Down Expand Up @@ -27,7 +26,7 @@ export default {

var at = null;
if (options.redirectsHistory) {
var original_url = _.find(options.redirectsHistory, function(u) {
var original_url = options.redirectsHistory.find(function(u) {
return u.indexOf('at=') > -1;
});
var query = original_url && URL.parse(original_url, true).query;
Expand Down
8 changes: 3 additions & 5 deletions plugins/links/hosted/promo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as _ from 'underscore';

export default {

provides: 'self',
Expand All @@ -19,7 +17,7 @@ export default {
promoUri = 'http:' + promoUri;
}

var options2 = _.extend({}, options, {debug: false, mixAllWithDomainPlugin: false});
var options2 = {...options, ...{debug: false, mixAllWithDomainPlugin: false}};
delete options2.promoUri;
delete options2.jar;

Expand Down Expand Up @@ -51,7 +49,7 @@ export default {

var hasGoodLinks = false;
var links = promo.links.filter(function(link) {
var match = _.intersection(link.rel, CONFIG.PROMO_RELS);
var match = CONFIG.PROMO_RELS.filter(rel => link.rel.indexOf(rel) > -1);
if (match.length > 1 || (match.length > 0 && match.indexOf(CONFIG.R.thumbnail) === -1)) {
// Detect if has something except thumbnail.
hasGoodLinks = true;
Expand Down Expand Up @@ -79,7 +77,7 @@ export default {
delete link[attr];
}
});
if (!_.isEmpty(m)) {
if (Object.keys(m).length > 0) {
link.media = m;
}
if (typeof __promoUri === "string") {
Expand Down
10 changes: 5 additions & 5 deletions plugins/links/og-video.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from "underscore";
import utils from './utils.js';

function getVideoLinks(video, whitelistRecord) {
Expand Down Expand Up @@ -57,12 +56,13 @@ export default {

if (og.video instanceof Array) {

return utils.mergeMediaSize(_.flatten(og.video.map(function(video) {
return getVideoLinks(video, whitelistRecord);
})));
return utils.mergeMediaSize(
og.video.map(function(video) {
return getVideoLinks(video, whitelistRecord);
}).flat()
);

} else if (og.video) {

return getVideoLinks(og.video, whitelistRecord);
}
}
Expand Down
8 changes: 2 additions & 6 deletions plugins/links/twitter-stream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as _ from "underscore";

function getStreamLinks(twitter, stream, whitelistRecord) {

var player = {
Expand Down Expand Up @@ -44,13 +42,11 @@ export default {
var stream = twitter.player.stream;

if (stream instanceof Array) {

return _.flatten(stream.map(function(s) {
return stream.map(function(s) {
return getStreamLinks(twitter, s, whitelistRecord);
}));
}).flat();

} else if (stream) {

return getStreamLinks(twitter, stream, whitelistRecord);
}
}
Expand Down

0 comments on commit b17982a

Please sign in to comment.