assertions.js
1.72 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
/**
* @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
*/
import { isDevMode } from '@angular/core';
import { isBlank, isPresent } from '../src/facade/lang';
/**
* @param {?} identifier
* @param {?} value
* @return {?}
*/
export function assertArrayOfStrings(identifier, value) {
if (!isDevMode() || isBlank(value)) {
return;
}
if (!Array.isArray(value)) {
throw new Error("Expected '" + identifier + "' to be an array of strings.");
}
for (var /** @type {?} */ i = 0; i < value.length; i += 1) {
if (typeof value[i] !== 'string') {
throw new Error("Expected '" + identifier + "' to be an array of strings.");
}
}
}
var /** @type {?} */ INTERPOLATION_BLACKLIST_REGEXPS = [
/^\s*$/,
/[<>]/,
/^[{}]$/,
/&(#|[a-z])/i,
/^\/\//,
];
/**
* @param {?} identifier
* @param {?} value
* @return {?}
*/
export function assertInterpolationSymbols(identifier, value) {
if (isPresent(value) && !(Array.isArray(value) && value.length == 2)) {
throw new Error("Expected '" + identifier + "' to be an array, [start, end].");
}
else if (isDevMode() && !isBlank(value)) {
var /** @type {?} */ start_1 = (value[0]);
var /** @type {?} */ end_1 = (value[1]);
// black list checking
INTERPOLATION_BLACKLIST_REGEXPS.forEach(function (regexp) {
if (regexp.test(start_1) || regexp.test(end_1)) {
throw new Error("['" + start_1 + "', '" + end_1 + "'] contains unusable interpolation symbol.");
}
});
}
}
//# sourceMappingURL=assertions.js.map