@athree/helpers 2.0.0
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/package.json +12 -0
- package/src/main/clone.ts +3 -0
- package/src/main/compare.ts +19 -0
- package/src/main/error.ts +9 -0
- package/src/main/extract.ts +34 -0
- package/src/main/id.ts +5 -0
- package/src/main/index.ts +7 -0
- package/src/main/markdown.ts +9 -0
- package/src/main/workflow.ts +8 -0
- package/tsconfig.json +8 -0
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function deepEqual(a: any, b: any): boolean {
|
|
2
|
+
if (a === b) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
if (a == null && b == null) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
9
|
+
return a.length === b.length &&
|
|
10
|
+
a.every((value, index) => deepEqual(value, b[index]));
|
|
11
|
+
}
|
|
12
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
13
|
+
const keysA = Object.keys(a);
|
|
14
|
+
const keysB = Object.keys(b);
|
|
15
|
+
return keysA.length === keysB.length &&
|
|
16
|
+
keysA.every(key => deepEqual(a[key], b[key]));
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function extractCodeFromMarkdown(markdown: string) {
|
|
2
|
+
const match = /```(js|javascript)?\n([\s\S]*)\n```/.exec(markdown);
|
|
3
|
+
if (!match) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
return removeCommonIndentation(match[2]);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function extractJsonFromMarkdown(markdown: string) {
|
|
10
|
+
const match = /```(json)?\n([\s\S]*)\n```/.exec(markdown);
|
|
11
|
+
if (!match) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return removeCommonIndentation(match[2]);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function extractXmlFromMarkdown(markdown: string, tag: string) {
|
|
18
|
+
const match = new RegExp(`</?\\s*${tag}\\s*>(.*)</?\\s*${tag}\\s*>`, 'si').exec(markdown);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return removeCommonIndentation(match[1]).trim();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function removeCommonIndentation(text: string) {
|
|
26
|
+
const lines = text.split('\n');
|
|
27
|
+
const minIndent = Math.min(...lines.map(line => getLineIndentSize(line)));
|
|
28
|
+
return lines.map(line => line.slice(minIndent)).join('\n');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getLineIndentSize(line: string) {
|
|
32
|
+
const match = line.match(/^ */);
|
|
33
|
+
return match ? match[0].length : 0;
|
|
34
|
+
}
|
package/src/main/id.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { customAlphabet } from 'nanoid';
|
|
2
|
+
|
|
3
|
+
export const standardId = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 16);
|
|
4
|
+
export const safeId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 16);
|
|
5
|
+
export const tinyId = customAlphabet('abcdefghijklmnopqrstuvwxyz0123456789', 4);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function toWorkflowId(modulePath: string, className: string) {
|
|
2
|
+
return `${modulePath}:${className}`;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function parseWorkflowId(workflowId: string) {
|
|
6
|
+
const [modulePath, className] = workflowId.split(':');
|
|
7
|
+
return { modulePath, className };
|
|
8
|
+
}
|