@axi-engine/configs 0.1.0 → 0.1.1

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 +73 -1
  2. package/package.json +7 -2
package/README.md CHANGED
@@ -5,4 +5,76 @@
5
5
 
6
6
  ## Description
7
7
 
8
- Description
8
+ A lightweight, type-safe, and hierarchical configuration resolver.
9
+ It allows you to manage complex configurations by defining variants
10
+ that inherit properties from one another, reducing duplication.
11
+
12
+ Installation
13
+
14
+ This package requires @axi-engine/utils as a peer dependency. You need to install both:
15
+ code
16
+
17
+ ```bash
18
+ npm install @axi-engine/configs @axi-engine/utils
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ The main idea is to define a base configuration and then create specialized
24
+ variants that `extend` it.
25
+ The resolver will automatically merge them for you.
26
+
27
+ Here is a quick example:
28
+
29
+ ```typescript
30
+ import { ConfigResolver, ConfigTree } from '@axi-engine/configs';
31
+
32
+ // 1. Define your configuration structure
33
+ interface ComponentConfig {
34
+ visible: boolean;
35
+ x: number;
36
+ y: number;
37
+ sprite: string;
38
+ }
39
+
40
+ // 2. Create the configuration tree
41
+ const uiConfig: ConfigTree<ComponentConfig> = {
42
+ base: {
43
+ fields: {
44
+ visible: true,
45
+ x: 0,
46
+ y: 0,
47
+ sprite: 'default.png',
48
+ },
49
+ },
50
+ mainMenu: {
51
+ button: {
52
+ extends: 'base', // Inherits from the base config
53
+ fields: {
54
+ x: 100, // Overrides base 'x'
55
+ sprite: 'button.png', // Overrides base 'sprite'
56
+ },
57
+ },
58
+ },
59
+ };
60
+
61
+ // 3. Initialize the resolver and get the final config
62
+ const resolver = new ConfigResolver<ComponentConfig>(uiConfig);
63
+ const buttonConfig = resolver.get('mainMenu/button');
64
+
65
+ console.log(buttonConfig);
66
+
67
+ /*
68
+ Output:
69
+ {
70
+ visible: true, // from 'base'
71
+ x: 100, // from 'mainMenu/button'
72
+ y: 0, // from 'base'
73
+ sprite: 'button.png' // from 'mainMenu/button'
74
+ }
75
+ */
76
+ ```
77
+
78
+ ## License
79
+
80
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axi-engine/configs",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -28,7 +28,12 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@axi-engine/utils": "^0.1.6",
32
31
  "deepmerge-ts": "^7.1.5"
32
+ },
33
+ "devDependencies": {
34
+ "@axi-engine/utils": "^0.1.6"
35
+ },
36
+ "peerDependencies": {
37
+ "@axi-engine/utils": "^0.1.6"
33
38
  }
34
39
  }