UNPKG

1.89 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
9exports.default = function (path) {
10 var BabelRootImportHelper = function () {
11 function BabelRootImportHelper() {
12 _classCallCheck(this, BabelRootImportHelper);
13
14 this.root = global.rootPath || process.cwd();
15 }
16
17 _createClass(BabelRootImportHelper, [{
18 key: 'transformRelativeToRootPath',
19 value: function transformRelativeToRootPath(path, rootPathSuffix) {
20 if (this.hasRoot(path)) {
21 var withoutRoot = path.substring(1, path.length);
22 return '' + this.root + (rootPathSuffix ? rootPathSuffix : '') + '/' + withoutRoot;
23 }
24 if (typeof path === 'string') {
25 return path;
26 }
27 throw new Error('ERROR: No path passed');
28 }
29 }, {
30 key: 'hasRoot',
31 value: function hasRoot(string) {
32 var containsTilde = false;
33
34 if (typeof string !== 'string') {
35 return false;
36 }
37
38 var firstChar = string.substring(0, 1);
39 return firstChar === '/';
40 }
41 }]);
42
43 return BabelRootImportHelper;
44 }();
45
46 return new BabelRootImportHelper();
47};
48
49function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
\No newline at end of file