You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
706 B
JavaScript
22 lines
706 B
JavaScript
'use strict';
|
|
|
|
const rfr = require("rfr");
|
|
const inExtensions = rfr("lib/path/in-extensions");
|
|
const subtractExtension = rfr("lib/path/subtract-extension");
|
|
|
|
module.exports = function(filename, extension, candidateFilenames, candidateExtensions) {
|
|
let basename = subtractExtension(filename, extension);
|
|
|
|
return candidateFilenames.map((candidate) => {
|
|
return {
|
|
filename: candidate,
|
|
extensionMatch: inExtensions(candidate, candidateExtensions)
|
|
}
|
|
}).filter((candidate) => {
|
|
return candidate.extensionMatch !== false;
|
|
}).filter((candidate) => {
|
|
return (subtractExtension(candidate.filename, candidate.extensionMatch) === basename);
|
|
}).map((candidate) => {
|
|
return candidate.filename;
|
|
});
|
|
} |