@123ishatest/louter 0.2.0 → 0.3.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/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # Louter
2
+
3
+ > Louter is a zod-based content parser that transforms YAML into type-safe runtime data.
4
+
5
+ It consists of 2 parts:
6
+
7
+ - A build step, running in a node-only context such as a vite plugin or the `server` context of SvelteKit.
8
+ - A content manager, providing fully-typed access to your content at run-time.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @123ishatest/louter
14
+ ```
15
+
16
+ ## Setup
17
+
18
+ Define your content kinds, a mapping between the `kind` of content and the Zod schema that represents it.
19
+
20
+ ```ts
21
+ import { z } from 'zod';
22
+
23
+ const schemas = {
24
+ currency: z.strictObject({ id: z.string(), name: z.string() }),
25
+ upgrade: z.strictObject({
26
+ id: z.string(),
27
+ name: z.string(),
28
+ cost: z.strictObject({
29
+ currency: z.string(),
30
+ amount: z.number().default(4),
31
+ }),
32
+ }),
33
+ };
34
+ ```
35
+
36
+ Add your content!
37
+
38
+ ```yaml
39
+ # money.currency.yaml
40
+ id: /currency/money
41
+ name: Money
42
+ ```
43
+
44
+ ```yaml
45
+ # more-money.upgrade.yaml
46
+ id: /upgrade/more-money
47
+ name: More money
48
+ cost:
49
+ currency: /currency/money
50
+ amount: 4
51
+ ```
52
+
53
+ ## Usage (node)
54
+
55
+ Louter comes with a composable pipeline, so you can add or remove behaviour to your heart's desire.
56
+
57
+ ```ts
58
+ import { Louter, LouterValidator, LouterYamlParser } from '@123ishatest/louter';
59
+ import { LouterContentWriter, LouterFileLoader, LouterJsonSchemaWriter } from '@123ishatest/louter/node';
60
+
61
+ const louter = new Louter([
62
+ // Loads all files in the specified folder
63
+ new LouterFileLoader('content'),
64
+
65
+ // Parses the YAML that was found
66
+ new LouterYamlParser(),
67
+
68
+ // Validates it against the schemas
69
+ new LouterValidator(),
70
+
71
+ // Writes a big content object to the specified folder
72
+ new LouterContentWriter('.generated'),
73
+
74
+ // Writes utility JSON Schemas to the specified folder
75
+ new LouterJsonSchemaWriter('.generated'),
76
+ ]);
77
+
78
+ const result = louter.run(schemas);
79
+
80
+ // Check for warnings
81
+ result.warnings.forEach(console.warn);
82
+ ```
83
+
84
+ This result contains all parsed content, which can be used by your game!
85
+
86
+ ## Usage (browser)
87
+
88
+ ```ts
89
+ import { ContentManager } from '@123ishatest/louter';
90
+
91
+ const manager = new ContentManager(schemas);
92
+ manager.load(result.content);
93
+
94
+ // Type-safe accessors
95
+ const currencies = manager.getList('currency');
96
+ const currencyMap = manager.getMap('currency');
97
+
98
+ // Fully typed objects
99
+ const money = manager.get('/currency/money', 'currency');
100
+ console.log(money.name);
101
+ ```
@@ -0,0 +1,9 @@
1
+ import { LouterContext } from '../core/LouterContext';
2
+ import { LouterStage } from '../core/LouterStage';
3
+ import { KindDefinitions } from '../core/types';
4
+ export declare class LouterVsCodeSettingsWriter implements LouterStage {
5
+ private readonly _settingsPath;
6
+ constructor(settingsPath?: string);
7
+ run<Kinds extends KindDefinitions>(ctx: LouterContext<Kinds>): void;
8
+ }
9
+ //# sourceMappingURL=LouterVsCodeSettingsWriter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LouterVsCodeSettingsWriter.d.ts","sourceRoot":"","sources":["../../src/export/LouterVsCodeSettingsWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAKrD,qBAAa,0BAA2B,YAAW,WAAW;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;gBAE3B,YAAY,GAAE,MAAgC;IAI1D,GAAG,CAAC,KAAK,SAAS,eAAe,EAAE,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC;CA4C7D"}
@@ -0,0 +1,6 @@
1
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
2
+ export declare function isJsonSchemaEntry(value: unknown): value is {
3
+ fileMatch: string[];
4
+ url: string;
5
+ };
6
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/util/type.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI;IAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAU/F"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@123ishatest/louter",
3
3
  "private": false,
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true