转换 file 地址 执行顺序：ignore > map > normalize
178663
function getUrl (file) {

            if (!that.ignore(file)) {
                file = that.map(file);
                file = utils.normalize(file);
                return file;
            }
        }
37075
function normalize(p) {
    var isAbsolutePath = isAbsolute(p);
    var trailingSlash = p && p[p.length - 1] === '/';

    p = normalizeArray(p.split('/'), !isAbsolutePath).join('/');

    if (!p && !isAbsolutePath) {
      p += '.';
    }
    if (p && trailingSlash) {
      p += '/';
    }
    return (isAbsolutePath ? '/' : '') + p;
  }
1292535
function skip() {
    rimraf(file, function() {})
    delete f.versions[v]
    if (f._attachments)
      delete f._attachments[file]
    need.splice(need.indexOf(v), 1)
    maybeDone(null)
  }
897797
function filter(results, data, ignored) {
    if (!data.length) return results;
    //这里是为了缓存match匹配函数
    var preMatchesCache = matchesCache;
    matchesCache = createMatches(data);
    for (var i = results.length; i--;) {
      if (!matchData(results[i], data, ignored)) {
        results.splice(i, 1);
      }
    }
    // Fixed: 因为一次filter可能会有字filter调用，比如matches、not、include
    matchesCache = preMatchesCache; // warning :以后写全局变量一定当心
    return results;
  }
1299242
function normalizeMap (map) {
  return Array.isArray(map)
    ? map.map(key => ({ key, val: key }))
    : Object.keys(map).map(key => ({ key, val: map[key] }))
}
765206
function normalizePath(path, keys, params) {
        for (var name in params) {
            var param = params[name];
            if (typeof param == "string" || param instanceof RegExp)
                params[name] = {type: param};
        }

        path = path
            .concat("/?")
            .replace(/\/:([\w.\-_]+)(\*?)/g, function(match, key, wildcard) {
                keys.push(key);
                if (!params[key]) {
                    params[key] = {};
                }
                // url params default to type string and optional=false
                var param = params[key];
                param.type = param.type || "string";
                param.optional = false;

                if (!param.source) param.source = "url";

                if (param.source !== "url")
                    throw new Error(
                        "Url parameters must have 'url' as source but found '" +
                            param.source +
                            "'"
                    );

                if (wildcard) return "(/*)";
                else return "/([^\\/]+)";
            })
            .replace(/([/.])/g, "\\$1")
            .replace(/\*/g, "(.*)");

        return new RegExp("^" + path + "$");
    }
486506
function stageFiles (patterns, ignorePatterns) {
  const baseDir = getBaseDir()

  // 如果 baseDir 根本不存在 sgf 会抛出异常
  if (!fs.existsSync(baseDir)) {
    return Promise.resolve([])
  }

  sgf.cwd = baseDir

  return new Promise(resolve => {
    sgf((err, result) => {
      if (err) {
        debug('staged-git-files error: %o', err)
        return resolve([])
      }

      const fileList = result
        .filter(item => item.status !== 'Deleted') // 过滤已删除的文件
        .filter(item => match(item.filename, patterns, ignorePatterns))
        .map(item => item.filename)

      resolve(fileList)
    })
  })
}
823585
function FileMap(config) {
  this.config = config || {};
  this.config.exclude = config && config.exclude ? config.exclude : [];
  this.config.exclude.push('/_site');
  this.ignoreDotFiles = true;
  this.root = config.root;
  this.files = [];
  this.events = new EventEmitter();
  this.filesLeft = 0;
  this.dirsLeft = 1;
}
1141930
function filesInRepository(dir) {
        var ignoreDirs = cog.getOption('ignore_dirs');
        // TODO: Allow an array and move to config.
        var ignoreFiles = /~$/;
        var files = glob.sync(dir ? dir + '/*' : '*');
        var ret = [];
        for (var i = 0; i < files.length; i++) {
            if (fs.lstatSync(files[i]).isDirectory()) {
                // Ignore standard directories of uninterest.
                if (!dir && ignoreDirs.indexOf(files[i]) >= 0) {
                    continue;
                }
                ret = filesInRepository(files[i]).concat(ret);
            } else {
                if (!ignoreFiles.test(files[i])) {
                    ret.push(files[i]);
                }
            }
        }
        return ret;
    }
