npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@skwalexe/winmb

v0.1.4

Published

Windows-like dialogue boxes for your website

Downloads

11

Readme

WinMB.js

Setting up ⬇️

Package Managers

Install the NPM package using your package manager.

# npm
npm install @skwalexe/winmb

# yarn
yarn add @skwalexe/winmb

Then import the library.

// For CommonJS
const WinMB = require('@skwalexe/winmb')

// For ES Modules
import WinMB from '@skwalexe/winmb'

Import with <script> tag

If you use this method, the library will be available globally as WinMB.

<script src="https://cdn.jsdelivr.net/npm/@skwalexe/[email protected]/dist/winmb.umd.js"></script>

Using this library 📦

This library exports a WinMB class which acccepts the following parameters:

  • assetsUrl / required: WinMB needs to load remote assets such as css stylesheets, sounds, and images, which you can host on your own servers. This parameter is used to tell WinMB where it can find these assets. You must provide a base url, to which WinMB will just append the requested asset's file name. If you don't want to host the assets yourself, you can use JSDelivr like in the example below.
const wmbEngine = WinMB('https://cdn.jsdelivr.net/gh/SkwalExe/[email protected]/src/assets/')

Once you instanciated the WinMB class, it exposes the follwing methods:

  • wmbEngine.removeAll(): Removes all the dialogue boxes from the page.
  • wmbEngine.show(): Creates and displays a new dialogue box.

wmbEngine.removeAll()

This method will remove all the dialogue boxes from the page. It doesn't use any parameters and doesn't return anything.

wmbEngine.removeAll()

wmbEngine.show()

This method will create a new dialogue box and display it on the page. All the parameters will be demonstrated later on. It accepts the following parameters:

  • title: string: The message box's title.
  • message: string: The message box's content.
  • ?type: string: The message box type, one of: error, info, or warning. This parameter will change the message box's icon and sound. Default: error
  • ?buttons: object[]: Default: one ok button. An array of objects, each with the following properties:
    • text: string: The text displayed inside the button.
    • ?value: string | number | boolean: The value returned by show() when the button is clicked. If not supplied, the return value will be the text property.
  • ?position: string | [x, y]: If you supply a string, it must be random, or default. If you supply an array, the box will be placed at coordinates (x, y).
    • random: The box will be placed at random coordinates on the page.
    • default: The boxes will follow the default windows bahavior.

This function returns a Promise() which will resolve when a button is clicked or when the message box is closed. The return value will be the clicked button's corresponding value (see buttons), and false if the box was dismissed with the close button.

Contributing 🤝

Please, open an issue if you have any suggestion or if you found a bug. I will try to fix it as soon as possible.

General Info About the Project 📖

This is a simple library that can create Windows message boxes on a web page. It uses the following technologies for the development process and for the build pipeline:

  • TypeScript for typechecking.
  • Babel.js for creating polyfills (browser retro-compatiblity).
    • Node that we will only create polyfills for the final UMD bundle, and not for the CJS/ESM builds because creating polyfills is in my opinion the responsability of the library users.
  • Rollup for UMD bundle generation.
  • ESLint for linting.
  • Prettier.js for formatting.

This library uses pnpm as a package manager. You can install it with:

sudo npm install -g pnpm

Setting up the development environment 🖥️

git clone https://github.com/YOUR_USERNAME/WinMB.js
cd ./WinMB.js
  • Install (dev)dependencies
pnpm install
  • Run the pnpm serve script to start a local development server on port 10001
    • This will continuously rebuild the UMD bundle and reload the page.
pnpm run serve
  • Open the local development server on https://localhost:10001/ and open the project in your IDE.

Files and directories 📂

Unreferenced files are just not important.

Configuration Files:

  • babel.config.js: Babel configuration file.
  • eslint.config.mjs: ESLint configuration file.
  • rollup.config.mjs: Rollup configuration file.
  • tsconfig.json: TypeScript configuration file.
  • package.json: NPM package configuration.

Source: 🔢

  • src/assets/: Contains library assets (CSS styleshetts, audio files, images...)
  • src/main.ts: Library entry point (only imports/exports)

Builds: 👷

  • dist/lib-cjs/: CommonJS build.
  • dist/lib-esm/: ESM build.
  • dist/winmb.umd.js: UMD bundle.

Other: 📄

  • assets/: Assets for the GitHub repo only.
  • index.html: Simple HTML page for testing the library.

Creating a pull request 👍

If you'd like to contribute, please open an empty pull request and provide an explanation of your proposed changes. Once I approve it, you can begin your work. It's always disheartening to reject a pull request after someone has invested a lot of time and effort into it. 😿

  • Create a branch for your contribution
git checkout -b my-new-feature
  • When you finished your changes, you must check your code's formatting and linting and fix all the errors.
pnpm run lint:fix # check for linting errors
pnpm run check-types # check for type errors
pnpm run format # comply with foramtting rules
  • After that, add your changes to CHANGELOG.md and update the README if needed.

  • Do not increment the NPM package version yourself, the maintainer will do it.

  • Then, you can commit your work and push to your fork.

git add --all 
git commit -m "Added a new feature"
git push -u origin my-new-feature
  • Finally, you can create your pull request from your fork repo's github page.

PNPM scripts

  • lint: Perform ESLint checks.
  • format: Format codebase with prettier.
  • clean: Remove ./dist/.
  • build:cjs: Build CommonJS version from source.
  • build:esm: Build ESM version from source.
  • build:umd: Build UMD bundle from ESM version.
  • watch-esm: Rebuid ESM version on any detected change.
  • watch-umd: Creates local dev server, rebuild UMD bundle and reload the server automatically on any change detected from ESM version.
  • build: Build all versions: ESM, CJS, UMD bundle.
  • serve: Rebuild ESM and UMD bundle on any detected change, while creating a local dev server.

Examples 📸

Title and message

wmbEngine.show("I am a title", "I am a message")

Example 1


Box types

wmbEngine.show("skwal.net", "Message box types", "info")

Example 2

wmbEngine.show("skwal.net", "Message box types", "error")

Example 3

wmbEngine.show("skwal.net", "Message box types", "warning")

Example 4

Buttons

wmbEngine.show("skwal.net", "Buttons", "info", [{text: "Hello", value: true}, {text: "World", value: false}])

Example 5


Position

wmbEngine.show("skwal.net", "Default position", "info", [{text: "Hello", value: true}], "default")

Example 6

wmbEngine.show("skwal.net", "Random position", "warning", [{text: "Hello", value: true}], "random")

Example 7