No description
.vscode | ||
public | ||
src | ||
.gitignore | ||
astro.config.mjs | ||
index.ts | ||
LICENSE | ||
package-lock.json | ||
package.json | ||
README.md | ||
tsconfig.json |
Astro deserialize
Utilities for serializing data from server for use in the client.
Serialize
Astro component takesid
anddata
deserialize(id: string): Object
function for use int he client takes anid
string and returns thedata
as Object
Installation & Usage
Install via npm
On your Astro project:
npm i @ayco/astro-resume
Usage
Serializing and deserializing basic primitive data
---
import Serialize from "@ayco/astro-resume";
const data = {
hello: 'world',
}
---
<Serialize id="my-data" data={data} />
<script>
import {deserialize} from '@ayco/astro-resume';
const data = deserialize('my-data');
console.log(data) // {hello: 'world'}
</script>
Type Safety
You can define a type for the data and use it in the client script.
---
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;
---
<Serialize id="my-data" data={data} />
<script>
import {deserialize} from '@ayco/astro-resume';
/**
* reuse the type in the client
* assuming this component's name is `Component.astro`
*/
import type {Data} from './Component.astro';
const data = deserialize<Data>('my-data');
console.log(data) // {hello: 'world'}
</script>
Reporting Issues
To report issues or request features, send a plain text email to ~ayoayco/astro-resume@todo.sr.ht or file a ticket via SourceHut