mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(join) add
This commit is contained in:
parent
1ae70be714
commit
bf20f6aadb
1 changed files with 36 additions and 0 deletions
36
lib/join.js
Normal file
36
lib/join.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(function(scope) {
|
||||
'use strict';
|
||||
|
||||
var Scope = scope.window ? window : global;
|
||||
|
||||
if (typeof module === 'object' && module.exports)
|
||||
module.exports = join;
|
||||
else
|
||||
Scope.join = join;
|
||||
|
||||
function join (names) {
|
||||
var url,
|
||||
regExp = new RegExp(',', 'g'),
|
||||
nameStr = names + '';
|
||||
|
||||
if (!names)
|
||||
throw(Error('names must be array!'));
|
||||
|
||||
nameStr = nameStr.replace(regExp, ':');
|
||||
nameStr = rmFirstSlash(nameStr);
|
||||
url = '/join/' + nameStr;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
function rmFirstSlash(url) {
|
||||
var regExp = new RegExp('^/'),
|
||||
is = url.match(regExp);
|
||||
|
||||
if (is)
|
||||
url = url.replace('/', '');
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
})(this);
|
||||
Loading…
Add table
Add a link
Reference in a new issue