feat(datePipe): numeric string support
This commit is contained in:

committed by
Victor Berchet

parent
40f8a45b95
commit
5c8d3154d7
@ -189,6 +189,13 @@ class NumberWrapper {
|
||||
|
||||
static double get NaN => double.NAN;
|
||||
|
||||
static bool isNumeric(value) {
|
||||
if(value == null) {
|
||||
return false;
|
||||
}
|
||||
return double.parse(value, (e) => null) != null;
|
||||
}
|
||||
|
||||
static bool isNaN(num value) => value.isNaN;
|
||||
|
||||
static bool isInteger(value) => value is int;
|
||||
|
@ -320,6 +320,8 @@ export class NumberWrapper {
|
||||
|
||||
static get NaN(): number { return NaN; }
|
||||
|
||||
static isNumeric(value: any): boolean { return !isNaN(value - parseFloat(value)); }
|
||||
|
||||
static isNaN(value: any): boolean { return isNaN(value); }
|
||||
|
||||
static isInteger(value: any): boolean { return Number.isInteger(value); }
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {beforeEach, ddescribe, describe, expect, iit, it, xit} from '@angular/core/testing';
|
||||
|
||||
import {RegExpMatcherWrapper, RegExpWrapper, StringWrapper, hasConstructor, isPresent, resolveEnumToken} from '../src/lang';
|
||||
import {NumberWrapper, RegExpMatcherWrapper, RegExpWrapper, StringWrapper, hasConstructor, isPresent, resolveEnumToken} from '../src/lang';
|
||||
|
||||
enum UsefulEnum {
|
||||
MyToken,
|
||||
@ -51,6 +50,28 @@ export function main() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Number', () => {
|
||||
describe('isNumeric', () => {
|
||||
it('should return true when passing correct numeric string',
|
||||
() => { expect(NumberWrapper.isNumeric('2')).toBe(true); });
|
||||
|
||||
it('should return true when passing correct double string',
|
||||
() => { expect(NumberWrapper.isNumeric('1.123')).toBe(true); });
|
||||
|
||||
it('should return true when passing correct negative string',
|
||||
() => { expect(NumberWrapper.isNumeric('-2')).toBe(true); });
|
||||
|
||||
it('should return true when passing correct scientific notation string',
|
||||
() => { expect(NumberWrapper.isNumeric('1e5')).toBe(true); });
|
||||
|
||||
it('should return false when passing incorrect numeric',
|
||||
() => { expect(NumberWrapper.isNumeric('a')).toBe(false); });
|
||||
|
||||
it('should return false when passing parseable but non numeric',
|
||||
() => { expect(NumberWrapper.isNumeric('2a')).toBe(false); });
|
||||
});
|
||||
});
|
||||
|
||||
describe('String', () => {
|
||||
var s: any /** TODO #9100 */;
|
||||
|
||||
|
Reference in New Issue
Block a user