Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const filterByExtension = function (files: FileList) {
const re = new RegExp('(' + extensionsAccepted.split(/\s*,\s*/).join('|') + ')$', 'i');
return Arr.filter(Arr.from(files), (file) => re.test(file.name));
};
const getImagesFromDataTransfer = (dataTransfer: DataTransfer) => {
const items = dataTransfer.items ? Arr.map(Arr.from(dataTransfer.items), (item) => item.getAsFile()) : [];
const files = dataTransfer.files ? Arr.from(dataTransfer.files) : [];
const images = Arr.filter(items.length > 0 ? items : files, (file) => /^image\/(jpeg|png|gif|bmp)$/.test(file.type));
return images;
};
const getMultipleToolbarsSetting = (editor: Editor): Option => {
const keys = Obj.keys(editor.settings);
const toolbarKeys = Arr.filter(keys, (key) => /^toolbar([1-9])$/.test(key));
const toolbars = Arr.map(toolbarKeys, (key) => editor.getParam(key, false, 'string'));
const toolbarArray = Arr.filter(toolbars, (toolbar) => typeof toolbar === 'string');
return toolbarArray.length > 0 ? Option.some(toolbarArray) : Option.none();
};
const getClosestBlock = (root: Element, pos: CaretPosition): Element => {
const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
return Arr.head(parentBlocks).getOr(root);
};
const indentSelectedEntries = (entries: Entry[], indentation: Indentation): void => {
Arr.each(Arr.filter(entries, isSelected), (entry) => indentEntry(indentation, entry));
};
const getSelectedDlItems = (editor: Editor): Node[] => {
return Arr.filter(getSelectedListItems(editor), NodeType.isDlItemNode);
};
const findBr = (forward: boolean, root: Element, pos: CaretPosition) => {
const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
const scope = Arr.head(parentBlocks).getOr(root);
return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr);
};
return () => {
changeHandlers.set(Arr.filter(changeHandlers.get(), (h) => h !== handler));
};
};
const getSelectedLists = (editor: Editor): Node[] => {
const firstList = findLastParentListNode(editor, editor.selection.getStart());
const subsequentLists = Arr.filter(editor.selection.getSelectedBlocks(), NodeType.isOlUlNode);
return firstList.toArray().concat(subsequentLists);
};