coldsnip - v0.9.1
Table of contents
Interfaces
Type Aliases
Functions
Type Aliases
ExtractSnippetOptions
Ƭ ExtractSnippetOptions: Object
Options to customize the snippet extraction process.
Type declaration
Name | Type | Description |
---|---|---|
branch | string | The branch to use when extracting snippets from remote Git repositories. Default ts "main" |
Defined in
LookupOptions
Ƭ LookupOptions: Object
Snippet lookup options. The key
is always required, the other properties are useful for matching multi-language snippets indexed by the same key.
Type declaration
Name | Type | Description |
---|---|---|
key | string | the snippet identifier |
language? | string | the snippet source language |
qualifier? | string | the snippet qualifier. Often use to differentiate snippets |
Defined in
Snippets
Ƭ Snippets: Object
A map between a key
and a collection of Snippet represented by it. Different snippets can be identified by the same key, which is the case in projects with support to multiple languages that want to provide samples of the same API in each supported language.
Index signature
▪ [key: string
]: Snippet
[]
Defined in
SourcePath
Ƭ SourcePath: LocalPath
| GitRepo
A union between LocalPath and GitRepo and serves as the main entry point of the library.
Defined in
Functions
extractSnippets
▸ extractSnippets(sources
, options?
): Promise
<Snippets
>
The main function of the library. It takes a list of SourcePath that represents local directories or Git repositories where source files containing tagged code snippets will be parsed and extracted into an indexed data structure (represented by Snippets).
const snippets = await extractSnippets([
{ path: "~/dev/projects/local", pattern: "*.js" },
{ url: "https://github.com/roxlabs/coldsnip", pattern: "*.ts" },
]);
Parameters
Name | Type | Default value | Description |
---|---|---|---|
sources | SourcePath [] | undefined | a collection of local or remote (i.e. Git) sources. |
options | ExtractSnippetOptions | DEFAULT_EXTRACT_OPTIONS | a set of optional parameters to customize the snippet extraction process. |
Returns
Promise
<Snippets
>
an object indexed by a key, representing the snippet identifier and an array of one or more code snippets.
Name
extractSnippets
Defined in
lookupSnippets
▸ lookupSnippets(snippets
, options
): Snippet
| undefined
Lookup for a specific snippet.
Implementation note: in case more than one snippet match the options the first matched result will be returned.
Parameters
Name | Type | Description |
---|---|---|
snippets | Snippets | all extracted snippets |
options | LookupOptions | the lookup options |
Returns
Snippet
| undefined
the matching snippet or undefined
in case it couldn’t be found.