UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.DefaultTypeNameConvertor = function (id) {
4 var url = id.id;
5 var ids = [];
6 if (url.host) {
7 ids.push(decodeURIComponent(url.host));
8 }
9 var addAllParts = function (path) {
10 var paths = path.split('/');
11 if (paths.length > 1 && paths[0] === '') {
12 paths.shift();
13 }
14 paths.forEach(function (item) {
15 ids.push(decodeURIComponent(item));
16 });
17 };
18 if (url.pathname) {
19 addAllParts(url.pathname);
20 }
21 if (url.hash && url.hash.length > 1) {
22 addAllParts(url.hash.substr(1));
23 }
24 return ids.map(toTypeName);
25};
26function toTypeName(str) {
27 if (!str) {
28 return str;
29 }
30 str = str.trim();
31 return str.split('$').map(function (s) { return s.replace(/(?:^|[^A-Za-z0-9])([A-Za-z0-9])/g, function (_, m) {
32 return m.toUpperCase();
33 }); }).join('$');
34}
35function normalizeTypeName(type) {
36 type = type.replace(/^\//, '').replace(/[^0-9A-Za-z_$]+/g, '_');
37 if (/^\d/.test(type)) {
38 type = '$' + type;
39 }
40 return type;
41}
42exports.normalizeTypeName = normalizeTypeName;
43//# sourceMappingURL=typeNameConvertor.js.map
\No newline at end of file