gulpjs / vinyl

Virtual file format.
MIT License
1.28k stars 105 forks source link

File.stem for basename without suffix #64

Closed soslan closed 9 years ago

soslan commented 9 years ago

Hello! This patch adds stem property to File for getting and setting filename part preceding the last period (sometimes also called basename[1]).

[1] https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

kevva commented 9 years ago

You could just use https://github.com/hparra/gulp-rename.

soslan commented 9 years ago

I see in gulp-rename, basename means filename without the suffix, while here, basename is effectively the whole filename.

soslan commented 9 years ago

@kevva You still have to gulp.dest() it. Handling names in gulp.dest() is more concise, IMO.

phated commented 9 years ago

In node, basename is both with and without extension. See https://nodejs.org/api/path.html#path_path_basename_p_ext

I'm not sure about adding this.

sindresorhus commented 9 years ago

:+1:

@phated But to do so with the Node.js API you need to know the extension, which means you'll end up with something like this: path.basename(filepath, path.extname(filepath)) which is very verbose. I wish the Node.js API had a stem method too.

phated commented 9 years ago

@sindresorhus okay, what is the best name for this? The linked document doesn't mention "stem"

sindresorhus commented 9 years ago

PHP uses filename for basename without extension.

phated commented 9 years ago

Looks like C++ calls it a stem

phated commented 9 years ago

So does python and rust. Probably stick with stem then.

sindresorhus commented 9 years ago

I prefer stem too.

phated commented 9 years ago

@soslan This looks to be failing the updated linting/jscs rules. Can you update this PR? Everything else looks good.

soslan commented 9 years ago

@phated Done. I should have not synced it with upstream though.

phated commented 9 years ago

Published as 1.1.0 - Thanks for this feature!

gilly3 commented 8 years ago

I want this in gulp ^3.9.0. Can we merge this into a vinyl v0.* release? Or update gulp 3 to use vinyl ^1.1.0?

I'd submit a pull request, but I don't see a vinyl v0.* branch - is vinyl v0.* no longer maintained or supported?

phated commented 8 years ago

@gilly3 nope, I recommend you just depend directly on a new version of vinyl-fs