1.0.2 • Published 8 months ago

@123ishatest/content-parser v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Content Parser

A utility library that parses YAML files based on Zod schemas

The perfect way to manage your game content :)

Usage

Create a content type with a Zod schema.

export const ItemDetailSchema = z
  .object({
    hrid: z.string(),
    name: z.string(),
    description: z.string(),
  })
  .strict();

Create your content in YAML files.

# fish.item.yaml
hrid: /items/fish
name: Regular Fish
description: Goes blub

And use the ContentParser to grab it.

const parser = new ContentParser({
  // The name of the key here determines the file.<name>.yaml that is searched.
  item: ItemDetailSchema,
});

const result = parser.parse({
  root: '/path/to/content',
  debug: true,
  idKey: 'hrid',
});

// Enjoy your content!
const items = parser.getContent('item');
const fish = items['/items/fish'];
const description = fish.description;

// Full TS support!
parser.getContent('wrongType'); // TS2345: Argument of type 'wrongType' is not assignable to parameter of type 'item'
fish.invalidAttribute; // TS2339: Property invalidAttribute does not exist on type ItemDetail

Development

If you want to contribute to this project,

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago