Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.js « services « content_editor « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a2c7f617da99954dbca9eeece0eafe5a77cb7ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
export const hasSelection = (tiptapEditor) => {
  const { from, to } = tiptapEditor.state.selection;

  return from < to;
};

export const getImageAlt = (src) => {
  return src.replace(/^.*\/|\..*$/g, '').replace(/\W+/g, ' ');
};

export const readFileAsDataURL = (file) => {
  return new Promise((resolve) => {
    const reader = new FileReader();
    reader.addEventListener('load', (e) => resolve(e.target.result), { once: true });
    reader.readAsDataURL(file);
  });
};

export const clamp = (n, min, max) => Math.max(Math.min(n, max), min);