From b0df4cb7eef38cb59473bd1b5672ea0feecd959e Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Tue, 8 Mar 2022 18:28:48 +0100 Subject: [PATCH 1/3] fix: special missings accept - regular missing . --- src/utils/convertToCsv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/convertToCsv.ts b/src/utils/convertToCsv.ts index 73af3ba..f6a1a5b 100644 --- a/src/utils/convertToCsv.ts +++ b/src/utils/convertToCsv.ts @@ -10,7 +10,7 @@ export const convertToCSV = ( let headers: string[] = [] let csvTest let invalidString = false - const specialMissingValueRegExp = /^[a-z_]{1}$/i + const specialMissingValueRegExp = /^[a-z_.]{1}$/i if (formats) { headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`) From d2ea67e5d6e881a0dc5630eb26c9887754bfac8d Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Tue, 8 Mar 2022 18:32:45 +0100 Subject: [PATCH 2/3] chore: docs --- README.md | 2 +- src/utils/convertToCsv.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 92c09d0..fc17fa3 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ The SAS type (char/numeric) of the values is determined according to a set of ru * If the values are numeric, the SAS type is numeric * If the values are all string, the SAS type is character -* If the values contain a single character (a-Z + underscore) AND a numeric, then the SAS type is numeric (with special missing values). +* If the values contain a single character (a-Z + underscore + .) AND a numeric, then the SAS type is numeric (with special missing values). * `null` is set to either '.' or '' depending on the assigned or derived type per the above rules. If entire column is `null` then the type will be numeric. The following table illustrates the formats applied to columns under various scenarios: diff --git a/src/utils/convertToCsv.ts b/src/utils/convertToCsv.ts index f6a1a5b..64c6988 100644 --- a/src/utils/convertToCsv.ts +++ b/src/utils/convertToCsv.ts @@ -125,7 +125,7 @@ export const convertToCSV = ( if (value && !specialMissingValueRegExp.test(value)) { console.log(`🤖[value]🤖`, value) throw new Error( - 'Special missing value can only be a single character from A to Z or _' + 'Special missing value can only be a single character from A to Z or _ or .' ) } From 076ed1cc7adec3323733c92f0ea5cc7817db7bf3 Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Mon, 23 May 2022 12:59:48 +0200 Subject: [PATCH 3/3] chore: added special missing test --- src/test/utils/formatDataForRequest.spec.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/utils/formatDataForRequest.spec.ts b/src/test/utils/formatDataForRequest.spec.ts index eee87a4..4527de9 100644 --- a/src/test/utils/formatDataForRequest.spec.ts +++ b/src/test/utils/formatDataForRequest.spec.ts @@ -54,6 +54,17 @@ describe('formatDataForRequest', () => { expect(formatDataForRequest(data)).toEqual(expectedOutput) }) + it('should accept . as special missing value', () => { + let tableWithMissingValues = { + [testTable]: [{ var: '.' }, { var: 0 }], + [`$${testTable}`]: { formats: { var: 'best.' } } + } + + expect(() => + formatDataForRequest(tableWithMissingValues) + ).not.toThrowError() + }) + it('should throw an error if special missing values is not valid', () => { let tableWithMissingValues = { [testTable]: [{ var: 'AA' }, { var: 0 }],