@credentum/parse-lei
v0.0.1
Published
Validate and parse Legal Entity Identifiers (LEI, ISO 17442) — LOU prefix, entity code, MOD 97-10 check digits. Zero dependencies.
Maintainers
Readme
@credentum/parse-lei
Validate and parse Legal Entity Identifiers (LEI, ISO 17442).
Decomposes a 20-character LEI into LOU prefix, entity code, and check digits. Verifies check digits via MOD 97-10 (ISO/IEC 7064).
Zero dependencies. Pure functions. TypeScript-first.
Installation
npm install @credentum/parse-leiUsage
import { parseLEI, isValidLEI, computeCheckDigits } from '@credentum/parse-lei';
// Parse Apple Inc.'s LEI
const result = parseLEI('HWUPKR0MPOU8FGXBT394');
// {
// raw: 'HWUPKR0MPOU8FGXBT394',
// valid: true,
// lou: 'HWUP', // Local Operating Unit
// entity: 'KR0MPOU8FGXBT3', // Entity-specific code
// checkDigits: '94', // Provided check digits
// computedCheckDigits: '94' // Computed check digits
// }
// Quick validation
isValidLEI('INR2EJN1ERAN0W5ZP974'); // true (Microsoft)
isValidLEI('INR2EJN1ERAN0W5ZP900'); // false (wrong check digits)
// Compute check digits for an 18-character body
computeCheckDigits('HWUPKR0MPOU8FGXBT3'); // '94'API
parseLEI(lei: string): LEIResult
Parse a 20-character LEI string into structured data.
isValidLEI(lei: string): boolean
Returns true if the input is a valid LEI with correct check digits.
computeCheckDigits(body: string): string
Compute two check digits for an 18-character LEI body. Returns '' on invalid input.
LEIResult
interface LEIResult {
raw: string; // Original input
valid: boolean; // Structurally valid with correct check digits
lou: string; // Characters 1-4: LOU prefix
entity: string; // Characters 5-18: Entity code
checkDigits: string; // Characters 19-20: Provided check digits
computedCheckDigits: string; // Computed via MOD 97-10
}Why Use This?
| Use Case | Function |
|----------|----------|
| "Is this LEI valid?" | isValidLEI(lei) |
| "What LOU issued this?" | parseLEI(lei).lou |
| "What check digit should this be?" | computeCheckDigits(body) |
| "Show me the full breakdown" | parseLEI(lei) |
Tested Against Real LEIs
- Apple Inc. (
HWUPKR0MPOU8FGXBT394) - Microsoft Corporation (
INR2EJN1ERAN0W5ZP974) - The Goldman Sachs Group (
784F5XWPLTWKTBV3E584) - Goldman Sachs International (
W22LROWP2IHZNBB6K528) - Apple Distribution International (
54930027SQL2KPSDBM58)
All verified against GLEIF registry.
License
MIT
