CommunityResearch & Data Analysisgithub.com

field-aligner

A Chinese-English field name alignment and mapping tool: maps messy field names (Chinese/English/camelCase/snake_case) to canonical keys, with alias and fuzzy matching support. Ideal for third-party API integration, ERP field organization, and data cleaning.

What is field-aligner?

field-aligner is a lightweight, zero-dependency Node ESM library that solves the common problem of field name mismatches when integrating data from multiple sources, especially in bilingual (Chinese-English) environments. It provides functions to normalize field names (lowercase, strip separators), build customizable vocabularies, and perform both exact and fuzzy matching to map arbitrary input names to your defined canonical keys. The matching strategy prioritizes exact alias matches, then falls back to substring-based fuzzy scoring (default threshold 0.6). A built-in default vocabulary for generic e-commerce/common fields is provided, but users can easily inject their own field key-aliases mappings. The library supports batch matching and includes a self-test mode. Key use cases include ERP integration, multi-source data merging, and table header standardization, making it a practical tool for developers dealing with data cleaning and API adaptation tasks on platforms supporting Node ESM (e.g., Node.js, and potentially AI agent runtimes with ESM support).

Works with~Claude Code~Codex CLI~Cursor
npx skills add shuangying0001-beep/field-aligner

Installed? Explore more Research & Data Analysis skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

field-aligner – Field Name Fuzzy Matching and Alignment

Map field names from any source to your defined canonical field keys. Recognizes Chinese, English, camelCase, and snake_case mixed usage. Pure function implementation (Node ESM, zero dependencies). Vocabulary is injectable, with a built-in generic example vocabulary.

Use Cases

  • Integrating with ERP / open platforms / internal middle platforms: the field names from the other side differ from those in your database
  • Merging multiple data sources: different systems have different names for the same semantic field
  • Structuring documents / tables: mapping table headers to standard fields

Provided Functions

FunctionDescription
normalize(name)Normalize: lowercase + remove _-space
buildVocabulary(input)Normalize {key:[aliases]} or [{key,aliases}] into a unified structure
matchField(name, vocabulary, opts?)Single field matching, returns {key, matched, score, via}
batchMatchFields(names, vocabulary, opts?)Batch matching
DEFAULT_VOCABULARYGeneric example vocabulary (e-commerce/common fields)

Matching strategy:

  1. Exact: After normalization, the key or any alias matches exactly → via:'exact'
  2. Fuzzy: Substring containment (longer overlap yields higher score), score ≥ fuzzyThreshold (default 0.6) → via:'fuzzy'
  3. No match → {key:null, matched:false, via:'none'}

Usage

import { matchField, batchMatchFields, DEFAULT_VOCABULARY } from './scripts/field-aligner.mjs';

// 1) Using the default vocabulary
const r = matchField('product title', DEFAULT_VOCABULARY);
// => { key: 'title', matched: true, score: 1, via: 'exact' }

// 2) Inject your own vocabulary
const myVocab = {
  order_no:   ['order number', 'orderNo'],
  buyer_name: ['buyer', 'recipient'],
};
batchMatchFields(['order number', 'buyer', 'notes'], myVocab);
// => { order number:{key:'order_no',...}, buyer:{key:'buyer_name',...}, notes:{key:null,...} }

Self-Test

node scripts/field-aligner.mjs --selftest

Related Skills