Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kmdr-ast

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kmdr-ast - npm Package Compare versions

Comparing version 3.6.0 to 3.6.1

11

dist/astNodePoint.d.ts

@@ -8,3 +8,14 @@ import { NodePoint } from "./interfaces";

static deserializeRange(serialized: string): NodePoint[];
/**
* Checks if a point is inside a node range
*
* @param range the range (start, end positions) of a node
* @param point the point defined by row and column
*/
static isInRange(range: ASTNodePoint[], point: ASTNodePoint): boolean;
/**
*
* @param range
* @param subrange
*/
static rangeContainsRange(range: ASTNodePoint[], subrange: ASTNodePoint[]): boolean;

@@ -11,0 +22,0 @@ static serializeRange(startPosition: ASTNodePoint, endPosition: ASTNodePoint): string;

@@ -27,2 +27,8 @@ "use strict";

}
/**
* Checks if a point is inside a node range
*
* @param range the range (start, end positions) of a node
* @param point the point defined by row and column
*/
static isInRange(range, point) {

@@ -46,2 +52,7 @@ const [startPosition, endPosition] = range;

}
/**
*
* @param range
* @param subrange
*/
static rangeContainsRange(range, subrange) {

@@ -48,0 +59,0 @@ return (range[0].row <= subrange[0].row &&

7

dist/highlight.d.ts

@@ -1,8 +0,11 @@

import { Decorators, NodeDefinition } from "./interfaces";
import { ThemeDecorators, NodeDefinition } from "./interfaces";
import Tree from "./tree";
export default class Highlight<R extends string | Text | Element | any> {
private static findNodeDefinition;
/**
* Text-based (ansi colors) highlighting or HTML
*/
private mode;
private decorators;
constructor(decorators: Decorators<R>, mode: string);
constructor(decorators: ThemeDecorators<R>, mode: string);
source(source: string, tree: Tree, definitions?: NodeDefinition[]): R[];

@@ -9,0 +12,0 @@ private decorateNode;

@@ -33,19 +33,16 @@ "use strict";

if (inRange) {
// For CSS
decoratedStrings.push(...this.decorateNode(wordInRange, nodes[currentToken], definitions));
decoratedStrings.push(this.decorators.newLine());
wordInRange = "";
row++;
columnAtLine = 0;
inRange = false;
decoratedStrings.push(this.decorateText("\n", "new_line"));
}
else {
decoratedStrings.push(this.decorators.newLine());
wordInRange = "";
decoratedStrings.push(this.decorateText("\n", "new_line"));
if (currentToken < nodes.length && nodes[currentToken].type === "\n") {
currentToken += 1;
}
row++;
columnAtLine = 0;
inRange = false;
}
wordInRange = "";
row++;
columnAtLine = 0;
inRange = false;
continue;

@@ -76,7 +73,7 @@ }

// if the current char is not part of any token, then append it to the array
decoratedStrings.push(this.decorators.word(char));
decoratedStrings.push(this.decorateText(char));
}
}
catch (err) {
decoratedStrings.push(this.decorators.word(char));
decoratedStrings.push(this.decorateText(char));
}

@@ -98,3 +95,3 @@ columnAtLine++;

if (matches.length === 0) {
decoratedStrings.push(this.decorateText(text, node.type, node));
decoratedStrings.push(this.decorateText(text, node.type));
}

