Skip to content

Commit

Permalink
Merge pull request #67 from vizzuhq/na-detection-in-unit
Browse files Browse the repository at this point in the history
Add N.A. detection in data types unit check
  • Loading branch information
dovicsin authored Dec 13, 2024
2 parents 9c57271 + 9be2ae2 commit dd9a5f2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions plugins/data-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [0.7.2]

- Add N/A detection in unit check

## [0.7.1]

- Add N/A protection in number detect
Expand Down
2 changes: 1 addition & 1 deletion plugins/data-types/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vizzu/data-types",
"description": "Vizzu plugin for data types",
"version": "0.7.1",
"version": "0.7.2",
"type": "module",
"exports": {
".": {
Expand Down
6 changes: 2 additions & 4 deletions plugins/data-types/src/utils/clearValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export const clearValue = (value: string | null | undefined): string | null | un
.replace(/^[]/, '-')
.replace(/[\u2012\u2013\u2014\u2015]/g, '-')

const naText = naVariants.find((na) => cleanedValue === na)
if (naText) {
if (naVariants.includes(cleanedValue)) {
return ''
}
if (cleanedValue.includes('.')) {
Expand All @@ -38,8 +37,7 @@ const excelErrors = [
]

export const fixErrorValues = (value: string): string => {
const errorText = excelErrors.find((error) => value === error)
if (errorText) {
if (excelErrors.includes(value)) {
return ''
}
return value
Expand Down
5 changes: 3 additions & 2 deletions plugins/data-types/src/utils/unitCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ export const unitCheck = (series: TypedSeries): void => {
(value) =>
value === '' ||
(typeof value === 'string' &&
(value.endsWith(unit) || value.startsWith(unit)) &&
!isNaN(Number(clearValue(value.replace(unit, '')))))
(clearValue(value) === '' ||
((value.endsWith(unit) || value.startsWith(unit)) &&
!isNaN(Number(clearValue(value.replace(unit, '')))))))
)

if (series?.values && hasUnit(series)) {
Expand Down

0 comments on commit dd9a5f2

Please sign in to comment.