Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/diplodoc-platform/utils
Diplodoc cross-packages utils
https://github.com/diplodoc-platform/utils
Last synced: about 2 months ago
JSON representation
Diplodoc cross-packages utils
- Host: GitHub
- URL: https://github.com/diplodoc-platform/utils
- Owner: diplodoc-platform
- License: mit
- Created: 2024-08-28T14:55:31.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-09-27T10:47:10.000Z (3 months ago)
- Last Synced: 2024-10-01T11:45:20.478Z (3 months ago)
- Language: TypeScript
- Size: 966 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.MD
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Diplodoc utils
[![NPM version](https://img.shields.io/npm/v/@diplodoc/utils.svg?style=flat)](https://www.npmjs.org/package/@diplodoc/utils)
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](#AttrsParser)
- [Extension Load Queue](#Extension Load Queue)### AttrsParser
### Purpose
Support [markdown-it-attrs](https://github.com/arve0/markdown-it-attrs)-like attributes parser. Used in custom Diplodoc MarkdownIt plugins to add classes and anchors, enabling subsequent customization through CSS.
### Interface
```typescript
/*
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
```typescript
// create a unique symbol
export const GLOBAL_SYMBOL: unique symbol = Symbol.for('someController');// get the store
const store = getScriptStore(GLOBAL_SYMBOL);// get the controller
const controller = useController(store);
```See example in [diplodoc-platform/html-extension](https://github.com/diplodoc-platform/html-extension/blob/main/src/react/useDiplodocHtml.ts)