From 94664e8c49dace7815d2b51df7c7c814a07adc1b Mon Sep 17 00:00:00 2001 From: Ayo Ayco Date: Tue, 18 Jul 2023 23:35:51 +0200 Subject: [PATCH] chore: update readme, code clean up --- README.md | 35 +++++++++++++++-------------------- package-lock.json | 3 +-- package.json | 3 +-- src/pages/index.astro | 14 +++++--------- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index a57e9cd..979c701 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,9 @@ Utilities for serializing data from server for use in the client. 1. `Serialize` - Astro component that takes `id` and `data` -1. `deserialize(id: string)` - a function for use in the client that takes an `id` string and returns the `data` object +1. `deserialize()` - a function for use in the client that takes an `id` string and returns the `data` object -## Installation & Examples - -### Install via npm +## Install via npm On your [Astro](https://astro.build) project: @@ -15,7 +13,7 @@ On your [Astro](https://astro.build) project: npm i @ayco/astro-resume ``` -### Usage +## Usage Serializing and deserializing basic primitive data @@ -38,7 +36,7 @@ const data = { ``` -### Type Safety +## Type Safety You can define a type for the data and use it in the client script. @@ -71,7 +69,7 @@ export type Data = typeof data; ``` -### Passing all Astro.props to client +## Passing all Astro.props to client If you need to make all the component props to the client script: @@ -94,20 +92,17 @@ export interface Props { ``` -### Using a custom serializer and parser +## Using a custom serializer and parser -If you want to opt for more complex data, you can bring your custom serializer/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 "../Serialize.astro"; +import Serialize from "@ayco/astro-resume"; const data = { - name: 'John Doe', - isOkay: true, - mood: null, now: new Date(), age: BigInt('3218378192378') } @@ -117,17 +112,17 @@ export type Data = typeof data; ``` -### Errors & Warning in `deserialize()` +## 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 diff --git a/package-lock.json b/package-lock.json index 4bf885f..f616bb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,7 @@ "license": "MIT", "dependencies": { "@astrojs/node": "^5.3.0", - "astro": "^2.8.4", - "devalue": "^4.3.2" + "astro": "^2.8.4" } }, "node_modules/@ampproject/remapping": { diff --git a/package.json b/package.json index 8738f81..e57d6f6 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ }, "dependencies": { "@astrojs/node": "^5.3.0", - "astro": "^2.8.4", - "devalue": "^4.3.2" + "astro": "^2.8.4" } } diff --git a/src/pages/index.astro b/src/pages/index.astro index d1e150c..285d332 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,27 +1,23 @@ --- -import { stringify } from 'devalue'; import Serialize from "../Serialize.astro"; const data = { name: 'John Doe', isOkay: true, mood: null, - now: new Date(), - age: BigInt('3218378192378') + // now: new Date(), + // age: BigInt('3218378192378') } export type Data = typeof data; ---
- +