refactor(RegExpWrapper): remove the facade (#10512)
This commit is contained in:
committed by
Alex Rickabaugh
parent
b4613ab2d2
commit
83e2d3d1cb
@@ -9,12 +9,12 @@
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
import {NumberFormatStyle, NumberFormatter} from '../facade/intl';
|
||||
import {NumberWrapper, RegExpWrapper, Type, isBlank, isNumber, isPresent, isString} from '../facade/lang';
|
||||
import {NumberWrapper, Type, isBlank, isNumber, isPresent, isString} from '../facade/lang';
|
||||
|
||||
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||
|
||||
var defaultLocale: string = 'en-US';
|
||||
const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/g;
|
||||
const _NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(\-(\d+))?)?$/;
|
||||
|
||||
function formatNumber(
|
||||
pipe: Type, value: number | string, style: NumberFormatStyle, digits: string,
|
||||
@@ -36,8 +36,8 @@ function formatNumber(
|
||||
}
|
||||
|
||||
if (isPresent(digits)) {
|
||||
var parts = RegExpWrapper.firstMatch(_NUMBER_FORMAT_REGEXP, digits);
|
||||
if (!parts) {
|
||||
var parts = digits.match(_NUMBER_FORMAT_REGEXP);
|
||||
if (parts === null) {
|
||||
throw new Error(`${digits} is not a valid digit info for number pipes`);
|
||||
}
|
||||
if (isPresent(parts[1])) { // min integer digits
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {RegExpWrapper, StringWrapper, isBlank, isFunction, isNumber, isString} from '../facade/lang';
|
||||
import {StringWrapper, isBlank, isFunction, isNumber, isString} from '../facade/lang';
|
||||
import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
|
||||
|
||||
/**
|
||||
@@ -61,7 +61,7 @@ export class ReplacePipe implements PipeTransform {
|
||||
}
|
||||
|
||||
if (isFunction(replacement)) {
|
||||
const rgxPattern = isString(pattern) ? RegExpWrapper.create(pattern) : pattern;
|
||||
const rgxPattern = isString(pattern) ? new RegExp(pattern, 'g') : pattern;
|
||||
|
||||
return StringWrapper.replaceAllMapped(
|
||||
input, rgxPattern, <(m: string[]) => string>replacement);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject,} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {ReplacePipe} from '@angular/common';
|
||||
import {RegExpWrapper, StringJoiner} from '../../src/facade/lang';
|
||||
import {StringJoiner} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
describe('ReplacePipe', () => {
|
||||
@@ -45,9 +45,9 @@ export function main() {
|
||||
it('should return a new string with the pattern replaced', () => {
|
||||
var result1 = pipe.transform(str, 'Douglas', 'Hugh');
|
||||
|
||||
var result2 = pipe.transform(str, RegExpWrapper.create('a'), '_');
|
||||
var result2 = pipe.transform(str, /a/g, '_');
|
||||
|
||||
var result3 = pipe.transform(str, RegExpWrapper.create('a', 'i'), '_');
|
||||
var result3 = pipe.transform(str, /a/gi, '_');
|
||||
|
||||
var f = ((x: any) => { return 'Adams!'; });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user