Git Product home page Git Product logo

eznv's People

Contributors

codechaotic avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

eznv's Issues

Load and LoadSync argument `options` is required

Excluding the options object from a call to Schema.load() or Schema.loadSync() results in a typescript error.

Expected 1 arguments, but got 0.

These methods should be callable without supplying an options object since all options have safe defaults.

Better Docs

Current documentation is minimal and could be improved

Validators and Transformations

Add an ability to add custom validation to any configuration
Add an ability to transform the resulting configuration value

Method 1: Dedicated validation and transform function as an option for interpreters. There doesn't seem to be an obvious return value for the validator. Would it be better to provide special handling for errors thrown from within this method instead?

EZ.Number({
  validate (x: string): boolean {
    // return false or maybe just throw error?
  }
  transform (x: number): any {
    // The return type of the transform method would need to be
    // used on the resulting env object
  }
})

Method 2: Singular function option to do any post-processing. Functions as both a validator and a transformer. Would it make sense to have a pre-processing function as an option as well? before and after, pre and post, or similar?

EZ.Integer({
  after (x: number): any {
    if (x % 2 === 1) throw new Error('Must be an even number')
    else return x / 2
  }
})

This may be solvable alongside #11

Custom Interpreters

In addition to String, Number, Integer, and Boolean, users may have their own unique parsing rules to apply to their environment variables. This could include validation of the raw value, as well as custom result types.

Off the wall idea for the design:

import EZ from 'eznv'

interface SomeType {
  //
}

const schema = EZ.Schema({
  variable: EZ.Custom<SomeType>({
    parse (x: string) : SomeType {
      // custom parsing logic
      return { /* some type */ }
    }
  })
})

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.