πŸš€ Big News:Socket Has Acquired Secure Annex.Learn More β†’
Socket
Book a DemoSign in
Socket

@scm-manager/refractor-flatten

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@scm-manager/refractor-flatten

A utility to transform Refractor ASTs to flat arrays.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
5
400%
Maintainers
5
Weekly downloads
Β 
Created
Source

@suin/refractor-flatten

A utility to transform Refractor ASTs to flat arrays.

Installation

yarn add @suin/refractor-flatten
# or
npm install @suin/refractor-flatten

Usage

Basic Usage

import refractor from "refractor";
import flatten from "@suin/refractor-flatten";

const tree = refractor.highlight("`${value}`", "js");
const flat = flatten(tree);

The structure of tree is:

root[1]
└─0 element<span>[3]
    β”‚ properties: {"className":["token","template-string"]}
    β”œβ”€0 element<span>[1]
    β”‚   β”‚ properties: {"className":["token","template-punctuation","string"]}
    β”‚   └─0 text "`"
    β”œβ”€1 element<span>[3]
    β”‚   β”‚ properties: {"className":["token","interpolation"]}
    β”‚   β”œβ”€0 element<span>[1]
    β”‚   β”‚   β”‚ properties: {"className":["token","interpolation-punctuation","punctuation"]}
    β”‚   β”‚   └─0 text "${"
    β”‚   β”œβ”€1 text "value"
    β”‚   └─2 element<span>[1]
    β”‚       β”‚ properties: {"className":["token","interpolation-punctuation","punctuation"]}
    β”‚       └─0 text "}"
    └─2 element<span>[1]
        β”‚ properties: {"className":["token","template-punctuation","string"]}
        └─0 text "`"

The structure of the flat above becomes:

root[5]
β”œβ”€0 element<span>[1]
β”‚   β”‚ properties: {"className":["token","template-string","template-punctuation","string"]}
β”‚   └─0 text "`"
β”œβ”€1 element<span>[1]
β”‚   β”‚ properties: {"className":["token","template-string","interpolation","interpolation-punctuation","punctuation"]}
β”‚   └─0 text "${"
β”œβ”€2 element<span>[1]
β”‚   β”‚ properties: {"className":["token","template-string","interpolation"]}
β”‚   └─0 text "value"
β”œβ”€3 element<span>[1]
β”‚   β”‚ properties: {"className":["token","template-string","interpolation","interpolation-punctuation","punctuation"]}
β”‚   └─0 text "}"
└─4 element<span>[1]
    β”‚ properties: {"className":["token","template-string","template-punctuation","string"]}
    └─0 text "`"

API Reference

https://suin.github.io/refractor-flatten/

Keywords

refractor

FAQs

Package last updated on 08 Apr 2022

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