editions

  • Version 6.21.0
  • Published
  • 105 kB
  • 1 dependency
  • Artistic-2.0 license

Install

npm i editions
yarn add editions
pnpm add editions

Overview

Publish multiple editions for your JavaScript packages consistently and easily (e.g. source edition, esnext edition, es2015 edition)

Index

Functions

function determineEdition

determineEdition: (editions: Editions, opts: VersionOptions) => Edition;
  • Determine which edition should be loaded. If VersionOptions.broadenRange is unspecified (the default behavior), then we attempt to determine a suitable edition without broadening the range, and if that fails, then we try again with the range broadened.

    Returns

    any suitable editions

    Throws

    if no suitable editions

function isCompatibleEdition

isCompatibleEdition: (edition: Edition, opts: VersionOptions) => true;
  • Checks that the Edition is compatible against the provided versions.

    Returns

    if compatible

    Throws

    if incompatible

function isCompatibleEngines

isCompatibleEngines: (engines: Engines, opts: VersionOptions) => true;
  • Checks that the provided engines are compatible against the provided versions.

    Returns

    if compatible

    Throws

    if incompatible

function isCompatibleVersion

isCompatibleVersion: (range: Range, version: string, opts: RangeOptions) => true;
  • Is this Edition suitable for these versions?

    Returns

    if compatible

    Throws

    if incompatible

function isValidEdition

isValidEdition: (edition: Edition) => true;
  • Verify the Edition has all the required properties.

    Returns

    if valid

    Throws

    if invalid

function loadEdition

loadEdition: <T>(edition: Edition, opts: LoaderOptions) => T;
  • Load the Edition with the loader.

    Returns

    The result of the loaded edition.

    Throws

    If failed to load, an error is thrown with the reason.

function requirePackage

requirePackage: <T>(
cwd: PathOptions['cwd'],
loader: LoaderOptions['loader'],
entry: PathOptions['entry']
) => T;
  • Cycle through the editions for a package, determine the compatible edition, and load it.

    Returns

    the loaded result of the suitable edition

    Throws

    if no suitable editions, or if the edition failed to load

function solicitEdition

solicitEdition: <T>(editions: Editions, opts: SolicitOptions) => T;
  • Determine which edition should be loaded, and attempt to load it.

    Returns

    the loaded result of the suitable edition

    Throws

    if no suitable editions, or the edition failed to load

Interfaces

interface Edition

interface Edition {}
  • Edition entries must conform to the following specification.

    Example 1

    {
    "description": "esnext source code with require for modules",
    "directory": "source",
    "entry": "index.js",
    "tags": [
    "javascript",
    "esnext",
    "require"
    ],
    "engines": {
    "node": ">=6",
    "browsers": "defaults"
    }
    }

property debugging

debugging?: Errtion;
  • If this edition fails to load, then this property provides any accompanying information.

property description

description: string;
  • Use this property to describe the edition in human readable terms. Such as what it does and who it is for. It is used to reference the edition in user facing reporting, such as error messages.

    Example 1

    "esnext source code with require for modules"

property directory

directory: string;
  • The location to where this directory is located. It should be a relative path from the package.json file.

    Example 1

    "source"

property engines

engines: Engines;
  • This field is used to specific which environments this edition supports. If false this edition does not any environment. If deno is a string, it should be a semver range of Deno versions that the edition targets. If node is a string, it should be a semver range of Node.js versions that the edition targets. If browsers is a string, it should be a [browserlist](https://github.com/browserslist/browserslist) value of the specific browser values the edition targets. If multiple engines are truthy, it indicates that this edition is compatible with those multiple environments.

    Example 1

    {
    "deno": ">=1",
    "node": ">=6",
    "browsers": "defaults"
    }

property entry

entry: string;
  • The default entry location for this edition, relative to the edition's directory.

    Example 1

    "index.js"

property tags

tags?: string[];
  • Any keywords you wish to associate to the edition. Useful for various ecosystem tooling, such as automatic ESNext lint configuration if the esnext tag is present in the source edition tags.

    Example 1

    ["javascript", "esnext", "require"]

interface LoaderOptions

interface LoaderOptions extends Partial<PathOptions> {}

    property loader

    loader: <T>(this: Edition, path: string) => T;
    • The method that will load the entry of the edition. For CJS files this should be set to the require method. For MJS files this should be set to (path: string) => import(path).

    interface PathOptions

    interface PathOptions {}

      property cwd

      cwd: string;
      • If provided, edition loading will be resolved against this.

      property entry

      entry: string;
      • If provided, this edition entry is used instead of the default entry.

      interface RangeOptions

      interface RangeOptions {}

        property broadenRange

        broadenRange?: boolean;
        • If true, then ranges such as x || y are changed to >=x.

        interface SolicitOptions

        interface SolicitOptions extends LoaderOptions, VersionOptions {}

          interface VersionOptions

          interface VersionOptions extends RangeOptions {}

            property versions

            versions: Versions;
            • The versions of our current environment.

            Type Aliases

            type Editions

            type Editions = Array<Edition>;
            • Editions should be ordered from most preferable first to least desirable last. The source edition should always be first, proceeded by compiled editions.

            type Engines

            type Engines =
            | false
            | {
            [engine: string]: Range;
            };

              type Range

              type Range = string | boolean;

                type Versions

                type Versions = {
                [engine: string]: string;
                };

                  Package Files (1)

                  Dependencies (1)

                  Dev Dependencies (15)

                  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/editions.

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