Skip to content

Commit 254ec86

Browse files
committed
feat: add array format & validate boolean
1 parent 982e0dc commit 254ec86

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/helpers/Common.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs'
2+
import { isEmpty } from 'lodash'
23

34
const invalidValues = [null, undefined, '', false, 0]
45

@@ -32,4 +33,39 @@ function readHTMLFile(path: any, callback: any) {
3233
})
3334
}
3435

35-
export { getUniqueCodev2, readHTMLFile, invalidValues }
36+
function arrayFormatter(arrayData: string | string[]) {
37+
// check if data not empty
38+
if (!isEmpty(arrayData)) {
39+
// check if data is array
40+
if (Array.isArray(arrayData)) {
41+
return arrayData
42+
}
43+
return JSON.parse(arrayData)
44+
}
45+
46+
return []
47+
}
48+
49+
/**
50+
*
51+
* @param value
52+
*/
53+
function validateBoolean(value: string | boolean | Number) {
54+
if (value === 'true' || value === 1 || value === '1' || value === true) {
55+
return true
56+
}
57+
58+
if (value === 'false' || value === 0 || value === '0' || value === false) {
59+
return false
60+
}
61+
62+
return null
63+
}
64+
65+
export {
66+
getUniqueCodev2,
67+
readHTMLFile,
68+
invalidValues,
69+
arrayFormatter,
70+
validateBoolean,
71+
}

0 commit comments

Comments
 (0)