gitea源码

1234567891011121314151617181920212223242526272829303132333435
  1. try {
  2. // some browsers like PaleMoon don't have full support for Intl.NumberFormat, so do the minimum polyfill to support "relative-time-element"
  3. // https://repo.palemoon.org/MoonchildProductions/UXP/issues/2289
  4. new Intl.NumberFormat('en', {style: 'unit', unit: 'minute'}).format(1);
  5. } catch {
  6. const intlNumberFormat = Intl.NumberFormat;
  7. // @ts-expect-error - polyfill is incomplete
  8. Intl.NumberFormat = function(locales: string | string[], options: Intl.NumberFormatOptions) {
  9. if (options.style === 'unit') {
  10. return {
  11. format(value: number | bigint | string) {
  12. return ` ${value} ${options.unit}`;
  13. },
  14. };
  15. }
  16. return intlNumberFormat(locales, options);
  17. };
  18. }
  19. export function weakRefClass() {
  20. const weakMap = new WeakMap();
  21. return class {
  22. constructor(target: any) {
  23. weakMap.set(this, target);
  24. }
  25. deref() {
  26. return weakMap.get(this);
  27. }
  28. };
  29. }
  30. if (!window.WeakRef) {
  31. window.WeakRef = weakRefClass() as any;
  32. }