Fix #109: is.numericString behaves correctly on whitespaces
This commit is contained in:
parent
05cdaccf92
commit
3d0bf3e7cd
2 changed files with 5 additions and 2 deletions
|
|
@ -130,7 +130,7 @@ is.boolean = (value: unknown): value is boolean => value === true || value === f
|
||||||
is.symbol = isOfType<symbol>('symbol');
|
is.symbol = isOfType<symbol>('symbol');
|
||||||
|
|
||||||
is.numericString = (value: unknown): value is string =>
|
is.numericString = (value: unknown): value is string =>
|
||||||
is.string(value) && value.length > 0 && !Number.isNaN(Number(value));
|
is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
|
||||||
|
|
||||||
is.array = Array.isArray;
|
is.array = Array.isArray;
|
||||||
is.buffer = (value: unknown): value is Buffer => (value as any)?.constructor?.isBuffer?.(value) ?? false;
|
is.buffer = (value: unknown): value is Buffer => (value as any)?.constructor?.isBuffer?.(value) ?? false;
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,8 @@ const types = new Map<string, Test>([
|
||||||
fixtures: [
|
fixtures: [
|
||||||
'5',
|
'5',
|
||||||
'-3.2',
|
'-3.2',
|
||||||
'Infinity'
|
'Infinity',
|
||||||
|
'0x56'
|
||||||
],
|
],
|
||||||
typename: TypeName.string,
|
typename: TypeName.string,
|
||||||
typeDescription: AssertionTypeDescription.numericString
|
typeDescription: AssertionTypeDescription.numericString
|
||||||
|
|
@ -627,6 +628,8 @@ test('is.symbol', t => {
|
||||||
test('is.numericString', t => {
|
test('is.numericString', t => {
|
||||||
testType(t, 'numericString');
|
testType(t, 'numericString');
|
||||||
t.false(is.numericString(''));
|
t.false(is.numericString(''));
|
||||||
|
t.false(is.numericString(' '));
|
||||||
|
t.false(is.numericString(' \t\t\n'));
|
||||||
t.false(is.numericString(1));
|
t.false(is.numericString(1));
|
||||||
t.throws(() => {
|
t.throws(() => {
|
||||||
assert.numericString('');
|
assert.numericString('');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue