Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addLikelySubtags(match);
if (fastTagEquals(match, max)) {
return returnTag(tag, tmp);
}
// 2. Match "en-Zzzz-US"
tmp[Tag.REGION] = max[Tag.REGION];
match = tmp.slice(0);
addLikelySubtags(match);
if (fastTagEquals(match, max)) {
tmp[Tag.LANGUAGE] = max[Tag.LANGUAGE];
return returnTag(tag, tmp);
}
// 3. Match "en-Latn-ZZ"
tmp[Tag.REGION] = Tag.REGION;
tmp[Tag.SCRIPT] = max[Tag.SCRIPT];
match = tmp.slice(0);
addLikelySubtags(match);
if (fastTagEquals(match, max)) {
return returnTag(tag, tmp);
}
// 4. Nothing matched, so return a copy of the original tag.
return returnTag(tag, max);
}
const fastTag = (real: LanguageTag): FastTag => {
// Hack to get fast access to internal core fields without exposing them.
const fake = (real as any) as FakeLanguageTag;
// The fast tag is used for indexing purposes. Since a field may be
// undefined, and we don't want to use its string representation of
// the undefined value (e.g. 'und', 'Zzzz', etc), we use the field's
// index number to represent undefined.
const language = fake.core[Tag.LANGUAGE];
const script = fake.core[Tag.SCRIPT];
const region = fake.core[Tag.REGION];
return [
language || Tag.LANGUAGE,
script || Tag.SCRIPT,
region || Tag.REGION
];
};
const setFields = (src: FastTag, dst: FastTag, flags: number): void => {
dst[Tag.LANGUAGE] = (flags & F.LANGUAGE) === 0 ? Tag.LANGUAGE : src[Tag.LANGUAGE];
dst[Tag.SCRIPT] = (flags & F.SCRIPT) === 0 ? Tag.SCRIPT : src[Tag.SCRIPT];
dst[Tag.REGION] = (flags & F.REGION) === 0 ? Tag.REGION : src[Tag.REGION];
};