@hardlydifficult/text 1.0.41 → 1.0.43
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 +57 -54
- package/dist/codeBlock.d.ts +5 -0
- package/dist/codeBlock.d.ts.map +1 -0
- package/dist/codeBlock.js +26 -0
- package/dist/codeBlock.js.map +1 -0
- package/dist/conditionParser.d.ts +30 -0
- package/dist/conditionParser.d.ts.map +1 -0
- package/dist/conditionParser.js +248 -0
- package/dist/conditionParser.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/linker.d.ts +37 -51
- package/dist/linker.d.ts.map +1 -1
- package/dist/linker.js +63 -83
- package/dist/linker.js.map +1 -1
- package/dist/sessionId.d.ts +5 -0
- package/dist/sessionId.d.ts.map +1 -0
- package/dist/sessionId.js +10 -0
- package/dist/sessionId.js.map +1 -0
- package/package.json +1 -1
- package/dist/escapeFence.d.ts +0 -9
- package/dist/escapeFence.d.ts.map +0 -1
- package/dist/escapeFence.js +0 -22
- package/dist/escapeFence.js.map +0 -1
package/README.md
CHANGED
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
buildFileTree,
|
|
22
22
|
convertFormat,
|
|
23
23
|
healYaml,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
linkText,
|
|
25
|
+
codeBlock,
|
|
26
26
|
stripAnsi
|
|
27
27
|
} from "@hardlydifficult/text";
|
|
28
28
|
|
|
@@ -63,13 +63,12 @@ healYaml('description: "Text with: colon"');
|
|
|
63
63
|
// 'description: "Text with: colon"'
|
|
64
64
|
|
|
65
65
|
// Linkify issue references
|
|
66
|
-
|
|
67
|
-
linker.apply("Fix ENG-533", { format: "slack" });
|
|
66
|
+
linkText("Fix ENG-533", { linear: "fairmint", for: "slack" });
|
|
68
67
|
// "Fix <https://linear.app/fairmint/issue/ENG-533|ENG-533>"
|
|
69
68
|
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
// "````"
|
|
69
|
+
// Build a safe markdown code block
|
|
70
|
+
codeBlock("code with ``` backticks", "ts");
|
|
71
|
+
// "````ts\ncode with ``` backticks\n````"
|
|
73
72
|
|
|
74
73
|
// Strip ANSI codes
|
|
75
74
|
stripAnsi("\x1b[31mRed text\x1b[0m");
|
|
@@ -309,84 +308,88 @@ healYaml("description: Text: with colons");
|
|
|
309
308
|
// 'description: "Text: with colons"'
|
|
310
309
|
```
|
|
311
310
|
|
|
312
|
-
##
|
|
311
|
+
## Linkifying References
|
|
313
312
|
|
|
314
|
-
|
|
313
|
+
Turns issue and PR references into links without builder ceremony.
|
|
315
314
|
|
|
316
|
-
###
|
|
315
|
+
### linkText
|
|
317
316
|
|
|
318
|
-
|
|
317
|
+
Best for one-off calls. Built-in presets cover the formats used in this repo.
|
|
319
318
|
|
|
320
319
|
```typescript
|
|
321
|
-
import {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
320
|
+
import { linkText } from "@hardlydifficult/text";
|
|
321
|
+
|
|
322
|
+
linkText("Fix ENG-533 PR#42", {
|
|
323
|
+
linear: "fairmint",
|
|
324
|
+
githubPrs: "Fairmint/api",
|
|
325
|
+
for: "slack",
|
|
326
|
+
});
|
|
327
|
+
// "Fix <https://linear.app/fairmint/issue/ENG-533|ENG-533> <https://github.com/Fairmint/api/pull/42|PR#42>"
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
interface LinkTextOptions {
|
|
332
|
+
linear?: string;
|
|
333
|
+
githubPrs?: string;
|
|
334
|
+
rules?: LinkRule[];
|
|
335
|
+
for?: LinkStyle; // "slack" | "discord" | "markdown" | "plain"
|
|
336
|
+
ignoreCode?: boolean; // default: true
|
|
337
|
+
ignoreExistingLinks?: boolean; // default: true
|
|
329
338
|
}
|
|
330
339
|
```
|
|
331
340
|
|
|
332
341
|
### createLinker
|
|
333
342
|
|
|
334
|
-
|
|
343
|
+
Use this when the same link rules are applied repeatedly.
|
|
335
344
|
|
|
336
345
|
```typescript
|
|
337
346
|
import { createLinker } from "@hardlydifficult/text";
|
|
338
347
|
|
|
339
|
-
const linker = createLinker(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
348
|
+
const linker = createLinker({
|
|
349
|
+
linear: "fairmint",
|
|
350
|
+
githubPrs: "Fairmint/api",
|
|
351
|
+
rules: [
|
|
352
|
+
{
|
|
353
|
+
name: "incident",
|
|
354
|
+
match: /\bINC-\d+\b/g,
|
|
355
|
+
to: ({ text }) => `https://incident.io/${text}`,
|
|
356
|
+
},
|
|
357
|
+
],
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
linker.link("Fix ENG-533 PR#42 INC-99", { for: "slack" });
|
|
349
361
|
// "Fix <https://linear.app/fairmint/issue/ENG-533|ENG-533> <https://github.com/Fairmint/api/pull/42|PR#42> <https://incident.io/INC-99|INC-99>"
|
|
350
362
|
```
|
|
351
363
|
|
|
352
|
-
###
|
|
364
|
+
### LinkRule
|
|
353
365
|
|
|
354
|
-
Custom rules
|
|
366
|
+
Custom rules are small and direct: match text, map it to a URL, optionally set a priority.
|
|
355
367
|
|
|
356
368
|
```typescript
|
|
357
369
|
interface LinkRule {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
skipCode?: boolean;
|
|
363
|
-
skipExistingLinks?: boolean;
|
|
370
|
+
name?: string;
|
|
371
|
+
match: RegExp;
|
|
372
|
+
to: string | ((ctx: { text: string; groups: string[] }) => string);
|
|
373
|
+
priority?: number;
|
|
364
374
|
}
|
|
365
375
|
```
|
|
366
376
|
|
|
367
|
-
### Methods
|
|
368
|
-
|
|
369
|
-
- `custom(pattern, href, options)`: Add custom rule
|
|
370
|
-
- `linear(orgOrProject)`: Link Linear issues
|
|
371
|
-
- `githubPr(repo)`: Link GitHub PRs
|
|
372
|
-
- `apply(text, options)`: Linkify and preserve format
|
|
373
|
-
- `linkText(text, options)`: Linkify plain text
|
|
374
|
-
- `linkMarkdown(text, options)`: Linkify markdown content
|
|
375
|
-
- `reset()`: Clear rules
|
|
376
|
-
|
|
377
377
|
## Markdown Utilities
|
|
378
378
|
|
|
379
379
|
Tools for working with markdown fences and formatting.
|
|
380
380
|
|
|
381
|
-
###
|
|
381
|
+
### codeBlock
|
|
382
382
|
|
|
383
|
-
|
|
383
|
+
Wraps content in a safe fenced code block and picks a longer fence automatically when needed.
|
|
384
384
|
|
|
385
385
|
```typescript
|
|
386
|
-
import {
|
|
386
|
+
import { codeBlock } from "@hardlydifficult/text";
|
|
387
|
+
|
|
388
|
+
codeBlock("hello");
|
|
389
|
+
// "```\nhello\n```"
|
|
387
390
|
|
|
388
|
-
|
|
389
|
-
|
|
391
|
+
codeBlock("const x = 1;", "ts");
|
|
392
|
+
// "```ts\nconst x = 1;\n```"
|
|
390
393
|
```
|
|
391
394
|
|
|
392
395
|
### stripAnsi
|
|
@@ -401,4 +404,4 @@ stripAnsi("\x1b[31mRed\x1b[0m"); // "Red"
|
|
|
401
404
|
|
|
402
405
|
## License
|
|
403
406
|
|
|
404
|
-
MIT
|
|
407
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeBlock.d.ts","sourceRoot":"","sources":["../src/codeBlock.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAMpE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codeBlock = codeBlock;
|
|
4
|
+
function pickFence(content) {
|
|
5
|
+
let maxBackticks = 3;
|
|
6
|
+
const backtickMatches = content.match(/`+/g);
|
|
7
|
+
if (backtickMatches === null) {
|
|
8
|
+
return "`".repeat(maxBackticks);
|
|
9
|
+
}
|
|
10
|
+
for (const match of backtickMatches) {
|
|
11
|
+
if (match.length >= maxBackticks) {
|
|
12
|
+
maxBackticks = match.length + 1;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return "`".repeat(maxBackticks);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wrap content in a safe fenced markdown code block.
|
|
19
|
+
*/
|
|
20
|
+
function codeBlock(content, language) {
|
|
21
|
+
const fence = pickFence(content);
|
|
22
|
+
const openingLine = language !== undefined && language !== "" ? `${fence}${language}` : fence;
|
|
23
|
+
const closingPrefix = content.endsWith("\n") ? "" : "\n";
|
|
24
|
+
return `${openingLine}\n${content}${closingPrefix}${fence}`;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=codeBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeBlock.js","sourceRoot":"","sources":["../src/codeBlock.ts"],"names":[],"mappings":";;AAmBA,8BAMC;AAzBD,SAAS,SAAS,CAAC,OAAe;IAChC,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;QAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAClC,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;YACjC,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,OAAe,EAAE,QAAiB;IAC1D,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,WAAW,GACf,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5E,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACzD,OAAO,GAAG,WAAW,KAAK,OAAO,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe condition parser for strategy expressions.
|
|
3
|
+
*
|
|
4
|
+
* Supports: indicator aliases, numeric literals, comparison operators (>, <, >=, <=, ==),
|
|
5
|
+
* logical operators (AND, OR), and parentheses.
|
|
6
|
+
*
|
|
7
|
+
* Examples:
|
|
8
|
+
* "sma_7 > sma_30"
|
|
9
|
+
* "rsi_14 < 30"
|
|
10
|
+
* "macd_signal > 0 AND rsi_14 < 70"
|
|
11
|
+
* "(sma_7 > sma_30) AND (rsi_14 < 70 OR bollinger < 0.2)"
|
|
12
|
+
*
|
|
13
|
+
* NO eval() - uses a simple recursive descent parser.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Evaluate a condition expression against a set of variable values.
|
|
17
|
+
*
|
|
18
|
+
* @param condition - Expression string, e.g. "sma_7 > sma_30 AND rsi_14 < 70"
|
|
19
|
+
* @param variables - Map of variable names to their current values
|
|
20
|
+
* @returns true if the condition is met
|
|
21
|
+
*/
|
|
22
|
+
export declare function evaluateCondition(condition: string, variables: Record<string, number>): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Extract all variable names referenced in a condition expression.
|
|
25
|
+
*
|
|
26
|
+
* @param condition - Expression string to extract variables from
|
|
27
|
+
* @returns Array of variable name strings found in the expression
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractVariables(condition: string): string[];
|
|
30
|
+
//# sourceMappingURL=conditionParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionParser.d.ts","sourceRoot":"","sources":["../src/conditionParser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiPH;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,OAAO,CAOT;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAO5D"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Safe condition parser for strategy expressions.
|
|
4
|
+
*
|
|
5
|
+
* Supports: indicator aliases, numeric literals, comparison operators (>, <, >=, <=, ==),
|
|
6
|
+
* logical operators (AND, OR), and parentheses.
|
|
7
|
+
*
|
|
8
|
+
* Examples:
|
|
9
|
+
* "sma_7 > sma_30"
|
|
10
|
+
* "rsi_14 < 30"
|
|
11
|
+
* "macd_signal > 0 AND rsi_14 < 70"
|
|
12
|
+
* "(sma_7 > sma_30) AND (rsi_14 < 70 OR bollinger < 0.2)"
|
|
13
|
+
*
|
|
14
|
+
* NO eval() - uses a simple recursive descent parser.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.evaluateCondition = evaluateCondition;
|
|
18
|
+
exports.extractVariables = extractVariables;
|
|
19
|
+
function tokenize(input) {
|
|
20
|
+
const tokens = [];
|
|
21
|
+
let i = 0;
|
|
22
|
+
const s = input.trim();
|
|
23
|
+
while (i < s.length) {
|
|
24
|
+
const ch = s[i];
|
|
25
|
+
// Skip whitespace
|
|
26
|
+
if (ch === " " || ch === "\t") {
|
|
27
|
+
i++;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
// Parentheses
|
|
31
|
+
if (ch === "(" || ch === ")") {
|
|
32
|
+
tokens.push({ type: "paren", value: ch });
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
// Two-char operators
|
|
37
|
+
if (i + 1 < s.length) {
|
|
38
|
+
const twoChar = s.slice(i, i + 2);
|
|
39
|
+
if (twoChar === ">=" || twoChar === "<=" || twoChar === "==") {
|
|
40
|
+
tokens.push({
|
|
41
|
+
type: "operator",
|
|
42
|
+
value: twoChar,
|
|
43
|
+
});
|
|
44
|
+
i += 2;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Single-char operators
|
|
49
|
+
if (ch === ">" || ch === "<") {
|
|
50
|
+
tokens.push({ type: "operator", value: ch });
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
// Number (including negative and decimal)
|
|
55
|
+
if (ch === "-" || (ch >= "0" && ch <= "9")) {
|
|
56
|
+
// Check if minus is a negative sign (not subtraction)
|
|
57
|
+
if (ch === "-") {
|
|
58
|
+
// Minus is negative if at start, after operator, after logical, or after open paren
|
|
59
|
+
if (tokens.length > 0) {
|
|
60
|
+
const prev = tokens[tokens.length - 1];
|
|
61
|
+
if (prev.type !== "operator" &&
|
|
62
|
+
prev.type !== "logical" &&
|
|
63
|
+
!(prev.type === "paren" && prev.value === "(")) {
|
|
64
|
+
// This would be subtraction — not supported
|
|
65
|
+
throw new Error(`Unexpected '-' at position ${String(i)}. Subtraction is not supported.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
let numStr = "";
|
|
70
|
+
if (ch === "-") {
|
|
71
|
+
numStr += "-";
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
while (i < s.length) {
|
|
75
|
+
const digit = s[i];
|
|
76
|
+
if (!((digit >= "0" && digit <= "9") || digit === ".")) {
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
numStr += digit;
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
tokens.push({ type: "number", value: parseFloat(numStr) });
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
// Identifier or logical operator
|
|
86
|
+
if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z") || ch === "_") {
|
|
87
|
+
let ident = "";
|
|
88
|
+
while (i < s.length) {
|
|
89
|
+
const c = s[i];
|
|
90
|
+
if (!((c >= "a" && c <= "z") ||
|
|
91
|
+
(c >= "A" && c <= "Z") ||
|
|
92
|
+
(c >= "0" && c <= "9") ||
|
|
93
|
+
c === "_")) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
ident += c;
|
|
97
|
+
i++;
|
|
98
|
+
}
|
|
99
|
+
if (ident === "AND" || ident === "OR") {
|
|
100
|
+
tokens.push({ type: "logical", value: ident });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
tokens.push({ type: "identifier", value: ident });
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
throw new Error(`Unexpected character '${ch}' at position ${String(i)}`);
|
|
108
|
+
}
|
|
109
|
+
return tokens;
|
|
110
|
+
}
|
|
111
|
+
/*
|
|
112
|
+
* Recursive descent parser for condition expressions.
|
|
113
|
+
*
|
|
114
|
+
* Grammar:
|
|
115
|
+
* expr := orExpr
|
|
116
|
+
* orExpr := andExpr ('OR' andExpr)*
|
|
117
|
+
* andExpr := compare ('AND' compare)*
|
|
118
|
+
* compare := value (op value)?
|
|
119
|
+
* value := NUMBER | IDENTIFIER | '(' expr ')'
|
|
120
|
+
*/
|
|
121
|
+
class Parser {
|
|
122
|
+
tokens;
|
|
123
|
+
variables;
|
|
124
|
+
pos = 0;
|
|
125
|
+
constructor(tokens, variables) {
|
|
126
|
+
this.tokens = tokens;
|
|
127
|
+
this.variables = variables;
|
|
128
|
+
}
|
|
129
|
+
evaluate() {
|
|
130
|
+
const result = this.orExpr();
|
|
131
|
+
if (this.pos < this.tokens.length) {
|
|
132
|
+
throw new Error(`Unexpected token at position ${String(this.pos)}: ${JSON.stringify(this.tokens[this.pos])}`);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
orExpr() {
|
|
137
|
+
let left = this.andExpr();
|
|
138
|
+
while (this.pos < this.tokens.length) {
|
|
139
|
+
const token = this.tokens[this.pos];
|
|
140
|
+
if (token.type !== "logical" || token.value !== "OR") {
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
this.pos++; // consume OR
|
|
144
|
+
const right = this.andExpr();
|
|
145
|
+
left = left || right;
|
|
146
|
+
}
|
|
147
|
+
return left;
|
|
148
|
+
}
|
|
149
|
+
andExpr() {
|
|
150
|
+
let left = this.compare();
|
|
151
|
+
while (this.pos < this.tokens.length) {
|
|
152
|
+
const token = this.tokens[this.pos];
|
|
153
|
+
if (token.type !== "logical" || token.value !== "AND") {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
this.pos++; // consume AND
|
|
157
|
+
const right = this.compare();
|
|
158
|
+
left = left && right;
|
|
159
|
+
}
|
|
160
|
+
return left;
|
|
161
|
+
}
|
|
162
|
+
compare() {
|
|
163
|
+
const left = this.value();
|
|
164
|
+
if (this.pos < this.tokens.length) {
|
|
165
|
+
const token = this.tokens[this.pos];
|
|
166
|
+
if (token.type === "operator") {
|
|
167
|
+
const { value: op } = token;
|
|
168
|
+
this.pos++; // consume operator
|
|
169
|
+
const right = this.value();
|
|
170
|
+
switch (op) {
|
|
171
|
+
case ">":
|
|
172
|
+
return left > right;
|
|
173
|
+
case "<":
|
|
174
|
+
return left < right;
|
|
175
|
+
case ">=":
|
|
176
|
+
return left >= right;
|
|
177
|
+
case "<=":
|
|
178
|
+
return left <= right;
|
|
179
|
+
case "==":
|
|
180
|
+
return left === right;
|
|
181
|
+
default: {
|
|
182
|
+
const _exhaustive = op;
|
|
183
|
+
throw new Error(`Unknown operator: ${_exhaustive}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Bare truthy check (non-zero = true)
|
|
189
|
+
return left !== 0 && !isNaN(left);
|
|
190
|
+
}
|
|
191
|
+
value() {
|
|
192
|
+
if (this.pos >= this.tokens.length) {
|
|
193
|
+
throw new Error("Unexpected end of expression");
|
|
194
|
+
}
|
|
195
|
+
const token = this.tokens[this.pos];
|
|
196
|
+
if (token.type === "number") {
|
|
197
|
+
this.pos++;
|
|
198
|
+
return token.value;
|
|
199
|
+
}
|
|
200
|
+
if (token.type === "identifier") {
|
|
201
|
+
this.pos++;
|
|
202
|
+
if (!(token.value in this.variables)) {
|
|
203
|
+
throw new Error(`Unknown variable: ${token.value}`);
|
|
204
|
+
}
|
|
205
|
+
return this.variables[token.value];
|
|
206
|
+
}
|
|
207
|
+
if (token.type === "paren" && token.value === "(") {
|
|
208
|
+
this.pos++; // consume '('
|
|
209
|
+
const result = this.orExpr();
|
|
210
|
+
const closeParen = this.tokens[this.pos];
|
|
211
|
+
if (closeParen.type !== "paren" || closeParen.value !== ")") {
|
|
212
|
+
throw new Error("Expected closing parenthesis");
|
|
213
|
+
}
|
|
214
|
+
this.pos++; // consume ')'
|
|
215
|
+
// Return as number (boolean -> 1/0)
|
|
216
|
+
return result ? 1 : 0;
|
|
217
|
+
}
|
|
218
|
+
throw new Error(`Unexpected token: ${JSON.stringify(token)}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Evaluate a condition expression against a set of variable values.
|
|
223
|
+
*
|
|
224
|
+
* @param condition - Expression string, e.g. "sma_7 > sma_30 AND rsi_14 < 70"
|
|
225
|
+
* @param variables - Map of variable names to their current values
|
|
226
|
+
* @returns true if the condition is met
|
|
227
|
+
*/
|
|
228
|
+
function evaluateCondition(condition, variables) {
|
|
229
|
+
const tokens = tokenize(condition);
|
|
230
|
+
if (tokens.length === 0) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
const parser = new Parser(tokens, variables);
|
|
234
|
+
return parser.evaluate();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Extract all variable names referenced in a condition expression.
|
|
238
|
+
*
|
|
239
|
+
* @param condition - Expression string to extract variables from
|
|
240
|
+
* @returns Array of variable name strings found in the expression
|
|
241
|
+
*/
|
|
242
|
+
function extractVariables(condition) {
|
|
243
|
+
const tokens = tokenize(condition);
|
|
244
|
+
return tokens
|
|
245
|
+
.filter((t) => t.type === "identifier")
|
|
246
|
+
.map((t) => t.value);
|
|
247
|
+
}
|
|
248
|
+
//# sourceMappingURL=conditionParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditionParser.js","sourceRoot":"","sources":["../src/conditionParser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAwPH,8CAUC;AAQD,4CAOC;AAxQD,SAAS,QAAQ,CAAC,KAAa;IAC7B,MAAM,MAAM,GAAY,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAEvB,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACpB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAEhB,kBAAkB;QAClB,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YAC9B,CAAC,EAAE,CAAC;YACJ,SAAS;QACX,CAAC;QAED,cAAc;QACd,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1C,CAAC,EAAE,CAAC;YACJ,SAAS;QAC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;AACH,SAAgB,gBAAgB,CAAC,SAAiB;IAChD,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,MAAM;SACV,MAAM,CACL,CAAC,CAAC,EAA8C,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAC3E;SACA,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ export type { TextFormat } from "./convertFormat.js";
|
|
|
10
10
|
export { formatWithLineNumbers } from "./formatWithLineNumbers.js";
|
|
11
11
|
export { formatYaml } from "./formatYaml.js";
|
|
12
12
|
export { healYaml } from "./healYaml.js";
|
|
13
|
-
export { Linker, createLinker, type LinkRule, type
|
|
14
|
-
export {
|
|
13
|
+
export { Linker, createLinker, linkText, type LinkRule, type LinkTarget, type LinkContext, type LinkerConfig, type LinkOptions, type LinkStyle, type LinkTextOptions, } from "./linker.js";
|
|
14
|
+
export { codeBlock } from "./codeBlock.js";
|
|
15
15
|
export { stripAnsi } from "./stripAnsi.js";
|
|
16
16
|
export { isWaitingForInput } from "./questionDetection.js";
|
|
17
|
+
export { createSessionId } from "./sessionId.js";
|
|
18
|
+
export { evaluateCondition, extractVariables } from "./conditionParser.js";
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,O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L,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWaitingForInput = exports.stripAnsi = exports.
|
|
3
|
+
exports.extractVariables = exports.evaluateCondition = exports.createSessionId = exports.isWaitingForInput = exports.stripAnsi = exports.codeBlock = exports.linkText = exports.createLinker = exports.Linker = exports.healYaml = exports.formatYaml = exports.formatWithLineNumbers = exports.convertFormat = exports.FILE_TREE_DEFAULTS = exports.buildFileTree = exports.formatDuration = exports.slugify = exports.chunkText = exports.extractPlaceholders = exports.replaceTemplate = exports.formatErrorForLog = exports.formatError = exports.getErrorMessage = void 0;
|
|
4
4
|
var errors_js_1 = require("./errors.js");
|
|
5
5
|
Object.defineProperty(exports, "getErrorMessage", { enumerable: true, get: function () { return errors_js_1.getErrorMessage; } });
|
|
6
6
|
Object.defineProperty(exports, "formatError", { enumerable: true, get: function () { return errors_js_1.formatError; } });
|
|
@@ -28,10 +28,16 @@ Object.defineProperty(exports, "healYaml", { enumerable: true, get: function ()
|
|
|
28
28
|
var linker_js_1 = require("./linker.js");
|
|
29
29
|
Object.defineProperty(exports, "Linker", { enumerable: true, get: function () { return linker_js_1.Linker; } });
|
|
30
30
|
Object.defineProperty(exports, "createLinker", { enumerable: true, get: function () { return linker_js_1.createLinker; } });
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Object.defineProperty(exports, "linkText", { enumerable: true, get: function () { return linker_js_1.linkText; } });
|
|
32
|
+
var codeBlock_js_1 = require("./codeBlock.js");
|
|
33
|
+
Object.defineProperty(exports, "codeBlock", { enumerable: true, get: function () { return codeBlock_js_1.codeBlock; } });
|
|
33
34
|
var stripAnsi_js_1 = require("./stripAnsi.js");
|
|
34
35
|
Object.defineProperty(exports, "stripAnsi", { enumerable: true, get: function () { return stripAnsi_js_1.stripAnsi; } });
|
|
35
36
|
var questionDetection_js_1 = require("./questionDetection.js");
|
|
36
37
|
Object.defineProperty(exports, "isWaitingForInput", { enumerable: true, get: function () { return questionDetection_js_1.isWaitingForInput; } });
|
|
38
|
+
var sessionId_js_1 = require("./sessionId.js");
|
|
39
|
+
Object.defineProperty(exports, "createSessionId", { enumerable: true, get: function () { return sessionId_js_1.createSessionId; } });
|
|
40
|
+
var conditionParser_js_1 = require("./conditionParser.js");
|
|
41
|
+
Object.defineProperty(exports, "evaluateCondition", { enumerable: true, get: function () { return conditionParser_js_1.evaluateCondition; } });
|
|
42
|
+
Object.defineProperty(exports, "extractVariables", { enumerable: true, get: function () { return conditionParser_js_1.extractVariables; } });
|
|
37
43
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAA8E;AAArE,4GAAA,eAAe,OAAA;AAAE,wGAAA,WAAW,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACxD,6CAAqE;AAA5D,8GAAA,eAAe,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAC7C,+CAA2C;AAAlC,yGAAA,SAAS,OAAA;AAClB,2CAAuC;AAA9B,qGAAA,OAAO,OAAA;AAChB,yDAA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-1,90 +1,76 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export interface
|
|
1
|
+
export type LinkStyle = "slack" | "discord" | "markdown" | "plain";
|
|
2
|
+
export interface LinkOptions {
|
|
3
3
|
/**
|
|
4
|
-
* Target output
|
|
5
|
-
* Alias: `platform`.
|
|
4
|
+
* Target output style.
|
|
6
5
|
* Default: "markdown"
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
platform?: LinkerPlatform;
|
|
7
|
+
for?: LinkStyle;
|
|
10
8
|
/**
|
|
11
9
|
* When true (default), skips linkification inside inline/fenced code spans.
|
|
12
10
|
*/
|
|
13
|
-
|
|
11
|
+
ignoreCode?: boolean;
|
|
14
12
|
/**
|
|
15
13
|
* When true (default), skips linkification inside existing links.
|
|
16
14
|
*/
|
|
17
|
-
|
|
15
|
+
ignoreExistingLinks?: boolean;
|
|
18
16
|
}
|
|
19
|
-
export interface
|
|
20
|
-
/** Full
|
|
21
|
-
|
|
17
|
+
export interface LinkContext {
|
|
18
|
+
/** Full matched text. */
|
|
19
|
+
text: string;
|
|
22
20
|
/** Positional capture groups. */
|
|
23
21
|
groups: string[];
|
|
24
22
|
/** Rule name assigned at registration time. */
|
|
25
|
-
|
|
23
|
+
name: string;
|
|
26
24
|
/** Match start index in the original input. */
|
|
27
25
|
index: number;
|
|
28
26
|
/** Original input string. */
|
|
29
27
|
input: string;
|
|
30
28
|
}
|
|
31
|
-
export type
|
|
29
|
+
export type LinkTarget = (context: LinkContext) => string;
|
|
32
30
|
export interface LinkRule {
|
|
33
31
|
/** Optional stable name for diagnostics and conflict visibility. */
|
|
34
32
|
name?: string;
|
|
35
33
|
/** Match pattern. Global matching is enforced automatically. */
|
|
36
|
-
|
|
34
|
+
match: RegExp;
|
|
37
35
|
/**
|
|
38
|
-
* URL template string
|
|
39
|
-
*
|
|
36
|
+
* Either a URL template string or a callback that builds a URL from match
|
|
37
|
+
* context. Template strings support `$0`/`$&` for the full match and
|
|
38
|
+
* `$1..$N` for groups.
|
|
40
39
|
*/
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Either a URL template string or a callback that builds an href from match context.
|
|
44
|
-
* If both `href` and `toHref` are provided, `toHref` wins.
|
|
45
|
-
*/
|
|
46
|
-
toHref?: string | LinkHrefBuilder;
|
|
40
|
+
to: string | LinkTarget;
|
|
47
41
|
/**
|
|
48
42
|
* Higher priority wins for overlapping matches that start at the same index.
|
|
49
43
|
* Default: 0
|
|
50
44
|
*/
|
|
51
45
|
priority?: number;
|
|
52
46
|
}
|
|
47
|
+
export interface LinkerConfig {
|
|
48
|
+
/** Linear workspace slug, used for issue references like `ENG-533`. */
|
|
49
|
+
linear?: string;
|
|
50
|
+
/** GitHub repository for PR references like `PR#42`. */
|
|
51
|
+
githubPrs?: string;
|
|
52
|
+
/** Additional custom rules appended after built-in presets. */
|
|
53
|
+
rules?: readonly LinkRule[];
|
|
54
|
+
}
|
|
55
|
+
export interface LinkTextOptions extends LinkerConfig, LinkOptions {
|
|
56
|
+
}
|
|
53
57
|
/**
|
|
54
|
-
*
|
|
58
|
+
* Compiled linker utility.
|
|
55
59
|
*
|
|
56
|
-
*
|
|
57
|
-
* -
|
|
58
|
-
* - skips code spans by default
|
|
59
|
-
* - deterministic overlap resolution (priority, length, then declaration order)
|
|
60
|
+
* Built-in presets cover the repo references used in this workspace.
|
|
61
|
+
* For one-off usage, prefer the top-level `linkText()` helper.
|
|
60
62
|
*/
|
|
61
63
|
export declare class Linker {
|
|
62
64
|
private readonly rules;
|
|
63
|
-
constructor(
|
|
64
|
-
|
|
65
|
-
rule(rule: LinkRule): this;
|
|
66
|
-
rule(name: string, rule: Omit<LinkRule, "name">): this;
|
|
67
|
-
custom(pattern: RegExp, toHref: string | LinkHrefBuilder, options?: {
|
|
68
|
-
name?: string;
|
|
69
|
-
priority?: number;
|
|
70
|
-
}): this;
|
|
71
|
-
linear(workspace: string, options?: {
|
|
72
|
-
name?: string;
|
|
73
|
-
priority?: number;
|
|
74
|
-
}): this;
|
|
75
|
-
githubPr(repository: string, options?: {
|
|
76
|
-
name?: string;
|
|
77
|
-
priority?: number;
|
|
78
|
-
}): this;
|
|
79
|
-
apply(input: string, options?: LinkerApplyOptions): string;
|
|
80
|
-
linkText(input: string, options?: LinkerApplyOptions): string;
|
|
65
|
+
constructor(config?: LinkerConfig);
|
|
66
|
+
link(input: string, options?: LinkOptions): string;
|
|
81
67
|
}
|
|
82
68
|
/**
|
|
83
|
-
* Create a linker with
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
*
|
|
69
|
+
* Create a reusable text linker with compiled matching rules.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createLinker(config?: LinkerConfig): Linker;
|
|
72
|
+
/**
|
|
73
|
+
* Link known ticket/PR references in text using one-shot linker options.
|
|
88
74
|
*/
|
|
89
|
-
export declare function
|
|
75
|
+
export declare function linkText(input: string, options?: LinkTextOptions): string;
|
|
90
76
|
//# sourceMappingURL=linker.d.ts.map
|
package/dist/linker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../src/linker.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"linker.d.ts","sourceRoot":"","sources":["../src/linker.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,CAAC;AAE1D,MAAM,WAAW,QAAQ;IACvB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,eAAgB,SAAQ,YAAY,EAAE,WAAW;CAAG;AAmKrE;;;;;GAKG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiB;gBAE3B,MAAM,GAAE,YAAiB;IAIrC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,MAAM;CAkFvD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,GAAE,YAAiB,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CAgB7E"}
|
package/dist/linker.js
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Linker = void 0;
|
|
4
4
|
exports.createLinker = createLinker;
|
|
5
|
+
exports.linkText = linkText;
|
|
5
6
|
function ensureGlobal(pattern) {
|
|
6
7
|
if (pattern.flags.includes("g")) {
|
|
7
8
|
return new RegExp(pattern.source, pattern.flags);
|
|
8
9
|
}
|
|
9
10
|
return new RegExp(pattern.source, `${pattern.flags}g`);
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return ({
|
|
12
|
+
function templateToTarget(template) {
|
|
13
|
+
return ({ text, groups }) => template.replace(/\$\$|\$(\d+|&|0)/g, (token, capture) => {
|
|
13
14
|
if (token === "$$") {
|
|
14
15
|
return "$";
|
|
15
16
|
}
|
|
16
17
|
if (capture === "&" || capture === "0") {
|
|
17
|
-
return
|
|
18
|
+
return text;
|
|
18
19
|
}
|
|
19
20
|
const index = Number(capture);
|
|
20
21
|
if (!Number.isInteger(index) || index < 0) {
|
|
@@ -24,16 +25,11 @@ function templateToHref(template) {
|
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
27
|
function compileRule(rule, index) {
|
|
27
|
-
const source = rule.toHref ?? rule.href;
|
|
28
|
-
if (source === undefined) {
|
|
29
|
-
throw new Error(`Invalid linker rule "${rule.name ?? `rule-${String(index + 1)}`}": missing href/toHref`);
|
|
30
|
-
}
|
|
31
|
-
const toHref = typeof source === "string" ? templateToHref(source) : source;
|
|
32
28
|
return {
|
|
33
29
|
name: rule.name ?? `rule-${String(index + 1)}`,
|
|
34
|
-
|
|
30
|
+
match: ensureGlobal(rule.match),
|
|
35
31
|
priority: rule.priority ?? 0,
|
|
36
|
-
|
|
32
|
+
to: typeof rule.to === "string" ? templateToTarget(rule.to) : rule.to,
|
|
37
33
|
};
|
|
38
34
|
}
|
|
39
35
|
function pushSpans(source, pattern, spans) {
|
|
@@ -71,17 +67,13 @@ function normalizeSpans(spans) {
|
|
|
71
67
|
}
|
|
72
68
|
function getProtectedSpans(input, options) {
|
|
73
69
|
const spans = [];
|
|
74
|
-
if (options.
|
|
75
|
-
// Fenced code blocks first, then inline spans.
|
|
70
|
+
if (options.ignoreCode) {
|
|
76
71
|
pushSpans(input, /```[\s\S]*?```/g, spans);
|
|
77
72
|
pushSpans(input, /`[^`\n]+`/g, spans);
|
|
78
73
|
}
|
|
79
|
-
if (options.
|
|
80
|
-
// Slack and angle-bracket links/mentions.
|
|
74
|
+
if (options.ignoreExistingLinks) {
|
|
81
75
|
pushSpans(input, /<[^>\n]+>/g, spans);
|
|
82
|
-
// Markdown links.
|
|
83
76
|
pushSpans(input, /\[[^\]]+\]\([^)]+\)/g, spans);
|
|
84
|
-
// Plain URLs.
|
|
85
77
|
pushSpans(input, /https?:\/\/[^\s<>()]+/g, spans);
|
|
86
78
|
}
|
|
87
79
|
return normalizeSpans(spans);
|
|
@@ -98,80 +90,64 @@ function overlapsProtected(spans, start, end) {
|
|
|
98
90
|
}
|
|
99
91
|
return false;
|
|
100
92
|
}
|
|
101
|
-
function formatLink(href, text,
|
|
102
|
-
switch (
|
|
93
|
+
function formatLink(href, text, style) {
|
|
94
|
+
switch (style) {
|
|
103
95
|
case "slack":
|
|
104
96
|
return `<${href}|${text}>`;
|
|
105
97
|
case "discord":
|
|
106
98
|
case "markdown":
|
|
107
99
|
return `[${text}](${href})`;
|
|
108
|
-
case "
|
|
100
|
+
case "plain":
|
|
109
101
|
return href;
|
|
110
102
|
default:
|
|
111
103
|
return text;
|
|
112
104
|
}
|
|
113
105
|
}
|
|
114
|
-
function
|
|
115
|
-
|
|
106
|
+
function buildRules(config) {
|
|
107
|
+
const rules = [];
|
|
108
|
+
const linearWorkspace = config.linear;
|
|
109
|
+
const githubRepo = config.githubPrs;
|
|
110
|
+
if (linearWorkspace !== undefined && linearWorkspace !== "") {
|
|
111
|
+
rules.push({
|
|
112
|
+
name: "linear",
|
|
113
|
+
match: /\b([A-Z]{2,6}-\d+)\b/g,
|
|
114
|
+
to: ({ text }) => `https://linear.app/${linearWorkspace}/issue/${text}`,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (githubRepo !== undefined && githubRepo !== "") {
|
|
118
|
+
rules.push({
|
|
119
|
+
name: "github-prs",
|
|
120
|
+
match: /\bPR#(\d+)\b/g,
|
|
121
|
+
to: ({ groups }) => `https://github.com/${githubRepo}/pull/${groups[0] ?? ""}`,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
rules.push(...(config.rules ?? []));
|
|
125
|
+
return rules.map(compileRule);
|
|
116
126
|
}
|
|
117
127
|
/**
|
|
118
|
-
*
|
|
128
|
+
* Compiled linker utility.
|
|
119
129
|
*
|
|
120
|
-
*
|
|
121
|
-
* -
|
|
122
|
-
* - skips code spans by default
|
|
123
|
-
* - deterministic overlap resolution (priority, length, then declaration order)
|
|
130
|
+
* Built-in presets cover the repo references used in this workspace.
|
|
131
|
+
* For one-off usage, prefer the top-level `linkText()` helper.
|
|
124
132
|
*/
|
|
125
133
|
class Linker {
|
|
126
|
-
rules
|
|
127
|
-
constructor(
|
|
128
|
-
|
|
129
|
-
this.addRule(rule);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
addRule(rule) {
|
|
133
|
-
this.rules.push(compileRule(rule, this.rules.length));
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
rule(ruleOrName, maybeRule) {
|
|
137
|
-
if (typeof ruleOrName === "string") {
|
|
138
|
-
if (maybeRule === undefined) {
|
|
139
|
-
throw new Error(`Missing rule config for "${ruleOrName}"`);
|
|
140
|
-
}
|
|
141
|
-
return this.addRule({ ...maybeRule, name: ruleOrName });
|
|
142
|
-
}
|
|
143
|
-
return this.addRule(ruleOrName);
|
|
134
|
+
rules;
|
|
135
|
+
constructor(config = {}) {
|
|
136
|
+
this.rules = buildRules(config);
|
|
144
137
|
}
|
|
145
|
-
|
|
146
|
-
return this.addRule({
|
|
147
|
-
name: options.name,
|
|
148
|
-
pattern,
|
|
149
|
-
toHref,
|
|
150
|
-
priority: options.priority,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
linear(workspace, options = {}) {
|
|
154
|
-
return this.custom(/\b([A-Z]{2,6}-\d+)\b/g, ({ match }) => `https://linear.app/${workspace}/issue/${match}`, { name: options.name ?? "linear", priority: options.priority });
|
|
155
|
-
}
|
|
156
|
-
githubPr(repository, options = {}) {
|
|
157
|
-
return this.custom(/\bPR#(\d+)\b/g, ({ groups }) => `https://github.com/${repository}/pull/${groups[0] ?? ""}`, { name: options.name ?? "github-pr", priority: options.priority });
|
|
158
|
-
}
|
|
159
|
-
apply(input, options = {}) {
|
|
160
|
-
return this.linkText(input, options);
|
|
161
|
-
}
|
|
162
|
-
linkText(input, options = {}) {
|
|
138
|
+
link(input, options = {}) {
|
|
163
139
|
if (this.rules.length === 0 || input === "") {
|
|
164
140
|
return input;
|
|
165
141
|
}
|
|
166
|
-
const
|
|
142
|
+
const style = options.for ?? "markdown";
|
|
167
143
|
const protectedSpans = getProtectedSpans(input, {
|
|
168
|
-
|
|
169
|
-
|
|
144
|
+
ignoreCode: options.ignoreCode ?? true,
|
|
145
|
+
ignoreExistingLinks: options.ignoreExistingLinks ?? true,
|
|
170
146
|
});
|
|
171
147
|
const candidates = [];
|
|
172
148
|
for (let ruleOrder = 0; ruleOrder < this.rules.length; ruleOrder++) {
|
|
173
149
|
const rule = this.rules[ruleOrder];
|
|
174
|
-
const matcher = rule.
|
|
150
|
+
const matcher = rule.match;
|
|
175
151
|
matcher.lastIndex = 0;
|
|
176
152
|
let match = matcher.exec(input);
|
|
177
153
|
while (match !== null) {
|
|
@@ -190,7 +166,7 @@ class Linker {
|
|
|
190
166
|
text: matchedText,
|
|
191
167
|
groups: match.slice(1),
|
|
192
168
|
ruleOrder,
|
|
193
|
-
|
|
169
|
+
name: rule.name,
|
|
194
170
|
priority: rule.priority,
|
|
195
171
|
});
|
|
196
172
|
}
|
|
@@ -218,19 +194,15 @@ class Linker {
|
|
|
218
194
|
for (const candidate of selected) {
|
|
219
195
|
output += input.slice(inputCursor, candidate.start);
|
|
220
196
|
const rule = this.rules[candidate.ruleOrder];
|
|
221
|
-
const href = rule.
|
|
222
|
-
|
|
197
|
+
const href = rule.to({
|
|
198
|
+
text: candidate.text,
|
|
223
199
|
groups: candidate.groups,
|
|
224
|
-
|
|
200
|
+
name: candidate.name,
|
|
225
201
|
index: candidate.start,
|
|
226
202
|
input,
|
|
227
203
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
output += formatLink(href, candidate.text, platform);
|
|
233
|
-
}
|
|
204
|
+
output +=
|
|
205
|
+
href === "" ? candidate.text : formatLink(href, candidate.text, style);
|
|
234
206
|
inputCursor = candidate.end;
|
|
235
207
|
}
|
|
236
208
|
output += input.slice(inputCursor);
|
|
@@ -239,13 +211,21 @@ class Linker {
|
|
|
239
211
|
}
|
|
240
212
|
exports.Linker = Linker;
|
|
241
213
|
/**
|
|
242
|
-
* Create a linker with
|
|
243
|
-
*
|
|
244
|
-
* - `href` accepts template substitutions (`$0`/`$&`, `$1..$N`)
|
|
245
|
-
* - `toHref` callback, when provided, takes precedence over `href`
|
|
246
|
-
* - omitted `priority` defaults to `0`
|
|
214
|
+
* Create a reusable text linker with compiled matching rules.
|
|
247
215
|
*/
|
|
248
|
-
function createLinker(
|
|
249
|
-
return new Linker(
|
|
216
|
+
function createLinker(config = {}) {
|
|
217
|
+
return new Linker(config);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Link known ticket/PR references in text using one-shot linker options.
|
|
221
|
+
*/
|
|
222
|
+
function linkText(input, options = {}) {
|
|
223
|
+
const { linear, githubPrs, rules, for: style, ignoreCode, ignoreExistingLinks, } = options;
|
|
224
|
+
const linker = createLinker({ linear, githubPrs, rules });
|
|
225
|
+
return linker.link(input, {
|
|
226
|
+
for: style,
|
|
227
|
+
ignoreCode,
|
|
228
|
+
ignoreExistingLinks,
|
|
229
|
+
});
|
|
250
230
|
}
|
|
251
231
|
//# sourceMappingURL=linker.js.map
|
package/dist/linker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linker.js","sourceRoot":"","sources":["../src/linker.ts"],"names":[],"mappings":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,EACJ,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EAAE,KAAK,EACV,UAAU,EACV,mBAAmB,GACpB,GAAG,OAAO,CAAC;IAEZ,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE;QACxB,GAAG,EAAE,KAAK;QACV,UAAU;QACV,mBAAmB;KACpB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionId.d.ts","sourceRoot":"","sources":["../src/sessionId.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSessionId = createSessionId;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a unique session ID with the given prefix, a base-36 timestamp, and a random suffix.
|
|
6
|
+
*/
|
|
7
|
+
function createSessionId(prefix) {
|
|
8
|
+
return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=sessionId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionId.js","sourceRoot":"","sources":["../src/sessionId.ts"],"names":[],"mappings":";;AAGA,0CAEC;AALD;;GAEG;AACH,SAAgB,eAAe,CAAC,MAAc;IAC5C,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC1F,CAAC"}
|
package/package.json
CHANGED
package/dist/escapeFence.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Escapes markdown code fences by wrapping content with more backticks than it contains.
|
|
3
|
-
* If content has ```, wraps with ````. If content has ````, wraps with `````, etc.
|
|
4
|
-
*/
|
|
5
|
-
export declare function escapeFence(content: string): {
|
|
6
|
-
fence: string;
|
|
7
|
-
content: string;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=escapeFence.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"escapeFence.d.ts","sourceRoot":"","sources":["../src/escapeFence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAeA"}
|
package/dist/escapeFence.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.escapeFence = escapeFence;
|
|
4
|
-
/**
|
|
5
|
-
* Escapes markdown code fences by wrapping content with more backticks than it contains.
|
|
6
|
-
* If content has ```, wraps with ````. If content has ````, wraps with `````, etc.
|
|
7
|
-
*/
|
|
8
|
-
function escapeFence(content) {
|
|
9
|
-
let maxBackticks = 3; // Start with triple backticks (standard markdown fence)
|
|
10
|
-
// Find the longest sequence of consecutive backticks in the content
|
|
11
|
-
const backtickMatches = content.match(/`+/g);
|
|
12
|
-
if (backtickMatches) {
|
|
13
|
-
for (const match of backtickMatches) {
|
|
14
|
-
if (match.length >= maxBackticks) {
|
|
15
|
-
maxBackticks = match.length + 1;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const fence = "`".repeat(maxBackticks);
|
|
20
|
-
return { fence, content };
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=escapeFence.js.map
|
package/dist/escapeFence.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"escapeFence.js","sourceRoot":"","sources":["../src/escapeFence.ts"],"names":[],"mappings":";;AAIA,kCAkBC;AAtBD;;;GAGG;AACH,SAAgB,WAAW,CAAC,OAAe;IAIzC,IAAI,YAAY,GAAG,CAAC,CAAC,CAAC,wDAAwD;IAE9E,oEAAoE;IACpE,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,eAAe,EAAE,CAAC;QACpB,KAAK,MAAM,KAAK,IAAI,eAAe,EAAE,CAAC;YACpC,IAAI,KAAK,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;gBACjC,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAC5B,CAAC"}
|