Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
28 lines
779 B
Plaintext
28 lines
779 B
Plaintext
import { IsSanctionedSimpleUnitIdentifier } from "./IsSanctionedSimpleUnitIdentifier.js";
|
|
/**
|
|
* 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, (_, c) => c.toLowerCase());
|
|
}
|
|
/**
|
|
* https://tc39.es/ecma402/#sec-iswellformedunitidentifier
|
|
* @param unit
|
|
*/
|
|
export function IsWellFormedUnitIdentifier(unit) {
|
|
unit = toLowerCase(unit);
|
|
if (IsSanctionedSimpleUnitIdentifier(unit)) {
|
|
return true;
|
|
}
|
|
const units = unit.split("-per-");
|
|
if (units.length !== 2) {
|
|
return false;
|
|
}
|
|
const [numerator, denominator] = units;
|
|
if (!IsSanctionedSimpleUnitIdentifier(numerator) || !IsSanctionedSimpleUnitIdentifier(denominator)) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|