Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@portabletext/toolkit
Advanced tools
Toolkit of handy utility functions for dealing with Portable Text
@portabletext/toolkit is a JavaScript toolkit for working with Portable Text, a JSON-based rich text format. It provides utilities for parsing, serializing, and rendering Portable Text content, making it easier to integrate rich text content into web applications.
Parsing Portable Text
This feature allows you to parse Portable Text into plain text. The `toPlainText` function takes Portable Text JSON and converts it into a plain text string.
const { toPlainText } = require('@portabletext/toolkit');
const portableText = [
{ _type: 'block', children: [{ _type: 'span', text: 'Hello, world!' }] }
];
const plainText = toPlainText(portableText);
console.log(plainText); // Output: 'Hello, world!'
Serializing Portable Text
This feature allows you to serialize plain text into Portable Text format. The `toPortableText` function takes a plain text string and converts it into Portable Text JSON.
const { toPortableText } = require('@portabletext/toolkit');
const plainText = 'Hello, world!';
const portableText = toPortableText(plainText);
console.log(portableText); // Output: [{ _type: 'block', children: [{ _type: 'span', text: 'Hello, world!' }] }]
Rendering Portable Text
This feature allows you to render Portable Text content in a React application. The `PortableText` component takes Portable Text JSON as a prop and renders it as React elements.
const { PortableText } = require('@portabletext/toolkit');
const portableText = [
{ _type: 'block', children: [{ _type: 'span', text: 'Hello, world!' }] }
];
const React = require('react');
const ReactDOM = require('react-dom');
ReactDOM.render(
React.createElement(PortableText, { value: portableText }),
document.getElementById('root')
);
Draft.js is a rich text editor framework for React. It provides a set of tools for building rich text editors with a focus on extensibility and customization. Unlike @portabletext/toolkit, which focuses on parsing and rendering Portable Text, Draft.js is more about creating and managing rich text content within a React application.
Slate is a completely customizable framework for building rich text editors. It provides a set of tools for creating complex, nested, and highly interactive rich text editors. Slate is more focused on the editor experience and less on the specific format of the content, whereas @portabletext/toolkit is specifically designed for working with Portable Text.
ProseMirror is a toolkit for building rich text editors with a focus on performance and flexibility. It provides a set of tools for creating highly customizable and performant rich text editors. ProseMirror is similar to Slate in that it focuses on the editor experience, while @portabletext/toolkit is more about working with Portable Text content.
Javascript toolkit of handy utility functions for dealing with Portable Text.
Particularly useful for building rendering libraries for Portable Text that outputs HTML.
npm install --save @portabletext/toolkit
See https://portabletext.github.io/toolkit/
import {toPlainText} from '@portabletext/toolkit'
console.log(toPlainText(myPortableTextBlocks))
MIT © Sanity.io
FAQs
Toolkit of handy utility functions for dealing with Portable Text
The npm package @portabletext/toolkit receives a total of 168,370 weekly downloads. As such, @portabletext/toolkit popularity was classified as popular.
We found that @portabletext/toolkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.