Skip to content

Installation & Setup

Paul Köhler edited this page Jan 22, 2026 · 7 revisions

CmpStr is distributed as an npm package and can be used across a wide range of JavaScript environments. It supports modern ESM-based projects, legacy CommonJS setups, and direct usage in the browser via UMD or ESM bundles.

If you are unsure which format to choose, ES modules (ESM) are recommended whenever supported by your environment. The provided ESM and UMD bundles are optimized and minified for production use.

Install via npm

The recommended way to use CmpStr is to install it from npm:

npm install cmpstr

This installs the latest stable release and makes the package available in your local node_modules directory.

Import in Your Project

CmpStr can be imported in different ways depending on your runtime and module system.

TypeScript / ESM

For TypeScript projects or environments using ES modules:

import { CmpStr } from 'cmpstr';

ESM support is fully native. Type definitions are bundled with the package, providing IntelliSense and compile-time type safety out of the box.

CommonJS

For Node.js projects that still rely on CommonJS:

const { CmpStr } = require( 'cmpstr' );

CmpStr includes CommonJS-compatible exports and works reliably in most legacy Node.js environments.

Browser

CmpStr provides prebuilt browser bundles located in the dist/ directory of the package.

You can choose between the following formats:

UMD (Universal Module Definition)

Use the UMD bundle for maximum compatibility or when no bundler is available:

<script src="./dist/CmpStr.umd.min.js"></script>
<script>
  const cmp = CmpStr.CmpStr.create().setMetric( 'levenshtein' );
  console.log( cmp.compare( 'kitten', 'sitting' ) );
</script>

This exposes the CmpStr namespace on the global window object.

ESM (type="module")

For modern browsers with native ES module support:

<script type="module">
  import { CmpStr } from './dist/CmpStr.esm.min.js';

  const cmp = CmpStr.create().setMetric( 'levenshtein' );
  console.log( cmp.compare( 'kitten', 'sitting' ) );
</script>

Note: ESM imports are scoped and do not pollute the global namespace.

Load from CDN (jsDelivr)

CmpStr can also be loaded directly from a jsDelivr CDN without a local installation. This is useful for rapid prototyping, testing, or lightweight client-side integrations.

UMD via jsDelivr

<script src="https://cdn.jsdelivr.net/npm/cmpstr/dist/CmpStr.umd.min.js"></script>

ESM via jsDelivr

<script type="module">
  import { CmpStr } from 'https://cdn.jsdelivr.net/npm/cmpstr/dist/CmpStr.esm.min.js';
</script>

Clone this wiki locally