UNPKG

1.06 kBJavaScriptView Raw
1/*
2 * MIT License http://opensource.org/licenses/MIT
3 * Author: Ben Holloway @bholloway
4 */
5'use strict';
6
7/**
8 * Prepend file:// protocol to source path string or source-map sources.
9 */
10function prepend(candidate) {
11 if (typeof candidate === 'string') {
12 return 'file://' + candidate;
13 } else if (candidate && (typeof candidate === 'object') && Array.isArray(candidate.sources)) {
14 return Object.assign({}, candidate, {
15 sources: candidate.sources.map(prepend)
16 });
17 } else {
18 throw new Error('expected string|object');
19 }
20}
21
22exports.prepend = prepend;
23
24/**
25 * Remove file:// protocol from source path string or source-map sources.
26 */
27function remove(candidate) {
28 if (typeof candidate === 'string') {
29 return candidate.replace(/^file:\/{2}/, '');
30 } else if (candidate && (typeof candidate === 'object') && Array.isArray(candidate.sources)) {
31 return Object.assign({}, candidate, {
32 sources: candidate.sources.map(remove)
33 });
34 } else {
35 throw new Error('expected string|object');
36 }
37}
38
39exports.remove = remove;