Options
All
  • Public
  • Public/Protected
  • All
Menu

@vangware/window-open-promise logo

Build Status Coverage License NPM Version Open Issues Size

🪟 Promised Window.open();.

Usage

📦 Node

import { windowOpenPromise } from "@vangware/window-open-promise";

const windowOpen = windowOpenPromise(window);

windowOpen({
    url: "https://example.com", // URL is not required, you can open a blank window
    top: 10,
    left: 10
})
    .then(newWindow => {
        newWindow.console.log("This will log in the new window.");
        newWindow.addEventListener("beforeunload", _event => {
            console.log("This will log when the new window is closed.");
        });
    })
    .catch(_error => {
        console.error("This will log if the new window can't be opened.");
    });

🦕 Deno

import { windowOpenPromise } from "https://cdn.skypack.dev/@vangware/window-open-promise?dts";

const windowOpen = windowOpenPromise(window);

try {
    const newWindow = await windowOpen({
        url: "https://example.com", // URL is not required, you can open a blank window
        top: 10,
        left: 10
    })
    newWindow.console.log("This will log in the new window.");
    newWindow.addEventListener("beforeunload", _event => {
      console.log("This will log when the new window is closed.");
    });
} catch (_error) {
    console.error("This will log if the new window can't be opened.");
}

Documentation

Documentation can be found HERE. It is auto-generated with typedoc based on the JSDocs and the types in the source. Shouldn't be necessary to read this, code editors like VSCode integrate the documentation in the UI.

Changelog

Changelog can be found HERE.

Test coverage

Test coverage can be found HERE.

Index

Type aliases

WindowOpenPromiseFeatures

WindowOpenPromiseFeatures: Omit<WindowOpenPromiseOptions, "url" | "target" | "replace">

WindowOpenPromise features.

WindowOpenPromiseOptions

WindowOpenPromiseOptions: { height?: undefined | number; left?: undefined | number; menuBar?: undefined | false | true; noOpener?: undefined | false | true; replace?: undefined | false | true; resizable?: undefined | false | true; scrollbars?: undefined | false | true; target?: undefined | string; titleBar?: undefined | false | true; toolBar?: undefined | false | true; top?: undefined | number; url?: undefined | string; width?: undefined | number }

WindowOpenPromise options.

Type declaration

  • Optional Readonly height?: undefined | number

    WindowOpenPromise height (minimum 100).

  • Optional Readonly left?: undefined | number

    WindowOpenPromise left position.

  • Optional Readonly menuBar?: undefined | false | true

    WindowOpenPromise renders the menu bar.

  • Optional Readonly noOpener?: undefined | false | true

    WindowOpenPromise can't access it's opener.

  • Optional Readonly replace?: undefined | false | true

    WindowOpenPromise replace.

  • Optional Readonly resizable?: undefined | false | true

    WindowOpenPromise is resizable.

  • Optional Readonly scrollbars?: undefined | false | true

    WindowOpenPromise has scrollbars.

  • Optional Readonly target?: undefined | string

    WindowOpenPromise target.

  • Optional Readonly titleBar?: undefined | false | true

    WindowOpenPromise renders the title bar.

  • Optional Readonly toolBar?: undefined | false | true

    WindowOpenPromise renders the tool bar.

  • Optional Readonly top?: undefined | number

    WindowOpenPromise top position.

  • Optional Readonly url?: undefined | string

    WindowOpenPromise url.

  • Optional Readonly width?: undefined | number

    WindowOpenPromise width (minimum 100).

Variables

Const ERROR_MESSAGE

ERROR_MESSAGE: "Window can't be opened" = "Window can't be opened"

Const FEATURE_DISABLED

FEATURE_DISABLED: "0" = "0"

Const FEATURE_ENABLED

FEATURE_ENABLED: "1" = "1"

Const FEATURE_SEPARATOR

FEATURE_SEPARATOR: "," = ","

Functions

Const featureParser

  • Parses features object into features string.

    example
    featureParser({
        top: 10,
        left: 10,
        resizable: true
    }); // "top=10,left=10,resizable=1"

    Parameters

    Returns string

    Parsed string.

Const windowOpenPromise

  • windowOpenPromise(window: Pick<Window, "open">): (Anonymous function)
  • Promised Window.open.

    example
    const windowOpen = windowOpenPromise(window);
    windowOpen({
        url: "https://example.com",
        top: 10,
        left: 10
    })
        .then(newWindow => {
            newWindow.console.log("This will log in the new window.");
            newWindow.addEventListener("beforeunload", _event => {
                console.log("This will log when the new window is closed.");
            });
        })
        .catch(_error => {
            console.error("This will log if the new window can't be opened.");
        });

    Parameters

    • window: Pick<Window, "open">

      Window object (or maybe a mock :D).

    Returns (Anonymous function)

    Curried function with window in context.

Legend

Generated using TypeDoc