Infer RAML type name from file name

@param  {string} fileName - File in which type is located.
@returns  {string}
497391
function inferRAMLTypeName (fileName) {
  const cleanName = fileName.replace(/^.*[\\/]/, '')
  const filename = cleanName.split('.')[0]
  return capitalize(filename)
}
324681
public ProvFormat getTypeForFile(String filename) {
        int count = filename.lastIndexOf(".");
        if (count == -1)
            return null;
        String extension = filename.substring(count + 1);
        return extensionRevMap.get(extension);
    }
180977
function (fileName) {
            var dir;
            if (currDirRegExp.test(fileName)) {
                dir = frontSlash(location.href);
                if (dir.indexOf('/') !== -1) {
                    dir = dir.split('/');

                    //Pull off protocol and host, just want
                    //to allow paths (other build parts, like
                    //require._isSupportedBuildUrl do not support
                    //full URLs), but a full path from
                    //the root.
                    dir.splice(0, 3);

                    dir.pop();
                    dir = '/' + dir.join('/');
                }

                fileName = dir + fileName.substring(1);
            }

            return fileName;
        }
560728
function toFileName(typeName) {
  var result = '';
  var wasLower = false;
  for (var i = 0; i < typeName.length; i++) {
    var c = typeName.charAt(i);
    var isLower = /[a-z]/.test(c);
    if (!isLower && wasLower) {
      result += '-';
    }
    result += c.toLowerCase();
    wasLower = isLower;
  }
  return result;
}
980433
function inferFileMetadata (file) {
  file.mimeType = lowercase(mime.lookup(file.url) || null);
  file.encoding = lowercase(mime.charset(file.mimeType) || null);
}
1345447
protected function get_mimetype_from_filename($filename) {
        $mimetype = 'application/unknown';
        $types = core_filetypes::get_types();
        $fileextension = '.bin';
        if (strpos($filename, '.') !== false) {
            $fileextension = substr($filename, strrpos($filename, '.') + 1);
        }

        if (isset($types[$fileextension])) {
            $mimetype = $types[$fileextension]['type'];
        }
        return $mimetype;
    }
992018
function getNameFromFileName(filename) {
  var file = basename(filename).replace(/\.(?:pug|jade)$/, '');
  return file.toLowerCase().replace(/[^a-z0-9]+([a-z])/g, function (_, character) {
    return character.toUpperCase();
  }) + 'Template';
}
579219
public static StructureFiletype guessFiletype(String filename) {
		String lower = filename.toLowerCase();
		for(StructureFiletype type : StructureFiletype.values()) {
			for(String ext : type.getExtensions()) {
				if(lower.endsWith(ext.toLowerCase())) {
					return type;
				}
			}
		}
		return StructureFiletype.UNKNOWN;
	}
685904
function fileName(file) {
  let prefix = null
  let reference = null

  if (isPathSubDirOf(file, PROJECT_DIR)) {
    // Assets from the target project.
    prefix = []
    reference = PROJECT_DIR
  } else if (isPathSubDirOf(file, TOOLBOX_DIR)) {
    // Assets from the Toolbox.
    prefix = ['__borela__']
    reference = TOOLBOX_DIR
  }

  const RELATIVE = relative(reference, file)
  let nodes = RELATIVE.split(sep)

  if (nodes[0] === 'src')
    nodes.shift()

  if (prefix.length > 0)
    nodes = [...prefix, ...nodes]

  return `${nodes.join('/')}?[sha512:hash:base64:8]`
}
208240
function bufferFromFile( filename ) {
	console.info( ("Loading "+filename).grey );
	var buf = fs.readFileSync( filename ),	// Load Buffer
    	ab = new ArrayBuffer( buf.length ),	// Create an ArrayBuffer to fit the data
    	view = new Uint8Array(ab);			// Create an Uint8Array view

    // Copy buffer into view
    for (var i = 0; i < buf.length; ++i)
        view[i] = buf[i];

    // Return buffer view
    return view;
}
35720
function getFileTypeReg(type) {
  var map = [];
  if (type === 'text') {
    map = TEXT_FILE_EXTS;
  } else if (type === 'image') {
    map = IMAGE_FILE_EXTS;
  } else {
    throw new Error('invalid file type [' + type + ']');
  }
  map = map.join('|');
  return new RegExp('\\.(?:' + map + ')$', 'i');
}
334976
def determine_file_type(filename):
    
    if filename.endswith('.cls'):
        return FileType.CLS
    elif filename.endswith('.go'):
        return FileType.GO
    elif filename.endswith('.java'):
        return FileType.JAVA
    elif filename.endswith('.js'):
        return FileType.JAVASCRIPT
    elif filename.endswith('.php'):
        return FileType.PHP
    elif filename.endswith('.py'):
        return FileType.PYTHON
    elif (
        filename.endswith(
            ('.yaml', '.yml'),
        )
    ):
        return FileType.YAML
    return FileType.OTHER
979791
def backend_from_fname(name):
    """"""
    ext = splitext(name)[1]

    try:
        mime = EXTS_TO_MIMETYPES[ext]

    except KeyError:
        try:
            f = open(name, 'rb')

        except IOError as e:
            # The file may not exist, we are being asked to determine it's type
            # from it's name. Other errors are unexpected.
            if e.errno != errno.ENOENT:
                raise

            # We will have to fall back upon the default backend.
            msg = "No handler for %r, defaulting to %r" % (ext, DEFAULT_MIME)
            if 'FULLTEXT_TESTING' in os.environ:
                warn(msg)
            else:
                LOGGER.debug(msg)

            mod_name = MIMETYPE_TO_BACKENDS[DEFAULT_MIME]

        else:
            with f:
                return backend_from_fobj(f)

    else:
        mod_name = MIMETYPE_TO_BACKENDS[mime]

    mod = import_mod(mod_name)
    return mod
937218
def guess(filename, fallback='application/octet-stream'):
    
    guessed, encoding = mimetypes.guess_type(filename, strict=False)
    if guessed is None:
        return fallback, encoding
    return guessed, encoding
1056202
public static MediaType getFileMediaType(String fileName) {
        String extension = getUrlExtension(fileName);
        if (!MimeTypeMap.getSingleton().hasExtension(extension)) {
            return MediaType.APPLICATION_OCTET_STREAM;
        }

        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        try {
            return MediaType.parseMediaType(mimeType);
        } catch (Exception e) {
            return MediaType.APPLICATION_OCTET_STREAM;
        }
    }
4513
private static InputStream getInputStreamFromFilename(String filename) {
        try {
            return new FileInputStream(filename);
        } catch (FileNotFoundException e) {
            log.debug("Error initializing RdfStreamReader, file '{}' not found", filename);
            // do not handle exception at construction time
            return null;
        }
    }
442819
def file_type(filename, param='rb'):
    """"""
    magic_dict = {
        b"\x1f\x8b\x08": "gz",
        b"\x42\x5a\x68": "bz2",
        b"\x50\x4b\x03\x04": "zip"
    }
    if param.startswith('w'):
        return filename.split('.')[-1]
    max_len = max(len(x) for x in magic_dict)
    with open(filename, 'rb') as f:
        file_start = f.read(max_len)
    for magic, filetype in list(magic_dict.items()):
        if file_start.startswith(magic):
            return filetype
    return "no match"