@unified-latex/unified-latex-util-split 1.0.7 → 1.0.11

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.
Files changed (2) hide show
  1. package/README.md +106 -0
  2. package/package.json +5 -5
package/README.md ADDED
@@ -0,0 +1,106 @@
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
+ ## Install
17
+
18
+ ```bash
19
+ npm install @unified-latex/unified-latex-util-split
20
+ ```
21
+
22
+ This package contains both esm and commonjs exports. To explicitly access the esm export,
23
+ import the `.js` file. To explicitly access the commonjs export, import the `.cjs` file.
24
+
25
+ # Functions
26
+
27
+ ## `arrayJoin(array, sep)`
28
+
29
+ Joins an array of arrays with the item `sep`
30
+
31
+ ```typescript
32
+ function arrayJoin<T>(array: T[][], sep: T | T[]): T[];
33
+ ```
34
+
35
+ **Parameters**
36
+
37
+ | Param | Type |
38
+ | :---- | :--------- |
39
+ | array | `T[][]` |
40
+ | sep | `T \| T[]` |
41
+
42
+ ## `splitOnCondition(nodes, splitFunc, options)`
43
+
44
+ Split a list of nodes based on whether `splitFunc` returns `true`.
45
+ If `onlySplitOnFirstOccurrence` is set to true in the `options` object, then
46
+ there will be at most two segments returned.
47
+
48
+ ```typescript
49
+ function splitOnCondition(
50
+ nodes: Ast.Node[],
51
+ splitFunc: (node: Ast.Node) => boolean,
52
+ options: { onlySplitOnFirstOccurrence?: boolean }
53
+ ): { segments: Ast.Node[][]; separators: Ast.Node[] };
54
+ ```
55
+
56
+ **Parameters**
57
+
58
+ | Param | Type |
59
+ | :-------- | :-------------------------------- |
60
+ | nodes | `Ast.Node[]` |
61
+ | splitFunc | `(node: Ast.Node) => boolean` |
62
+ | options | <span color='gray'>Omitted</span> |
63
+
64
+ ## `splitOnMacro(ast, macroName)`
65
+
66
+ Split an array of AST nodes based on a macro. An object `{segments: [], macros: []}`
67
+ is returned. The original array is reconstructed as
68
+ `segments[0] + macros[0] + segments[1] + ...`.
69
+
70
+ ```typescript
71
+ function splitOnMacro(
72
+ ast: Ast.Node[],
73
+ macroName: string | string[]
74
+ ): { segments: Ast.Node[][]; macros: Ast.Macro[] };
75
+ ```
76
+
77
+ **Parameters**
78
+
79
+ | Param | Type |
80
+ | :-------- | :------------------- |
81
+ | ast | `Ast.Node[]` |
82
+ | macroName | `string \| string[]` |
83
+
84
+ `unsplitOnMacro({
85
+ segments,
86
+ macros,
87
+ })`
88
+ ---
89
+
90
+ Does the reverse of `splitOnMacro`
91
+
92
+ ```typescript
93
+ function unsplitOnMacro({
94
+ segments,
95
+ macros,
96
+ }: {
97
+ segments: Ast.Node[][];
98
+ macros: Ast.Node[] | Ast.Node[][];
99
+ }): Ast.Node[];
100
+ ```
101
+
102
+ **Parameters**
103
+
104
+ | Param | Type |
105
+ | :---------------------------------------- | :-------------------------------- |
106
+ | {&#xA; segments,&#xA; macros,&#xA;} | <span color='gray'>Omitted</span> |
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@unified-latex/unified-latex-util-split",
3
- "version": "1.0.7",
3
+ "version": "1.0.11",
4
4
  "description": "Functions for modifying a unified-latex AST",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@unified-latex/unified-latex-types": "^1.0.7",
9
- "@unified-latex/unified-latex-util-match": "^1.0.7"
8
+ "@unified-latex/unified-latex-types": "^1.0.11",
9
+ "@unified-latex/unified-latex-util-match": "^1.0.11"
10
10
  },
11
11
  "repository": {
12
12
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  "homepage": "https://github.com/siefkenj/unified-latex#readme",
29
29
  "exports": {
30
30
  ".": {
31
- "import": "index.js",
32
- "require": "index.cjs"
31
+ "import": "./index.js",
32
+ "require": "./index.cjs"
33
33
  },
34
34
  "./*js": "./*js",
35
35
  "./*": {