How to use the path.extname function in path

To help you get started, we’ve selected a few path 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 wonderunit / storyboarder / src / js / main.js View on Github external
let data = fs.readFileSync(filepath, 'utf-8')

    if (path.extname(filepath) === '.fountain') {
      try {
        // write scene ids for any new scenes
        data = ensureFountainSceneIds(filepath, data)
        let [scriptData, locations, characters, metadata] = processFountainData(data, false, false)
        mainWindow.webContents.send('reloadScript', [scriptData, locations, characters])
      } catch (error) {
        dialog.showMessageBox({
          type: 'error',
          message: 'Could not reload script.\n' + error.message
        })
      }

    } else if (path.extname(filepath) === '.fdx') {
      let parser = new xml2js.Parser()
      parser.parseString(data, (err, fdxObj) => {
        if (err) {
          dialog.showMessageBox({
            type: 'error',
            message: 'Could not parse Final Draft XML.\n' + error.message,
          })
          return
        }

        try {
          ensureFdxSceneIds(fdxObj)
          let [scriptData, locations, characters, metadata] = processFdxData(fdxObj)
          mainWindow.webContents.send('reloadScript', [scriptData, locations, characters])
        } catch (error) {
          dialog.showMessageBox({
github wm123450405 / linqjs / pack.js View on Github external
	let defaultApis = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'apis'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt)).toArray();
	// let defaultChanges = Enumerable(fs.readdirSync(path.join(resources, common.defaultLang, 'change'))).where(name => path.extname(name) === jsonExt).orderBy(element => path.basename(element, jsonExt), (element, other) => {
github webpack / node-libs-browser / test / suite / node / simple / test-path.js View on Github external
assert.equal(path.dirname('\\\\unc\\share\\foo'), '\\\\unc\\share\\');
  assert.equal(path.dirname('\\\\unc\\share\\foo\\'), '\\\\unc\\share\\');
  assert.equal(path.dirname('\\\\unc\\share\\foo\\bar'),
               '\\\\unc\\share\\foo');
  assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\'),
               '\\\\unc\\share\\foo');
  assert.equal(path.dirname('\\\\unc\\share\\foo\\bar\\baz'),
               '\\\\unc\\share\\foo\\bar');
}


assert.equal(path.extname(''), '');
assert.equal(path.extname('/path/to/file'), '');
assert.equal(path.extname('/path/to/file.ext'), '.ext');
assert.equal(path.extname('/path.to/file.ext'), '.ext');
assert.equal(path.extname('/path.to/file'), '');
assert.equal(path.extname('/path.to/.file'), '');
assert.equal(path.extname('/path.to/.file.ext'), '.ext');
assert.equal(path.extname('/path/to/f.ext'), '.ext');
assert.equal(path.extname('/path/to/..ext'), '.ext');
assert.equal(path.extname('file'), '');
assert.equal(path.extname('file.ext'), '.ext');
assert.equal(path.extname('.file'), '');
assert.equal(path.extname('.file.ext'), '.ext');
assert.equal(path.extname('/file'), '');
assert.equal(path.extname('/file.ext'), '.ext');
assert.equal(path.extname('/.file'), '');
assert.equal(path.extname('/.file.ext'), '.ext');
assert.equal(path.extname('.path/file.ext'), '.ext');
assert.equal(path.extname('file.ext.ext'), '.ext');
assert.equal(path.extname('file.'), '.');
assert.equal(path.extname('.'), '');
github houshuang / madoko / web / server.js View on Github external
function mimeFromExt( fname ) {
  var ext = path.extname(fname);
  if (ext) {
    var mime = mimeTypes[ext.substr(1)];
    if (mime) return mime;
  }
  return "text/plain";
}
github frontainer / frontplate-cli / lib / cmds / serve.js View on Github external
css = util.flatten(css).filter((filepath) => {
          return (path.extname(filepath) !== '.map')
        });
        browser.reload(css);
github compodoc / compodoc / src-refactored / core / use-cases / scan-files.ts View on Github external
finder.on('file', (file, stat) => {
                if (path.extname(file) === '.ts') {
                    this.scannedFiles.push(file);
                }
            });
github rguerreiro / express-device / lib / device.js View on Github external
function check(req, res, name) {
    var ext = path.extname(name) || '.' + (res.app.get('view engine') || 'html');
    var root = req.app.get('views') || process.cwd() + '/views';
    var dir = path.dirname(name) == '.' ? root : path.resolve(root, path.dirname(name));
    return partials.lookup(dir, path.basename(name, ext), ext);
}
github fansenze / parcel-plugin-url-loader / lib / assets / CSSAsset.js View on Github external
async postProcess (generated) {
    const css = generated.find(e => e.type === 'css')
    if (css) {
      const { exts, limit } = await getOptions()
      for (let i of this.dependencies) {
        const [key, val] = i
        const { name, resolved } = val
        const basename = path.basename(name)
        const extname = path.extname(basename).replace('.', '')
        if (exts.includes(extname)) {
          const file = await read(resolved, 'binary')
          if (file.length <= limit) {
            const hashname = this.generateBundleName.call({
              relativeName: basename,
              type: extname
            })
            const regexp = new RegExp(hashname, 'g')
            collection.set(hashname, { basename, path: resolved })
            const base64str = await base64(file, basename)
            css.value = css.value.replace(regexp, base64str)
          }
        }
      }
    }
    return generated
github break-stuff / clarion / src / services / fileService.ts View on Github external
getManifestExtension(directory: string): string {
        let manifest = this.getManifestFile(directory);
        return manifest ? path.extname(manifest).replace('.', '') : 'scss';
    }