@unified-latex/unified-latex-util-scan
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -1,12 +0,46 @@ | ||
export * from "./libs/scan"; | ||
export * from "./libs/prefix-match"; | ||
import * as Ast from '@unified-latex/unified-latex-types'; | ||
import Trie from 'trie-prefix-tree'; | ||
/** | ||
* ## What is this? | ||
* Efficiently search for a large number of strings using a prefix-tree. | ||
* The longest match is returned. | ||
* | ||
* Functions to analyze `unified-latex` Abstract Syntax Tree (AST). | ||
* | ||
* ## When should I use this? | ||
* | ||
* If you want to look for particular AST nodes in an array; useful when making plugins. | ||
* @param options.startIndex the index to start scanning at. Defaults to 0. | ||
* @param options.matchSubstrings whether to allow matching only part of a substring. | ||
* @param options.assumeOneCharStrings assume that all strings are one character long (for example, like they are in math mode) | ||
*/ | ||
//# sourceMappingURL=index.d.ts.map | ||
export declare function prefixMatch(nodes: Ast.Node[], prefixes: string | string[] | ReturnType<typeof Trie>, options?: { | ||
startIndex?: number; | ||
matchSubstrings?: boolean; | ||
assumeOneCharStrings?: boolean; | ||
}): { | ||
match: string; | ||
endNodeIndex: number; | ||
endNodePartialMatch: string | null; | ||
} | null; | ||
/** | ||
* Scan `nodes` looking for the first occurrence of `token`. | ||
* If `options.onlySkipWhitespaceAndComments==true`, then the scan | ||
* will only skip whitespace/comment nodes. | ||
*/ | ||
export declare function scan(nodes: (Ast.Node | Ast.Argument)[], token: string | Ast.Node | Ast.Argument, options?: { | ||
/** | ||
* Index to start scanning. | ||
*/ | ||
startIndex?: number; | ||
/** | ||
* If `true`, whitespace and comments will be skilled but any other | ||
* node that doesn't match `token` will cause the scan to terminate. | ||
*/ | ||
onlySkipWhitespaceAndComments?: boolean; | ||
/** | ||
* If `true`, will look inside `Ast.String` nodes to see if the string contents | ||
* contain `token`. | ||
*/ | ||
allowSubstringMatches?: boolean; | ||
}): number | null; | ||
export { Trie } | ||
export { } |
11
index.js
@@ -1,4 +0,5 @@ | ||
// libs/scan.ts | ||
import { match } from "@unified-latex/unified-latex-util-match"; | ||
import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; | ||
import Trie from "trie-prefix-tree"; | ||
import { default as default2 } from "trie-prefix-tree"; | ||
function scan(nodes, token, options) { | ||
@@ -50,6 +51,2 @@ const { startIndex, onlySkipWhitespaceAndComments, allowSubstringMatches } = options || {}; | ||
} | ||
// libs/prefix-match.ts | ||
import Trie from "trie-prefix-tree"; | ||
import { match as match2 } from "@unified-latex/unified-latex-util-match"; | ||
function prefixMatch(nodes, prefixes, options) { | ||
@@ -88,3 +85,3 @@ const { | ||
const node = nodes[startIndex + i]; | ||
if (!match2.string(node)) { | ||
if (!match.string(node)) { | ||
break; | ||
@@ -125,3 +122,3 @@ } | ||
export { | ||
Trie, | ||
default2 as Trie, | ||
prefixMatch, | ||
@@ -128,0 +125,0 @@ scan |
{ | ||
"name": "@unified-latex/unified-latex-util-scan", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "Functions for modifying a unified-latex AST", | ||
@@ -8,5 +8,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"@unified-latex/unified-latex-types": "^1.6.1", | ||
"@unified-latex/unified-latex-util-match": "^1.6.1", | ||
"@unified-latex/unified-latex-util-print-raw": "^1.6.1", | ||
"@unified-latex/unified-latex-types": "^1.7.0", | ||
"@unified-latex/unified-latex-util-match": "^1.7.0", | ||
"@unified-latex/unified-latex-util-print-raw": "^1.7.0", | ||
"trie-prefix-tree": "^1.5.1" | ||
@@ -13,0 +13,0 @@ }, |
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
29713
7
289