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

cm-web-modules

v2.4.1

Published

Collection of clean and small ES6 modules for the web

Downloads

802

Readme

cm-web-modules – Library of ES6 Web Modules

cm-web-modules is a library of JavaScript ES6 (ECMAScript 6) modules, used for coding chessmail.

The main purpose of cm-web-modules is, to prevent the usage of large libraries, and to provide needed functionality with the smallest and cleanest amount of code possible.

The cm-web-modules modules have no external dependencies, they don't use jQuery or other frameworks. They are written with modern vanilla JavaScript in ECMAScript 6 syntax.

The cm-web-modules modules are:

Modules

Audio

Module for the Web Audio API. For playing audio samples in a web page.

Cache

Cache data on client site.

Cookie

Module to read, write and delete cookies.

I18n

Module to handle the internationalisation of frontend text.

const i18n = new I18n(props)

default props:

this.props = {
    locale: null,
    fallbackLang: "en" // used, when the translation was not found for locale
}

load language files:

i18n.load("translations.json").then(() => {
    // do this after loading
})

where the json file has the form

{
  "de": {
    "start_game": "Ein neues Spiel starten",
    "undo_move": "Zug zurück nehmen"
  },
  "en": {
    "start_game": "Start a new game",
    "undo_move": "Undo move"
  }
}

or directly add the translations in your js code

i18n.load({
    de: {
        "0_starts_game": "$0 startet ein neues Spiel",
        "undo_move": "Zug zurück nehmen"
    },
    en: {
        "0_starts_game": "$0 starts a new game",
        "undo_move": "Undo move"
    }
})

Use placeholder $n [0-9] to replace them when using.

To handle the translations in your frontend code use

i18n.t("0_starts_game", ["John Doe"])
i18n.t("undo_move")

to render the needed text in the needed language. You can specify the language in the props when calling new or it uses the browser preferences.

MessageBroker

Observe

Module to observe object properties used for reactive coding the simple way.

Stopwatch

const stopwatch = new Stopwatch({
    onStateChanged: (running) => {
        stateOutput.innerText = running
    },
    onTimeChanged: (seconds) => {
        secondsOutput.innerText = seconds.toFixed(1)
    }
})
buttonStart.addEventListener("click", () => {
    stopwatch.start()
})
buttonStop.addEventListener("click", () => {
    stopwatch.stop()
})
buttonReset.addEventListener("click", () => {
    stopwatch.reset()
})

SVG

Module to render SVG elements and load sprites.

Template

Utils

ArrayUtils, ColorUtils, CoreUtils, DateUtils, DomUtils, EncryptionUtils, EventUtils, TextUtils

LibraryManager

The LibraryManager is the glue between the web-modules.

It is configured in postinstall.js. Add postinstall.js to the automtically excuted install-scripts from npm by adding it to package.json like this

package.json

"scripts": {
    "test": "mocha --require babel-core/register ./test/*.js",
    "postinstall": "node postinstall.js"
  }

In postinstall.js, add the used modules via manager.addProject("module-name")

The source of the module is then copied to PROJECT_ROOT/lib/modules/name. It provides the same include-folder (/lib) for the local and for the via npm installed modules.

You must call npm install after every npm update, because it is only automatically started by the initial install.

Example postinstall.js

const LibraryManager = require("cm-web-modules/src/LibraryManager.js")
const manager = new LibraryManager(__dirname)

manager.addProject("cm-web-modules")
manager.addProject("chess.js", "", "chess.js")