1.2.1 • Published 10 months ago

@diplodoc/utils v1.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Diplodoc utils

NPM version

Diplodoc cross-packages utils.

Motivation

The Diplodoc ecosystem consists of many packages that have similar problems and needs. This package will contain all the general logic that is duplicated in our code base.

Table of contents

AttrsParser

Purpose

Support markdown-it-attrs-like attributes parser. Used in custom Diplodoc MarkdownIt plugins to add classes and anchors, enabling subsequent customization through CSS.

Interface

/* 
    optional first query
    if provided parser will parse it immediately
    each 'parse' call is pure
*/
const attrs = new AttrsParser('{.class #id data-name=diplodoc}');

attrs.state /* { class: ['class'], id: ['id'], 'data-name': ['diplodoc'] } */

const other = attrs.parse('{data-wide title="Support quotes too"}')

other /* { attr: ['data-wide'], title: ['Support quotes too'] } */

Extension Load Queue

Purpose

This queue mechanism allows asynchronous loading of extensions by setting a property on the "window" object in the browser. This property has a Symbol data type, which makes it difficult for external manipulations to access it.

Interface

// create a unique symbol
export const GLOBAL_SYMBOL: unique symbol = Symbol.for('someController');

// get the store
const store = getScriptStore<SomeController>(GLOBAL_SYMBOL);

// get the controller
const controller = useController<SomeController>(store);

See example in diplodoc-platform/html-extension

1.2.1

10 months ago

1.2.0

10 months ago

1.1.0-beta2

10 months ago

1.1.0-beta1

10 months ago

1.1.0-beta

10 months ago

1.1.0

11 months ago

1.0.0

11 months ago