> **>>> TL;DR:** This facilitates the *creation* and *usage* of global, immutable data for [Astro](https://astro.build) apps
# Astro Resume
Utilities for serializing data from server for use in the client.
1. `Serialize` - Astro component that takes `id` and `data`
1. `deserialize()` - a function for use in the client that takes an `id` string and returns the `data` object
## Install via npm
On your [Astro](https://astro.build) project:
```
npm i @ayco/astro-resume
```
## Usage
Serializing and deserializing basic primitive data
```astro
---
import Serialize from "@ayco/astro-resume";
const data = {
hello: 'world',
}
---
```
## Type Safety
You can define a type for the data and use it in the client script.
```astro
---
import Serialize from "@ayco/astro-resume";
const data = {
hello: 'world',
isOkay: true
}
// define the type of data to be serialized
export type Data = typeof data;
---
```
## Passing all Astro.props to client
If you need to make all the component props to the client script:
```astro
---
import Serialize from "@ayco/astro-resume";
export interface Props {
hello: string;
isOkay: boolean;
}
---
```
## Serialize server data once, access everywhere
If you have shared data that needs to be initialized from the server and accessed in several places on the client-side, you can use `Serialize` once and `deserialize` in any number of Astro components as long as they are in the same page.
In this example, an appConfig object is built and serialized in index.astro and accessed in child Astro components.
In index.astro:
```astro
import Serialize from "@ayco/astro-resume";
const appConfig = {
someClientSideKey: '1234hello',
}
export type AppConfig = typeof appConfig;
---
```
In Child.astro:
```astro
I'm a child. I have access to the appConfig in index!
```
In GrandChild.astro:
```astro
I'm a grand child. I also have access to the appConfig in index!
```
## Using a custom serializer and parser
You can bring your own custom serializer/parser if you want to opt for more complex data handling.
Here's an example of serializing data that `JSON.stringify` cannot (e.g., Date or BigInt) using Rich Harris' [`devalue`](https://github.com/Rich-Harris/devalue):
```astro
---
import {stringify} from 'devalue';
import Serialize from "@ayco/astro-resume";
const data = {
now: new Date(),
age: BigInt('3218378192378')
}
export type Data = typeof data;
---
```
## Errors & Warning in `deserialize()`
The `deserialize()` function may give you the following:
1. **ERR: No match found** - there are no `JSON` scripts with the given ID
1. **WARNING: Multiple matches for ** - there were multiple `JSON` scripts found with the same ID
## About
This is a quick and easy pattern to embed serialized information into your HTML and make it available in the client-side script with type safety.
The `Serialize` component will write the data as JSON wrapped in a `