mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
Merge pull request #699 from sasjs/special-missing
Special missing function from @sasjs/utils
This commit is contained in:
14
package-lock.json
generated
14
package-lock.json
generated
@@ -8,7 +8,7 @@
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@sasjs/utils": "2.42.0",
|
||||
"@sasjs/utils": "2.44.0",
|
||||
"axios": "0.26.0",
|
||||
"axios-cookiejar-support": "1.0.1",
|
||||
"form-data": "4.0.0",
|
||||
@@ -1142,9 +1142,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@sasjs/utils": {
|
||||
"version": "2.42.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz",
|
||||
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==",
|
||||
"version": "2.44.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.44.0.tgz",
|
||||
"integrity": "sha512-hpC4erHYA8Mcb38mzxFEP0cXehfa0iKeqSW2d9MmxZ9g2qpy0BU6xyZJohN9kOiafXo5H359ndNKsg4DOq5YgA==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@types/fs-extra": "9.0.13",
|
||||
@@ -13870,9 +13870,9 @@
|
||||
}
|
||||
},
|
||||
"@sasjs/utils": {
|
||||
"version": "2.42.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.42.0.tgz",
|
||||
"integrity": "sha512-Y69l89PYNF/h9xvVH72om/39xA+cY80bhiVLzp/fJb3BlvzCf4RNswBBanUOv2I5JNa7gPpJuE7mEiXOlhD3eg==",
|
||||
"version": "2.44.0",
|
||||
"resolved": "https://registry.npmjs.org/@sasjs/utils/-/utils-2.44.0.tgz",
|
||||
"integrity": "sha512-hpC4erHYA8Mcb38mzxFEP0cXehfa0iKeqSW2d9MmxZ9g2qpy0BU6xyZJohN9kOiafXo5H359ndNKsg4DOq5YgA==",
|
||||
"requires": {
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/prompts": "2.0.13",
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@sasjs/utils": "2.42.0",
|
||||
"@sasjs/utils": "2.44.0",
|
||||
"axios": "0.26.0",
|
||||
"axios-cookiejar-support": "1.0.1",
|
||||
"form-data": "4.0.0",
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('formatDataForRequest', () => {
|
||||
|
||||
expect(() => formatDataForRequest(tableWithMissingValues)).toThrow(
|
||||
new Error(
|
||||
'Special missing value can only be a single character from A to Z or _'
|
||||
`A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { isSpecialMissing } from '@sasjs/utils'
|
||||
|
||||
/**
|
||||
* Converts the given JSON object array to a CSV string.
|
||||
* @param data - the array of JSON objects to convert.
|
||||
@@ -18,7 +20,6 @@ export const convertToCSV = (
|
||||
let headers: string[] = []
|
||||
let csvTest
|
||||
let invalidString = false
|
||||
const specialMissingValueRegExp = /^[a-z_]{1}$/i
|
||||
|
||||
if (formats) {
|
||||
headers = Object.keys(formats).map((key) => `${key}:${formats![key]}`)
|
||||
@@ -36,7 +37,7 @@ export const convertToCSV = (
|
||||
hasNullOrNumber = true
|
||||
} else if (
|
||||
typeof row[field] === 'string' &&
|
||||
specialMissingValueRegExp.test(row[field])
|
||||
isSpecialMissing(row[field])
|
||||
) {
|
||||
hasSpecialMissingString = true
|
||||
}
|
||||
@@ -130,10 +131,10 @@ export const convertToCSV = (
|
||||
value = currentCell === null ? '' : currentCell
|
||||
|
||||
if (formats && formats[fieldName] === 'best.') {
|
||||
if (value && !specialMissingValueRegExp.test(value)) {
|
||||
if (value && !isSpecialMissing(value)) {
|
||||
console.log(`🤖[value]🤖`, value)
|
||||
throw new Error(
|
||||
'Special missing value can only be a single character from A to Z or _'
|
||||
`A Special missing value can only be a single character from 'A' to 'Z', '_', '.[a-z]', '._'`
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user