mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
fb711b4d4a
* fix: when payload type is 'json' validate value on toggle variable validation * test: add missing feature toggle creation with variant type json Ref https://github.com/Unleash/unleash/pull/1704#discussion_r896476042 * refractor: remove verbose comment on validateJsonString Ref https://github.com/Unleash/unleash/pull/1704#discussion_r896482210 * test: add missing feature toggle creation with variant type string Ref https://github.com/Unleash/unleash/pull/1704#discussion_r896476042 * refractor: move variant value joi validation Ref https://github.com/Unleash/unleash/pull/1704#discussion_r896478563
13 lines
351 B
TypeScript
13 lines
351 B
TypeScript
export const validateJsonString = (value: string): boolean => {
|
|
// from https://stackoverflow.com/a/20392392
|
|
try {
|
|
const parsedStr = JSON.parse(value);
|
|
if (parsedStr && typeof parsedStr === 'object') {
|
|
return true;
|
|
}
|
|
} catch (err) {}
|
|
|
|
// an error is considered a non valid json
|
|
return false;
|
|
};
|