Code Monkey home page Code Monkey logo

meteor-settings-validator's Introduction

Meteor Settings Validator

The MeteorSettingsValidator class simplifies the validation of Meteor.settings using a specified Zod schema. This utility ensures that the settings adhere to the expected structure and provides a straightforward method, get(), to fetch and utilize them in a TypeScript project.

How it works

The class is tailored for use with Zod, a TypeScript-centric schema declaration and validation library. It takes a ZodObject representing the anticipated shape of Meteor.settings and furnishes a get() method to fetch and validate the settings.

Upon successful validation, the method returns the verified settings. If executed on the client side, it exclusively returns the public settings to bolster security.

Usage

  1. Installation: Ensure Zod and meteor-settings-validator are installed in your project.
meteor add hschmaiske:meteor-settings-validator
meteor npm i zod
  1. Import the class: Import the MeteorSettingsValidator class into your TypeScript file.
import { MeteorSettingsValidator } from "hschmaiske:meteor-settings-validator";
  1. Create a ZodObject for Meteor.settings: Define a ZodObject that represents the expected structure of Meteor.settings. For example:
const MeteorSettingsSchema = z.object({
  public: z.object({
    // Define your public settings structure here
  }),
  // Add other properties as needed
});
  1. Instantiate the Validator: Create an instance of MeteorSettingsValidator with your ZodObject.
const settingsValidator = new MeteorSettingsValidator(MeteorSettingsSchema);
  1. Retrieve and Use Meteor.settings:
  • Call the get() method to retrieve and validate Meteor.settings.
const settingsValidator = new MeteorSettingsValidator(MeteorSettingsSchema);
const settings = settingsValidator.get();

// and you can use like this:
settings.public.myCustomKey
  • TODO: add tests

meteor-settings-validator's People

Contributors

henriquealbert avatar

Stargazers

G avatar Gabriel Grubba avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.