frontend/.pnpm-store/v3/files/44/9ab8854c9916d6c033d0efb3b31121b80975da0826b904ad15daf73ada9d624264b10a6c4555d8262b3e75e517f18d3343bc91497a67630aa7971b242948e6-exec

33 lines
1.1 KiB
Plaintext
Executable File

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsWellFormedUnitIdentifier = void 0;
var IsSanctionedSimpleUnitIdentifier_1 = require("./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
*/
function IsWellFormedUnitIdentifier(unit) {
unit = toLowerCase(unit);
if ((0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(unit)) {
return true;
}
var units = unit.split('-per-');
if (units.length !== 2) {
return false;
}
var numerator = units[0], denominator = units[1];
if (!(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(numerator) ||
!(0, IsSanctionedSimpleUnitIdentifier_1.IsSanctionedSimpleUnitIdentifier)(denominator)) {
return false;
}
return true;
}
exports.IsWellFormedUnitIdentifier = IsWellFormedUnitIdentifier;