@@ -120,3 +117,3 @@ else {

if (column === text.length - 1 || columnInNode === matches[currentToken].endPosition.column - 1) {
decoratedStrings.push(this.decorateText(wordInRange, matches[currentToken].type, node, matches[currentToken]));
decoratedStrings.push(this.decorateText(wordInRange, matches[currentToken].type, matches[currentToken]));
wordInRange = "";

@@ -129,3 +126,3 @@ currentToken += 1;

if (inRange) {
decoratedStrings.push(this.decorateText(wordInRange, matches[currentToken].type, node, matches[currentToken]));
decoratedStrings.push(this.decorateText(wordInRange, matches[currentToken].type, matches[currentToken]));
wordInRange = "";

@@ -137,3 +134,3 @@ currentToken += 1;

// decoratedStrings.push(char);
decoratedStrings.push(this.decorateText(char, node.type, node));
decoratedStrings.push(this.decorateText(char, node.type));
}

@@ -144,115 +141,112 @@ }

}
decorateText(text, type, node, definition) {
switch (type) {
case "`":
return this.decorators.backtick(text, node);
case `"`:
return this.decorators.doubleQuotes(text);
case "|":
return this.decorators.pipeline(text, definition);
case "&&":
case "||":
case "!":
return this.decorators.logicalOperator(text, definition);
case "(":
case "$(":
case ")":
return this.decorators.parens(text);
case "{":
case `\${`:
case "}":
return this.decorators.braces(text);
case "[[":
case "]]":
case "[":
case "]":
return this.decorators.brackets(text);
case ">":
case ">&":
case ">>":
case "&>":
return this.decorators.redirect(text, definition);
case ";":
return this.decorators.semicolon(text, definition);
case "=":
return this.decorators.equal(text, definition);
case "==":
case "!=":
case "<":
case "<=":
case ">=":
return this.decorators.relationalOperator(text, definition);
case "argument":
return this.decorators.argument(text, definition);
case "command":
return this.decorators.command(text);
case "command_name":
case "program":
return this.decorators.program(text, definition);
case "comment":
return this.decorators.comment(text, definition);
case "do":
return this.decorators.do(text, definition);
case "done":
return this.decorators.done(text, definition);
case "file_descriptor":
return this.decorators.fileDescriptor(text, definition);
case "for":
return this.decorators.for(text, definition);
case "function":
return this.decorators.fn(text, definition);
case "if":
return this.decorators.if(text, definition);
case "else":
return this.decorators.else(text, definition);
case "elif":
return this.decorators.elif(text, definition);
case "fi":
return this.decorators.fi(text, definition);
case "in":
return this.decorators.in(text, definition);
case "missing_program":
return this.decorators.missingProgram(text, definition);
case "option":
return this.decorators.option(text, definition);
case "optionArg":
return this.decorators.optionArg(text, definition);
case "pipeline":
return this.decorators.bitwiseOperator(text, definition);
case "subcommand":
return this.decorators.subcommand(text, definition);
case "test_operator":
return this.decorators.testOperator(text, definition);
case "then":
return this.decorators.then(text, definition);
case "variable_name":
return this.decorators.variableName(text, definition);
case "while":
return this.decorators.while(text, definition);
/////////////////////////////
// CSS
////////////////////////////
case "property": {
if (this.decorators.property)
return this.decorators.property(text, definition);
return this.decorators.word(text, definition);
}
case "class_name": {
if (this.decorators.className)
return this.decorators.className(text, definition);
return this.decorators.word(text, definition);
}
case "*": {
if (this.decorators.universalSelector)
return this.decorators.universalSelector(text, definition);
return this.decorators.word(text, definition);
}
case "tag_name": {
if (this.decorators.tagName)
return this.decorators.tagName(text, definition);
return this.decorators.word(text, definition);
}
default:
return this.decorators.word(text, definition);
}
decorateText(text, type, definition) {
return this.decorators.createToken(text, type, definition);
// switch (type) {
// case "`":
// return this.decorators.backtick(text, node);
// case `"`:
// return this.decorators.doubleQuotes(text);
// case "|":
// return this.decorators.pipeline(text, definition);
// case "&&":
// case "||":
// case "!":
// return this.decorators.logicalOperator(text, definition);
// case "(":
// case "$(":
// case ")":
// return this.decorators.parens(text);
// case "{":
// case `\${`:
// case "}":
// return this.decorators.braces(text);
// case "[[":
// case "]]":
// case "[":
// case "]":
// return this.decorators.brackets(text);
// case ">":
// case ">&":
// case ">>":
// case "&>":
// return this.decorators.redirect(text, definition);
// case ";":
// return this.decorators.semicolon(text, definition);
// case "=":
// return this.decorators.equal(text, definition);
// case "==":
// case "!=":
// case "<":
// case "<=":
// case ">=":
// return this.decorators.relationalOperator(text, definition);
// case "argument":
// return this.decorators.argument(text, definition);
// case "command":
// return this.decorators.command(text);
// case "command_name":
// case "program":
// return this.decorators.program(text, definition);
// case "comment":
// return this.decorators.comment(text, definition);
// case "do":
// return this.decorators.do(text, definition);
// case "done":
// return this.decorators.done(text, definition);
// case "file_descriptor":
// return this.decorators.fileDescriptor(text, definition);
// case "for":
// return this.decorators.for(text, definition);
// case "function":
// return this.decorators.fn(text, definition);
// case "if":
// return this.decorators.if(text, definition);
// case "else":
// return this.decorators.else(text, definition);
// case "elif":
// return this.decorators.elif(text, definition);
// case "fi":
// return this.decorators.fi(text, definition);
// case "in":
// return this.decorators.in(text, definition);
// case "missing_program":
// return this.decorators.missingProgram(text, definition);
// case "option":
// return this.decorators.option(text, definition);
// case "optionArg":
// return this.decorators.optionArg(text, definition);
// case "pipeline":
// return this.decorators.bitwiseOperator(text, definition);
// case "subcommand":
// return this.decorators.subcommand(text, definition);
// case "test_operator":
// return this.decorators.testOperator(text, definition);
// case "then":
// return this.decorators.then(text, definition);
// case "variable_name":
// return this.decorators.variableName(text, definition);
// case "while":
// return this.decorators.while(text, definition);
// /////////////////////////////
// // CSS
// ////////////////////////////
// case "property": {
// if (this.decorators.property) return this.decorators.property(text, definition);
// return this.decorators.word(text, definition);
// }
// case "class_name": {
// if (this.decorators.className) return this.decorators.className(text, definition);
// return this.decorators.word(text, definition);
// }
// case "*": {
// if (this.decorators.universalSelector) return this.decorators.universalSelector(text, definition);
// return this.decorators.word(text, definition);
// }
// case "tag_name": {
// if (this.decorators.tagName) return this.decorators.tagName(text, definition);
// return this.decorators.word(text, definition);
// }
// default:
// return this.decorators.word(text, definition);
// }
}

@@ -259,0 +253,0 @@ }

