@unified-latex/unified-latex-util-split 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ <!-- DO NOT MODIFY -->
2
+ <!-- This file was autogenerated by build-docs.ts -->
3
+ <!-- Edit the docstring in index.ts and regenerate -->
4
+ <!-- rather than editing this file directly. -->
5
+ # unified-latex-util-split
6
+
7
+ ## What is this?
8
+
9
+ Functions to manipulate `unified-latex` Abstract Syntax Tree (AST).
10
+
11
+ ## When should I use this?
12
+
13
+ If you want break apart or join an array of nodes based on a condition. For example,
14
+ this is used to split on `&` characters in the `align` environment.
15
+
16
+ # Functions
17
+
18
+ ## `arrayJoin(array, sep)`
19
+
20
+ Joins an array of arrays with the item `sep`
21
+
22
+ ```typescript
23
+ function arrayJoin<T>(array: T[][], sep: T | T[]): T[];
24
+ ```
25
+
26
+ **Parameters**
27
+
28
+ | Param | Type |
29
+ | :---- | :--------- |
30
+ | array | `T[][]` |
31
+ | sep | `T \| T[]` |
32
+
33
+ ## `splitOnCondition(nodes, splitFunc, options)`
34
+
35
+ Split a list of nodes based on whether `splitFunc` returns `true`.
36
+ If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then
37
+ there will be at most two segments returned.
38
+
39
+ ```typescript
40
+ function splitOnCondition(
41
+ nodes: Ast.Node[],
42
+ splitFunc: (node: Ast.Node) => boolean,
43
+ options: { onlySplitOnFirstOccurrence?: boolean }
44
+ ): { segments: Ast.Node[][]; separators: Ast.Node[] };
45
+ ```
46
+
47
+ **Parameters**
48
+
49
+ | Param | Type |
50
+ | :-------- | :-------------------------------- |
51
+ | nodes | `Ast.Node[]` |
52
+ | splitFunc | `(node: Ast.Node) => boolean` |
53
+ | options | <span color='gray'>Omitted</span> |
54
+
55
+ ## `splitOnMacro(ast, macroName)`
56
+
57
+ Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`
58
+ is returned. The original array is reconstructed as
59
+ `segments[0] + macros[0] + segments[1] + ...`.
60
+
61
+ ```typescript
62
+ function splitOnMacro(
63
+ ast: Ast.Node[],
64
+ macroName: string | string[]
65
+ ): { segments: Ast.Node[][]; macros: Ast.Macro[] };
66
+ ```
67
+
68
+ **Parameters**
69
+
70
+ | Param | Type |
71
+ | :-------- | :------------------- |
72
+ | ast | `Ast.Node[]` |
73
+ | macroName | `string \| string[]` |
74
+
75
+ `unsplitOnMacro({
76
+ segments,
77
+ macros,
78
+ })`
79
+ ---
80
+
81
+ Does the reverse of `splitOnMacro`
82
+
83
+ ```typescript
84
+ function unsplitOnMacro({
85
+ segments,
86
+ macros,
87
+ }: {
88
+ segments: Ast.Node[][];
89
+ macros: Ast.Node[] | Ast.Node[][];
90
+ }): Ast.Node[];
91
+ ```
92
+
93
+ **Parameters**
94
+
95
+ | Param | Type |
96
+ | :---------------------------------------- | :-------------------------------- |
97
+ | {&#xA; segments,&#xA; macros,&#xA;} | <span color='gray'>Omitted</span> |
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../index.ts", "../libs/split-on-macro.ts", "../libs/split-on-condition.ts", "../libs/unsplit-on-macro.ts", "../libs/array-join.ts"],
4
+ "sourcesContent": ["export * from \"./libs/split-on-macro\";\nexport * from \"./libs/split-on-condition\";\nexport * from \"./libs/unsplit-on-macro\";\nexport * from \"./libs/array-join\";\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Functions to manipulate `unified-latex` Abstract Syntax Tree (AST).\n *\n * ## When should I use this?\n *\n * If you want break apart or join an array of nodes based on a condition. For example,\n * this is used to split on `&` characters in the `align` environment.\n */", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { splitOnCondition } from \"./split-on-condition\";\n\n/**\n * Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`\n * is returned. The original array is reconstructed as\n * `segments[0] + macros[0] + segments[1] + ...`.\n *\n * @param {[object]} ast\n * @param {(string|[string])} macroName\n * @returns {{segments: [object], macros: [object]}}\n */\nexport function splitOnMacro(\n ast: Ast.Node[],\n macroName: string | string[]\n): { segments: Ast.Node[][]; macros: Ast.Macro[] } {\n if (typeof macroName === \"string\") {\n macroName = [macroName];\n }\n if (!Array.isArray(macroName)) {\n throw new Error(\"Type coercion failed\");\n }\n const isSeparator = match.createMacroMatcher(macroName);\n const { segments, separators } = splitOnCondition(ast, isSeparator);\n return { segments, macros: separators as Ast.Macro[] };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Split a list of nodes based on whether `splitFunc` returns `true`.\n * If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then\n * there will be at most two segments returned.\n */\nexport function splitOnCondition(\n nodes: Ast.Node[],\n splitFunc: (node: Ast.Node) => boolean = () => false,\n options?: { onlySplitOnFirstOccurrence?: boolean }\n): { segments: Ast.Node[][]; separators: Ast.Node[] } {\n if (!Array.isArray(nodes)) {\n throw new Error(`Can only split an Array, not ${nodes}`);\n }\n\n const { onlySplitOnFirstOccurrence = false } = options || {};\n\n const splitIndices: number[] = [];\n for (let i = 0; i < nodes.length; i++) {\n if (splitFunc(nodes[i])) {\n splitIndices.push(i);\n if (onlySplitOnFirstOccurrence) {\n break;\n }\n }\n }\n\n // Short circuit if there is no splitting to be done\n if (splitIndices.length === 0) {\n return { segments: [nodes], separators: [] };\n }\n\n let separators = splitIndices.map((i) => nodes[i]);\n let segments = splitIndices.map((splitEnd, i) => {\n const splitStart = i === 0 ? 0 : splitIndices[i - 1] + 1;\n return nodes.slice(splitStart, splitEnd);\n });\n segments.push(\n nodes.slice(splitIndices[splitIndices.length - 1] + 1, nodes.length)\n );\n\n return { segments, separators };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Does the reverse of `splitOnMacro`\n */\nexport function unsplitOnMacro({\n segments,\n macros,\n}: {\n segments: Ast.Node[][];\n macros: Ast.Node[] | Ast.Node[][];\n}) {\n if (segments.length === 0) {\n console.warn(\"Trying to join zero segments\");\n return [];\n }\n if (segments.length !== macros.length + 1) {\n console.warn(\n \"Mismatch between lengths of macros and segments when trying to unsplit\"\n );\n }\n\n let ret = segments[0];\n for (let i = 0; i < macros.length; i++) {\n // Even though the type of macros[i] is node and not array,\n // Array.concat still works\n ret = ret.concat(macros[i]).concat(segments[i + 1]);\n }\n\n return ret;\n}\n", "/**\n * Joins an array of arrays with the item `sep`\n */\nexport function arrayJoin<T>(array: T[][], sep: T | T[]): T[] {\n return array.flatMap((item, i) => {\n if (i === 0) {\n return item;\n }\n if (Array.isArray(sep)) {\n return [...sep, ...item];\n } else {\n return [sep, ...item];\n }\n });\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sCAAsB;;;ACMf,0BACH,OACA,YAAyC,MAAM,OAC/C,SACkD;AAClD,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACvB,UAAM,IAAI,MAAM,gCAAgC,OAAO;AAAA,EAC3D;AAEA,QAAM,EAAE,6BAA6B,UAAU,WAAW,CAAC;AAE3D,QAAM,eAAyB,CAAC;AAChC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,QAAI,UAAU,MAAM,EAAE,GAAG;AACrB,mBAAa,KAAK,CAAC;AACnB,UAAI,4BAA4B;AAC5B;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAGA,MAAI,aAAa,WAAW,GAAG;AAC3B,WAAO,EAAE,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC,EAAE;AAAA,EAC/C;AAEA,MAAI,aAAa,aAAa,IAAI,CAAC,MAAM,MAAM,EAAE;AACjD,MAAI,WAAW,aAAa,IAAI,CAAC,UAAU,MAAM;AAC7C,UAAM,aAAa,MAAM,IAAI,IAAI,aAAa,IAAI,KAAK;AACvD,WAAO,MAAM,MAAM,YAAY,QAAQ;AAAA,EAC3C,CAAC;AACD,WAAS,KACL,MAAM,MAAM,aAAa,aAAa,SAAS,KAAK,GAAG,MAAM,MAAM,CACvE;AAEA,SAAO,EAAE,UAAU,WAAW;AAClC;;;AD9BO,sBACH,KACA,WAC+C;AAC/C,MAAI,OAAO,cAAc,UAAU;AAC/B,gBAAY,CAAC,SAAS;AAAA,EAC1B;AACA,MAAI,CAAC,MAAM,QAAQ,SAAS,GAAG;AAC3B,UAAM,IAAI,MAAM,sBAAsB;AAAA,EAC1C;AACA,QAAM,cAAc,sCAAM,mBAAmB,SAAS;AACtD,QAAM,EAAE,UAAU,eAAe,iBAAiB,KAAK,WAAW;AAClE,SAAO,EAAE,UAAU,QAAQ,WAA0B;AACzD;;;AErBO,wBAAwB;AAAA,EAC3B;AAAA,EACA;AAAA,GAID;AACC,MAAI,SAAS,WAAW,GAAG;AACvB,YAAQ,KAAK,8BAA8B;AAC3C,WAAO,CAAC;AAAA,EACZ;AACA,MAAI,SAAS,WAAW,OAAO,SAAS,GAAG;AACvC,YAAQ,KACJ,wEACJ;AAAA,EACJ;AAEA,MAAI,MAAM,SAAS;AACnB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAGpC,UAAM,IAAI,OAAO,OAAO,EAAE,EAAE,OAAO,SAAS,IAAI,EAAE;AAAA,EACtD;AAEA,SAAO;AACX;;;AC3BO,mBAAsB,OAAc,KAAmB;AAC1D,SAAO,MAAM,QAAQ,CAAC,MAAM,MAAM;AAC9B,QAAI,MAAM,GAAG;AACT,aAAO;AAAA,IACX;AACA,QAAI,MAAM,QAAQ,GAAG,GAAG;AACpB,aAAO,CAAC,GAAG,KAAK,GAAG,IAAI;AAAA,IAC3B,OAAO;AACH,aAAO,CAAC,KAAK,GAAG,IAAI;AAAA,IACxB;AAAA,EACJ,CAAC;AACL;",
6
+ "names": []
7
+ }
@@ -0,0 +1,15 @@
1
+ export * from "./libs/split-on-macro";
2
+ export * from "./libs/split-on-condition";
3
+ export * from "./libs/unsplit-on-macro";
4
+ export * from "./libs/array-join";
5
+ /**
6
+ * ## What is this?
7
+ *
8
+ * Functions to manipulate `unified-latex` Abstract Syntax Tree (AST).
9
+ *
10
+ * ## When should I use this?
11
+ *
12
+ * If you want break apart or join an array of nodes based on a condition. For example,
13
+ * this is used to split on `&` characters in the `align` environment.
14
+ */
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAGlC;;;;;;;;;GASG"}
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ // libs/split-on-macro.ts
2
+ import { match } from "@unified-latex/unified-latex-util-match";
3
+
4
+ // libs/split-on-condition.ts
5
+ function splitOnCondition(nodes, splitFunc = () => false, options) {
6
+ if (!Array.isArray(nodes)) {
7
+ throw new Error(`Can only split an Array, not ${nodes}`);
8
+ }
9
+ const { onlySplitOnFirstOccurrence = false } = options || {};
10
+ const splitIndices = [];
11
+ for (let i = 0; i < nodes.length; i++) {
12
+ if (splitFunc(nodes[i])) {
13
+ splitIndices.push(i);
14
+ if (onlySplitOnFirstOccurrence) {
15
+ break;
16
+ }
17
+ }
18
+ }
19
+ if (splitIndices.length === 0) {
20
+ return { segments: [nodes], separators: [] };
21
+ }
22
+ let separators = splitIndices.map((i) => nodes[i]);
23
+ let segments = splitIndices.map((splitEnd, i) => {
24
+ const splitStart = i === 0 ? 0 : splitIndices[i - 1] + 1;
25
+ return nodes.slice(splitStart, splitEnd);
26
+ });
27
+ segments.push(nodes.slice(splitIndices[splitIndices.length - 1] + 1, nodes.length));
28
+ return { segments, separators };
29
+ }
30
+
31
+ // libs/split-on-macro.ts
32
+ function splitOnMacro(ast, macroName) {
33
+ if (typeof macroName === "string") {
34
+ macroName = [macroName];
35
+ }
36
+ if (!Array.isArray(macroName)) {
37
+ throw new Error("Type coercion failed");
38
+ }
39
+ const isSeparator = match.createMacroMatcher(macroName);
40
+ const { segments, separators } = splitOnCondition(ast, isSeparator);
41
+ return { segments, macros: separators };
42
+ }
43
+
44
+ // libs/unsplit-on-macro.ts
45
+ function unsplitOnMacro({
46
+ segments,
47
+ macros
48
+ }) {
49
+ if (segments.length === 0) {
50
+ console.warn("Trying to join zero segments");
51
+ return [];
52
+ }
53
+ if (segments.length !== macros.length + 1) {
54
+ console.warn("Mismatch between lengths of macros and segments when trying to unsplit");
55
+ }
56
+ let ret = segments[0];
57
+ for (let i = 0; i < macros.length; i++) {
58
+ ret = ret.concat(macros[i]).concat(segments[i + 1]);
59
+ }
60
+ return ret;
61
+ }
62
+
63
+ // libs/array-join.ts
64
+ function arrayJoin(array, sep) {
65
+ return array.flatMap((item, i) => {
66
+ if (i === 0) {
67
+ return item;
68
+ }
69
+ if (Array.isArray(sep)) {
70
+ return [...sep, ...item];
71
+ } else {
72
+ return [sep, ...item];
73
+ }
74
+ });
75
+ }
76
+ export {
77
+ arrayJoin,
78
+ splitOnCondition,
79
+ splitOnMacro,
80
+ unsplitOnMacro
81
+ };
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../libs/split-on-macro.ts", "../libs/split-on-condition.ts", "../libs/unsplit-on-macro.ts", "../libs/array-join.ts"],
4
+ "sourcesContent": ["import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { splitOnCondition } from \"./split-on-condition\";\n\n/**\n * Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`\n * is returned. The original array is reconstructed as\n * `segments[0] + macros[0] + segments[1] + ...`.\n *\n * @param {[object]} ast\n * @param {(string|[string])} macroName\n * @returns {{segments: [object], macros: [object]}}\n */\nexport function splitOnMacro(\n ast: Ast.Node[],\n macroName: string | string[]\n): { segments: Ast.Node[][]; macros: Ast.Macro[] } {\n if (typeof macroName === \"string\") {\n macroName = [macroName];\n }\n if (!Array.isArray(macroName)) {\n throw new Error(\"Type coercion failed\");\n }\n const isSeparator = match.createMacroMatcher(macroName);\n const { segments, separators } = splitOnCondition(ast, isSeparator);\n return { segments, macros: separators as Ast.Macro[] };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Split a list of nodes based on whether `splitFunc` returns `true`.\n * If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then\n * there will be at most two segments returned.\n */\nexport function splitOnCondition(\n nodes: Ast.Node[],\n splitFunc: (node: Ast.Node) => boolean = () => false,\n options?: { onlySplitOnFirstOccurrence?: boolean }\n): { segments: Ast.Node[][]; separators: Ast.Node[] } {\n if (!Array.isArray(nodes)) {\n throw new Error(`Can only split an Array, not ${nodes}`);\n }\n\n const { onlySplitOnFirstOccurrence = false } = options || {};\n\n const splitIndices: number[] = [];\n for (let i = 0; i < nodes.length; i++) {\n if (splitFunc(nodes[i])) {\n splitIndices.push(i);\n if (onlySplitOnFirstOccurrence) {\n break;\n }\n }\n }\n\n // Short circuit if there is no splitting to be done\n if (splitIndices.length === 0) {\n return { segments: [nodes], separators: [] };\n }\n\n let separators = splitIndices.map((i) => nodes[i]);\n let segments = splitIndices.map((splitEnd, i) => {\n const splitStart = i === 0 ? 0 : splitIndices[i - 1] + 1;\n return nodes.slice(splitStart, splitEnd);\n });\n segments.push(\n nodes.slice(splitIndices[splitIndices.length - 1] + 1, nodes.length)\n );\n\n return { segments, separators };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Does the reverse of `splitOnMacro`\n */\nexport function unsplitOnMacro({\n segments,\n macros,\n}: {\n segments: Ast.Node[][];\n macros: Ast.Node[] | Ast.Node[][];\n}) {\n if (segments.length === 0) {\n console.warn(\"Trying to join zero segments\");\n return [];\n }\n if (segments.length !== macros.length + 1) {\n console.warn(\n \"Mismatch between lengths of macros and segments when trying to unsplit\"\n );\n }\n\n let ret = segments[0];\n for (let i = 0; i < macros.length; i++) {\n // Even though the type of macros[i] is node and not array,\n // Array.concat still works\n ret = ret.concat(macros[i]).concat(segments[i + 1]);\n }\n\n return ret;\n}\n", "/**\n * Joins an array of arrays with the item `sep`\n */\nexport function arrayJoin<T>(array: T[][], sep: T | T[]): T[] {\n return array.flatMap((item, i) => {\n if (i === 0) {\n return item;\n }\n if (Array.isArray(sep)) {\n return [...sep, ...item];\n } else {\n return [sep, ...item];\n }\n });\n}\n"],
5
+ "mappings": ";AACA;;;ACMO,0BACH,OACA,YAAyC,MAAM,OAC/C,SACkD;AAClD,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACvB,UAAM,IAAI,MAAM,gCAAgC,OAAO;AAAA,EAC3D;AAEA,QAAM,EAAE,6BAA6B,UAAU,WAAW,CAAC;AAE3D,QAAM,eAAyB,CAAC;AAChC,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACnC,QAAI,UAAU,MAAM,EAAE,GAAG;AACrB,mBAAa,KAAK,CAAC;AACnB,UAAI,4BAA4B;AAC5B;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAGA,MAAI,aAAa,WAAW,GAAG;AAC3B,WAAO,EAAE,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC,EAAE;AAAA,EAC/C;AAEA,MAAI,aAAa,aAAa,IAAI,CAAC,MAAM,MAAM,EAAE;AACjD,MAAI,WAAW,aAAa,IAAI,CAAC,UAAU,MAAM;AAC7C,UAAM,aAAa,MAAM,IAAI,IAAI,aAAa,IAAI,KAAK;AACvD,WAAO,MAAM,MAAM,YAAY,QAAQ;AAAA,EAC3C,CAAC;AACD,WAAS,KACL,MAAM,MAAM,aAAa,aAAa,SAAS,KAAK,GAAG,MAAM,MAAM,CACvE;AAEA,SAAO,EAAE,UAAU,WAAW;AAClC;;;AD9BO,sBACH,KACA,WAC+C;AAC/C,MAAI,OAAO,cAAc,UAAU;AAC/B,gBAAY,CAAC,SAAS;AAAA,EAC1B;AACA,MAAI,CAAC,MAAM,QAAQ,SAAS,GAAG;AAC3B,UAAM,IAAI,MAAM,sBAAsB;AAAA,EAC1C;AACA,QAAM,cAAc,MAAM,mBAAmB,SAAS;AACtD,QAAM,EAAE,UAAU,eAAe,iBAAiB,KAAK,WAAW;AAClE,SAAO,EAAE,UAAU,QAAQ,WAA0B;AACzD;;;AErBO,wBAAwB;AAAA,EAC3B;AAAA,EACA;AAAA,GAID;AACC,MAAI,SAAS,WAAW,GAAG;AACvB,YAAQ,KAAK,8BAA8B;AAC3C,WAAO,CAAC;AAAA,EACZ;AACA,MAAI,SAAS,WAAW,OAAO,SAAS,GAAG;AACvC,YAAQ,KACJ,wEACJ;AAAA,EACJ;AAEA,MAAI,MAAM,SAAS;AACnB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AAGpC,UAAM,IAAI,OAAO,OAAO,EAAE,EAAE,OAAO,SAAS,IAAI,EAAE;AAAA,EACtD;AAEA,SAAO;AACX;;;AC3BO,mBAAsB,OAAc,KAAmB;AAC1D,SAAO,MAAM,QAAQ,CAAC,MAAM,MAAM;AAC9B,QAAI,MAAM,GAAG;AACT,aAAO;AAAA,IACX;AACA,QAAI,MAAM,QAAQ,GAAG,GAAG;AACpB,aAAO,CAAC,GAAG,KAAK,GAAG,IAAI;AAAA,IAC3B,OAAO;AACH,aAAO,CAAC,KAAK,GAAG,IAAI;AAAA,IACxB;AAAA,EACJ,CAAC;AACL;",
6
+ "names": []
7
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Joins an array of arrays with the item `sep`
3
+ */
4
+ export declare function arrayJoin<T>(array: T[][], sep: T | T[]): T[];
5
+ //# sourceMappingURL=array-join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-join.d.ts","sourceRoot":"","sources":["../../libs/array-join.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,CAW5D"}
@@ -0,0 +1,13 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Split a list of nodes based on whether `splitFunc` returns `true`.
4
+ * If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then
5
+ * there will be at most two segments returned.
6
+ */
7
+ export declare function splitOnCondition(nodes: Ast.Node[], splitFunc?: (node: Ast.Node) => boolean, options?: {
8
+ onlySplitOnFirstOccurrence?: boolean;
9
+ }): {
10
+ segments: Ast.Node[][];
11
+ separators: Ast.Node[];
12
+ };
13
+ //# sourceMappingURL=split-on-condition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-on-condition.d.ts","sourceRoot":"","sources":["../../libs/split-on-condition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EACjB,SAAS,GAAE,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,KAAK,OAAqB,EACpD,OAAO,CAAC,EAAE;IAAE,0BAA0B,CAAC,EAAE,OAAO,CAAA;CAAE,GACnD;IAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC,IAAI,EAAE,CAAA;CAAE,CAgCpD"}
@@ -0,0 +1,15 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`
4
+ * is returned. The original array is reconstructed as
5
+ * `segments[0] + macros[0] + segments[1] + ...`.
6
+ *
7
+ * @param {[object]} ast
8
+ * @param {(string|[string])} macroName
9
+ * @returns {{segments: [object], macros: [object]}}
10
+ */
11
+ export declare function splitOnMacro(ast: Ast.Node[], macroName: string | string[]): {
12
+ segments: Ast.Node[][];
13
+ macros: Ast.Macro[];
14
+ };
15
+ //# sourceMappingURL=split-on-macro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-on-macro.d.ts","sourceRoot":"","sources":["../../libs/split-on-macro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAI1D;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CACxB,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EACf,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAC7B;IAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAAC,MAAM,EAAE,GAAG,CAAC,KAAK,EAAE,CAAA;CAAE,CAUjD"}
@@ -0,0 +1,9 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Does the reverse of `splitOnMacro`
4
+ */
5
+ export declare function unsplitOnMacro({ segments, macros, }: {
6
+ segments: Ast.Node[][];
7
+ macros: Ast.Node[] | Ast.Node[][];
8
+ }): Ast.Node[];
9
+ //# sourceMappingURL=unsplit-on-macro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unsplit-on-macro.d.ts","sourceRoot":"","sources":["../../libs/unsplit-on-macro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAC3B,QAAQ,EACR,MAAM,GACT,EAAE;IACC,QAAQ,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IACvB,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;CACrC,cAmBA"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@unified-latex/unified-latex-util-split",
3
+ "version": "1.0.1",
4
+ "description": "Functions for modifying a unified-latex AST",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "dependencies": {
8
+ "@unified-latex/unified-latex-types": "*",
9
+ "@unified-latex/unified-latex-util-match": "*"
10
+ },
11
+ "files": [
12
+ "dist/**/*.ts",
13
+ "dist/**/*.js",
14
+ "dist/**/*.map",
15
+ "dist/**/*.json"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ },
22
+ "./*js": "./dist/*js",
23
+ "./*": {
24
+ "import": "./dist/*.js",
25
+ "require": "./dist/*.cjs"
26
+ }
27
+ },
28
+ "scripts": {
29
+ "build": "npm run clean && mkdirp ./dist && npm run compile",
30
+ "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
31
+ "compile": "tsc -b tsconfig.json & node build.js",
32
+ "test": "jest"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/siefkenj/unified-latex.git"
37
+ },
38
+ "keywords": [
39
+ "pegjs",
40
+ "latex",
41
+ "parser",
42
+ "prettier",
43
+ "unified-latex",
44
+ "unified"
45
+ ],
46
+ "author": "Jason Siefken",
47
+ "license": "MIT",
48
+ "bugs": {
49
+ "url": "https://github.com/siefkenj/unified-latex/issues"
50
+ },
51
+ "homepage": "https://github.com/siefkenj/unified-latex#readme",
52
+ "jest": {
53
+ "transformIgnorePatterns": [
54
+ "node_modules/(?!unified|bail|is-plain-obj|trough|vfile.*|unist.*|hast.*|property-information|html-void-elements|.*-separated-tokens|.*entities.*|ccount|rehype*|string-width|strip-ansi|ansi-regex|supports-color)"
55
+ ],
56
+ "transform": {
57
+ "\\.m?jsx?$": "esbuild-jest",
58
+ "latex.pegjs$": "<rootDir>/../../tests/pegjs-preprocessor-latex.js",
59
+ "\\.pegjs$": "<rootDir>/../../tests/pegjs-preprocessor.js",
60
+ "^.+\\.tsx?$": "ts-jest"
61
+ }
62
+ }
63
+ }