Improve tests and check if string is empty
This commit is contained in:
parent
522c7482f2
commit
605b4f4470
2 changed files with 14 additions and 6 deletions
|
|
@ -136,8 +136,8 @@ namespace is { // tslint:disable-line:no-namespace
|
||||||
// tslint:enable:variable-name
|
// tslint:enable:variable-name
|
||||||
|
|
||||||
export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value);
|
export const nullOrUndefined = (value: any): value is null | undefined => null_(value) || undefined(value);
|
||||||
export const numericString = (value: string): boolean =>
|
export const numericString = (value: any): boolean =>
|
||||||
!Number.isNaN(Number(value));
|
string(value) && value.length > 0 && !Number.isNaN(Number(value));
|
||||||
|
|
||||||
export const array = Array.isArray;
|
export const array = Array.isArray;
|
||||||
export const buffer = isBuffer;
|
export const buffer = isBuffer;
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,14 @@ const types = new Map<string, Test>([
|
||||||
Symbol('🦄')
|
Symbol('🦄')
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
|
['numericString', {
|
||||||
|
is: m.numericString,
|
||||||
|
fixtures: [
|
||||||
|
'5',
|
||||||
|
'-3.2',
|
||||||
|
'Infinity'
|
||||||
|
]
|
||||||
|
}],
|
||||||
['array', {
|
['array', {
|
||||||
is: m.array,
|
is: m.array,
|
||||||
fixtures: [
|
fixtures: [
|
||||||
|
|
@ -411,7 +419,7 @@ test('is.null', t => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is.string', t => {
|
test('is.string', t => {
|
||||||
testType(t, 'string', ['emptyString']);
|
testType(t, 'string', ['emptyString', 'numericString']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is.number', t => {
|
test('is.number', t => {
|
||||||
|
|
@ -427,9 +435,9 @@ test('is.symbol', t => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is.numericString', t => {
|
test('is.numericString', t => {
|
||||||
t.true(m.numericString('5'));
|
testType(t, 'numericString');
|
||||||
t.true(m.numericString('-3.2'));
|
t.false(m.numericString(''));
|
||||||
t.true(m.numericString('Infinity'));
|
t.false(m.numericString(1));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is.array', t => {
|
test('is.array', t => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue