Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
ed79c67e
Commit
ed79c67e
authored
Jul 18, 2022
by
Medicean
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #318
parent
2a263951
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
0 deletions
+97
-0
Mime.js
node_modules/mime/Mime.js
+97
-0
No files found.
node_modules/mime/Mime.js
0 → 100644
View file @
ed79c67e
'use strict'
;
/**
* @param typeMap [Object] Map of MIME type -> Array[extensions]
* @param ...
*/
function
Mime
()
{
this
.
_types
=
Object
.
create
(
null
);
this
.
_extensions
=
Object
.
create
(
null
);
for
(
let
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
this
.
define
(
arguments
[
i
]);
}
this
.
define
=
this
.
define
.
bind
(
this
);
this
.
getType
=
this
.
getType
.
bind
(
this
);
this
.
getExtension
=
this
.
getExtension
.
bind
(
this
);
}
/**
* 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 type declares an extension that has already been defined, an error will
* be thrown. To suppress this error and force the extension to be associated
* with the new type, pass `force`=true. Alternatively, you may prefix the
* extension with "*" to map the type to extension, without mapping the
* extension to the type.
*
* e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
*
*
* @param map (Object) type definitions
* @param force (Boolean) if true, force overriding of existing definitions
*/
Mime
.
prototype
.
define
=
function
(
typeMap
,
force
)
{
for
(
let
type
in
typeMap
)
{
let
extensions
=
typeMap
[
type
].
map
(
function
(
t
)
{
return
t
.
toLowerCase
();
});
type
=
type
.
toLowerCase
();
for
(
let
i
=
0
;
i
<
extensions
.
length
;
i
++
)
{
const
ext
=
extensions
[
i
];
// '*' prefix = not the preferred type for this extension. So fixup the
// extension, and skip it.
if
(
ext
[
0
]
===
'*'
)
{
continue
;
}
if
(
!
force
&&
(
ext
in
this
.
_types
))
{
throw
new
Error
(
'Attempt to change mapping for "'
+
ext
+
'" extension from "'
+
this
.
_types
[
ext
]
+
'" to "'
+
type
+
'". Pass `force=true` to allow this, otherwise remove "'
+
ext
+
'" from the list of extensions for "'
+
type
+
'".'
);
}
this
.
_types
[
ext
]
=
type
;
}
// Use first extension as default
if
(
force
||
!
this
.
_extensions
[
type
])
{
const
ext
=
extensions
[
0
];
this
.
_extensions
[
type
]
=
(
ext
[
0
]
!==
'*'
)
?
ext
:
ext
.
substr
(
1
);
}
}
};
/**
* Lookup a mime type based on extension
*/
Mime
.
prototype
.
getType
=
function
(
path
)
{
path
=
String
(
path
);
let
last
=
path
.
replace
(
/^.*
[/\\]
/
,
''
).
toLowerCase
();
let
ext
=
last
.
replace
(
/^.*
\.
/
,
''
).
toLowerCase
();
let
hasPath
=
last
.
length
<
path
.
length
;
let
hasDot
=
ext
.
length
<
last
.
length
-
1
;
return
(
hasDot
||
!
hasPath
)
&&
this
.
_types
[
ext
]
||
null
;
};
/**
* Return file extension associated with a mime type
*/
Mime
.
prototype
.
getExtension
=
function
(
type
)
{
type
=
/^
\s
*
([^
;
\s]
*
)
/
.
test
(
type
)
&&
RegExp
.
$1
;
return
type
&&
this
.
_extensions
[
type
.
toLowerCase
()]
||
null
;
};
module
.
exports
=
Mime
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment