npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kirz/expo-env

v1.4.1

Published

Simple Expo env loader with TypeScript and schema validation

Downloads

968

Readme

@kirz/expo-env

Description

@kirz/expo-env is a simple environment loader designed for Expo projects, offering TypeScript support and schema validation using Zod. This package helps ensure your environment variables are correctly typed and validated, providing an easy way to manage them within your Expo app.

Installation

You can install the package using your preferred package manager:

npm install @kirz/expo-env
# or
yarn add @kirz/expo-env
# or
pnpm add @kirz/expo-env

Schema validation

This package requires Zod as a peer dependency for schema validation. You can install it as follows:

npm install zod
# or
yarn add zod
# or
pnpm add zod

Usage

Step 1: Update package.json

Add the following script to your package.json to automatically load environment variables before starting your Expo project:

"scripts": {
  "prestart": "load-env"
}

To significantly enhance script execution speed, we’ve adopted the modern Bun JavaScript runtime. This change has led to a roughly 50% reduction in the time required to run scripts. To take advantage of this performance boost, please install Bun.sh.

Step 2: Create env.ts

In the root of your project, create a file named env.ts. This file will define your environment variables using Zod for schema validation. Here’s an example:

import z from "zod";

export default {
  APP_NAME: z.string(),
  APP_BUNDLE_ID: z.string(),
  APP_VERSION: z.string().default("1.0"),
};

Step 3: Import Env

In any file where you need to access your environment variables, import the Env object like this:

import { Env } from "@kirz/expo-env";

Step 4: Use Env in Your Project

You can now access your validated environment variables anywhere in your project, including in app.config.ts. For example:

import { Env } from "@kirz/expo-env";
import { ConfigContext, ExpoConfig } from "@expo/config";

export default ({ config }: ConfigContext): ExpoConfig => {
  return {
    ...config,
    name: Env.APP_NAME,
    slug: Env.APP_BUNDLE_ID,
    version: Env.APP_VERSION,
  };
};