-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Open
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.
Description
What is the problem this feature will solve?
Adding path.mimeType()
and path.charset
will solve the dependency on an external library, mime-types, to get the content type of a file based on its extension. This can be done with Node.js itself, just as Bun.js does with Bun.file(file).type
.
What is the feature you are proposing to solve the problem?
I am proposing to add two new methods to the path module:
mimeType
- returns the MIME type of a file based on its extension.charset
- returns the charset of a MIME type.
path.mimeType('file.js'); // returns 'application/javascript'
// or:
path.mimeType(path.extname('file.js')); // returns 'application/javascript'
And:
path.charset('file.js'); // returns 'utf-8'
// or:
path.charset(path.mimeType('file.js')); // returns 'utf-8'
What alternatives have you considered?
Alternatively, instead of being in node:path
, it could be in fs.stat
, but I think that in the end it can be extracted from the path without having to parse the file, besides it is better to use functions for this and the work is done only if they are executed individually.
CC: @vdeturckheim
bjohansebas and avivkeller
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.pathIssues and PRs related to the path subsystem.Issues and PRs related to the path subsystem.
Type
Projects
Status
Awaiting Triage