refactor: remove lang.ts (#14837)

This commit is contained in:
Miško Hevery
2017-03-02 09:37:01 -08:00
committed by Chuck Jazdzewski
parent 84a65cf788
commit 8343fb7740
139 changed files with 406 additions and 676 deletions

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directive, DoCheck, ElementRef, Input, IterableChanges, IterableDiffer, IterableDiffers, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer, ɵisListLikeIterable as isListLikeIterable} from '@angular/core';
import {stringify} from '../facade/lang';
import {Directive, DoCheck, ElementRef, Input, IterableChanges, IterableDiffer, IterableDiffers, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer, ɵisListLikeIterable as isListLikeIterable, ɵstringify as stringify} from '@angular/core';
/**
* @ngModule CommonModule

View File

@ -8,8 +8,6 @@
import {ChangeDetectorRef, Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, OnChanges, SimpleChanges, TemplateRef, TrackByFunction, ViewContainerRef, forwardRef, isDevMode} from '@angular/core';
import {getTypeNameForDebugging} from '../facade/lang';
export class NgForOfRow<T> {
constructor(public $implicit: T, public index: number, public count: number) {}
@ -195,3 +193,7 @@ export type NgFor = NgForOf<any>;
* @deprecated from v4.0.0 - Use NgForOf instead.
*/
export const NgFor = NgForOf;
export function getTypeNameForDebugging(type: any): string {
return type['name'] || typeof type;
}

View File

@ -1 +0,0 @@
../../facade/src

View File

@ -8,7 +8,6 @@
import {Inject, Injectable, Optional} from '@angular/core';
import {isPresent} from '../facade/lang';
import {Location} from './location';
import {APP_BASE_HREF, LocationStrategy} from './location_strategy';
@ -40,7 +39,7 @@ export class HashLocationStrategy extends LocationStrategy {
private _platformLocation: PlatformLocation,
@Optional() @Inject(APP_BASE_HREF) _baseHref?: string) {
super();
if (isPresent(_baseHref)) {
if (_baseHref != null) {
this._baseHref = _baseHref;
}
}
@ -56,7 +55,7 @@ export class HashLocationStrategy extends LocationStrategy {
// the hash value is always prefixed with a `#`
// and if it is empty then it will stay empty
let path = this._platformLocation.hash;
if (!isPresent(path)) path = '#';
if (path == null) path = '#';
return path.length > 0 ? path.substring(1) : path;
}

View File

@ -8,7 +8,6 @@
import {Inject, Injectable, Optional} from '@angular/core';
import {isBlank} from '../facade/lang';
import {Location} from './location';
import {APP_BASE_HREF, LocationStrategy} from './location_strategy';
@ -51,11 +50,11 @@ export class PathLocationStrategy extends LocationStrategy {
@Optional() @Inject(APP_BASE_HREF) href?: string) {
super();
if (isBlank(href)) {
if (href == null) {
href = this._platformLocation.getBaseHrefFromDOM();
}
if (isBlank(href)) {
if (href == null) {
throw new Error(
`No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.`);
}

View File

@ -7,9 +7,9 @@
*/
import {Inject, LOCALE_ID, Pipe, PipeTransform} from '@angular/core';
import {NumberWrapper} from '../facade/lang';
import {DateFormatter} from './intl';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
import {isNumeric} from './number_pipe';
const ISO8601_DATE_REGEX =
/^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?::?(\d\d)(?::?(\d\d)(?:\.(\d+))?)?)?(Z|([+-])(\d\d):?(\d\d))?)?$/;
@ -111,7 +111,7 @@ export class DatePipe implements PipeTransform {
if (isDate(value)) {
date = value;
} else if (NumberWrapper.isNumeric(value)) {
} else if (isNumeric(value)) {
date = new Date(parseFloat(value));
} else if (typeof value === 'string' && /^(\d{4}-\d{1,2}-\d{1,2})$/.test(value)) {
/**

View File

@ -6,9 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '@angular/core';
import {stringify} from '../facade/lang';
import {Type, ɵstringify as stringify} from '@angular/core';
export function invalidPipeArgumentError(type: Type<any>, value: Object) {
return Error(`InvalidPipeArgument: '${value}' for pipe '${stringify(type)}'`);

View File

@ -7,9 +7,6 @@
*/
import {Inject, LOCALE_ID, Pipe, PipeTransform, Type} from '@angular/core';
import {NumberWrapper} from '../facade/lang';
import {NumberFormatStyle, NumberFormatter} from './intl';
import {invalidPipeArgumentError} from './invalid_pipe_argument_error';
@ -21,7 +18,7 @@ function formatNumber(
if (value == null) return null;
// Convert strings to numbers
value = typeof value === 'string' && NumberWrapper.isNumeric(value) ? +value : value;
value = typeof value === 'string' && isNumeric(value) ? +value : value;
if (typeof value !== 'number') {
throw invalidPipeArgumentError(pipe, value);
}
@ -42,13 +39,13 @@ function formatNumber(
throw new Error(`${digits} is not a valid digit info for number pipes`);
}
if (parts[1] != null) { // min integer digits
minInt = NumberWrapper.parseIntAutoRadix(parts[1]);
minInt = parseIntAutoRadix(parts[1]);
}
if (parts[3] != null) { // min fraction digits
minFraction = NumberWrapper.parseIntAutoRadix(parts[3]);
minFraction = parseIntAutoRadix(parts[3]);
}
if (parts[5] != null) { // max fraction digits
maxFraction = NumberWrapper.parseIntAutoRadix(parts[5]);
maxFraction = parseIntAutoRadix(parts[5]);
}
}
@ -162,3 +159,15 @@ export class CurrencyPipe implements PipeTransform {
symbolDisplay);
}
}
function parseIntAutoRadix(text: string): number {
const result: number = parseInt(text);
if (isNaN(result)) {
throw new Error('Invalid integer literal when parsing ' + text);
}
return result;
}
export function isNumeric(value: any): boolean {
return !isNaN(value - parseFloat(value));
}