util.js
4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { BaseError } from './facade/errors';
import { isPrimitive, isStrictStringMap } from './facade/lang';
export var /** @type {?} */ MODULE_SUFFIX = '';
var /** @type {?} */ CAMEL_CASE_REGEXP = /([A-Z])/g;
var /** @type {?} */ DASH_CASE_REGEXP = /-+([a-z0-9])/g;
/**
* @param {?} input
* @return {?}
*/
export function camelCaseToDashCase(input) {
return input.replace(CAMEL_CASE_REGEXP, function () {
var m = [];
for (var _i = 0; _i < arguments.length; _i++) {
m[_i - 0] = arguments[_i];
}
return '-' + m[1].toLowerCase();
});
}
/**
* @param {?} input
* @return {?}
*/
export function dashCaseToCamelCase(input) {
return input.replace(DASH_CASE_REGEXP, function () {
var m = [];
for (var _i = 0; _i < arguments.length; _i++) {
m[_i - 0] = arguments[_i];
}
return m[1].toUpperCase();
});
}
/**
* @param {?} input
* @param {?} defaultValues
* @return {?}
*/
export function splitAtColon(input, defaultValues) {
return _splitAt(input, ':', defaultValues);
}
/**
* @param {?} input
* @param {?} defaultValues
* @return {?}
*/
export function splitAtPeriod(input, defaultValues) {
return _splitAt(input, '.', defaultValues);
}
/**
* @param {?} input
* @param {?} character
* @param {?} defaultValues
* @return {?}
*/
function _splitAt(input, character, defaultValues) {
var /** @type {?} */ characterIndex = input.indexOf(character);
if (characterIndex == -1)
return defaultValues;
return [input.slice(0, characterIndex).trim(), input.slice(characterIndex + 1).trim()];
}
/**
* @param {?} value
* @param {?} visitor
* @param {?} context
* @return {?}
*/
export function visitValue(value, visitor, context) {
if (Array.isArray(value)) {
return visitor.visitArray(/** @type {?} */ (value), context);
}
if (isStrictStringMap(value)) {
return visitor.visitStringMap(/** @type {?} */ (value), context);
}
if (value == null || isPrimitive(value)) {
return visitor.visitPrimitive(value, context);
}
return visitor.visitOther(value, context);
}
export var ValueTransformer = (function () {
function ValueTransformer() {
}
/**
* @param {?} arr
* @param {?} context
* @return {?}
*/
ValueTransformer.prototype.visitArray = function (arr, context) {
var _this = this;
return arr.map(function (value) { return visitValue(value, _this, context); });
};
/**
* @param {?} map
* @param {?} context
* @return {?}
*/
ValueTransformer.prototype.visitStringMap = function (map, context) {
var _this = this;
var /** @type {?} */ result = {};
Object.keys(map).forEach(function (key) { result[key] = visitValue(map[key], _this, context); });
return result;
};
/**
* @param {?} value
* @param {?} context
* @return {?}
*/
ValueTransformer.prototype.visitPrimitive = function (value, context) { return value; };
/**
* @param {?} value
* @param {?} context
* @return {?}
*/
ValueTransformer.prototype.visitOther = function (value, context) { return value; };
return ValueTransformer;
}());
export var SyncAsyncResult = (function () {
/**
* @param {?} syncResult
* @param {?=} asyncResult
*/
function SyncAsyncResult(syncResult, asyncResult) {
if (asyncResult === void 0) { asyncResult = null; }
this.syncResult = syncResult;
this.asyncResult = asyncResult;
if (!asyncResult) {
this.asyncResult = Promise.resolve(syncResult);
}
}
return SyncAsyncResult;
}());
function SyncAsyncResult_tsickle_Closure_declarations() {
/** @type {?} */
SyncAsyncResult.prototype.syncResult;
/** @type {?} */
SyncAsyncResult.prototype.asyncResult;
}
export var SyntaxError = (function (_super) {
__extends(SyntaxError, _super);
function SyntaxError() {
_super.apply(this, arguments);
}
return SyntaxError;
}(BaseError));
//# sourceMappingURL=util.js.map