1 | /*
|
2 | * Copyright (c) 2013, Yahoo! Inc. All rights reserved.
|
3 | * Copyrights licensed under the New BSD License.
|
4 | * See the accompanying LICENSE file for terms.
|
5 | */
|
6 |
|
7 | /*jslint node:true, nomen: true */
|
8 |
|
9 | ;
|
10 |
|
11 | var libpath = require('path');
|
12 |
|
13 | /**
|
14 | Produces a normalized web path by joining all the parts and normalizing the
|
15 | filesystem-like path into web compatible url. This is useful when you have to
|
16 | generate urls based on filesystem path where unix uses `/` and windows uses `\\`.
|
17 | Node is pretty smart and it will do the heavy lifting, we just need to adjust
|
18 | the separtor so it uses the `/`. This method also support relative and absolute
|
19 | paths.
|
20 |
|
21 | util.webpath('foo/bar' ,'baz');
|
22 | // => foo/bar/baz
|
23 | util.webpath('foo\\bar', 'baz/');
|
24 | // => foo/bar/baz/
|
25 | util.webpath('./foo/bar', './baz');
|
26 | // => foo/bar/baz
|
27 | util.webpath(['foo', 'bar', 'baz']);
|
28 | // => foo/bar/baz
|
29 |
|
30 | @method webpath
|
31 | @param {Array|String*} url the list of parts to be joined and normalized
|
32 | @return {String} The joined and normalized url
|
33 | **/
|
34 | exports.webpath = function (url) {
|
35 | var args = [].concat.apply([], arguments),
|
36 | parts = libpath.join.apply(libpath, args).split(libpath.sep);
|
37 | return parts.join('/');
|
38 | };
|