@unified-latex/unified-latex-builder
Advanced tools
Comparing version 1.0.12 to 1.1.0
21
index.js
@@ -9,2 +9,5 @@ // libs/builders.ts | ||
function normalizeArgument(arg2, openMark = "{", closeMark = "}") { | ||
if (arg2 == null) { | ||
return { type: "argument", content: [], openMark: "", closeMark: "" }; | ||
} | ||
if (typeof arg2 === "string") { | ||
@@ -36,5 +39,8 @@ return { | ||
"[": { openMark: "[", closeMark: "]" }, | ||
"(": { openMark: "(", closeMark: ")" } | ||
"(": { openMark: "(", closeMark: ")" }, | ||
"<": { openMark: "<", closeMark: ">" } | ||
}; | ||
var CLOSE_BRACES = new Set(Object.values(BRACES_MAP).map((x) => x.closeMark).filter((x) => x)); | ||
var CLOSE_BRACES = new Set( | ||
Object.values(BRACES_MAP).map((x) => x.closeMark).filter((x) => x) | ||
); | ||
function bracesToOpenAndCloseMarks(braces) { | ||
@@ -62,5 +68,9 @@ const ret = []; | ||
if (braces.length !== args2.length) { | ||
throw new Error(`There is a difference between the number of supplied braces and the number of supplied arguments. ${args2.length} supplied with braces signature ${special.braces}`); | ||
throw new Error( | ||
`There is a difference between the number of supplied braces and the number of supplied arguments. ${args2.length} supplied with braces signature ${special.braces}` | ||
); | ||
} | ||
return args2.map((arg2, i) => normalizeArgument(arg2, braces[i].openMark, braces[i].closeMark)); | ||
return args2.map( | ||
(arg2, i) => normalizeArgument(arg2, braces[i].openMark, braces[i].closeMark) | ||
); | ||
} | ||
@@ -72,2 +82,5 @@ const openMark = (special == null ? void 0 : special.defaultOpenMark) ?? "{"; | ||
function arg(args2, special) { | ||
if (args2 == null) { | ||
return { type: "argument", content: [], openMark: "", closeMark: "" }; | ||
} | ||
if (typeof args2 === "string") { | ||
@@ -74,0 +87,0 @@ args2 = s(args2); |
import type * as Ast from "@unified-latex/unified-latex-types"; | ||
declare type CoercibleNode = string | Ast.Node; | ||
declare type CoercibleArgument = CoercibleNode | Ast.Argument; | ||
declare type CoercibleArgument = null | CoercibleNode | Ast.Argument; | ||
declare type MacroSpecialOptions = { | ||
@@ -23,3 +23,11 @@ escapeToken?: string; | ||
* ``` | ||
* will result in arguments `[a]{b}`. Valid braces are `*`, `[`, `{`, and `(`. | ||
* will result in arguments `[a]{b}`. Valid braces are `*`, `[`, `{`, `(`, and `<`. | ||
* | ||
* `null` may be passed as the value of an empty optional argument. If `null` is passed, | ||
* the `openBrace` and `closeBrace` of the argument will be set to empty strings and the | ||
* contents will be set to an empty array. For example, | ||
* ``` | ||
* args([null, "b"], { braces: "[]{}" }); | ||
* ``` | ||
* will produce the same structure as if the the first "optional argument" were omitted in regular parsing. | ||
*/ | ||
@@ -33,3 +41,11 @@ export declare function args(args: CoercibleArgument | CoercibleArgument[], special?: ArgumentsSpecialOptions): Ast.Argument[]; | ||
* ``` | ||
* will result in arguments `[a]`. Valid braces are `*`, `[`, `{`, and `(`. | ||
* will result in arguments `[a]`. Valid braces are `*`, `[`, `{`, `<`, and `(`. | ||
* | ||
* `null` may be passed as the value of an empty optional argument. If `null` is passed, | ||
* the `openBrace` and `closeBrace` of the argument will be set to empty strings and the | ||
* contents will be set to an empty array. For example, | ||
* ``` | ||
* args([null, "b"], { braces: "[]{}" }); | ||
* ``` | ||
* will produce the same structure as if the the first "optional argument" were omitted in regular parsing. | ||
*/ | ||
@@ -36,0 +52,0 @@ export declare function arg(args: CoercibleArgument | Ast.Node[], special?: ArgumentSpecialOptions): Ast.Argument; |
{ | ||
"name": "@unified-latex/unified-latex-builder", | ||
"version": "1.0.12", | ||
"version": "1.1.0", | ||
"description": "Tools for constructing unified-latex ASTs", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@unified-latex/unified-latex-types": "^1.0.12" | ||
"@unified-latex/unified-latex-types": "^1.1.0" | ||
}, | ||
@@ -11,0 +11,0 @@ "repository": { |
@@ -34,4 +34,12 @@ <!-- DO NOT MODIFY --> | ||
will result in arguments `[a]`. Valid braces are `*`, `[`, `{`, and `(`. | ||
will result in arguments `[a]`. Valid braces are `*`, `[`, `{`, `<`, and `(`. | ||
`null` may be passed as the value of an empty optional argument. If `null` is passed, | ||
the `openBrace` and `closeBrace` of the argument will be set to empty strings and the | ||
contents will be set to an empty array. For example, | ||
args([null, "b"], { braces: "[]{}" }); | ||
will produce the same structure as if the the first "optional argument" were omitted in regular parsing. | ||
```typescript | ||
@@ -68,4 +76,12 @@ function arg( | ||
will result in arguments `[a]{b}`. Valid braces are `*`, `[`, `{`, and `(`. | ||
will result in arguments `[a]{b}`. Valid braces are `*`, `[`, `{`, `(`, and `<`. | ||
`null` may be passed as the value of an empty optional argument. If `null` is passed, | ||
the `openBrace` and `closeBrace` of the argument will be set to empty strings and the | ||
contents will be set to an empty array. For example, | ||
args([null, "b"], { braces: "[]{}" }); | ||
will produce the same structure as if the the first "optional argument" were omitted in regular parsing. | ||
```typescript | ||
@@ -72,0 +88,0 @@ function args( |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40839
389
179