Configuration Handler for Deno with Support for .env and Scopes

Cfg

Cfg is a configuration handler for Deno with support for .env and scopes.

Run

Some features require access to the file system and the environment. Please run your project with the flags --allow-read, --allow-env and --unstable.

Import

Import the latest release.

// As named import
import { cfg } from "https://deno.land/x/cfg@v1.0.0-beta.3/mod.ts";

// Or as default import
import cfg from "https://deno.land/x/cfg@v1.0.0-beta.3/mod.ts";

Basic usage

This is the easiest way to use Cfg.

const config = cfg([{ foo: "bar" }]);

console.log(config.get("foo"))
// Or
console.log(config.getp("foo"))

A type parameter can also be used in order to benefit from intellisense.

const obj = { foo: "bar" };

const config = cfg<typeof obj>([obj]);

console.log(config.get("foo"));
// Or
console.log(config.getp("foo"))

Usage

cfg() function

cfg is an overloaded function. It has the following signature:

cfg<Config extends Configuration, Env extends ENVConfiguration = {}>(arguments): Cfg<Config, Env>

Call without argument

Calling cfg() without arguments is used to access a configuration which has already been initiated on the default scope

Call with a scope

Calling cfg(scope) is used to access a configuration which has already been initiated on the specified scope

Call with a Loadable

Calling cfg([Loadable]) is used to create a configuration on the default scope. An array of Loadable is passed as argument. Loadable is the type that describes anything that can loaded to the configuration.

Call with a scope and a Loadable

Calling cfg(scope, [Loadable]) is used to create a configuration on the specified scope.

Call with an options object

Calling cfg(options) allow to specify additional options

Persistance & scopes

All configurations are stored by Cfg and can be accessed at any time by calling cfg(scope). There are a few things to keep in mind:

  • When no scope is specified in the options, a default scope is used.
  • Scopes are shared between modules. It’s therefore best for each module to have its own scope and leave the default scope for the final user.
  • Only one configuration per scope can be created. Once it’s there, it can’t be deleted

Options

The Opts interface describes the option object that is used to configure cfg().

interface Opts {
  env?: boolean | string | EnvOpt;
  load?: Loadable | Loadable[];
  scope?: string;
}

The Opts.scope property defines the scope. The Opts.load property is used to specify one or several Loadable which will be merged to a Configuration object. The Opts.env property is used to configure the environment variables. When Opts.env is true, Cfg will look for an .env file in the root directory. Opts.env can also be a string that represents the path to the .env file. More options can be configured by using an EnvOpt object.

interface EnvOpt {
  export?: boolean;
  import?: ENVConfiguration;
  merge?: boolean;
  path?: string;
}

When true, EnvOpt.export exports the environment variables to Deno.env. It will never overwrite a value that already exist. With EnvOpt.import, an object of type ENVConfiguration can be imported. This can be useful if, for example, one needs to use another parser for .env files. When true, EnvOpt.merge will merge the environment variables with the configuration. Finally, EnvOpt.path is a string that that represents the path to the .env file.

Methods

Cfg.get(…props: string[])

This method returns the configuration. Parameters can be used to return a specific property. When cfg() is called with a type parameter, intellisense checks that the paramters are correct and knows the type of the value returned.

Cfg.get() allows up to 4 parameters.

Cfg.getp(path: string)

This method returns the configuration just like Cfg.get(). But it accepts a path as parameter with the syntax a.b.c or a[b][c]. This method will always return a value with type unknown.

Cfg.getEnv(prop: string)

Cfg.getEnv() is similar to Cfg.get() except that it accepts only one parameter and returns environment variables.

Types

Configuration

The interface Configuration defines the configuration object.

interface Configuration {
  [key: string]: (string | number | boolean | Configuration) | (string | number | boolean | Configuration)[];
}

ENVConfiguration

The interface ENVConfiguration defines the .env object

interface ENVConfiguration {
  [key: string]: string | number | boolean;
}

Loadable

The type Loadable defines the sources of configuration that will be merged to a Configuration object.

type Loadable = string | Configuration | ConfigFunction;

ConfigFunction

The type ConfigFunction defines a function that returns a Configuration object.

type ConfigFunction<T extends ENVConfiguration = {}> = (env: T) => Configuration;

Contributions

PRs are welcome!

Download Details:

Author: ymonb1291

Source Code: https://github.com/ymonb1291/cfg

#deno #nodejs #node #javascript

What is GEEK

Buddha Community

Configuration Handler for Deno with Support for .env and Scopes

Configuration Handler for Deno with Support for .env and Scopes

Cfg

Cfg is a configuration handler for Deno with support for .env and scopes.

Run

Some features require access to the file system and the environment. Please run your project with the flags --allow-read, --allow-env and --unstable.

Import

Import the latest release.

// As named import
import { cfg } from "https://deno.land/x/cfg@v1.0.0-beta.3/mod.ts";

// Or as default import
import cfg from "https://deno.land/x/cfg@v1.0.0-beta.3/mod.ts";

Basic usage

This is the easiest way to use Cfg.

const config = cfg([{ foo: "bar" }]);

console.log(config.get("foo"))
// Or
console.log(config.getp("foo"))

A type parameter can also be used in order to benefit from intellisense.

const obj = { foo: "bar" };

const config = cfg<typeof obj>([obj]);

console.log(config.get("foo"));
// Or
console.log(config.getp("foo"))

Usage

cfg() function

cfg is an overloaded function. It has the following signature:

cfg<Config extends Configuration, Env extends ENVConfiguration = {}>(arguments): Cfg<Config, Env>

Call without argument

Calling cfg() without arguments is used to access a configuration which has already been initiated on the default scope

Call with a scope

Calling cfg(scope) is used to access a configuration which has already been initiated on the specified scope

