mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	* 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;
 | |
| };
 |