增加了git功能,但是还未完善
This commit is contained in:
33
node_modules/clean-git-ref/lib/index.js
generated
vendored
Normal file
33
node_modules/clean-git-ref/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
function escapeRegExp(string) {
|
||||
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||
}
|
||||
|
||||
function replaceAll(str, search, replacement) {
|
||||
search = search instanceof RegExp ? search : new RegExp(escapeRegExp(search), 'g');
|
||||
|
||||
return str.replace(search, replacement);
|
||||
}
|
||||
|
||||
var CleanGitRef = {
|
||||
clean: function clean(value) {
|
||||
if (typeof value !== 'string') {
|
||||
throw new Error('Expected a string, received: ' + value);
|
||||
}
|
||||
|
||||
value = replaceAll(value, './', '/');
|
||||
value = replaceAll(value, '..', '.');
|
||||
value = replaceAll(value, ' ', '-');
|
||||
value = replaceAll(value, /^[~^:?*\\\-]/g, '');
|
||||
value = replaceAll(value, /[~^:?*\\]/g, '-');
|
||||
value = replaceAll(value, /[~^:?*\\\-]$/g, '');
|
||||
value = replaceAll(value, '@{', '-');
|
||||
value = replaceAll(value, /\.$/g, '');
|
||||
value = replaceAll(value, /\/$/g, '');
|
||||
value = replaceAll(value, /\.lock$/g, '');
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = CleanGitRef;
|
||||
Reference in New Issue
Block a user