617526
function fixOldLinearGradient (args) {
	let angle;
	// 从args[0]中获取起始点信息
	const start = normalizePos(args[0]);
	// 从args[1]中获取终止点信息
	const end = normalizePos(args[1]);

	// 根据起始点和终止点计算角度
	angle = 180 - Math.atan2(end.x - start.x, end.y - start.y) * (180 / Math.PI);
	// 将角度进行坐标系变换
	angle = require("normalize-range").wrap(0, 360, angle);
	// 如果角度不等于180°，将其转换为字符串后返回
	if (angle !== 180) {
		angle = angle2String({
			deg: angle,
		});
		return angle;
	}
}
1141440
function _normalizeUploadParams(file, options, callback) {
    if (!file) {
        callback(new Error('The "file" parameter is empty.'))
        return
    }

    if (!(is.string(file) || is.buffer(file) || is.readableStream(file))) {
        callback(new Error('The "file" parameter is invalid, it must be a String, Buffer, or ReadableStream'))
        return
    }

    if (is.string(file)) {
        fs.stat(file, function(err, stats) {
            if (err || !stats) {
                callback(new Error('File [' + file + '] is not exists!'))
                return
            }

            options.size = stats.size
            if (!options.ext) {
                options.ext = path.extname(file)
                if (options.ext) {
                    // 去掉.
                    options.ext = options.ext.substring(1)
                }
            }
            callback(null)
        })
        return
    }

    if (is.readableStream(file) && !options.size) {
        callback(new Error('when the "file" parameter\'s is ReadableStream, options.size must specified'))
        return
    }

    if (is.buffer(file)) {
        options.size = file.length
    }

    callback(null)
}
1254348
function normalize(def) {
  if (~noMergeCmds.indexOf(command))
    return stiks.argv.splitArgs(def);
  return stiks.argv.mergeArgs(def, input);
}
1231251
function AnalysisURI (config, {
    basefile, type, target
}) {
    if (!target) return '';

    if (_absolute(target)) {
        return _format(target);
    }

    if (basefile && target.indexOf('.') == 0) {
        target = _root(basefile) + target;
    }

    target = _slash(_amdpath(target, type, config));

    const _uri2 = target.replace(
        _reg, function ($1, $2) {
            return (config.root[$2] || $2) + '/';
        }
    );

    /**
     * 如果不是绝对路径，则相对于当前位置做处理
     * @type {*}
     * @private
     */
    const abs = path.resolve(path.parse(basefile).dir, _uri2);

    return _format(abs);
}
1128935
private byte[] normalize(byte[] path) {
    if (path.length == 0)
      return path;
    byte prevC = 0;
    for (int i = 0; i < path.length; i++) {
      byte c = path[i];
      if (c == '\\')
        return normalize(path, i);
      if (c == (byte) '/' && prevC == '/')
        return normalize(path, i - 1);
      if (c == '\u0000')
        throw new InvalidPathException(this.hdfs.getString(path),
            "Path: nul character not allowed");
      prevC = c;
    }
    return path;
  }
905220
function normalize(obj) {
    const isMultipart = isFormData(obj);
    const content = { filename: '', value: '', mime: '' };
    const result = ((isMultipart) ? new FormData() : {});
    let file = null;

    Object.keys(obj).forEach((item) => {
        if (isMultipart) {
            if (obj[item].value) content.value = obj[item].value;
            else content.value = obj[item];

            content.filename = obj[item].filename || null;
            content.mime = obj[item].mime || null;

            if (content.value instanceof stream.Stream) {
                result.append(item, content.value, {
                    contentType: content.mime,
                    filename: content.filename,
                });

                return;
            }

            if (Buffer.isBuffer(content.value)) {
                file = FileType(content.value);
                result.append(item, content.value, {
                    contentType: content.mime || file.mime || 'application/octet-stream',
                    filename: content.filename || `data-${Date.now()}.${file.ext || ''}`,
                });

                return;
            }

            if (typeof content.value === 'object') {
                result.append(item, JSON.stringify(content.value), {
                    contentType: 'application/json',
                });

                return;
            }

            result.append(item, content.value);
        } else {
            if (typeof obj[item] === 'object') {
                result[item] = JSON.stringify(obj[item]);
                return;
            }

            result[item] = obj[item];
        }
    });

    return result;
}
822632
def file_should_be_skipped(
    filename: str,
    config: Mapping[str, Any],
    path: str = ''
) -> bool:
    """"""
    os_path = os.path.join(path, filename)

    normalized_path = os_path.replace('\\', '/')
    if normalized_path[1:2] == ':':
        normalized_path = normalized_path[2:]

    if path and config['safety_excludes']:
        check_exclude = '/' + filename.replace('\\', '/') + '/'
        if path and os.path.basename(path) in ('lib', ):
            check_exclude = '/' + os.path.basename(path) + check_exclude
        if safety_exclude_re.search(check_exclude):
            return True

    for skip_path in config['skip']:
        if posixpath.abspath(normalized_path) == posixpath.abspath(skip_path.replace('\\', '/')):
            return True

    position = os.path.split(filename)
    while position[1]:
        if position[1] in config['skip']:
            return True
        position = os.path.split(position[0])

    for glob in config['skip_glob']:
        if fnmatch.fnmatch(filename, glob) or fnmatch.fnmatch('/' + filename, glob):
            return True

    if not (os.path.isfile(os_path) or os.path.isdir(os_path) or os.path.islink(os_path)):
        return True

    return False
192786
function(file) {
        this.number++;

        var resource;
        var adapter = this.adapter;
        var resourceCache = adapter.resourceCache;
        var that = this;

        // ignore > map > normalize
        if (adapter.resourceIgnore(file)) {
            return Promise.resolve('');
        }
        file = adapter.resourceMap(file);
        file = this.normalize(file);

        if (this.number > this.adapter.resourceMaxNumber) {
            var errors = new Error('Exceed the maximum load limit on the number of resources');
            errors = new Resource.Error(errors, file);
            return Promise.reject(errors);
        }

        adapter.resourceBeforeLoad(file);

        if (resourceCache && this.cache[file]) {
            resource = this.cache[file];
            if (resource) {
                return resource;
            }
        }


        resource = new Promise(function(resolve, reject) {

            if (that.isRemoteFile(file)) {
                that.loadRemoteFile(file, onload);
            } else {
                that.loadLocalFile(file, onload);
            }

            function onload(errors, data) {
                if (errors) {
                    errors = new Resource.Error(errors, file);
                    reject(errors);
                } else {
                    resolve(data.toString());
                }
            }

        });


        if (resourceCache) {
            this.cache[file] = resource;
        }

        return resource;
    }