@featurevisor/sdk 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/coverage/clover.xml +15 -17
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/bucketer.ts.html +1 -1
- package/coverage/lcov-report/child.ts.html +1 -1
- package/coverage/lcov-report/conditions.ts.html +1 -1
- package/coverage/lcov-report/datafileReader.ts.html +1 -1
- package/coverage/lcov-report/emitter.ts.html +1 -1
- package/coverage/lcov-report/evaluate.ts.html +1 -1
- package/coverage/lcov-report/events.ts.html +1 -1
- package/coverage/lcov-report/helpers.ts.html +39 -54
- package/coverage/lcov-report/hooks.ts.html +1 -1
- package/coverage/lcov-report/index.html +15 -15
- package/coverage/lcov-report/instance.ts.html +1 -1
- package/coverage/lcov-report/logger.ts.html +1 -1
- package/coverage/lcov.info +28 -30
- package/dist/helpers.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/lib/helpers.d.ts +1 -1
- package/package.json +2 -2
- package/src/helpers.spec.ts +49 -0
- package/src/helpers.ts +20 -25
package/src/helpers.ts
CHANGED
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import type { VariableType, VariableValue } from "@featurevisor/types";
|
|
2
2
|
|
|
3
3
|
type FieldType = string | VariableType;
|
|
4
|
-
type ValueType = VariableValue;
|
|
4
|
+
export type ValueType = VariableValue;
|
|
5
5
|
|
|
6
6
|
export function getValueByType(value: ValueType, fieldType: FieldType): ValueType {
|
|
7
|
-
|
|
8
|
-
if (value === undefined) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
switch (fieldType) {
|
|
13
|
-
case "string":
|
|
14
|
-
return typeof value === "string" ? value : null;
|
|
15
|
-
case "integer":
|
|
16
|
-
return parseInt(value as string, 10);
|
|
17
|
-
case "double":
|
|
18
|
-
return parseFloat(value as string);
|
|
19
|
-
case "boolean":
|
|
20
|
-
return value === true;
|
|
21
|
-
case "array":
|
|
22
|
-
return Array.isArray(value) ? value : null;
|
|
23
|
-
case "object":
|
|
24
|
-
return typeof value === "object" ? value : null;
|
|
25
|
-
// @NOTE: `json` is not handled here intentionally
|
|
26
|
-
default:
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line
|
|
30
|
-
} catch (e) {
|
|
7
|
+
if (value === undefined) {
|
|
31
8
|
return null;
|
|
32
9
|
}
|
|
10
|
+
|
|
11
|
+
switch (fieldType) {
|
|
12
|
+
case "string":
|
|
13
|
+
return typeof value === "string" ? value : null;
|
|
14
|
+
case "integer":
|
|
15
|
+
return parseInt(value as string, 10);
|
|
16
|
+
case "double":
|
|
17
|
+
return parseFloat(value as string);
|
|
18
|
+
case "boolean":
|
|
19
|
+
return value === true;
|
|
20
|
+
case "array":
|
|
21
|
+
return Array.isArray(value) ? value : null;
|
|
22
|
+
case "object":
|
|
23
|
+
return typeof value === "object" ? value : null;
|
|
24
|
+
// @NOTE: `json` is not handled here intentionally
|
|
25
|
+
default:
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
33
28
|
}
|