import ASTNode from "./astNode";
import ASTNodePoint from "./astNodePoint";
import Highlight from "./highlight";
import { Decorators, NodeDefinition, DefinitionFeedback } from "./interfaces";
import { ThemeDecorators, NodeDefinition, DefinitionFeedback } from "./interfaces";
import Tree from "./tree";
import TreeCursor from "./treeCursor";
import { ArgumentNodeDefinition, OptionArgNodeDefinition, OptionNodeDefinition, ProgramNodeDefinition, SubcommandNodeDefinition } from "./nodeDefinition";
export { ASTNode, ArgumentNodeDefinition, OptionArgNodeDefinition, OptionNodeDefinition, ProgramNodeDefinition, DefinitionFeedback, SubcommandNodeDefinition, Tree, TreeCursor, ASTNodePoint, Highlight, NodeDefinition, Decorators, };
export { ASTNode, ArgumentNodeDefinition, OptionArgNodeDefinition, OptionNodeDefinition, ProgramNodeDefinition, DefinitionFeedback, SubcommandNodeDefinition, Tree, TreeCursor, ASTNodePoint, Highlight, NodeDefinition, ThemeDecorators, };
//# sourceMappingURL=index.d.ts.map

@@ -39,9 +39,47 @@ import { ArgumentSchema, OptionSchema, ProgramSchema, SubcommandSchema } from "kmdr-parser";

}
export interface Decorators<T extends Element | Text | string | any> {
argument(text: string, node?: Node, definition?: NodeDefinition): T;
arithmeticOperator(text: string, node?: Node, definition?: NodeDefinition): T;
backtick(text: string, node?: Node, definition?: NodeDefinition): T;
bitwiseOperator(text: string, node?: Node, definition?: NodeDefinition): T;
braces(text: string, node?: Node, definition?: NodeDefinition): T;
brackets(text: string, node?: Node, definition?: NodeDefinition): T;
export interface ThemeDecorators<T extends Element | Text | string | any> {
language: "bash" | "css";
createToken(text: string, type?: string, definition?: NodeDefinition): T;
}
export interface BashDecorators<T extends Element | Text | string | any> extends ThemeDecorators<T> {
argument(text: string, definition?: NodeDefinition): T;
arithmeticOperator(text: string, definition?: NodeDefinition): T;
backtick(text: string, definition?: NodeDefinition): T;
bitwiseOperator(text: string, definition?: NodeDefinition): T;
braces(text: string, definition?: NodeDefinition): T;
brackets(text: string, definition?: NodeDefinition): T;
comment(text: string, definition?: NodeDefinition): T;
do(text: string, definition?: NodeDefinition): T;
doubleQuotes(text: string, definition?: NodeDefinition): T;
done(text: string, definition?: NodeDefinition): T;
elif(text: string, definition?: NodeDefinition): T;
else(text: string, definition?: NodeDefinition): T;
equal(text: string, definition?: NodeDefinition): T;
fi(text: string, definition?: NodeDefinition): T;
fileDescriptor(text: string, definition?: NodeDefinition): T;
fn(text: string, definition?: NodeDefinition): T;
for(text: string, definition?: NodeDefinition): T;
if(text: string, definition?: NodeDefinition): T;
in(text: string, definition?: NodeDefinition): T;
missingProgram(text: string, definition?: NodeDefinition): T;
option(text: string, definition?: NodeDefinition): T;
optionArg(text: string, definition?: NodeDefinition): T;
logicalOperator(text: string, definition?: NodeDefinition): T;
parens(test: string, definition?: NodeDefinition): T;
pipeline(text: string, definition?: NodeDefinition): T;
program(text: string, definition?: NodeDefinition): T;
redirect(text: string, definition?: NodeDefinition): T;
relationalOperator(text: string, definition?: NodeDefinition): T;
semicolon(text: string, definition?: NodeDefinition): T;
space(): T;
subcommand(text: string, definition?: NodeDefinition): T;
testOperator(text: string, definition?: NodeDefinition): T;
then(text: string, definition?: NodeDefinition): T;
variableName(text: string, definition?: NodeDefinition): T;
while(text: string, definition?: NodeDefinition): T;
word(text: string, definition?: NodeDefinition): T;
}
export interface CSSDecorators<T extends Element | Text | string | any> extends ThemeDecorators<Element | Text | string | any> {
braces(text: string, definition?: NodeDefinition): T;
brackets(text: string, definition?: NodeDefinition): T;
/**

@@ -54,30 +92,9 @@ * lang: css

*/
className?(text: string, node?: Node, definition?: NodeDefinition): T;
command(text: string, node?: Node): T;
comment(text: string, node?: Node, definition?: NodeDefinition): T;
do(text: string, node?: Node, definition?: NodeDefinition): T;
doubleQuotes(text: string, node?: Node, definition?: NodeDefinition): T;
done(text: string, node?: Node, definition?: NodeDefinition): T;
elif(text: string, node?: Node, definition?: NodeDefinition): T;
else(text: string, node?: Node, definition?: NodeDefinition): T;
equal(text: string, node?: Node, definition?: NodeDefinition): T;
fi(text: string, node?: Node, definition?: NodeDefinition): T;
fileDescriptor(text: string, node?: Node, definition?: NodeDefinition): T;
fn(text: string, node?: Node, definition?: NodeDefinition): T;
for(text: string, node?: Node, definition?: NodeDefinition): T;
if(text: string, node?: Node, definition?: NodeDefinition): T;
in(text: string, node?: Node, definition?: NodeDefinition): T;
missingProgram(text: string, node?: Node, definition?: NodeDefinition): T;
newLine(): T;
option(text: string, node?: Node, definition?: NodeDefinition): T;
optionArg(text: string, node?: Node, definition?: NodeDefinition): T;
logicalOperator(text: string, node?: Node, definition?: NodeDefinition): T;
parens(test: string, node?: Node, definition?: NodeDefinition): T;
pipeline(text: string, node?: Node, definition?: NodeDefinition): T;
program(text: string, node?: Node, definition?: NodeDefinition): T;
redirect(text: string, node?: Node, definition?: NodeDefinition): T;
relationalOperator(text: string, node?: Node, definition?: NodeDefinition): T;
semicolon(text: string, node?: Node, definition?: NodeDefinition): T;
className?(text: string, definition?: NodeDefinition): T;
comment(text: string, definition?: NodeDefinition): T;
doubleQuotes(text: string, definition?: NodeDefinition): T;
equal(text: string, definition?: NodeDefinition): T;
parens(test: string, definition?: NodeDefinition): T;
semicolon(text: string, definition?: NodeDefinition): T;
space(): T;
subcommand(text: string, node?: Node, definition?: NodeDefinition): T;
/**

@@ -90,5 +107,3 @@ * lang: css

*/
tagName?(text: string, node?: Node, definition?: NodeDefinition): T;
testOperator(text: string, node?: Node, definition?: NodeDefinition): T;
then(text: string, node?: Node, definition?: NodeDefinition): T;
tagName?(text: string, definition?: NodeDefinition): T;
/**

@@ -101,6 +116,3 @@ * lang: css

*/
universalSelector?(text: string, node?: Node, definition?: Node): T;
variableName(text: string, node?: Node, definition?: NodeDefinition): T;
while(text: string, node?: Node, definition?: NodeDefinition): T;
word(text: string, node?: Node, definition?: NodeDefinition): T;
universalSelector?(text: string, definition?: Node): T;
/**

@@ -113,4 +125,4 @@ * lang: bash

*/
property?(text: string, node?: Node, definition?: NodeDefinition): T;
property?(text: string, definition?: NodeDefinition): T;
}
//# sourceMappingURL=interfaces.d.ts.map
{
"name": "kmdr-ast",
"version": "3.6.0",
"version": "3.6.1",
"description": "Traverse the AST of an explanation by kmdr",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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