Github actions require checking in the entire node_modules or using a vercel service what the fuck github
This commit is contained in:
137
node_modules/mime/src/Mime.ts
generated
vendored
Normal file
137
node_modules/mime/src/Mime.ts
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
type TypeMap = { [key: string]: string[] };
|
||||
|
||||
export default class Mime {
|
||||
#extensionToType = new Map<string, string>();
|
||||
#typeToExtension = new Map<string, string>();
|
||||
#typeToExtensions = new Map<string, Set<string>>();
|
||||
|
||||
constructor(...args: TypeMap[]) {
|
||||
for (const arg of args) {
|
||||
this.define(arg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Define mimetype -> extension mappings. Each key is a mime-type that maps
|
||||
* to an array of extensions associated with the type. The first extension is
|
||||
* used as the default extension for the type.
|
||||
*
|
||||
* e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
|
||||
*
|
||||
* If a mapping for an extension has already been defined an error will be
|
||||
* thrown unless the `force` argument is set to `true`.
|
||||
*
|
||||
* e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
|
||||
*/
|
||||
define(typeMap: TypeMap, force = false) {
|
||||
for (let [type, extensions] of Object.entries(typeMap)) {
|
||||
// Lowercase thingz
|
||||
type = type.toLowerCase();
|
||||
extensions = extensions.map((ext) => ext.toLowerCase());
|
||||
|
||||
if (!this.#typeToExtensions.has(type)) {
|
||||
this.#typeToExtensions.set(type, new Set<string>());
|
||||
}
|
||||
const allExtensions = this.#typeToExtensions.get(type);
|
||||
|
||||
let first = true;
|
||||
for (let extension of extensions) {
|
||||
const starred = extension.startsWith('*');
|
||||
|
||||
extension = starred ? extension.slice(1) : extension;
|
||||
|
||||
// Add to list of extensions for the type
|
||||
allExtensions?.add(extension);
|
||||
|
||||
if (first) {
|
||||
// Map type to default extension (first in list)
|
||||
this.#typeToExtension.set(type, extension);
|
||||
}
|
||||
first = false;
|
||||
|
||||
// Starred types are not eligible to be the default extension
|
||||
if (starred) continue;
|
||||
|
||||
// Map extension to type
|
||||
const currentType = this.#extensionToType.get(extension);
|
||||
if (currentType && currentType != type && !force) {
|
||||
throw new Error(
|
||||
`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`,
|
||||
);
|
||||
}
|
||||
this.#extensionToType.set(extension, type);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mime type associated with an extension
|
||||
*/
|
||||
getType(path: string) {
|
||||
if (typeof path !== 'string') return null;
|
||||
|
||||
// Remove chars preceeding `/` or `\`
|
||||
const last = path.replace(/^.*[/\\]/, '').toLowerCase();
|
||||
|
||||
// Remove chars preceeding '.'
|
||||
const ext = last.replace(/^.*\./, '').toLowerCase();
|
||||
|
||||
const hasPath = last.length < path.length;
|
||||
const hasDot = ext.length < last.length - 1;
|
||||
|
||||
// Extension-less file?
|
||||
if (!hasDot && hasPath) return null;
|
||||
|
||||
return this.#extensionToType.get(ext) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default file extension associated with a mime type
|
||||
*/
|
||||
getExtension(type: string) {
|
||||
if (typeof type !== 'string') return null;
|
||||
|
||||
// Remove http header parameter(s) (specifically, charset)
|
||||
type = type?.split?.(';')[0];
|
||||
|
||||
return (
|
||||
(type && this.#typeToExtension.get(type.trim().toLowerCase())) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all file extensions associated with a mime type
|
||||
*/
|
||||
getAllExtensions(type: string) {
|
||||
if (typeof type !== 'string') return null;
|
||||
|
||||
return this.#typeToExtensions.get(type.toLowerCase()) ?? null;
|
||||
}
|
||||
|
||||
//
|
||||
// Private API, for internal use only. These APIs may change at any time
|
||||
//
|
||||
|
||||
_freeze() {
|
||||
this.define = () => {
|
||||
throw new Error('define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances');
|
||||
};
|
||||
|
||||
Object.freeze(this);
|
||||
|
||||
for (const extensions of this.#typeToExtensions.values()) {
|
||||
Object.freeze(extensions);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
_getTestState() {
|
||||
return {
|
||||
types: this.#extensionToType,
|
||||
extensions: this.#typeToExtension,
|
||||
};
|
||||
}
|
||||
}
|
||||
7
node_modules/mime/src/index.ts
generated
vendored
Normal file
7
node_modules/mime/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import otherTypes from '../types/other.js';
|
||||
import standardTypes from '../types/standard.js';
|
||||
import Mime from './Mime.js';
|
||||
|
||||
export { default as Mime } from './Mime.js';
|
||||
|
||||
export default new Mime(standardTypes, otherTypes)._freeze();
|
||||
6
node_modules/mime/src/index_lite.ts
generated
vendored
Normal file
6
node_modules/mime/src/index_lite.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import standardTypes from '../types/standard.js';
|
||||
import Mime from './Mime.js';
|
||||
|
||||
export { default as Mime } from './Mime.js';
|
||||
|
||||
export default new Mime(standardTypes)._freeze();
|
||||
85
node_modules/mime/src/mime_cli.ts
generated
vendored
Executable file
85
node_modules/mime/src/mime_cli.ts
generated
vendored
Executable file
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import mime from './index.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export default async function () {
|
||||
process.title = 'mime';
|
||||
|
||||
// TODO: Use json imports to access package.json once "import attributes" are
|
||||
// a real, stable thing.
|
||||
//
|
||||
// See https://github.com/tc39/proposal-import-attributes
|
||||
const json = await fs.readFile(
|
||||
path.join(__dirname, '../../package.json'),
|
||||
'utf-8',
|
||||
);
|
||||
const pkg = JSON.parse(json);
|
||||
|
||||
const args = process.argv.splice(2);
|
||||
|
||||
if (
|
||||
args.includes('--version') ||
|
||||
args.includes('-v') ||
|
||||
args.includes('--v')
|
||||
) {
|
||||
console.log(pkg.version);
|
||||
process.exit(0);
|
||||
} else if (
|
||||
args.includes('--name') ||
|
||||
args.includes('-n') ||
|
||||
args.includes('--n')
|
||||
) {
|
||||
console.log(pkg.name);
|
||||
process.exit(0);
|
||||
} else if (
|
||||
args.includes('--help') ||
|
||||
args.includes('-h') ||
|
||||
args.includes('--h')
|
||||
) {
|
||||
console.log(pkg.name + ' - ' + pkg.description + '\n');
|
||||
console.log(`Usage:
|
||||
|
||||
mime [flags] [path_or_extension]
|
||||
|
||||
Flags:
|
||||
--help, -h Show this message
|
||||
--version, -v Display the version
|
||||
--name, -n Print the name of the program
|
||||
--reverse, -r Print the extension of the mime type
|
||||
|
||||
Note: the command will exit after it executes if a command is specified
|
||||
The path_or_extension is the path to the file or the extension of the file.
|
||||
|
||||
Examples:
|
||||
mime --help
|
||||
mime --version
|
||||
mime --name
|
||||
mime -v
|
||||
mime --reverse application/text
|
||||
mime src/log.js
|
||||
mime new.py
|
||||
mime foo.sh
|
||||
`);
|
||||
process.exit(0);
|
||||
} else if (args.includes('--reverse') || args.includes('-r')) {
|
||||
const mimeType = args[args.length - 1];
|
||||
const extension = mime.getExtension(mimeType);
|
||||
|
||||
if (!extension) process.exit(1);
|
||||
|
||||
process.stdout.write(extension + '\n');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const file = args[0];
|
||||
const type = mime.getType(file);
|
||||
|
||||
if (!type) process.exit(1);
|
||||
|
||||
process.stdout.write(type + '\n');
|
||||
}
|
||||
Reference in New Issue
Block a user