debian-mirror-gitlab/app/assets/javascripts/content_editor/services/utils.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
752 B
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
export const hasSelection = (tiptapEditor) => {
const { from, to } = tiptapEditor.state.selection;
return from < to;
};
2021-09-30 23:02:18 +05:30
2021-10-27 15:23:28 +05:30
/**
* Extracts filename from a URL
*
* @example
* > extractFilename('https://gitlab.com/images/logo-full.png')
* < 'logo-full'
*
* @param {string} src The URL to extract filename from
* @returns {string}
*/
export const extractFilename = (src) => {
return src.replace(/^.*\/|\..+?$/g, '');
2021-09-30 23:02:18 +05:30
};
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);