Add is.numericString()
This commit is contained in:
parent
c983ffa4cd
commit
b407e383f8
2 changed files with 12 additions and 1 deletions
|
|
@ -135,10 +135,13 @@ namespace is { // tslint:disable-line:no-namespace
|
|||
export const symbol = isOfType<Symbol>('symbol');
|
||||
// tslint:enable:variable-name
|
||||
|
||||
export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value);
|
||||
export const numericString = (value: any): value is String =>
|
||||
!Number.isNaN(Number(value)) && !nullOrUndefined(value);
|
||||
|
||||
export const array = Array.isArray;
|
||||
export const buffer = isBuffer;
|
||||
|
||||
export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value);
|
||||
export const object = (value: any): value is object => !nullOrUndefined(value) && (function_(value) || isObject(value));
|
||||
export const iterable = (value: any): value is IterableIterator<any> => !nullOrUndefined(value) && function_(value[Symbol.iterator]);
|
||||
export const asyncIterable = (value: any): value is AsyncIterableIterator<any> => !nullOrUndefined(value) && function_(value[Symbol.asyncIterator]);
|
||||
|
|
|
|||
|
|
@ -426,6 +426,14 @@ test('is.symbol', t => {
|
|||
testType(t, 'symbol');
|
||||
});
|
||||
|
||||
test('is.numericString', t => {
|
||||
t.true(m.numericString('5'));
|
||||
t.true(m.numericString('-3.2'));
|
||||
t.true(m.numericString('Infinity'));
|
||||
t.false(m.numericString(undefined));
|
||||
t.false(m.numericString(null));
|
||||
});
|
||||
|
||||
test('is.array', t => {
|
||||
testType(t, 'array', ['emptyArray']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue