T-38: M1.1b — Pass 2 normalization: ISIN/CUSIP validators, ticker root/suffix parser, IB fields in provider-symbol.ts

This commit is contained in:
Studio 2026-11-27 14:44:06 -05:00
parent 5483f7f127
commit eb8e2aa57a
4 changed files with 27 additions and 18 deletions

View file

@ -192,6 +192,11 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
return { isin, source: 'isin' };
}
const isinPrefix = isin !== null && isin.length >= 2 ? isin.slice(0, 2) : null;
if (country !== null && isNorthAmericaCountry(isinPrefix) && country !== isinPrefix) {
return { isin: null, reason: 'invalid_isin_and_no_valid_cusip' };
}
if (cusip !== null) {
if (isValidCusip(cusip)) {
if (country !== null) {
@ -203,7 +208,6 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
return { isin: derived, source: 'cusip_derived' };
}
} else {
const isinPrefix = isin !== null && isin.length >= 2 ? isin.slice(0, 2) : null;
if (!isNorthAmericaCountry(isinPrefix)) {
return { isin: null, reason: 'unsupported_country_for_cusip' };
}
@ -217,13 +221,10 @@ export function resolveIsin(input: ResolveIsinInput | null | undefined): Resolve
}
}
if (isin !== null && isin.length === 12) {
const isinPrefix = isin.slice(0, 2);
if (isNorthAmericaCountry(isinPrefix) && (country === null || country === isinPrefix)) {
const derived = cusipToIsin(isin.slice(2, 11), isinPrefix);
if (derived !== null) {
return { isin: derived, source: 'cusip_derived' };
}
if (isin !== null && isin.length === 12 && isNorthAmericaCountry(isinPrefix)) {
const derived = cusipToIsin(isin.slice(2, 11), isinPrefix);
if (derived !== null) {
return { isin: derived, source: 'cusip_derived' };
}
}

View file

@ -73,10 +73,8 @@ export function parseTicker(
const tickerRoot = s.slice(0, firstSep);
let pos = firstSep + 1;
if (isWhitespace(s.charCodeAt(firstSep))) {
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
pos++;
}
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
pos++;
}
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
return null;
@ -90,12 +88,9 @@ export function parseTicker(
let classSuffix = s.slice(pos, secondSep);
pos = secondSep;
while (pos < s.length) {
const sepCode = s.charCodeAt(pos);
pos++;
if (isWhitespace(sepCode)) {
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
pos++;
}
while (pos < s.length && isWhitespace(s.charCodeAt(pos))) {
pos++;
}
if (pos >= s.length || isSeparator(s.charCodeAt(pos))) {
return null;