New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@unified-latex/unified-latex-util-arguments

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@unified-latex/unified-latex-util-arguments - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

86

index.d.ts

@@ -1,24 +0,72 @@

export { gobbleArguments } from "./libs/gobble-arguments";
export { attachMacroArgs, attachMacroArgsInArray, } from "./libs/attach-arguments";
export * from "./libs/unified-latex-attach-macro-arguments";
export * from "./libs/get-args-content";
export * from "./libs/gobble-single-argument";
export * from "./libs/gobble-arguments";
import { ArgSpecAst } from '@unified-latex/unified-latex-util-argspec';
import { ArgumentParser } from '@unified-latex/unified-latex-types';
import * as Ast from '@unified-latex/unified-latex-types';
import { MacroInfoRecord } from '@unified-latex/unified-latex-types';
import { Plugin as Plugin_2 } from 'unified';
/**
* ## What is this?
* Recursively search for and attach the arguments for a
* particular macro to its AST node. `macros` should
* contain a `signature` property which specifies the arguments
* signature in xparse syntax.
*/
export declare function attachMacroArgs(tree: Ast.Ast, macros: MacroInfoRecord): void;
/**
* Search (in a right-associative way) through the array for instances of
* `macros` and attach arguments to the macro. Argument signatures are
* specified by `macros[].signature`.
*
* Functions to help modify and attach arguments to macros in a `unified-latex` Abstract Syntax Tree (AST).
* Info stored in `macros[].renderInfo` will be attached to the node
* with attribute `_renderInfo`.
*/
export declare function attachMacroArgsInArray(nodes: Ast.Node[], macros: MacroInfoRecord): void;
/**
* Returns the content of `args` for a macro or environment as an array. If an argument
* was omitted (e.g., because it was an optional arg that wasn't included), then `null` is returned.
*/
export declare function getArgsContent(node: Ast.Macro | Ast.Environment): (Ast.Node[] | null)[];
/**
* Returns the content of `args` for a macro or environment as an object whose keys are the "names"
* of each argument. These names of the arguments must be specified in the `_renderInfo` prop. If `_renderInfo`
* does not contain a `namedArguments` array, then an empty object will be returned.
*
* By default, TeX doesn't actually have a concept of macro "arguments". Instead, TeX searches the
* tokens after a macro and processes them according to the macro's rules. However, LaTeX attempts
* to make macros look like functions that accept arguments. To attach the "arguments" to a macro
* node, the `unified-latex` AST needs to be reparsed and manipulated.
* @namedArgumentsFallback - If `_renderInfo.namedArguments` is not provided, `namedArgumentsFallback` is ued.
*/
export declare function getNamedArgsContent(node: Ast.Macro | Ast.Environment, namedArgumentsFallback?: readonly (string | null)[]): Record<string, Ast.Node[] | null>;
/**
* Gobbles an argument of whose type is specified
* by `argSpec` starting at the position `startPos`. If an argument couldn't be found,
* `argument` will be `null`.
*/
export declare function gobbleArguments(nodes: Ast.Node[], argSpec: string | ArgSpecAst.Node[] | ArgumentParser, startPos?: number): {
args: Ast.Argument[];
nodesRemoved: number;
};
/**
* Gobbles an argument of whose type is specified
* by `argSpec` starting at the position `startPos`.
* If an argument couldn't be found, `argument` will be `null`.
*/
export declare function gobbleSingleArgument(nodes: Ast.Node[], argSpec: ArgSpecAst.Node, startPos?: number): {
argument: Ast.Argument | null;
nodesRemoved: number;
};
declare type PluginOptions = {
macros: MacroInfoRecord;
} | undefined;
/**
* Unified plugin to attach macro arguments to the macros specified via the `macros`
* option.
*
* ## When should I use this?
*
* If you have custom macros that you want arguments attached to.
*
* If you know ahead of time which macros need arguments attached to them, use `unified-latex-util-parse`
* and pass in the appropriate macro info instead.
* @param macros An object whose keys are macro names and values contains information about the macro and its argument signature.
*/
//# sourceMappingURL=index.d.ts.map
export declare const unifiedLatexAttachMacroArguments: Plugin_2<PluginOptions[], Ast.Root, Ast.Root>;
export { }

@@ -1,11 +0,7 @@

