function before_stack(href, filePath) { const stack = href.split('/'); const parts = filePath.split('/'); stack.pop(); for (const part of parts) { if (part === '.') { continue; } else if (part === '..') { stack.pop(); } else { stack.push(part); } } return `url(${stack.join('/')})`; } function after_url(href, filePath) { try { return `url(${new URL(filePath, href, ).toString()})` } catch(e) { return 'eerr' }}
before_stack('http://localhost/css/style.css', "../a.jpg")
after_url('http://localhost/css/style.css', "../a.jpg")