Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
draft-regex
Advanced tools
These helpers are written for Draft.js to improve Editor capabilities.
npm install draft-regex
or
yarn add draft-regex
import * as React from 'react';
import { EditorState, Editor } from 'draft-js';
import { clearEmptyBlocks, clearPastedStyle, replaceTextRegex } from 'draft-regex';
type State = {
editorState: EditorState,
};
class MyEditor extends React.Component<void, State> {
state: State = {
editorState: EditorState.createEmpty(),
};
onChange = (editorState: EditorState) => {
this.setState({ editorState: clearEmptyBlocks(editorState) });
};
handlePastedText = (text: ?string, html: ?string, editorState: EditorState) => {
this.setState({ editorState: clearPastedStyle(editorState) });
};
onSave = () => {
const { editorState } = this.state;
this.setState({ editorState: replaceTextRegex(editorState) });
};
render() {
const { editorState } = this.state;
return (
<>
<Editor
editorState={editorState}
onChange={this.onChange}
handlePastedText={this.handlePastedText}
/>
<button onClick={this.onSave}>Save</button>
</>
);
}
}
All helpers are taken by EditorState and options as an argument and returned EditorState.
Prevents the ability to add blank lines more than 3 (varies in settings).
A second argument can take a number
for remove blank lines (number + 1).
function clearEmptyBlocks(editorState: EditorState, maxEmptyLines?: number = 2): EditorState
Apply regular expressions to the entire text, in the process of typing or after copy/pasting text.
A second argument can take an array of rules. typoRules
is a set of basic rules that you can not use.
All regular expressions are used once in the entire text. If you use a lot of regular expressions, the performance of the editor can drop noticeably.
function replaceTextRegex(
editorState: EditorState,
rulesArray?: Array<Rule> = typoRules,
): EditorState
The rule looks like this: { reg: new RegExp(), shift: '' }
Clears styles of copy/pasted text to those that you have.
A second argument can take an object that can contain options
.
blockTypes
is an array of strings that contains all the types of blocks that you use in your editor. This is useful if you want to clear all styles, except those you can already ask yourself.
A list of all types can be found here.
If you do not want to use all six kinds of headings, you can bring the headers to the same view using shiftHeader
.
The same applies to lists.
function clearPastedStyle(
editorState: EditorState,
options?: {
blockTypes?: Array<string>,
shiftHeader?: string,
shiftList?: string,
}
): EditorState
To improve performance, use clearPastedStyle
to handlePastedText
method, and replaceTextRegex
to save the text editor.
FAQs
Helpers for draft-js
The npm package draft-regex receives a total of 126 weekly downloads. As such, draft-regex popularity was classified as not popular.
We found that draft-regex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.