Skip to content

Commit e9dc65c

Browse files
committed
Internal lib - Fix bug in sanitizeArray causing string values to default to 0
1 parent 353f2d2 commit e9dc65c

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/chartDetector.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function detectChart({dataset, barLineSwitch = 6}) {
6666
}
6767
dataset = dataset.map(d => uppercaseKeys(d))
6868
usableDataset = usableDataset.map(d => uppercaseKeys(d))
69+
6970
}
7071
}
7172

src/lib.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,7 @@ export function sanitizeArray(arr, keys = []) {
18471847
if ([NaN, undefined, Infinity, -Infinity, null].includes(value)) {
18481848
console.warn(`A non processable value was detected : ${value}`)
18491849
}
1850+
if (typeof value === 'string' && isNaN(Number(value))) return value;
18501851
return (typeof value === 'number' && isFinite(value)) ? value : 0;
18511852
}
18521853

tests/chartDetector.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function datasetObjectDonut(size) {
2121
const arr = []
2222
for (let i = 0; i < size; i += 1) {
2323
arr.push({
24-
name: `Serie ${i}`,
24+
name: `Serie name ${i}`,
2525
value: (i + 1) * 10
2626
})
2727
}
@@ -32,7 +32,7 @@ function datasetObjectXy(size, length) {
3232
const arr = []
3333
for (let i = 0; i < size; i += 1) {
3434
arr.push({
35-
name: `Serie ${i}`,
35+
name: `Serie name ${i}`,
3636
values: datasetNumbers(length)
3737
})
3838
}
@@ -257,7 +257,7 @@ describe('maxLengthOfArrayTypesInArrayOfObjects', () => {
257257
describe('getFirstEntryMatch', () => {
258258
test('returns the first entry in an object that matches a condition', () => {
259259
const dataset1 = datasetObjectXy(3, 3);
260-
expect(getFirstEntryMatch(dataset1[0], (v) => typeof v === 'string')).toBe('Serie 0')
260+
expect(getFirstEntryMatch(dataset1[0], (v) => typeof v === 'string')).toBe('Serie name 0')
261261
expect(getFirstEntryMatch(dataset1[0], (v) => isSimpleArrayOfNumbers(v))).toStrictEqual([0, 1, 2])
262262
})
263263
})

0 commit comments

Comments
 (0)