Skip to content

@dovenv/examples - API documentation

Classes

Examples

Extends

Constructors

new Examples()
ts
new Examples(opts?: Config, config?: Config): Examples
Parameters
ParameterType
opts?Config
config?Config
Returns

Examples

Inherited from

PluginCore<Config>.constructor

Methods

fromConfig()
ts
fromConfig(data: {
  config: ExampleProps<ExampleProps>;
  desc: string;
  input: string | ExampleProps<ExampleProps>;
  output: string;
  title: string | false;
}): Promise<string>
Parameters
ParameterTypeDescription
dataobject-
data.config?ExampleProps<ExampleProps>Override your config input
data.desc?stringDescription Default 'Examples'
data.inputstring | ExampleProps<ExampleProps>Input of your config (path or config object) Path formats: JSON, YAML, TOML JS etc
data.output?stringWrite a output if you want
data.title?string | falseh1 for markdown Default 'Examples'
Returns

Promise<string>

fromCustom()
ts
fromCustom(data: ExampleCustomProps): Promise<unknown>

Processes custom example data using provided handlers.

This method allows dynamic processing of example data based on the type by binding specific handler functions for each type. The function received in the data parameter is invoked with an object containing these handlers.

Parameters
ParameterTypeDescription
dataExampleCustomPropsObject containing the function to execute with the handlers.
Returns

Promise<unknown>

A promise that resolves to the result of the executed function.

fromJsdoc()
ts
fromJsdoc(data: {
  desc: string;
  input: string[];
  opts: Options;
  output: string;
  title: string | false;
}): Promise<string>

Process jsdoc examples.

Parameters
ParameterTypeDescription
dataobjectExample data.
data.desc?stringDescription Default 'Examples'
data.inputstring[]Input pattern
data.opts?OptionsOptions for input patterns
data.output?stringWrite a output if you want
data.title?string | falseh1 for markdown Default 'Examples'
Returns

Promise<string>

Resolved example content.

See

https://github.com/jsdoc2md/jsdoc-api/blob/master/docs/api.md

fromMultiple()
ts
fromMultiple(data: {
  config: Omit<{
     config: ExampleProps<ExampleProps>;
     desc: string;
     input: string | ExampleProps<ExampleProps>;
     output: string;
     title: string | false;
    }, "output">;
  desc: string;
  jsdoc: Omit<{
     desc: string;
     input: string[];
     opts: Options;
     output: string;
     title: string | false;
    }, "output">;
  output: string;
  path: Omit<{
     desc: string;
     input: string[];
     opts: Options;
     output: string;
     title: string | false;
    }, "output">;
  title: string | false;
}): Promise<string>

Process multiple examples.

Parameters
ParameterTypeDescription
dataobjectExample data.
data.config?Omit<{ config: ExampleProps<ExampleProps>; desc: string; input: string | ExampleProps<ExampleProps>; output: string; title: string | false; }, "output">-
data.desc?stringDescription Default 'Examples'
data.jsdoc?Omit<{ desc: string; input: string[]; opts: Options; output: string; title: string | false; }, "output">-
data.output?stringWrite a output if you want
data.path?Omit<{ desc: string; input: string[]; opts: Options; output: string; title: string | false; }, "output">-
data.title?string | falseh1 for markdown Default 'Examples'
Returns

Promise<string>

Resolved example content.

fromPath()
ts
fromPath(data: {
  desc: string;
  input: string[];
  opts: Options;
  output: string;
  title: string | false;
}): Promise<string>
Parameters
ParameterTypeDescription
dataobject-
data.desc?stringDescription Default 'Examples'
data.inputstring[]Input pattern
data.opts?OptionsOptions for input patterns
data.output?stringWrite a output if you want
data.title?string | falseh1 for markdown Default 'Examples'
Returns

Promise<string>

get()
ts
get(data: ConfigValue): Promise<any>

Get a custom Example content template.

Perfect method to be used outside an Dovenv environment.

Parameters
ParameterTypeDescription
dataConfigValueConfiguration object.
Returns

Promise<any>

A promise that resolves to the processed content as a string.

run()
ts
run(pattern?: string[]): Promise<unknown>

Process examples from the configuration object.

Parameters
ParameterTypeDescription
pattern?string[]An array of examples names to process. If not provided, all examples will be processed.
Returns

Promise<unknown>

A promise that resolves to an object containing the content of each processed example.

Properties

PropertyTypeDefault valueDescriptionOverridesInherited from
configundefined | ConfigundefinedThe dovenv configuration.-PluginCore.config
const__moduleconsts---
optsundefined | ConfigundefinedConfiguration options.-PluginCore.opts
titlestring'examples'-PluginCore.title-

Functions

examplesPlugin()

ts
function examplesPlugin(conf?: Config): Config

A plugin for dovenv providing tools for managing example paths.

Parameters

ParameterTypeDescription
conf?ConfigConfiguration for the plugin.

Returns

Config

  • The plugin configuration with custom examples.

Type Aliases

Config

ts
type Config: { [key in string]: ConfigValue };

ExampleConfigFileProps

ts
type ExampleConfigFileProps: Prettify<Shared & {
  config: ExampleConfig;
  input: string | ExampleConfig;
}>;

ExampleCustomProps

ts
type ExampleCustomProps: {
  fn: (data: {
     config: DovenvConfig;
     run: {
        config: (data: ExampleConfigFileProps) => Promise<string>;
        jsdoc: (data: ExampleJsdocProps) => Promise<string>;
        multiple: (data: ExampleMultipleProps) => Promise<string>;
        path: (data: ExamplePathProps) => Promise<string>;
       };
    }) => Promise<unknown>;
};

Type declaration

NameType
fn(data: { config: DovenvConfig; run: { config: (data: ExampleConfigFileProps) => Promise<string>; jsdoc: (data: ExampleJsdocProps) => Promise<string>; multiple: (data: ExampleMultipleProps) => Promise<string>; path: (data: ExamplePathProps) => Promise<string>; }; }) => Promise<unknown>

ExampleJsdocProps

ts
type ExampleJsdocProps: ExamplePathProps;

ExampleMultipleProps

ts
type ExampleMultipleProps: Prettify<Shared & {
  config: Omit<ExampleConfigFileProps, "output">;
  jsdoc: Omit<ExampleJsdocProps, "output">;
  path: Omit<ExamplePathProps, "output">;
}>;

ExamplePathProps

ts
type ExamplePathProps: Prettify<Shared & {
  input: string[];
  opts: Parameters<typeof getPaths>[1];
}>;

References

default

Renames and re-exports examplesPlugin