<commit_before>// asset/parsers - raw assets, parsers and mime-types
// Part of Stardazed
// (c) 2015-2017 by <NAME> - @zenmumbler
// https://github.com/stardazed/stardazed

/// <reference path="../core/util.ts" />

namespace sd.asset.parser {

	// library-wide file extension to mime-type registry

	const extensionMimeTypeMap = new Map<string, string>();

	export function registerFileExtension(extension: string, mimeType: string) {
		const ext = extension.toLowerCase().trim();
		const mime = mimeType.toLowerCase().trim();
		assert(ext.length > 0, "empty file extension provided");
		assert(mime.length > 0, "empty mime-type provided");
		extensionMimeTypeMap.set(ext, mime);
	}

	export function mimeTypeForFileExtension(extension: string): string | undefined {
		const ext = extension.toLowerCase().trim();
		return extensionMimeTypeMap.get(ext);
	}

	export function mimeTypeForURL(url: URL | string): string | undefined {
		const extension = io.fileExtensionOfURL(url);
		return mimeTypeForFileExtension(extension);
	}

	/**
	 * Unprocessed data and metadata describing an asset. The data is
	 * always provided as a Blob, the metadata is a basic key-value set.
	 * Because assets are loaded from arbitrary files, the keys in the
	 * metadata are all made optional to force AssetParsers to provide
	 * default values. Each asset has a name and it must be unique<commit_msg>feat(asset): add mime type to asset kind mapping<commit_after>// asset/parsers - raw assets, parsers and mime-types
// Part of Stardazed
// (c) 2015-2017 by <NAME> - @zenmumbler
// https://github.com/stardazed/stardazed

/// <reference path="../core/util.ts" />

namespace sd.asset.parser {

	const extensionMimeTypeMap = new Map<string, string>();

	export function registerFileExtension(extension: string, mimeType: string) {
		const ext = extension.toLowerCase();
		const mime = mimeType.toLowerCase();
		assert(ext.length > 0, "registerFileExtension: empty file extension provided");
		assert(mime.length > 0, "registerFileExtension: empty mime-type provided");
		extensionMimeTypeMap.set(ext, mime);
	}

	export function mimeTypeForFileExtension(extension: string): string | undefined {
		const ext = extension.toLowerCase().trim();
		return extensionMimeTypeMap.get(ext);
	}

	export function mimeTypeForURL(url: URL | string): string | undefined {
		const extension = io.fileExtensionOfURL(url);
		return mimeTypeForFileExtension(extension);
	}

	const mimeTypeAssetKindMap = new Map<string, string>();

	export const mapMimeTypeToAssetKind = (mimeType: string, assetKind: string) => {
		const mime = mimeType.toLowerCase();
		const kind = assetKind.toLowerCase();
		assert(mime.length > 0, "mapMimeTypeToAssetKind: empty mime-type provided");
		assert(kind.length > 0, "mapMimeTypeToAssetKind: empty asset kind provided");
		mimeTypeAssetKindMap.set(mime, kind);
	};

	export const assetKindForMimeType = (mimeType: string) =>
		mimeTypeAssetKindMap.get(mimeType.toLowerCase());

	/**
	 * Unprocessed data and metadata describing an asset. The data is
	 * always provided as a Blob, the metadata is a basic key-value set.
	 * Because assets are loaded from arbitrary files, the keys in the
	 * metadata are all made optional to force AssetParsers to provide
	 * default values. Each asset has a name and it must be unique
{'fraction_non_alphanumeric': 0.10872848082150408, 'fraction_numerical': 0.006644518272425249, 'mean_word_length': 4.613559322033899, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3265987', 'n_tokens_mistral': 1023, 'n_tokens_neox': 957, 'n_words': 309}