Coder Social home page Coder Social logo

merofuruya / environmentality Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 493 KB

Makes you have a good time with environment variables and dotenv

Home Page: https://www.npmjs.com/package/environmentality

License: MIT License

JavaScript 1.77% TypeScript 98.23%
dotenv environement helper typescript

environmentality's Introduction

Iโ€™m @MeroFuruya.

Interests:

  • Python
    • Discord bots (using i.py)
    • mongodb (pymongo/motor)
    • http/api stuff
    • webapps (flask, aiohttp)
  • js
    • typescript
    • express
    • typeorm
  • Pascal/Delphi

environmentality's People

Contributors

dependabot[bot] avatar merofuruya avatar

Stargazers

 avatar  avatar  avatar

environmentality's Issues

return value not null but undefined

Describe the bug

const result = envConverter.convert([
  {
    name: "WONG_BOOLEAN",
    type: "boolean",
  },
])
expect(result).toEqual({ WONG_BOOLEAN: null })

fails:

- Expected  - 3
+ Received  + 1

- Object {
-   "MISSING_REQUIRED": null,
- }
+ Object {}

Steps to reproduce

see Describe the bug

Expected behavior

i expect that to pass

Environment

Other information

No response

case insensitive naming option

Describe the feature

i would like to be able to set variable name matching to case insensitive

Example

Env var name: TEST_STRING
code var name: test_string

this isn't possible atm

Motivation

:)

write default values into process.env

Describe the feature

i would like default values to be written into process.env. that would help with other libraries that use environment variables.

Example

if i give NEW_RELIC_ENABLED a default value and it isnt set in process.env that it then will be set.

Motivation

this would allow one to use the library to set variables for other libraries

default value array - type error

Describe the bug

When trying to set a default value for an array, it gives an type error.

Steps to reproduce

const result = envConverter.convert([
  {
    name: "DEFAULT_ARRAY",
    type: "string",
    array: true,
    default: ["default1", "default2", "default3"],  // <- type error there
  },
])

Expected behavior

I expect it to enforce an array and be happy with it

Environment

Other information

fix:

export interface EnvironmentalityPropertyOptions<
  T extends EnvironmentalityPropertyTypes,
  IsArray extends boolean,
> {
  /*
   * The name of the environment variable to use. Defaults to the property name.
   */
  name?: string
  /*
   * Whether the environment variable is required. Defaults to true.
   */
  required?: boolean
  /*
   * The default value to use if the environment variable is not set. Defaults to undefined.
   */
  default?: IsArray extends true
    ? EnvironmentalityPropertyTypesConstructor<T>[]
    : EnvironmentalityPropertyTypesConstructor<T>
  /*
   * The type of the environment variable. Defaults to string.
   */
  type?: T
  array?: IsArray
  enumValues?: EnvironmentalityPropertyTypesConstructor<T>[]
}

export type EnvironmentalityPropertyOptionsAny =
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  EnvironmentalityPropertyOptions<any, any>

escape symbols when parsing

Describe the feature

i would like to be able to escape characters from being used for parsing

Example

escape , eg in lists by doing \,
same for other symbols

"a,b\,c,d" => ["a", "b,c", "d"]

Motivation

this would allow parsed characters to be in strings

import doesn't allow class parsing

Describe the bug

i was trying to import like that:

import { Env, EnvVar } from "environmentality"

but i had to do that:

import environmentality from "environmentality"
const { Env, EnvVar } = environmentality

Steps to reproduce

do as stated above

Expected behavior

i wanna do that maaaaan:

import { Env, EnvVar } from "environmentality"

Environment

  • Version: 2.1.0

Other information

No response

default values per NODE_ENV

Describe the feature

i would love to be able to set a default value while testing or just have some kind of easyness while testing.

Example

like when node_env is test that the "required" becomes obsolete. only if the value is really called.

Motivation

make testing easier.

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.