// libs/gobble-arguments.ts
import { arg as arg2 } from "@unified-latex/unified-latex-builder";
import {
parse as parseArgspec
} from "@unified-latex/unified-latex-util-argspec";
// libs/gobble-single-argument.ts
import { arg } from "@unified-latex/unified-latex-builder";
import { parse } from "@unified-latex/unified-latex-util-argspec";
import { match } from "@unified-latex/unified-latex-util-match";
import { scan } from "@unified-latex/unified-latex-util-scan";
import { updateRenderInfo } from "@unified-latex/unified-latex-util-render-info";
import { visit } from "@unified-latex/unified-latex-util-visit";
function gobbleSingleArgument(nodes, argSpec, startPos = 0) {

@@ -243,4 +239,2 @@ if (typeof argSpec === "string" || !argSpec.type) {

}
// libs/gobble-arguments.ts
function gobbleArguments(nodes, argSpec, startPos = 0) {

@@ -251,3 +245,3 @@ if (typeof argSpec === "function") {

if (typeof argSpec === "string") {
argSpec = parseArgspec(argSpec);
argSpec = parse(argSpec);
}

@@ -260,3 +254,7 @@ const args = [];

const argForToken = Object.fromEntries(
spec.embellishmentTokens.map((t) => [t, emptyArg()])
spec.embellishmentTokens.map((t, i) => {
var _a;
const defaultArg = "defaultArg" in spec ? (_a = spec.defaultArg) == null ? void 0 : _a[i] : void 0;
return [t, emptyArg(defaultArg)];
})
);

@@ -287,3 +285,4 @@ let { argument, nodesRemoved: removed } = gobbleSingleArgument(

);
args.push(argument || emptyArg());
const defaultArg = "defaultArg" in spec ? spec.defaultArg : void 0;
args.push(argument || emptyArg(defaultArg));
nodesRemoved += removed;

@@ -300,13 +299,12 @@ }

}
function emptyArg() {
return arg2([], { openMark: "", closeMark: "" });
function emptyArg(defaultArg) {
const ret = arg([], { openMark: "", closeMark: "" });
if (defaultArg != null) {
updateRenderInfo(ret, { defaultArg });
}
return ret;
}
// libs/attach-arguments.ts
import { match as match2 } from "@unified-latex/unified-latex-util-match";
import { updateRenderInfo } from "@unified-latex/unified-latex-util-render-info";
import { visit } from "@unified-latex/unified-latex-util-visit";
function attachMacroArgsInArray(nodes, macros) {
let currIndex;
const isRelevantMacro = match2.createMacroMatcher(macros);
const isRelevantMacro = match.createMacroMatcher(macros);
function gobbleUntilMacro() {

@@ -352,6 +350,3 @@ while (currIndex >= 0 && !isRelevantMacro(nodes[currIndex])) {

}
// libs/unified-latex-attach-macro-arguments.ts
import { visit as visit2 } from "@unified-latex/unified-latex-util-visit";
var unifiedLatexAttachMacroArguments = function unifiedLatexAttachMacroArguments2(options) {
const unifiedLatexAttachMacroArguments = function unifiedLatexAttachMacroArguments2(options) {
return (tree) => {

@@ -364,3 +359,3 @@ const { macros = {} } = options || {};

}
visit2(
visit(
tree,

@@ -374,4 +369,2 @@ (nodes) => {

};
// libs/get-args-content.ts
function getArgsContent(node) {

@@ -381,7 +374,7 @@ if (!Array.isArray(node.args)) {

}
return node.args.map((arg3) => {
if (arg3.openMark === "" && arg3.content.length === 0) {
return node.args.map((arg2) => {
if (arg2.openMark === "" && arg2.content.length === 0) {
return null;
}
return arg3.content;
return arg2.content;
});

@@ -396,3 +389,3 @@ }

const ret = {};
node.args.forEach((arg3, i) => {
node.args.forEach((arg2, i) => {
const name = names[i];

@@ -402,4 +395,4 @@ if (name == null) {

}
let val = arg3.content;
if (arg3.openMark === "" && arg3.content.length === 0) {
let val = arg2.content;
if (arg2.openMark === "" && arg2.content.length === 0) {
val = null;

@@ -406,0 +399,0 @@ }

{
"name": "@unified-latex/unified-latex-util-arguments",
"version": "1.6.1",
"version": "1.7.0",
"description": "Tools for manipulating unified-latex ASTs",

@@ -8,9 +8,9 @@ "main": "index.js",

"dependencies": {
"@unified-latex/unified-latex-builder": "^1.6.1",
"@unified-latex/unified-latex-types": "^1.6.1",
"@unified-latex/unified-latex-util-argspec": "^1.6.1",
"@unified-latex/unified-latex-util-match": "^1.6.1",
"@unified-latex/unified-latex-util-render-info": "^1.6.1",
"@unified-latex/unified-latex-util-scan": "^1.6.1",
"@unified-latex/unified-latex-util-visit": "^1.6.1",
"@unified-latex/unified-latex-builder": "^1.7.0",
"@unified-latex/unified-latex-types": "^1.7.0",
"@unified-latex/unified-latex-util-argspec": "^1.7.0",
"@unified-latex/unified-latex-util-match": "^1.7.0",
"@unified-latex/unified-latex-util-render-info": "^1.7.0",
"@unified-latex/unified-latex-util-scan": "^1.7.0",
"@unified-latex/unified-latex-util-visit": "^1.7.0",
"unified": "^10.1.2"

@@ -17,0 +17,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

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