Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dirname, basename and extname getters #46

Merged
merged 1 commit into from
May 23, 2015

Conversation

jeremyruppel
Copy link
Contributor

Not sure if you guys would consider this bloat or a useful feature, but I often find myself wanting these pathname-style helpers when working with vinyl Files. Cheers!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5f1f766 on jeremyruppel:pathname-helpers into 6fd2748 on wearefractal:master.

@@ -158,6 +158,36 @@ Object.defineProperty(File.prototype, 'relative', {
}
});

Object.defineProperty(File.prototype, 'dirname', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.base already exists, using dirname for output would be an antipattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dirname has a different meaning and can actually be different than file.base. For example:

gulp.src('assets/css/**/*.scss')

Every file's file.base will be assets/css but any file in a subdirectory will have a different dirname.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yup, different use-case.

@sindresorhus
Copy link

👍 This would be very handy. I would especially like being able to do `file.extension = '.foo' to change the extension, instead of having to use the gutil helper. So everything should have setters too IMHO.

@yocontra
Copy link
Member

@phated thoughts?

return path.extname(this.path);
},
set: function() {
throw new Error('File.extname is generated from the base and path attributes. Do not modify it.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do agree that if we have a setter for this it should use the replace-ext module on path

@jeremyruppel
Copy link
Contributor Author

Right on, I've added setters for all of these properties. What do you guys think?

return path.extname(this.path);
},
set: function(extname) {
this.path = replaceExt(this.path, extname);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setters should also throw the errors on no path, or just do nothing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree and personally prefer that they throw. Added.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling f869ff6 on jeremyruppel:pathname-helpers into 6fd2748 on wearefractal:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 5a41647 on jeremyruppel:pathname-helpers into 01ed2ef on wearefractal:master.

@sindresorhus
Copy link

@jeremyruppel Can you also update the docs?

@jeremyruppel
Copy link
Contributor Author

Just squashed these commits. @contra @sindresorhus @phated thoughts?

@yocontra
Copy link
Member

@jeremyruppel Rebase?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e09817f on jeremyruppel:pathname-helpers into 01ed2ef on wearefractal:master.

@jeremyruppel
Copy link
Contributor Author

@contra yep! README conflicts. Sorry about the trailing whitespace stuff.

yocontra pushed a commit that referenced this pull request May 23, 2015
Add dirname, basename and extname getters
@yocontra yocontra merged commit 2c80c43 into gulpjs:master May 23, 2015
@yocontra
Copy link
Member

Thanks @jeremyruppel !

@jeremyruppel jeremyruppel deleted the pathname-helpers branch May 25, 2015 03:35
@jeremyruppel
Copy link
Contributor Author

Thanks @contra & @sindresorhus!

@@ -38,42 +38,42 @@ var coffeeFile = new File({

#### options.cwd

Type: `String`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this whitespace should change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markdown treats double trailing whitespace as a newline. It's stupid, but @stevemao is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point. #52

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

phated pushed a commit that referenced this pull request Sep 27, 2016
Add dirname, basename and extname getters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants