Debian Codegraph @

path2/posix/normalize.js

raw
1 'use strict';
2
3 var isAbsolute = require('./is-absolute')
4 , normalizeArray = require('../_normalize-array');
5
6 module.exports = function (path) {
7 var isAbs = isAbsolute(path), trailingSlash = path[path.length - 1] === '/',
8 segments = path.split('/'), nonEmptySegments = [], i;
9
10 // Normalize the path
11 for (i = 0; i < segments.length; i++) {
12 if (segments[i]) {
13 nonEmptySegments.push(segments[i]);
14 }
15 }
16 path = normalizeArray(nonEmptySegments, !isAbs).join('/');
17
18 if (!path && !isAbs) {
19 path = '.';
20 }
21 if (path && trailingSlash) {
22 path += '/';
23 }
24
25 return (isAbs ? '/' : '') + path;
26 };