How to use the upath.defaultExt function in upath

To help you get started, we’ve selected a few upath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cosmicjs / cosmic-cli / non_standard_commands / add-media.js View on Github external
function handler(options) {
  var invokedCmd = options.invokedCmd
  var bucket = options.bucket
  
  var buffer = fs.readFileSync(invokedCmd.file)

  var fileExt = upath.extname(invokedCmd.file)
  var originalname = upath.defaultExt(invokedCmd.title || 'media', fileExt)
  var media_object = { originalname: originalname, buffer: buffer }

  bucket.addMedia({
    media: media_object,
    folder: invokedCmd.folder,
  }).then(function(res) {
    print.success('Success')
    console.log(res)
    process.exit()
  }).catch(function(err) {
    print.error('Error')
    console.log(err)
    process.exit(1)
  })
}

upath

A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis