本文整理汇总了TypeScript中@angular/common/src/facade/lang.isPresent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isPresent函数的具体用法?TypeScript isPresent怎么用?TypeScript isPresent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isPresent函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: format
static format(defaultLocale: string, value: number, style: NumberFormatStyle, digits: string, currency: string = null, currencyAsSymbol: boolean = false): string {
if (isBlank(value)) return null;
if (!isNumber(value)) {
throw new InvalidPipeArgumentException(LocaleNumber, value);
}
var minInt = 1, minFraction = 0, maxFraction = 3;
var re = RegExpWrapper.create('^(\\d+)?\\.((\\d+)(\\-(\\d+))?)?$');
if (isPresent(digits)) {
var parts = RegExpWrapper.firstMatch(re, digits);
if (isBlank(parts)) {
throw new BaseException(`${digits} is not a valid digit info for number pipes`);
}
if (isPresent(parts[1])) { // Min integer digits.
minInt = NumberWrapper.parseIntAutoRadix(parts[1]);
}
if (isPresent(parts[3])) { // Min fraction digits.
minFraction = NumberWrapper.parseIntAutoRadix(parts[3]);
}
if (isPresent(parts[5])) { // Max fraction digits.
maxFraction = NumberWrapper.parseIntAutoRadix(parts[5]);
}
}
return NumberFormatter.format(value, defaultLocale, style, {
minimumIntegerDigits: minInt,
minimumFractionDigits: minFraction,
maximumFractionDigits: maxFraction,
currency: currency,
currencyAsSymbol: currencyAsSymbol
});
}
示例2: validateEmail
export function validateEmail(control: Control) {
let pattern: RegExp = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
if (isPresent(Validators.required(control))) {
return null
}
return pattern.test(control.value) ? null : {
nbEmail: {
valid: false,
},
}
}
示例3: validateDate
export function validateDate(control: Control) {
let pattern: RegExp = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g
if (isPresent(Validators.required(control))) {
return null
}
return pattern.test(control.value) ? null : {
nbDate: {
valid: false,
},
}
}
示例4: OneOfMetadata
return function OneOfMetadata(target: any, key: string): void {
const defaultValue = values[0];
// Use a fallback if Symbol isn't available.
const localKey = isPresent(Symbol) ? Symbol(key) : `@@$${key}_`;
target[localKey] = defaultValue;
Object.defineProperty(target, key, {
get() { return this[localKey]; },
set(v) {
if (values.indexOf(v) === -1) {
this[localKey] = defaultValue;
} else {
this[localKey] = v;
}
}
});
};
示例5: parseTabIndexAttribute
export function parseTabIndexAttribute(attr: any): number {
return isPresent(attr) ? NumberWrapper.parseInt(attr, 10) : 0;
}