1.0.2 • Published 1 year ago

@dankreiger/validate-expo-config v1.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

@expo-tools/validate-config

Provides Zod schema for app.config.{json|js|ts} in an expo app.

Installation

  1. Install package

    npm install expo-tools

API Reference

validateExpoConfig

For more fine-grained control, you can use the ExpoConfigSchema directly.

import type { ExpoConfig } from '@expo/config';
import { validateExpoConfig } from '@expo-tools/validate-config';

validateExpoConfig(config: ExpoConfig); // throws if invalid
ParameterTypeDescription
configExpoConfigRequired. Expo App config object from @expo/config

ExpoConfigSchema

Returns a Zod schema for app.config.{json|js|ts}.

Example with .parse:

// app.config.ts
import { z } from 'zod';
import { ExpoConfigSchema } from '@expo-tools/validate-config';

const AppConfig = {
  // ...
};

// use schema with any zod methods
/**
 * use schema with any zod:
 * - schema methods
 *   @see https://github.com/colinhacks/zod#schema-methods
 */
// e.g. `parse` method
const config = ExpoConfigSchema.parse(AppConfig);

/*
 * - object methods
 *  @see https://github.com/colinhacks/zod#objects
 */

// e.g. `merge` method
const config = ExpoConfigSchema.merge(
  z.object({
    name: z.literal('my-app'),
    slug: z.literal('my-app'),
    version: z.literal('1.0.0'),
    extra: {
      ...ExpoConfigSchema.extra,
      apiKey: z.literal('1234'),
      baseUrl: z.literal('https://my-app.com'),
    },
  })
);