truemedian / luvit-api-design

11 stars 2 forks source link

Alternate path splitting #9

Closed RiskoZoSlovenska closed 2 years ago

RiskoZoSlovenska commented 2 years ago

Adds nameSplit() (if you have a better name, please do suggest), an alternate to dirname(), basename() and extension() that returns all of those at once. For example, /folder1/folder2/myFile.lua would be split into /folder1/folder2/, myFile and .lua.

Because in most contexts, you'll need at least two of those.

truemedian commented 2 years ago

While I see the reasoning in the function. dirname, basename and extension are all very standard in things that manipulate paths. The other issue is that there are many cases where you just need dirname, or just need extension, so I'm not sure we should do the extra work when its unnecessary

RiskoZoSlovenska commented 2 years ago

What will basename return? Just the root of the filename or the extension as well?

truemedian commented 2 years ago

basename should return the name of the file (everything after the last path separator).

For example basename('/path/to/fs.lua') should return fs.lua

RiskoZoSlovenska commented 2 years ago

Ah. I was hoping for a more convenient way to split the root and extension of a filename, something like Python's os.path.splitext.

If not, Luvit 2.x's path's basename accepts an expected_ext parameter which chops of the extension, any chance that could make it into 3.x too?

truemedian commented 2 years ago

If not, Luvit 2.x's path's basename accepts an expected_ext parameter which chops of the extension, any chance that could make it into 3.x too?

Yes, I missed this but it should exist