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

Would it be better to return the file extension with a period? #555

Closed
7anshuai opened this issue Aug 22, 2022 · 1 comment
Closed

Would it be better to return the file extension with a period? #555

7anshuai opened this issue Aug 22, 2022 · 1 comment

Comments

@7anshuai
Copy link

From Wikipedia:

A filename extension, file name extension or file extension is a suffix to the name of a computer file (e.g., .txt, .docx, .md).

When the ext without a period(.), i need write code like this:

import path from 'path';
import {fileTypeFromFile} from 'file-type';

const filetype =  await fileTypeFromFile('Unicorn.png'));
// {ext: 'png', mime: 'image/png'}

const pathname = path.format({ dir: '/path/to/somewhere', name: 'Unicorn', ext: filetype?.ext ? '.' + filetype?.txt : '' });
// /path/to/somewhere/Unicorn.png

With a period(.):

const filetype =  await fileTypeFromFile('Unicorn.png'));
// {ext: '.png', mime: 'image/png'}

const pathname = path.format({ dir: '/path/to/somewhere', name: 'Unicorn', ext: filetype?.ext });
// /path/to/somewhere/Unicorn.png

If the ext has a period, it's convenient to use it.

@sindresorhus
Copy link
Owner

The extension is png. The dot is just the separator. Same as the filename is not /Unicorn.png, since / is the path separator.

nodejs/node#44343

@sindresorhus sindresorhus closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2022
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

No branches or pull requests

2 participants