@oliversalzburg/js-utils 0.0.22-dev.1 → 0.0.22-dev.2

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.
@@ -0,0 +1 @@
1
+ export * from "./tree.js";
package/data/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./tree.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/data/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
package/data/tree.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Base class to quickly provide parent-child relationships.
3
+ * @typeParam TNode - Your sub-class.
4
+ * @group Data
5
+ */
6
+ export declare abstract class TreeNode<TNode> {
7
+ #private;
8
+ /**
9
+ * The parent.
10
+ * @returns The parent.
11
+ */
12
+ get parent(): TNode | undefined;
13
+ /**
14
+ * The children.
15
+ * @returns The children.
16
+ */
17
+ get children(): Set<TNode>;
18
+ /**
19
+ * Construct tree node.
20
+ * @param parent - The parent.
21
+ */
22
+ constructor(parent?: TNode | undefined);
23
+ /**
24
+ * Register a new child on the tree.
25
+ * @param child - A new child.
26
+ * @returns The child.
27
+ */
28
+ child(child: TNode): TNode;
29
+ }
package/data/tree.js ADDED
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Base class to quickly provide parent-child relationships.
3
+ * @typeParam TNode - Your sub-class.
4
+ * @group Data
5
+ */
6
+ export class TreeNode {
7
+ /**
8
+ * The parent.
9
+ */
10
+ #parent;
11
+ /**
12
+ * Our children.
13
+ */
14
+ #children = new Set();
15
+ /**
16
+ * The parent.
17
+ * @returns The parent.
18
+ */
19
+ get parent() {
20
+ return this.#parent;
21
+ }
22
+ /**
23
+ * The children.
24
+ * @returns The children.
25
+ */
26
+ get children() {
27
+ return this.#children;
28
+ }
29
+ /**
30
+ * Construct tree node.
31
+ * @param parent - The parent.
32
+ */
33
+ constructor(parent) {
34
+ this.#parent = parent;
35
+ }
36
+ /**
37
+ * Register a new child on the tree.
38
+ * @param child - A new child.
39
+ * @returns The child.
40
+ */
41
+ child(child) {
42
+ this.children.add(child);
43
+ return child;
44
+ }
45
+ }
46
+ //# sourceMappingURL=tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../source/data/tree.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAgB,QAAQ;IAC5B;;OAEG;IACH,OAAO,CAAoB;IAC3B;;OAEG;IACH,SAAS,GAAG,IAAI,GAAG,EAAS,CAAC;IAE7B;;;OAGG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY,MAA0B;QACpC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAY;QAChB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./array.js";
2
2
  export * from "./async.js";
3
3
  export * from "./core.js";
4
+ export * from "./data/index.js";
4
5
  export * from "./dom/index.js";
5
6
  export * from "./error-serializer.js";
6
7
  export * from "./errors/index.js";
package/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./array.js";
2
2
  export * from "./async.js";
3
3
  export * from "./core.js";
4
+ export * from "./data/index.js";
4
5
  export * from "./dom/index.js";
5
6
  export * from "./error-serializer.js";
6
7
  export * from "./errors/index.js";
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@oliversalzburg/js-utils",
4
- "version": "0.0.22-dev.1",
4
+ "version": "0.0.22-dev.2",
5
5
  "license": "MIT",
6
6
  "author": "Oliver Salzburg <oliver.salzburg@gmail.com>",
7
7
  "repository": {
@@ -11,7 +11,6 @@
11
11
  "type": "module",
12
12
  "exports": {
13
13
  ".": "./index.js",
14
- "./*": "./*.js",
15
14
  "./*.js": "./*.js"
16
15
  },
17
16
  "scripts": {
package/string.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Indent every line of the passed text.
3
+ * @param text - The text to indent.
4
+ * @param depth - How often to apply the indenting.
5
+ * @param prefix - The string to use as the indent.
6
+ * @returns The indented text.
7
+ * @group Strings
8
+ */
9
+ export declare const indent: (text: string, depth?: number, prefix?: string) => string;
package/string.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Indent every line of the passed text.
3
+ * @param text - The text to indent.
4
+ * @param depth - How often to apply the indenting.
5
+ * @param prefix - The string to use as the indent.
6
+ * @returns The indented text.
7
+ * @group Strings
8
+ */
9
+ export const indent = (text, depth = 0, prefix = " ") => text.replaceAll(/^/gm, prefix.repeat(depth));
10
+ //# sourceMappingURL=string.js.map
package/string.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../source/string.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,KAAK,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CACjE,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC"}