Skip to content

Commit 804c8dc

Browse files
committed
linting
1 parent 1d2fffd commit 804c8dc

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @eslint-community/eslint-comments/disable-enable-pair */
2+
/* eslint-disable @typescript-eslint/no-magic-numbers */
13
const numbers = '0123456789';
24
/**
35
* Retrieves the computer's locale decimal separator.
@@ -19,9 +21,9 @@ export function parseNumeric(numericString, userParsingOptions) {
1921
if (numericString === undefined || numericString === null) {
2022
return undefined;
2123
}
22-
const options = Object.assign({}, defaultParsingOptions, userParsingOptions);
24+
const options = { ...defaultParsingOptions, ...userParsingOptions };
2325
let finalMultiplier = 1;
24-
let processingString = (numericString ?? '').trim().toLowerCase();
26+
let processingString = numericString.trim().toLowerCase();
2527
/*
2628
* Remove thousands separators
2729
*/

index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable @eslint-community/eslint-comments/disable-enable-pair */
2+
/* eslint-disable @typescript-eslint/no-magic-numbers */
3+
14
type DecimalSeparator = '.' | ','
25

36
const numbers = '0123456789'
@@ -41,11 +44,11 @@ export function parseNumeric(
4144
return undefined
4245
}
4346

44-
const options = Object.assign({}, defaultParsingOptions, userParsingOptions)
47+
const options = { ...defaultParsingOptions, ...userParsingOptions}
4548

4649
let finalMultiplier = 1
4750

48-
let processingString = (numericString ?? '').trim().toLowerCase()
51+
let processingString = numericString.trim().toLowerCase()
4952

5053
/*
5154
* Remove thousands separators

test/test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1+
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
2+
/* eslint-disable @typescript-eslint/no-magic-numbers */
13
import assert from 'node:assert';
24
import { describe, it } from 'node:test';
35
import stringToNumeric from '../index.js';
46
await describe('string-to-numeric', async () => {
5-
await it('Converts simple strings into numeric values', async () => {
7+
await it('Converts simple strings into numeric values', () => {
68
assert.strictEqual(stringToNumeric('33'), 33);
79
assert.strictEqual(stringToNumeric('1.1'), 1.1);
810
});
9-
await it('Converts strings with thousands separators into numeric values', async () => {
11+
await it('Converts strings with thousands separators into numeric values', () => {
1012
assert.strictEqual(stringToNumeric('1,234.1'), 1234.1);
1113
assert.strictEqual(stringToNumeric('1.234,1', {
1214
decimalSeparator: ','
1315
}), 1234.1);
1416
});
15-
await it('Converts strings with leading decimal into numeric values', async () => {
17+
await it('Converts strings with leading decimal into numeric values', () => {
1618
assert.strictEqual(stringToNumeric('.2'), 0.2);
1719
assert.strictEqual(stringToNumeric(',3', { decimalSeparator: ',' }), 0.3);
1820
});
19-
await it('Converts strings with leading units into numeric values', async () => {
21+
await it('Converts strings with leading units into numeric values', () => {
2022
assert.strictEqual(stringToNumeric('$2'), 2);
2123
assert.strictEqual(stringToNumeric('# 456'), 456);
2224
assert.strictEqual(stringToNumeric('No. 812'), 812);
2325
assert.strictEqual(stringToNumeric('$58,742.200'), 58_742.2);
2426
});
25-
await it('Converts strings with trailing units into numeric values', async () => {
27+
await it('Converts strings with trailing units into numeric values', () => {
2628
assert.strictEqual(stringToNumeric('99 red balloons'), 99);
2729
assert.strictEqual(stringToNumeric('100mm'), 100);
2830
});
29-
await it('Converts strings with negative indicators into numeric values', async () => {
31+
await it('Converts strings with negative indicators into numeric values', () => {
3032
assert.strictEqual(stringToNumeric('-2'), -2);
3133
assert.strictEqual(stringToNumeric('(4.2)'), -4.2);
3234
assert.strictEqual(stringToNumeric('($4.000)'), -4);
3335
});
34-
await it('Handles errors', async () => {
36+
await it('Handles errors', () => {
3537
// eslint-disable-next-line unicorn/no-useless-undefined, @typescript-eslint/no-confusing-void-expression
3638
assert.strictEqual(stringToNumeric(undefined), undefined);
3739
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression, unicorn/no-null

test/test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
2+
/* eslint-disable @typescript-eslint/no-magic-numbers */
3+
14
import assert from 'node:assert'
25
import { describe, it } from 'node:test'
36

47
import stringToNumeric from '../index.js'
58

69
await describe('string-to-numeric', async () => {
7-
await it('Converts simple strings into numeric values', async () => {
10+
await it('Converts simple strings into numeric values', () => {
811
assert.strictEqual(stringToNumeric('33'), 33)
912
assert.strictEqual(stringToNumeric('1.1'), 1.1)
1013
})
1114

12-
await it('Converts strings with thousands separators into numeric values', async () => {
15+
await it('Converts strings with thousands separators into numeric values', () => {
1316
assert.strictEqual(stringToNumeric('1,234.1'), 1234.1)
1417

1518
assert.strictEqual(
@@ -20,13 +23,13 @@ await describe('string-to-numeric', async () => {
2023
)
2124
})
2225

23-
await it('Converts strings with leading decimal into numeric values', async () => {
26+
await it('Converts strings with leading decimal into numeric values', () => {
2427
assert.strictEqual(stringToNumeric('.2'), 0.2)
2528

2629
assert.strictEqual(stringToNumeric(',3', {decimalSeparator: ','}), 0.3)
2730
})
2831

29-
await it('Converts strings with leading units into numeric values', async () => {
32+
await it('Converts strings with leading units into numeric values', () => {
3033
assert.strictEqual(stringToNumeric('$2'), 2)
3134

3235
assert.strictEqual(stringToNumeric('# 456'), 456)
@@ -36,21 +39,21 @@ await describe('string-to-numeric', async () => {
3639
assert.strictEqual(stringToNumeric('$58,742.200'), 58_742.2)
3740
})
3841

39-
await it('Converts strings with trailing units into numeric values', async () => {
42+
await it('Converts strings with trailing units into numeric values', () => {
4043
assert.strictEqual(stringToNumeric('99 red balloons'), 99)
4144

4245
assert.strictEqual(stringToNumeric('100mm'), 100)
4346
})
4447

45-
await it('Converts strings with negative indicators into numeric values', async () => {
48+
await it('Converts strings with negative indicators into numeric values', () => {
4649
assert.strictEqual(stringToNumeric('-2'), -2)
4750

4851
assert.strictEqual(stringToNumeric('(4.2)'), -4.2)
4952

5053
assert.strictEqual(stringToNumeric('($4.000)'), -4)
5154
})
5255

53-
await it('Handles errors', async () => {
56+
await it('Handles errors', () => {
5457
// eslint-disable-next-line unicorn/no-useless-undefined, @typescript-eslint/no-confusing-void-expression
5558
assert.strictEqual(stringToNumeric(undefined), undefined)
5659

0 commit comments

Comments
 (0)