frontend/.pnpm-store/v3/files/e4/c7438bff982ec8f2ab4a6b052b51a01ee706d6108fc567f3ec813a4327044c9e0a0dc1f3066c0aa8645433127abc13089f5423430ee4cf4511f6009a310b45-exec

29 lines
867 B
Plaintext
Executable File

import { IsSanctionedSimpleUnitIdentifier } from './IsSanctionedSimpleUnitIdentifier';
/**
* This follows https://tc39.es/ecma402/#sec-case-sensitivity-and-case-mapping
* @param str string to convert
*/
function toLowerCase(str) {
return str.replace(/([A-Z])/g, function (_, c) { return c.toLowerCase(); });
}
/**
* https://tc39.es/ecma402/#sec-iswellformedunitidentifier
* @param unit
*/
export function IsWellFormedUnitIdentifier(unit) {
unit = toLowerCase(unit);
if (IsSanctionedSimpleUnitIdentifier(unit)) {
return true;
}
var units = unit.split('-per-');
if (units.length !== 2) {
return false;
}
var numerator = units[0], denominator = units[1];
if (!IsSanctionedSimpleUnitIdentifier(numerator) ||
!IsSanctionedSimpleUnitIdentifier(denominator)) {
return false;
}
return true;
}