@jsdocs-io/extractor

  • Version 2.0.0
  • Published
  • 116 kB
  • 9 dependencies
  • AGPL-3.0-or-later license

Install

npm i @jsdocs-io/extractor
yarn add @jsdocs-io/extractor
pnpm add @jsdocs-io/extractor

Overview

The API extractor for npm packages powering jsdocs.io

Index

Functions

function getPackageApi

getPackageApi: ({
pkg,
subpath,
maxDepth,
bun,
}: GetPackageApiOptions) => Promise<PackageApi>;
  • getPackageApi extracts the API from a package.

    If the extraction succeeds, getPackageApi returns a PackageApi object. If the extraction fails, getPackageApi throws an error.

    Warning: The extraction process is slow and blocks the main thread, using workers is recommended.

    Parameter options

    GetPackageApiOptions

    Returns

    A PackageApi object

    Example 1

    const packageApi = await getPackageApi({
    pkg: "foo", // Extract API from npm package `foo` [Required]
    subpath: ".", // Select subpath `.` (root subpath) [Optional]
    maxDepth: 5, // Maximum depth for analyzing nested namespaces [Optional]
    bun: new Bun() // Bun package manager instance [Optional]
    });
    console.log(JSON.stringify(packageApi, null, 2));

function getPackageJson

getPackageJson: (dir: string) => Promise<NormalizedPackageJson>;
  • getPackageJson returns the package.json file found in the given directory.

function getPackageTypes

getPackageTypes: ({
pkgJson,
subpath,
}: GetPackageTypesOptions) => string | undefined;
  • getPackageTypes returns the TypeScript type definition file (e.g., index.d.ts) that acts as the entry point for the package at the given subpath.

Classes

class Bun

class Bun {}
  • Bun is a wrapper for the Bun package manager.

constructor

