Nerdiest Precious Modules

    TypeScript icon, indicating that this package has built-in type declarations

    1.1.5 • Public • Published

    License: MIT Contributor Covenant JavaScript Style Guide

    Skeleton for developing modules for browser and Node.js in Typescript

    This entire section with all its subsections (Installation, Tooling, Scripts) should be removed from your src/docs/ after installing. The rest of sections may be useful for your package readme, and you may just modified them in src/docs/ to meet your needs.

    This is a skeleton for developing JS modules in Typescript that work both in Node.js and native JavaScript. The idea is that you should just focus on developing your typescript code in the src/ts folder, and the necessary JS files and bundles will be created so that it can be used with no effort in every environment.

    You can use string variable IS_BROWSER to create specific code for native JS or Node. For example:

    if (IS_BROWSER === 'true') {
      // browser specific code here
    } else {
      // node.js specific code here

    Besides the actual code, you should create unit testing (mocha+chai) files either in the test or the src/ts directory, although in the latter case only files ending with .spec.ts will be considered as test files.

    When creating the tests, you MUST NOT import either mocha, chai or your package. They have been automatically added to the global scope:

    • mocha global variable points to mocha,
    • chai points to chai,
    • _pkg points to your package (all your exports),
    • _pkgTypes points to your package typings.


    Clone this repo to your desired project directory (my-project in the following example) and reset the git.

    git clone my-project
    cd my-project
    rm -rf .git
    git init
    git add -A

    Edit package.json to suit your needs and initialize the project with:

    npm i
    npm update
    npm run build

    The file is automatically generated from the src/docs/ file. EDIT src/docs/ and rewrite it to your heart's content. Recall removing the section "Skeleton for developing modules for browser and Node.js in Typescript" with all its subsections (Installation, Tooling, Scripts).


    • Build: Rollup is used for generating in the dist directory UMD, IIFE, ESM and CJS modules with the corresponding Typescript declaration files and sourcemaps.
    • Coverage: Nyc-Istanbul is used to track how well your unit-tests exercise your codebase.
    • Doc: TsCode is used for automatically generating the API docs. Consider documenting your code with TsCode for it to be useful.
    • Lint: ts-stamdard is the chosen linter, although you can easily change it by any other linter (update scripts.lint in the package.json). If developing with Visual Studio Code, consider installing the Standard-JS extension and select ts-standard as the Standard:engine in the extension settings.
    • Test: Mocha with Chai running both in Node.js and browser (using puppeteer). Test files should be created assuming that Mocha methods and Chai are declared global, so there is no need to import them (see the provided test examples). There is also no need to create separate test files for browser and Node.js, since every file will be tested against both. Test files are transpiled using tsc CLI.


    • npm run build. Runs the linter (lint), builds the JS files (build:js), builds the and the API doc ./docs/ (docs), runs the unit tests in browser (test:browser), and creates a coverage report of the tests run in Node.js (coverage). See the specific scripts for more details.

    • npm run build:js. Creates your distributable module files (UMD, IIFE, ESM and CJS), along with the sourcemap and typescript declaration files in the dist directory.

    • npm run clean. Cleans all the artefacts created by the rest of the script (most likely not needed).

    • npm run coverage. Runs all the unit tests (src/**/*.spec.ts and test/**/*.ts) in Node.js and track how well they exercise your codebase. Besides the on-screen summary, a complete report in HTML will be generated in the coverage directory.

    • npm run docs. Generates the and the API doc ./docs/ Some labels in the src/ file will be automatically replaced in the generated

      • {{PKG_NAME}} is automatically replaced with property name in package.json file.
      • {{PKG_CAMELCASE}} will be replaced by a came case transformation of the package_name.
      • {{IIFE_BUNDLE}} will point to the IIFE bundle file if using github or gitlab as repository.
      • {{ESM_BUNDLE}} will point to the ESM bundle file if using github or gitlab as repository.
      • {{UMD_BUNDLE}} will point to the UMD bundle file if using github or gitlab as repository.
      • It has also some automatically added badges (see the top of this file), that you can remove if desired.
    • npm run lint. Uses the ts-standard linter to fix all the project files. If uncomfortable, change the linter for the one of your liking.

    • npm run mocha -- <glob>. Runs Node.js mocha for the selected tests (use glob pattern). Add --watch before the glob to start mocha in watch mode.

    • npm test. Runs all the unit tests (src/**/*.spec.ts and test/**/*.ts) in both Node.js and browser (using puppeteer).

    • npm run test:browser. Runs all the unit tests (src/**/*.spec.ts and test/**/*.ts) in a browser (using puppeteer). Until the browser window is closed, you can debug the tests.

    • npm run test:browser-headless. Runs all the unit tests (src/**/*.spec.ts and test/**/*.ts) in a browser (using puppeteer) but without opening a windows (results will be shown in the node's console). This is useful for just running tests (no debugging).

    • npm run test:node. Runs all the unit tests (src/**/*.spec.ts and test/**/*.ts) in Node.js.

    • npm run watch. Likely to be the default script during development. Tests are automatically reexecuted whenever a test or source file changes.


    Your package description


    @i3m/wallet-protocol can be imported to your project with npm. First create a .npmrc file with the following content:


    Then install it using npm:

    npm install @i3m/wallet-protocol

    Then either require (Node.js CJS):

    const walletProtocol = require('@i3m/wallet-protocol')

    or import (JavaScript ES module):

    import * as walletProtocol from '@i3m/wallet-protocol'

    The appropriate version for browser or node is automatically exported.

    You can also download the IIFE bundle, the ESM bundle or the UMD bundle and manually add it to your project, or, if you have already installed @i3m/wallet-protocol in your project, just get the bundles from node_modules/@i3m/wallet-protocol/dist/bundles/.

    An example of usage could be:


    API reference documentation

    Check the API


    npm i @i3m/wallet-protocol

    DownloadsWeekly Downloads






    Unpacked Size

    581 kB

    Total Files


    Last publish


    • rish2497
    • ferogar
    • juanelasisme