How to use the extname function from path

Find comprehensive JavaScript path.extname code examples handpicked from public code repositorys.

247
248
249
250
251
252
253
254
255
256
const destinationFile = path.join(
  destinationFolder,
  extraPath,
  prefix +
    (destinationFileBase
      ? destinationFileBase + path.extname(sourceFile)
      : path.basename(sourceFile))
);
// Copy from the source to the destination.
const sourceContents = fs.readFileSync(sourceFile, { encoding: 'utf-8' });
fork icon466
star icon582
watch icon40

+ 2 other calls in file

138
139
140
141
142
143
144
145
146
147
148
149
precinct.paperwork = (filename, options = {}) => {
  options = { includeCore: true, ...options };


  const fileSystem = options.fileSystem || fs;
  const content = fileSystem.readFileSync(filename, 'utf8');
  const ext = path.extname(filename);
  let type;


  if (ext === '.styl') {
    debug('paperwork: converting .styl into the stylus type');
fork icon39
star icon175
watch icon2

761
762
763
764
765
766
767
768
769
770
      'url': `${settings.baseUrl}${m[1]}`,
    };
  }), null, 2);

for (const fileName of files) {
  const ext = path.extname(fileName);
  if (!byFilename[path.basename(fileName)]) {
    if (!hackyProcessSelectFiles) {
      throw new Error(`${fileName} is not in toc.hanson`);
    }
fork icon5
star icon4
watch icon3

+ 5 other calls in file

52
53
54
55
56
57
58
59
60
61
if (err) {
  console.log("Final Step err:", err);
  return reject(err);
}
const filename =
  buf.toString("hex") + path.extname(file.originalname);
const fileInfo = {
  filename: filename,
  bucketName: "attachments",
};
fork icon0
star icon2
watch icon1

+ 3 other calls in file

49
50
51
52
53
54
55
56
57
58
  ) {
    FS.unlinkSync(
      `${__dirname}/Public/PostsImages/${req.body?.PREVIEWCODE}${req.body?.PREVIEWEXT}`
    );
  }
  const uniqueSuffix = ImageCode + Path.extname(file.originalname);
  cb(null, uniqueSuffix);
} else {
  let Model = new mongoose.model("users", UserSchema);
  let Result = await Model.find({ _id: req.body.ID });
fork icon0
star icon1
watch icon1

+ 9 other calls in file

929
930
931
932
933
934
935
936
937
  response.send({error: true});
  return;
}

// filter for JSON files
const jsonFiles = files.filter(file => path.extname(file) === '.jsonl');

// sort the files by name
//jsonFiles.sort().reverse();
fork icon0
star icon0
watch icon1

12167
12168
12169
12170
12171
12172
12173
12174
12175
12176

// image
if (image = options.image) {
  switch(cmd.type) {
    case 'Darwin-Growl':
      var flag, ext = path.extname(image).substr(1)
      flag = flag || ext == 'icns' && 'iconpath'
      flag = flag || /^[A-Z]/.test(image) && 'appIcon'
      flag = flag || /^png|gif|jpe?g$/.test(ext) && 'image'
      flag = flag || ext && (image = ext) && 'icon'
fork icon0
star icon0
watch icon2

+ 5 other calls in file

7
8
9
10
11
12
13
14
15
16
const storage = multer.diskStorage({
    destination: function(req, file, cb){
        cb(null, 'uploads/images/users/')
    },
    filename: function(req, file, cb){
        cb(null, Date.now() + path.extname(file.originalname))
    }
})
const upload = multer({
    storage: storage,
fork icon0
star icon0
watch icon1

13
14
15
16
17
18
19
20
21
22
23
      folder = "pets";
    }
    cb(null, `public/images/${folder}/`);
  },
  filename: (req, file, cb) => {
    cb(null, Date.now() + path.extname(file.originalname));
  },
});


const imageUpload = multer({
fork icon0
star icon0
watch icon1

4
5
6
7
8
9
10
11
12
13
14
15


//* Crear el storage engine
const storage = multer.diskStorage({
    destination: './public/uploads/',
    filename: function (req, file, cb) {
        cb(null, file.fieldname + "-" + Date.now()+ path.extname(file.originalname))
    }
}) 


//* Inicializanco a upload
fork icon0
star icon0
watch icon1