Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/spatialillusions/milsymbol/llms.txt

Use this file to discover all available pages before exploring further.

milsymbol is distributed as a single JavaScript package with no runtime dependencies. It ships with CommonJS, ES module, and browser-global builds, plus a bundled TypeScript declaration file. You can install it from the npm registry or load it directly in an HTML page via a <script> tag.

Package Installation

npm install milsymbol

Module Formats

milsymbol supports all common JavaScript module formats. Choose the one that matches your build environment.
Use the named default import in any ESM-capable environment — modern browsers, bundlers (Webpack, Rollup, Vite), or Node.js with "type": "module".
import ms from "milsymbol";

const sym = new ms.Symbol("130310001412110000000000000000", { size: 35 });
console.log(sym.asSVG());
The ESM entry point is index.js, which re-exports the fully assembled ms namespace including all built-in standard icon sets (APP-6 B, 2525B, 2525C, APP-6 D, 2525D, 2525E).

TypeScript Support

milsymbol ships with a bundled index.d.ts declaration file. No additional @types package is required. The "types" field in package.json points to ./index.d.ts, so TypeScript resolves types automatically.
import ms from "milsymbol";
import { type SymbolOptions } from "milsymbol";

const options: SymbolOptions = {
  size: 35,
  uniqueDesignation: "1PLT",
  direction: 90,
  fill: true,
  colorMode: "Light",
};

const sym = new ms.Symbol("130310001412110000000000000000", options);
const svgString: string = sym.asSVG();
Key exported types include:
TypeDescription
SymbolOptionsInterface for all constructor and setOptions arguments
SymbolMetadataReturn type of sym.getMetadata()
SymbolColorsReturn type of sym.getColors()
ColorModeColor object with per-affiliation color strings
DrawInstructionUnion type for all JSON draw instruction shapes
ExtensionFunctionFunction signature for ms.addSymbolPart extensions

Extending TypeScript Types

If you are building an extension that introduces custom symbol options, you can augment the SymbolOptions interface using TypeScript module augmentation. Create a declaration file in your project:
// ./src/milsymbol.d.ts
import "milsymbol";

declare module "milsymbol" {
  export interface SymbolOptions {
    customOption?: number;
  }
}
Your custom option is then type-safe throughout the extension:
import ms from "milsymbol";
import { type DrawInstruction } from "milsymbol";

ms.addSymbolPart(function (ms) {
  const options = this.getOptions();

  const bbox = new ms.BBox();
  const preDrawArray: DrawInstruction[] = [];
  const postDrawArray: DrawInstruction[] = [];

  const custom = options.customOption; // Type-safe: number | undefined

  // your rendering logic...

  return {
    pre: preDrawArray,
    post: postDrawArray,
    bbox,
  };
});

Node.js Usage

milsymbol works in Node.js without any additional setup for SVG output. The .asSVG() and .asDOM() methods have no browser DOM dependency. The .asCanvas() method requires a Canvas implementation — libraries such as node-canvas or canvas can be used to polyfill HTMLCanvasElement in a Node.js environment.
import ms from "milsymbol";

// SVG output works in Node.js with no extra setup
const svgString = new ms.Symbol("130310001412110000000000000000", {
  size: 35,
  uniqueDesignation: "1PLT",
}).asSVG();

console.log(svgString);
Entry point summary:
  • index.js — ES module entry point (used when bundlers or Node.js resolve the "import" condition). Import with import ms from "milsymbol".
  • dist/milsymbol.js — Minified UMD bundle (used by require("milsymbol"), browser <script> tags, and AMD loaders). The dist/ folder contains a package.json with "type": "commonjs" to ensure correct resolution in Node.js.
  • index.d.ts — TypeScript declarations, shared by both entry points.

Build docs developers (and LLMs) love