@credentum/parse-cusip
v0.0.1
Published
Validate and parse CUSIP identifiers — issuer, issue, check digit, CINS, Treasury detection. Zero dependencies.
Maintainers
Readme
parse-cusip
Validate and parse CUSIP identifiers (Committee on Uniform Securities Identification Procedures). Returns structured data: issuer, issue number, check digit, CINS detection, and security type classification.
Installation
npm install @credentum/parse-cusipUsage
import { parseCUSIP } from '@credentum/parse-cusip';
const result = parseCUSIP('037833100');
// => {
// raw: '037833100',
// valid: true,
// issuer: '037833',
// issue: '10',
// checkDigit: '0',
// computedCheckDigit: '0',
// isCINS: false,
// isTreasury: false,
// securityType: 'equity'
// }Quick Validation
import { isValidCUSIP } from '@credentum/parse-cusip';
isValidCUSIP('037833100'); // true (Apple)
isValidCUSIP('68389X106'); // false (bad check digit)Compute a Check Digit
import { computeCheckDigit } from '@credentum/parse-cusip';
computeCheckDigit('03783310'); // '0' (Apple)
computeCheckDigit('17275R10'); // '2' (Cisco)Why Use This?
Every fintech team working with US/Canadian securities encounters CUSIPs. The standard response is to copy-paste a gist or inline a validation function from Rosetta Code. There is no standalone, zero-dependency npm package that parses CUSIPs into structured data.
parse-cusip gives you:
- Validation via the ANSI X9.6 Modulus 10 Double Add Double algorithm
- Parsing that extracts issuer, issue number, check digit, and security type
- CINS detection (Committee on Uniform Security Identification Procedures International Numbering System — foreign securities)
- Treasury detection (US government securities starting with 9128/9127)
- Zero dependencies, pure TypeScript, <2KB
API
parseCUSIP(cusip: string): CUSIPResult
Parse a 9-character CUSIP string into structured data.
Parameters:
cusip— A 9-character CUSIP string (digits, uppercase letters,*,@,#)
Returns: CUSIPResult
interface CUSIPResult {
raw: string; // Original input
valid: boolean; // Whether check digit is correct
issuer: string; // Characters 1-6 (issuer code)
issue: string; // Characters 7-8 (issue number)
checkDigit: string; // Character 9 (provided check digit)
computedCheckDigit: string; // What the check digit should be
isCINS: boolean; // True if first character is a letter (foreign security)
isTreasury: boolean; // True if issuer starts with 9128 or 9127
securityType: 'equity' | 'debt' | 'unit' | 'unknown';
}isValidCUSIP(cusip: string): boolean
Returns true if the CUSIP has a valid format and correct check digit.
computeCheckDigit(cusip8: string): string
Compute the check digit for an 8-character CUSIP (without check digit). Returns a single digit character.
Test Vectors
| CUSIP | Company | Valid | |-------|---------|-------| | 037833100 | Apple Inc. | yes | | 17275R102 | Cisco Systems | yes | | 38259P508 | Google (Alphabet) | yes | | 594918104 | Microsoft | yes | | 68389X105 | Oracle | yes | | 68389X106 | Oracle (bad check) | no |
License
MIT