Call with a Loadable

Calling cfg([Loadable]) is used to create a configuration on the default scope. An array of Loadable is passed as argument. Loadable is the type that describes anything that can loaded to the configuration.

Call with a scope and a Loadable

Calling cfg(scope, [Loadable]) is used to create a configuration on the specified scope.

Call with an options object

Calling cfg(options) allow to specify additional options

Persistance & scopes

All configurations are stored by Cfg and can be accessed at any time by calling cfg(scope). There are a few things to keep in mind:

  • When no scope is specified in the options, a default scope is used.
  • Scopes are shared between modules. It’s therefore best for each module to have its own scope and leave the default scope for the final user.
  • Only one configuration per scope can be created. Once it’s there, it can’t be deleted

Options

The Opts interface describes the option object that is used to configure cfg().

interface Opts {
  env?: boolean | string | EnvOpt;
  load?: Loadable | Loadable[];
  scope?: string;
}

The Opts.scope property defines the scope. The Opts.load property is used to specify one or several Loadable which will be merged to a Configuration object. The Opts.env property is used to configure the environment variables. When Opts.env is true, Cfg will look for an .env file in the root directory. Opts.env can also be a string that represents the path to the .env file. More options can be configured by using an EnvOpt object.

interface EnvOpt {
  export?: boolean;
  import?: ENVConfiguration;
  merge?: boolean;
  path?: string;
}

When true, EnvOpt.export exports the environment variables to Deno.env. It will never overwrite a value that already exist. With EnvOpt.import, an object of type ENVConfiguration can be imported. This can be useful if, for example, one needs to use another parser for .env files. When true, EnvOpt.merge will merge the environment variables with the configuration. Finally, EnvOpt.path is a string that that represents the path to the .env file.

Methods

Cfg.get(…props: string[])

This method returns the configuration. Parameters can be used to return a specific property. When cfg() is called with a type parameter, intellisense checks that the paramters are correct and knows the type of the value returned.

Cfg.get() allows up to 4 parameters.

Cfg.getp(path: string)

This method returns the configuration just like Cfg.get(). But it accepts a path as parameter with the syntax a.b.c or a[b][c]. This method will always return a value with type unknown.

Cfg.getEnv(prop: string)

Cfg.getEnv() is similar to Cfg.get() except that it accepts only one parameter and returns environment variables.

Types

Configuration

The interface Configuration defines the configuration object.

interface Configuration {
  [key: string]: (string | number | boolean | Configuration) | (string | number | boolean | Configuration)[];
}

ENVConfiguration

The interface ENVConfiguration defines the .env object

interface ENVConfiguration {
  [key: string]: string | number | boolean;
}

Loadable

The type Loadable defines the sources of configuration that will be merged to a Configuration object.

type Loadable = string | Configuration | ConfigFunction;

ConfigFunction

The type ConfigFunction defines a function that returns a Configuration object.

type ConfigFunction<T extends ENVConfiguration = {}> = (env: T) => Configuration;

Contributions

PRs are welcome!

Download Details:

Author: ymonb1291

Source Code: https://github.com/ymonb1291/cfg

#deno #nodejs #node #javascript

Rahim Makhani

Rahim Makhani

1622519505

Maintain your Magento app for a smoother and faster user Experience

Magento is the best open-source eCommerce platform for website development. We all know the importance of a website in every sector; whether it is about business or anything else, it can represent the look and feel of your company. So to maintain these websites, it is essential to do Magento support and maintenance so that you can also maintain your website.

Nevina Infotech is the best Magento app development company that can guide you to maintain and support your Magento app. We have a dedicated team of developers who will help you with the maintenance and support of your app.

#magento maintenance and support services #magento support services #magento support and maintenance #magento support #magento maintenance support #magento technical support

Rahim Makhani

Rahim Makhani

1626851156

Get the latest Features in your current eCommerce App

Are you tired of outdated features in your eCommerce app and do you want some latest and trending features in your eCommerce app? Then you need to update your app regularly to stay updated with the latest and trending features to add to your app. For updating it you need to update to the latest version of the Magento so that whatever update occurs in the latest version can also occur in your eCommerce app.

You can hire Nevina Infotech that can help you to provide Magento support and maintenance and will also guide you to update your eCommerce app for adding the latest features to your app. Our team is great and enthusiastic about their work. You can easily rely on us to get the latest features in your eCommerce app.

#magento maintenance and support services #magento support services #magento support and maintenance #magento support #magento maintenance support #magento technical support

Rahim Makhani

Rahim Makhani

1618806778

Get the best Magento maintenance service for your e-commerce store

Magento is the most demanded technology for developing online eCommerce stores and Magento service is important for better working of the online store. Nevina Infotech provides you with Magento maintenance and services.

Magento maintenance is the process of checking the performance of the website and checking the regular updates, backups, online store management, and much more.

You can choose Nevina Infotech for Magento maintenance service for your eCommerce store. We provide the best Magento support and maintenance for eCommerce stores.

#magento maintenance and support services #magento support services #magento support and maintenance #magento support #magento maintenance support #magento technical support

Rahim Makhani

Rahim Makhani

1621223780

Maintain your Magento web app for better Performance

Magento is the best cross-platform framework that helps you to develop the best eCommerce web apps. It is important to maintain your Magento eCommerce web app to increase the performance of your web application.

Magento maintenance and support services play a vital role in maintaining the website because if the website or web app is not maintained properly it can create bugs in the future and many more problems can occur through which there is a chance that customers get frustrated and won’t visit your website again.

Nevina Infotech is the best choice for Magento maintenance and service of your web apps. We have a hardworking team of developers that will help you to increase the performance of your web apps.

#magento maintenance and support services #magento support services #magento support and maintenance #magento support #magento maintenance support #magento technical support