Issues (5)

impl/path.js (1 issue)

Severity
1
"use strict";
2
3
/*  ------------------------------------------------------------------------ */
4
5
const isBrowser = (typeof window !== 'undefined') && (window.window === window) && window.navigator
0 ignored issues
show
Parsing error: Unexpected token const
Loading history...
6
const cwd = isBrowser ? window.location.href : process.cwd ()
7
8
/*  ------------------------------------------------------------------------ */
9
10
const path = module.exports = {
11
12
    concat (a, b) {
13
14
                const a_endsWithSlash = (a[a.length - 1] === '/'),
15
                      b_startsWithSlash = (b[0] === '/')
16
17
                return a + ((a_endsWithSlash || b_startsWithSlash) ? '' : '/') +
18
                           ((a_endsWithSlash && b_startsWithSlash) ? b.substring (1) : b) },
19
20
    resolve (x) {
21
22
        if (path.isAbsolute (x)) {
23
            return path.normalize (x) }
24
25
        return path.normalize (path.concat (cwd, x))
26
    },
27
28
    normalize (x) {
29
30
        let output = [],
31
            skip = 0
32
33
        x.split ('/').reverse ().filter (x => x !== '.').forEach (x => {
34
35
                 if (x === '..') { skip++ }
36
            else if (skip === 0) { output.push (x) }
37
            else                 { skip-- }
38
        })
39
40
        const result = output.reverse ().join ('/')
41
42
        return ((isBrowser && (result[0] === '/')) ? window.location.origin : '') + result
43
    },
44
45
    isData: x => x.indexOf ('data:') === 0,
46
47
    isAbsolute: x => (x[0] === '/') || /^[^\/]*:/.test (x),
48
49
    relativeToFile (a, b) {
50
        
51
        return (path.isData (a) || path.isAbsolute (b)) ?
52
                    path.normalize (b) :
53
                    path.normalize (path.concat (a.split ('/').slice (0, -1).join ('/'), b))
54
    }
55
}
56
57
/*  ------------------------------------------------------------------------ */
58