utils.js 672 B

123456789101112131415161718192021222324
  1. export const isEmptyObject = (obj) => (JSON.stringify(obj) === '{}');
  2. export const getThemeConfigObject = (config) => {
  3. try {
  4. const conf = JSON.parse(config);
  5. const { global, local } = conf;
  6. if (!isEmptyObject(global) || !isEmptyObject(local)) {
  7. return conf;
  8. }
  9. return false;
  10. } catch (e) {
  11. return false;
  12. }
  13. };
  14. export const updateDomHeadStyle = (id, styleContent) => {
  15. let styleTag = document.getElementById(id);
  16. if (!styleTag) {
  17. styleTag = document.createElement('style');
  18. styleTag.setAttribute('id', id);
  19. document.head.appendChild(styleTag);
  20. }
  21. styleTag.innerText = styleContent.replace(/@font-face{[^}]+}/, '');
  22. };