New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

quill-delta-to-object

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quill-delta-to-object

Converts Quill's delta ops to Object

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
85
decreased by-13.27%
Maintainers
3
Weekly downloads
 
Created
Source

Quill Delta to Object Converter

Converts Quill's Delta format to Object (insert ops only) with properly nested lists.

This library is inspired by quill-delta-to-html.

Quickstart

Installation

npm install quill-delta-to-object

Usage

var QuillDeltaToObjectConverter = require('quill-delta-to-object').QuillDeltaToObjectConverter;

// TypeScript / ES6:
// import { QuillDeltaToObjectConverter } from 'quill-delta-to-object'; 

var deltaOps =  [
    {insert: "Hello\n"},
    {insert: "This is colorful", attributes: {color: '#f00'}}
];

var converter = new QuillDeltaToObjectConverter(deltaOps);

var object = converter.convert(); 

Supporting Formats

Not Supported:

  • Image
  • Video
  • Table
  • Nested List

Rendering Custom Blot Formats

You need to tell system how to render your custom blot by registering a renderer callback function to renderCustomWith method before calling the convert() method.

Example:

let ops = [
    { insert: { bolditalic: 'my text' } },
];

let converter = new QuillDeltaToObjectConverter(ops);

// customOp is your custom blot op
// contextOp is the block op that wraps this op, if any. 
// If, for example, your custom blot is located inside a list item,
// then contextOp would provide that op. 
converter.renderCustomWith(function(customOp, contextOp){
    if (op.insert.type === 'bolditalic') {
        return {
            type: 'text',
            value: op.insert.value,
            attributes: { bold: true, italic: true },
        };
    }
    return undefined;
});

object = converter.convert();

customOp object will have the following format:

{
    insert: {
        type: string //whatever you specified as key for insert, in above example: 'bolditalic'
        value: any // value for the custom blot  
    }, 
    attributes: {
        // ... any attributes custom blot may have
    }
}

Keywords

FAQs

Package last updated on 01 Nov 2021

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