@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 ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@athree/helpers",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": "./out/main/index.js"
8
+ },
9
+ "scripts": {
10
+ "clean": "rm -rf out/ *.tsbuildinfo"
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ export function clone<T>(value: T): T {
2
+ return JSON.parse(JSON.stringify(value));
3
+ }
@@ -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,9 @@
1
+ export function errorToJson(error: any) {
2
+ return {
3
+ name: error?.name ?? 'Error',
4
+ message: error?.message ?? 'Unknown error',
5
+ stack: error?.stack ?? '',
6
+ code: error?.code,
7
+ details: error?.details,
8
+ };
9
+ }
@@ -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,7 @@
1
+ export * from './clone.js';
2
+ export * from './compare.js';
3
+ export * from './error.js';
4
+ export * from './extract.js';
5
+ export * from './id.js';
6
+ export * from './markdown.js';
7
+ export * from './workflow.js';
@@ -0,0 +1,9 @@
1
+ import markdown from 'markdown-it';
2
+
3
+ const md = markdown({
4
+ html: true,
5
+ });
6
+
7
+ export function renderMarkdown(markdown: string) {
8
+ return md.render(markdown);
9
+ }
@@ -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
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"]
8
+ }