policy2Str.js 583 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.policy2Str = void 0;
  4. function policy2Str(policy) {
  5. let policyStr;
  6. if (policy) {
  7. if (typeof policy === 'string') {
  8. try {
  9. policyStr = JSON.stringify(JSON.parse(policy));
  10. }
  11. catch (err) {
  12. throw new Error(`Policy string is not a valid JSON: ${err.message}`);
  13. }
  14. }
  15. else {
  16. policyStr = JSON.stringify(policy);
  17. }
  18. }
  19. return policyStr;
  20. }
  21. exports.policy2Str = policy2Str;