0.0.12 • Published 2 months ago

mr-world v0.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

mr-world The global variable integration for Astro


Motivation

Provide an integration for Astro to define global variables that work in:

Quick start

Install

Install via npm:

npm install mr-world

Configure

In your Astro config file:

import { defineConfig } from "astro/config";
import { mrWorld } from "mr-world/integration";

export default defineConfig({
  site: "https://example.com",
  integrations: [
    mrWorld({
      id: "DEFAULT_LOCALE",
      useEffect: () => {

        // set global properties and functions
        globalThis.DEFAULT_LOCALE = "en";

        return () => {
          // cleanup side effects
        };
      },
    }),
  ],
});

In your Astro env.d.ts file:

declare module globalThis {
  var DEFAULT_LOCALE: "en";
}

Configure script tags

In the head of your document:

---
import { Serialize } from "mr-world/serialize";
---

<Serialize id="locale" data={{ DEFAULT_LOCALE: "en" }} />

After your <Serialize /> component:

<script>
  import { deserialize } from "mr-world/deserialize";

  const data = await deserialize({
    id: "locale",
  });
</script>

You can pass a custom serializer as props or a custom deserializer in parameters. Custom serializers may support nested structures or other data types like Date or ArrayBuffer:

By default, JSON.stringify and JSON.parse are used as serializers.

License

MIT Licensed

Contributing

PRs welcome! Thank you for your help.

0.0.11

2 months ago

0.0.12

2 months ago

0.0.10

5 months ago

0.0.9

6 months ago

0.0.7

8 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago

0.0.0

9 months ago