@types/convict
- Version 6.1.6
- Published
- 10.7 kB
- 1 dependency
- MIT license
Install
npm i @types/convict
yarn add @types/convict
pnpm add @types/convict
Overview
TypeScript definitions for convict
Index
Variables
Interfaces
Type Aliases
Variables
variable convict
var convict: convict;
Interfaces
interface Config
interface Config<T> {}
method default
default: <K extends Path<T> = undefined>( name?: K) => K extends null | undefined ? T : K extends Path<T> ? PathValue<T, K> : never;
Returns
the default value of the name property. name can use dot notation to reference nested values
method get
get: <K extends Path<T> = undefined>( name?: K) => K extends null | undefined ? T : K extends Path<T> ? PathValue<T, K> : never;
Returns
the current value of the name property. name can use dot notation to reference nested values
method getArgs
getArgs: () => string[];
Gets the array of process arguments, using the override passed to the convict function or process.argv if no override was passed.
method getEnv
getEnv: () => string[];
Gets the environment variable map, using the override passed to the convict function or process.env if no override was passed.
method getProperties
getProperties: () => T;
Exports all the properties (that is the keys and their current values) as a {JSON} {Object}
Returns
A {JSON} compliant {Object}
method getSchema
getSchema: () => InternalSchema<T>;
Exports the schema as a {JSON} {Object}
Returns
A {JSON} compliant {Object}
method getSchemaString
getSchemaString: () => string;
Exports the schema as a JSON string.
Returns
A string representing the schema of this {Config}
method has
has: <K extends Path<T>>(name: K) => boolean;
Returns
true if the property name is defined, or false otherwise
method load
load: <U>(conf: U) => Config<Overwrite<T, U>>;
Loads and merges a JavaScript object into config
method loadFile
loadFile: <U>(files: string | string[]) => Config<Overwrite<T, U>>;
Loads and merges JSON configuration file(s) into config
method reset
reset: <K extends Path<T>>(name: K) => void;
Resets a property to its default value as defined in the schema
method set
set: <K extends string | Path<T>>( name: K, value: K extends Path<T> ? PathValue<T, K> : any) => Config<T>;
Sets the value of name to value. name can use dot notation to reference nested values, e.g. "database.port". If objects in the chain don't yet exist, they will be initialized to empty objects
method toString
toString: () => string;
Exports all the properties (that is the keys and their current values) as a JSON string.
Returns
A string representing this object
method validate
validate: (options?: ValidateOptions) => Config<T>;
Validates config against the schema used to initialize it
interface convict
interface convict {}
method addFormat
addFormat: (format: convict.Format) => void;
method addFormats
addFormats: (formats: { [name: string]: convict.Format }) => void;
method addParser
addParser: (parsers: convict.Parser | convict.Parser[]) => void;
call signature
<T>( config: convict.Schema<T> | string, opts?: convict.Options): convict.Config<T>;
interface Format
interface Format {}
interface InternalSchema
interface InternalSchema<T> {}
interface Options
interface Options {}
interface Parser
interface Parser {}
interface SchemaObj
interface SchemaObj<T = any> {}
property arg
arg?: string | undefined;
property default
default: T | null;
You can define a configuration property as "required" without providing a default value. Set its default to null and if your format doesn't accept null it will throw an error.
property doc
doc?: string | undefined;
property env
env?: string | undefined;
property format
format?: | PredefinedFormat | any[] | ((val: any) => asserts val is T) | ((val: any) => void) | undefined;
From the implementation:
format can be a: - predefined type, as seen below - an array of enumerated values, e.g. ["production", "development", "testing"] - built-in JavaScript type, i.e. Object, Array, String, Number, Boolean - function that performs validation and throws an Error on failure
If omitted, format will be set to the value of Object.prototype.toString.call for the default value
property nullable
nullable?: boolean | undefined;
property sensitive
sensitive?: boolean | undefined;
index signature
[key: string]: any;
interface ValidateOptions
interface ValidateOptions {}
property allowed
allowed?: ValidationMethod | undefined;
If set to warn, any properties specified in config files that are not declared in the schema will print a warning. This is the default behavior. If set to strict, any properties specified in config files that are not declared in the schema will throw errors. This is to ensure that the schema and the config files are in sync.
property output
output?: ((message: string) => void) | undefined;
If specified, possible warnings will be passed to this function instead of being outputted to console.log, which would be the default behaviour.
property strict
strict?: boolean | undefined;
Deprecated
use allowed instead
Type Aliases
type Overwrite
type Overwrite<T, U> = { [P in Exclude<keyof T, keyof U>]: T[P] } & U;
type Path
type Path<T> = PathImpl<T, keyof T> | keyof T;
type PathImpl
type PathImpl<T, K extends keyof T> = K extends string ? T[K] extends Record<string, any> ? T[K] extends ArrayLike<any> ? K | `${K}.${PathImpl<T[K], Exclude<keyof T[K], keyof any[]>>}` : K | `${K}.${PathImpl<T[K], keyof T[K]>}` : K : never;
type PathValue
type PathValue<T, P extends Path<T>> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K]> ? PathValue<T[K], Rest> : never : never : P extends keyof T ? T[P] : never;
type PredefinedFormat
type PredefinedFormat = | '*' | 'int' | 'port' | 'windows_named_pipe' | 'port_or_windows_named_pipe' | 'url' | 'email' | 'ipaddress' | 'duration' | 'timestamp' | 'nat' | String | Object | Number | RegExp | Boolean;
type Schema
type Schema<T> = { [P in keyof T]: Schema<T[P]> | SchemaObj<T[P]>;};
type ValidationMethod
type ValidationMethod = 'strict' | 'warn';
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/convict
.
- Markdown[](https://www.jsdocs.io/package/@types/convict)
- HTML<a href="https://www.jsdocs.io/package/@types/convict"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3385 ms. - Missing or incorrect documentation? Open an issue for this package.