UNPKG

2.8 kBJavaScriptView Raw
1'use strict';
2
3var _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; }; })();
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8
9exports.default = function () {
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(importPath, rootPathSuffix, rootPathPrefix) {
20 var withoutRootPathPrefix = '';
21 if (this.hasRootPathPrefixInString(importPath, rootPathPrefix)) {
22 if (importPath.substring(0, 1) === '/') {
23 withoutRootPathPrefix = importPath.substring(1, importPath.length);
24 } else {
25 withoutRootPathPrefix = importPath.substring(2, importPath.length);
26 }
27 return '' + (0, _slash2.default)(this.root) + (rootPathSuffix ? rootPathSuffix : '') + '/' + withoutRootPathPrefix;
28 }
29
30 if (typeof importPath === 'string') {
31 return importPath;
32 }
33
34 throw new Error('ERROR: No path passed');
35 }
36 }, {
37 key: 'hasRootPathPrefixInString',
38 value: function hasRootPathPrefixInString(importPath) {
39 var rootPathPrefix = arguments.length <= 1 || arguments[1] === undefined ? '~' : arguments[1];
40
41 var containsRootPathPrefix = false;
42
43 if (typeof importPath === 'string') {
44 if (importPath.substring(0, 1) === rootPathPrefix) {
45 containsRootPathPrefix = true;
46 }
47
48 var firstTwoCharactersOfString = importPath.substring(0, 2);
49 if (firstTwoCharactersOfString === rootPathPrefix + '/') {
50 containsRootPathPrefix = true;
51 }
52 }
53
54 return containsRootPathPrefix;
55 }
56 }]);
57
58 return BabelRootImportHelper;
59 })();
60
61 return new BabelRootImportHelper();
62};
63
64var _slash = require('slash');
65
66var _slash2 = _interopRequireDefault(_slash);
67
68function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
69
70function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
\No newline at end of file