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 🙏

© 2026 – Pkg Stats / Ryan Hefner

universal-font-unicode-converter

v1.0.0

Published

Universal, language-independent library for converting legacy font-encoded text into genuine Unicode text using configurable mapping profiles and font analysis.

Readme

universal-font-unicode-converter

A universal, language-independent TypeScript/JavaScript library for converting legacy font-encoded text into genuine Unicode text using configurable mapping profiles and OpenType (TTF/OTF) font analysis.

Features

  • Language-Independent: Works with Tamil, Telugu, Hindi, Malayalam, Kannada, Bengali, Gujarati, Punjabi, Marathi, Arabic, and any other Unicode script via JSON mapping profiles.
  • Trie-Based Longest-Match-First Engine: Fast, cached, multi-character sequence matching without per-conversion font parsing.
  • Unicode Correctness: Validates scalar values, detects lone surrogates and Private Use Area (PUA) misuse, preserves unmapped characters, numbers, punctuation, whitespace, and emojis, and never reorders script characters unless normalization is explicitly requested.
  • Font Extraction & Classification: Parses TTF and OTF files via opentype.js to inspect metadata, cmap, glyph indexes/names/outlines, Unicode coverage, and GSUB/GPOS tables, classifying fonts as Unicode, Legacy encoded, Mixed encoding, Partial Unicode, or Unknown encoding.
  • Browser & Node.js Compatible: Ships ESM, CommonJS, and TypeScript declarations. Accepts Browser File/Blob/ArrayBuffer and Node.js Buffer/Uint8Array.

Important: A font's glyph outlines and cmap do not reveal intended language semantics. Never claim a legacy glyph has a particular Unicode meaning without a verified mapping.


Installation

npm install universal-font-unicode-converter

Quick Start

Node.js / ESM

import {
  FontConverter,
  loadMappingProfile,
} from 'universal-font-unicode-converter';

const profile = await loadMappingProfile('./profiles/simon-tamil.json');
const converter = new FontConverter(profile);

const result = converter.convert('legacy input');
console.log(result.text);
console.log(result.converted, result.profile, result.errors);

CommonJS

const {
  FontConverter,
  createMappingProfile,
} = require('universal-font-unicode-converter');

const profile = createMappingProfile({
  name: 'My Custom Font',
  language: 'ta',
  mappings: {
    f: 'க',
    j: 'ி',
    fj: 'கி',
  },
});

const converter = new FontConverter(profile);
console.log(converter.convertText('fj')); // கி

API Documentation

FontConverter

  • new FontConverter(profile, options?)
  • convert(text: string): ConversionResult — Returns { text, converted, errors, profile, stats }.
  • convertText(text: string): string — Convenience method returning the converted string.
  • convertCharacter(character: string): ConversionResult — Converts a single character or short sequence.
  • convertBatch(textArray: string[]): ConversionResult[] — Converts an array of strings.
  • validate(text: string): UnicodeValidationResult — Validates Unicode scalar values.
  • getMappingInfo(): MappingInfo — Returns profile metadata, entry count, max sequence length, and profile hash.
  • reset(): void — Resets conversion counters and recompiles the active profile.

Mapping Profile API

  • createMappingProfile(options) — Validates and creates a MappingProfile.
  • MappingBuilder — Fluent builder (addMapping, addMappings, validate, build).
  • loadMappingProfile(source, options?) — Loads from file path (Node.js), URL (fetch), JSON string, or object.
  • importMappingProfile(jsonOrObject, options?) — Parses JSON, detects duplicate keys, and validates Unicode.
  • exportMappingProfile(profile, options?) — Serializes a profile to formatted JSON.
  • validateMappingProfile(profile) — Checks empty mappings, invalid Unicode, PUA/control codepoints, and conflicts.
  • detectMappingConflicts(mappings) — Detects prefix overlaps and duplicate target outputs.
  • ProfileManager — Registers, versions, and queries multiple profiles by name, language, or font family.

Font Extraction API

  • parseFont(input, options?) — Accepts ArrayBuffer, Node Buffer, Uint8Array, or Browser File/Blob.
  • loadAndParseFont(pathOrUrl, options?) — Loads and parses a TTF/OTF file from disk or URL.

Returns FontAnalysisResult with metadata, classification, classificationReason, verificationRequired, notice, cmap, glyphs, unicodeCoverage, and layoutTables (GSUB/GPOS).


Mapping JSON Format

{
  "name": "Simon Tamil",
  "version": "1.0.0",
  "language": "ta",
  "encoding": "legacy",
  "fontFamily": "Simon",
  "targetEncoding": "Unicode",
  "verified": false,
  "mappings": {
    "f": "க",
    "j": "ி",
    "fj": "கி"
  }
}

Custom Mapping Tutorial

import {
  MappingBuilder,
  FontConverter,
  exportMappingProfile,
} from 'universal-font-unicode-converter';

const profile = new MappingBuilder('My Legacy Font', 'hi')
  .setVersion('1.0.0')
  .setFontFamily('LegacyHindi')
  .setVerified(true)
  .addMapping('d', 'क', true)
  .addMapping('k', 'ा', true)
  .addMapping('dk', 'का', true)
  .build();

const converter = new FontConverter(profile);
console.log(converter.convertText('dk')); // का

const json = exportMappingProfile(profile);

Font Extraction Tutorial

Browser

import { parseFont } from 'universal-font-unicode-converter';

const input = document.querySelector<HTMLInputElement>('#font-file')!;
input.addEventListener('change', async () => {
  const file = input.files?.[0];
  if (!file) return;

  const analysis = await parseFont(file);
  console.log(analysis.metadata.fontFamily, analysis.classification);
  console.log(analysis.notice);
});

Node.js

import { loadAndParseFont } from 'universal-font-unicode-converter';

const analysis = await loadAndParseFont('./fonts/legacy-font.ttf');
console.log(analysis.classification);
console.log('Cmap entries:', analysis.cmap.length);

Interactive Demo Application

The demo/ directory contains a standalone Vite + TypeScript web application where you can:

  1. Upload a TTF/OTF font file.
  2. Inspect extracted glyphs, source character codes, glyph indexes, and GSUB/GPOS metadata.
  3. Create or import a mapping profile and toggle Verified vs Unverified status per mapping.
  4. Enter legacy text, convert to Unicode, compare side-by-side, copy output, and download the JSON profile.

Run the demo:

npm run build
cd demo
npm install
npm run dev

Publishing to npm

  1. Verify typechecking, tests, and build:
    npm run typecheck
    npm test
    npm run build
  2. Inspect the generated package tarball:
    npm pack --dry-run
  3. Publish to npm:
    npm login
    npm publish --access public

License

MIT