Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

draftjs-utils

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftjs-utils

Collection of utility function for use with Draftjs.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
231K
decreased by-21.17%
Maintainers
1
Weekly downloads
 
Created

What is draftjs-utils?

The draftjs-utils package provides utility functions for working with Draft.js, a rich text editor framework for React. These utilities help in manipulating and converting Draft.js content states, blocks, and entities, making it easier to handle common tasks such as extracting text, converting content to HTML, and managing inline styles.

What are draftjs-utils's main functionalities?

Extracting Plain Text

This feature allows you to extract plain text from a Draft.js content state. The utility function `getTextFromContentState` takes a raw content state and returns the plain text.

const { convertToRaw, ContentState } = require('draft-js');
const { getTextFromContentState } = require('draftjs-utils');

const contentState = ContentState.createFromText('Hello, world!');
const rawContentState = convertToRaw(contentState);
const plainText = getTextFromContentState(rawContentState);
console.log(plainText); // Output: 'Hello, world!'

Converting Content to HTML

This feature allows you to convert Draft.js content state to HTML. The utility function `stateToHTML` takes a raw content state and returns the corresponding HTML string.

const { convertToRaw, ContentState } = require('draft-js');
const { stateToHTML } = require('draftjs-utils');

const contentState = ContentState.createFromText('Hello, world!');
const rawContentState = convertToRaw(contentState);
const html = stateToHTML(rawContentState);
console.log(html); // Output: '<p>Hello, world!</p>'

Managing Inline Styles

This feature allows you to manage inline styles in Draft.js. The utility function `getSelectedInlineStyles` returns a set of inline styles applied to the current selection in the editor state.

const { EditorState, RichUtils } = require('draft-js');
const { getSelectedInlineStyles } = require('draftjs-utils');

let editorState = EditorState.createEmpty();
editorState = RichUtils.toggleInlineStyle(editorState, 'BOLD');
const inlineStyles = getSelectedInlineStyles(editorState);
console.log(inlineStyles); // Output: Set { 'BOLD' }

Other packages similar to draftjs-utils

FAQs

Package last updated on 22 Jul 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc