MiguelCastillo / amd-resolver

Resolve module names to File objects
MIT License
0 stars 1 forks source link

Add File.replaceExtension #6

Closed Mark-Simulacrum closed 9 years ago

Mark-Simulacrum commented 9 years ago

This has a failing unit test:

it("then `test/.file.ext1.html` is `test/.file.js`", function() {
  var fileString = File.replaceExtension("test/.file.ext1.html", "js");
  expect(fileString).to.equal("test/.file.js");
});

File.replaceExtension does not currently work with file paths beginning with ".". This is due to the fact that it uses the first element in the array + the passed extension as the new file name. This breaks when the original file name string starts with . because the array after splitting on . equals ["", "file", "js", "html"].

I do have a work around for this, but I would like to hear your ideas - my workaround consists of doing a check on the first element being an empty string (or perhaps fileName.name.startsWith(".") in ES6) and then using the first two elements of the array as our "first element".

Fixes #4.

/cc @MiguelCastillo

Mark-Simulacrum commented 9 years ago

I believe this is ready now, ready for another review.

/cc @MiguelCastillo.

MiguelCastillo commented 9 years ago

This looks great!

MiguelCastillo commented 9 years ago

Looks good! Merging in