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, "replace" | "target" | "url">

WindowOpenPromise features.

WindowOpenPromiseOptions

WindowOpenPromiseOptions: { height?: number; left?: number; menuBar?: boolean; noOpener?: boolean; resizable?: boolean; scrollbars?: boolean; target?: string; titleBar?: boolean; toolBar?: boolean; top?: number; url?: string; width?: number }

WindowOpenPromise options.

Type declaration

  • Optional Readonly height?: number

    WindowOpenPromise height (minimum 100).

  • Optional Readonly left?: number

    WindowOpenPromise left position.

  • Optional Readonly menuBar?: boolean

    WindowOpenPromise renders the menu bar.

  • Optional Readonly noOpener?: boolean

    WindowOpenPromise can't access it's opener.

  • Optional Readonly resizable?: boolean

    WindowOpenPromise is resizable.

  • Optional Readonly scrollbars?: boolean

    WindowOpenPromise has scrollbars.

  • Optional Readonly target?: string

    WindowOpenPromise target.

  • Optional Readonly titleBar?: boolean

    WindowOpenPromise renders the title bar.

  • Optional Readonly toolBar?: boolean

    WindowOpenPromise renders the tool bar.

  • Optional Readonly top?: number

    WindowOpenPromise top position.

  • Optional Readonly url?: string

    WindowOpenPromise url.

  • Optional Readonly width?: number

    WindowOpenPromise width (minimum 100).

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: Readonly<Pick<Window, "open">>): (__namedParameters?: WindowOpenPromiseOptions) => Promise<Window>
  • 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: Readonly<Pick<Window, "open">>

      Window object (or maybe a mock :D).

    Returns (__namedParameters?: WindowOpenPromiseOptions) => Promise<Window>

    Curried function with window in context.

Legend

Generated using TypeDoc