policy2Str.ts 388 B

123456789101112131415
  1. export function policy2Str(policy: string | object) {
  2. let policyStr;
  3. if (policy) {
  4. if (typeof policy === 'string') {
  5. try {
  6. policyStr = JSON.stringify(JSON.parse(policy));
  7. } catch (err) {
  8. throw new Error(`Policy string is not a valid JSON: ${err.message}`);
  9. }
  10. } else {
  11. policyStr = JSON.stringify(policy);
  12. }
  13. }
  14. return policyStr;
  15. }