constructor(bunCmd?: string);

    method add

    add: (pkg: string, cwd: string) => Promise<string[]>;
    • add installs the given package in the given directory and returns a list of all installed packages (e.g., ["foo@1.0.0"]).

      See Also

    Interfaces

    interface BaseDeclaration

    interface BaseDeclaration {}
    • BaseDeclaration contains the properties common to extracted declarations.

    property docs

    docs: string[];
    • List of associated JSDoc comments.

    property file

    file: string;
    • Name of the file where the declaration is defined.

    property id

    id: string;
    • Unique ID.

    property line

    line: number;
    • Line number where the declaration is defined.

    property name

    name: string;
    • Export name (may differ from the original name).

    property signature

    signature: string;
    • Declaration signature.

    interface ExtractedClass

    interface ExtractedClass extends BaseDeclaration {}

      property constructors

      constructors: ExtractedClassConstructor[];

        property kind

        kind: 'class';

          property methods

          methods: ExtractedClassMethod[];

            property properties

            properties: ExtractedClassProperty[];

              interface ExtractedClassConstructor

              interface ExtractedClassConstructor extends BaseDeclaration {}

                property kind

                kind: 'class-constructor';

                  interface ExtractedClassMethod

                  interface ExtractedClassMethod extends BaseDeclaration {}

                    property kind

                    kind: 'class-method';

                      interface ExtractedClassProperty

                      interface ExtractedClassProperty extends BaseDeclaration {}

                        property kind

                        kind: 'class-property';

                          interface ExtractedEnum

                          interface ExtractedEnum extends BaseDeclaration {}

                            property kind

                            kind: 'enum';

                              property members

                              members: ExtractedEnumMember[];

                                interface ExtractedEnumMember

                                interface ExtractedEnumMember extends BaseDeclaration {}

                                  property kind

                                  kind: 'enum-member';

                                    interface ExtractedFunction

                                    interface ExtractedFunction extends BaseDeclaration {}

                                      property kind

                                      kind: 'function';

                                        interface ExtractedInterface

                                        interface ExtractedInterface extends BaseDeclaration {}

                                          property callSignatures

                                          callSignatures: ExtractedInterfaceCallSignature[];

                                            property constructSignatures

                                            constructSignatures: ExtractedInterfaceConstructSignature[];

                                              property getAccessors

                                              getAccessors: ExtractedInterfaceGetAccessor[];

                                                property indexSignatures

                                                indexSignatures: ExtractedInterfaceIndexSignature[];

                                                  property kind

                                                  kind: 'interface';

                                                    property methods

                                                    methods: ExtractedInterfaceMethod[];

                                                      property properties

                                                      properties: ExtractedInterfaceProperty[];

                                                        property setAccessors

                                                        setAccessors: ExtractedInterfaceSetAccessor[];

                                                          interface ExtractedInterfaceCallSignature

                                                          interface ExtractedInterfaceCallSignature extends BaseDeclaration {}

                                                            property kind

                                                            kind: 'interface-call-signature';

                                                              interface ExtractedInterfaceConstructSignature

                                                              interface ExtractedInterfaceConstructSignature extends BaseDeclaration {}

                                                                property kind

                                                                kind: 'interface-construct-signature';

                                                                  interface ExtractedInterfaceGetAccessor

                                                                  interface ExtractedInterfaceGetAccessor extends BaseDeclaration {}

                                                                    property kind

                                                                    kind: 'interface-get-accessor';

                                                                      interface ExtractedInterfaceIndexSignature

                                                                      interface ExtractedInterfaceIndexSignature extends BaseDeclaration {}

                                                                        property kind

                                                                        kind: 'interface-index-signature';

                                                                          interface ExtractedInterfaceMethod

                                                                          interface ExtractedInterfaceMethod extends BaseDeclaration {}

                                                                            property kind

                                                                            kind: 'interface-method';

                                                                              interface ExtractedInterfaceProperty

                                                                              interface ExtractedInterfaceProperty extends BaseDeclaration {}

                                                                                property kind

                                                                                kind: 'interface-property';

                                                                                  interface ExtractedInterfaceSetAccessor

                                                                                  interface ExtractedInterfaceSetAccessor extends BaseDeclaration {}

                                                                                    property kind

                                                                                    kind: 'interface-set-accessor';

                                                                                      interface ExtractedNamespace

                                                                                      interface ExtractedNamespace extends BaseDeclaration {}

                                                                                        property declarations

                                                                                        declarations: ExtractedDeclaration[];

                                                                                          property kind

                                                                                          kind: 'namespace';

                                                                                            interface ExtractedTypeAlias

                                                                                            interface ExtractedTypeAlias extends BaseDeclaration {}

                                                                                              property kind

                                                                                              kind: 'type';

                                                                                                interface ExtractedVariable

                                                                                                interface ExtractedVariable extends BaseDeclaration {}

                                                                                                  property kind

                                                                                                  kind: 'variable';

                                                                                                    interface GetPackageApiOptions

                                                                                                    interface GetPackageApiOptions {}
                                                                                                    • GetPackageApiOptions contains the options for calling getPackageApi.

                                                                                                    property bun

                                                                                                    bun?: Bun;
                                                                                                    • Bun instance used to install the package.

                                                                                                    property maxDepth

                                                                                                    maxDepth?: number;
                                                                                                    • Packages can have deeply nested modules and namespaces.

                                                                                                      Use maxDepth to limit the depth of the extraction. Declarations nested at levels deeper than this value will be ignored.

                                                                                                    property pkg

                                                                                                    pkg: string;
                                                                                                    • Package to extract the API from.

                                                                                                      This can be either a package name (e.g., foo, @foo/bar) or any other query that can be passed to bun add (e.g., foo@1.0.0).

                                                                                                      See Also

                                                                                                    property subpath

                                                                                                    subpath?: string;
                                                                                                    • Specific subpath to consider in a package.

                                                                                                      If a package has multiple entrypoints listed in the exports map property of its package.json, use subpath to select a specific one by its name (e.g., someFeature).

                                                                                                      See Also

                                                                                                    interface GetPackageTypesOptions

                                                                                                    interface GetPackageTypesOptions {}

                                                                                                    property pkgJson

                                                                                                    pkgJson: Partial<NormalizedPackageJson>;
                                                                                                    • The contents of the package.json file.

                                                                                                    property subpath

                                                                                                    subpath?: string;
                                                                                                    • The subpath for which to resolve the types condition.

                                                                                                    interface PackageApi

                                                                                                    interface PackageApi {}
                                                                                                    • PackageApi contains the data extracted from a package by calling getPackageApi.

                                                                                                    property analyzedAt

                                                                                                    analyzedAt: string;
                                                                                                    • Timestamp of when the package was analyzed.

                                                                                                    property analyzedIn

                                                                                                    analyzedIn: number;
                                                                                                    • Package analysis duration in milliseconds.

                                                                                                    property declarations

                                                                                                    declarations: ExtractedDeclaration[];
                                                                                                    • Declarations exported (or re-exported) by the package.

                                                                                                    property dependencies

                                                                                                    dependencies: string[];
                                                                                                    • All packages resolved and installed when installing the package (included).

                                                                                                      Example 1

                                                                                                      ```ts // Installing foo brings in also bar and baz as dependencies. ["foo@1.0.0", "bar@2.0.0", "baz@3.0.0"] ```

                                                                                                    property name

                                                                                                    name: string;
                                                                                                    • Package name (e.g., foo, @foo/bar).

                                                                                                    property overview

                                                                                                    overview?: string;
                                                                                                    • Package description extracted from the types file if a JSDoc comment with the @packageDocumentation tag is found.

                                                                                                    property subpath

                                                                                                    subpath: string;

                                                                                                    property types

                                                                                                    types?: string;
                                                                                                    • Type declarations file, resolved from the selected subpath, that acts as the entrypoint for the package (e.g., index.d.ts).

                                                                                                    property version

                                                                                                    version: string;
                                                                                                    • Package version number (e.g., 1.0.0).

                                                                                                    Type Aliases

                                                                                                    type AllExtractedDeclaration

                                                                                                    type AllExtractedDeclaration =
                                                                                                    | ExtractedVariable
                                                                                                    | ExtractedFunction
                                                                                                    | ExtractedClass
                                                                                                    | ExtractedClassConstructor
                                                                                                    | ExtractedClassProperty
                                                                                                    | ExtractedClassMethod
                                                                                                    | ExtractedInterface
                                                                                                    | ExtractedInterfaceProperty
                                                                                                    | ExtractedInterfaceMethod
                                                                                                    | ExtractedInterfaceConstructSignature
                                                                                                    | ExtractedInterfaceCallSignature
                                                                                                    | ExtractedInterfaceIndexSignature
                                                                                                    | ExtractedInterfaceGetAccessor
                                                                                                    | ExtractedInterfaceSetAccessor
                                                                                                    | ExtractedEnum
                                                                                                    | ExtractedEnumMember
                                                                                                    | ExtractedTypeAlias
                                                                                                    | ExtractedNamespace;
                                                                                                    • AllExtractedDeclaration is the union of all possible declarations that can be extracted, with some being found only in other declarations (e.g., class method declarations are found only in a class declaration).

                                                                                                    type AllExtractedDeclarationKind

                                                                                                    type AllExtractedDeclarationKind = AllExtractedDeclaration['kind'];
                                                                                                    • AllExtractedDeclarationKind is the union of all literal discriminators used to detect the kind of declaration.

                                                                                                    type ExtractedDeclaration

                                                                                                    type ExtractedDeclaration =
                                                                                                    | ExtractedVariable
                                                                                                    | ExtractedFunction
                                                                                                    | ExtractedClass
                                                                                                    | ExtractedInterface
                                                                                                    | ExtractedEnum
                                                                                                    | ExtractedTypeAlias
                                                                                                    | ExtractedNamespace;
                                                                                                    • ExtractedDeclaration is the union of all possible top-level declarations that can be extracted from a package, module, or namespace.

                                                                                                    type ExtractedDeclarationKind

                                                                                                    type ExtractedDeclarationKind = ExtractedDeclaration['kind'];
                                                                                                    • ExtractedDeclarationKind is the union of all literal discriminators used to detect the kind of top-level declaration.

                                                                                                    Package Files (6)

                                                                                                    Dependencies (9)

                                                                                                    Dev Dependencies (11)

                                                                                                    Peer Dependencies (0)

                                                                                                    No peer dependencies.

                                                                                                    Badge

                                                                                                    To add a badge like this onejsDocs.io badgeto 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/@jsdocs-io/extractor.

                                                                                                    • Markdown
                                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@jsdocs-io/extractor)
                                                                                                    • HTML
                                                                                                      <a href="https://www.jsdocs.io/package/@jsdocs-io/extractor"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>