Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/mime/Mime.js

    r59329aa re29cc2e  
    1 'use strict';
     1var path = require('path');
     2var fs = require('fs');
    23
    3 /**
    4  * @param typeMap [Object] Map of MIME type -> Array[extensions]
    5  * @param ...
    6  */
    74function Mime() {
    8   this._types = Object.create(null);
    9   this._extensions = Object.create(null);
     5  // Map of extension -> mime type
     6  this.types = Object.create(null);
    107
    11   for (let i = 0; i < arguments.length; i++) {
    12     this.define(arguments[i]);
    13   }
    14 
    15   this.define = this.define.bind(this);
    16   this.getType = this.getType.bind(this);
    17   this.getExtension = this.getExtension.bind(this);
     8  // Map of mime type -> extension
     9  this.extensions = Object.create(null);
    1810}
    1911
     
    2517 * e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
    2618 *
    27  * If a type declares an extension that has already been defined, an error will
    28  * be thrown.  To suppress this error and force the extension to be associated
    29  * with the new type, pass `force`=true.  Alternatively, you may prefix the
    30  * extension with "*" to map the type to extension, without mapping the
    31  * extension to the type.
    32  *
    33  * e.g. mime.define({'audio/wav', ['wav']}, {'audio/x-wav', ['*wav']});
    34  *
    35  *
    3619 * @param map (Object) type definitions
    37  * @param force (Boolean) if true, force overriding of existing definitions
    3820 */
    39 Mime.prototype.define = function(typeMap, force) {
    40   for (let type in typeMap) {
    41     let extensions = typeMap[type].map(function(t) {
    42       return t.toLowerCase();
    43     });
    44     type = type.toLowerCase();
    45 
    46     for (let i = 0; i < extensions.length; i++) {
    47       const ext = extensions[i];
    48 
    49       // '*' prefix = not the preferred type for this extension.  So fixup the
    50       // extension, and skip it.
    51       if (ext[0] === '*') {
    52         continue;
     21Mime.prototype.define = function (map) {
     22  for (var type in map) {
     23    var exts = map[type];
     24    for (var i = 0; i < exts.length; i++) {
     25      if (process.env.DEBUG_MIME && this.types[exts[i]]) {
     26        console.warn((this._loading || "define()").replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
     27          this.types[exts[i]] + ' to ' + type);
    5328      }
    5429
    55       if (!force && (ext in this._types)) {
    56         throw new Error(
    57           'Attempt to change mapping for "' + ext +
    58           '" extension from "' + this._types[ext] + '" to "' + type +
    59           '". Pass `force=true` to allow this, otherwise remove "' + ext +
    60           '" from the list of extensions for "' + type + '".'
    61         );
    62       }
    63 
    64       this._types[ext] = type;
     30      this.types[exts[i]] = type;
    6531    }
    6632
    67     // Use first extension as default
    68     if (force || !this._extensions[type]) {
    69       const ext = extensions[0];
    70       this._extensions[type] = (ext[0] !== '*') ? ext : ext.substr(1);
     33    // Default extension is the first one we encounter
     34    if (!this.extensions[type]) {
     35      this.extensions[type] = exts[0];
    7136    }
    7237  }
     
    7439
    7540/**
     41 * Load an Apache2-style ".types" file
     42 *
     43 * This may be called multiple times (it's expected).  Where files declare
     44 * overlapping types/extensions, the last file wins.
     45 *
     46 * @param file (String) path of file to load.
     47 */
     48Mime.prototype.load = function(file) {
     49  this._loading = file;
     50  // Read file and split into lines
     51  var map = {},
     52      content = fs.readFileSync(file, 'ascii'),
     53      lines = content.split(/[\r\n]+/);
     54
     55  lines.forEach(function(line) {
     56    // Clean up whitespace/comments, and split into fields
     57    var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
     58    map[fields.shift()] = fields;
     59  });
     60
     61  this.define(map);
     62
     63  this._loading = null;
     64};
     65
     66/**
    7667 * Lookup a mime type based on extension
    7768 */
    78 Mime.prototype.getType = function(path) {
    79   path = String(path);
    80   let last = path.replace(/^.*[/\\]/, '').toLowerCase();
    81   let ext = last.replace(/^.*\./, '').toLowerCase();
     69Mime.prototype.lookup = function(path, fallback) {
     70  var ext = path.replace(/^.*[\.\/\\]/, '').toLowerCase();
    8271
    83   let hasPath = last.length < path.length;
    84   let hasDot = ext.length < last.length - 1;
    85 
    86   return (hasDot || !hasPath) && this._types[ext] || null;
     72  return this.types[ext] || fallback || this.default_type;
    8773};
    8874
     
    9076 * Return file extension associated with a mime type
    9177 */
    92 Mime.prototype.getExtension = function(type) {
    93   type = /^\s*([^;\s]*)/.test(type) && RegExp.$1;
    94   return type && this._extensions[type.toLowerCase()] || null;
     78Mime.prototype.extension = function(mimeType) {
     79  var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
     80  return this.extensions[type];
    9581};
    9682
    97 module.exports = Mime;
     83// Default instance
     84var mime = new Mime();
     85
     86// Define built-in types
     87mime.define(require('./types.json'));
     88
     89// Default type
     90mime.default_type = mime.lookup('bin');
     91
     92//
     93// Additional API specific to the default instance
     94//
     95
     96mime.Mime = Mime;
     97
     98/**
     99 * Lookup a charset based on mime type.
     100 */
     101mime.charsets = {
     102  lookup: function(mimeType, fallback) {
     103    // Assume text types are utf8
     104    return (/^text\/|^application\/(javascript|json)/).test(mimeType) ? 'UTF-8' : fallback;
     105  }
     106};
     107
     108module.exports = mime;
Note: See TracChangeset for help on using the changeset viewer.