typia
Version:
Superfast runtime validators with only one line
29 lines (28 loc) • 1.09 kB
JavaScript
import { _randomInteger } from "./_randomInteger.mjs";
import { _randomString } from "./_randomString.mjs";
//#region src/internal/_randomFormatUrl.ts
const _randomFormatUrl = (props) => {
if (props?.minLength === void 0 && props?.maxLength === void 0) return `https://${random(10)}.${random(3)}`;
const base = `https://${random(1)}.${random(2)}`;
const target = pickLength(props, base.length);
return target <= base.length ? base : `${base}/${random(target - base.length - 1)}`;
};
const pickLength = (props, base) => {
let low = props.minLength === void 0 ? base : props.minLength;
if (low < base) low = base;
const high = props.maxLength === void 0 ? low + 14 : props.maxLength;
if (high < low) throw new Error("unable to generate a random URL satisfying both the format and the length constraints.");
return _randomInteger({
type: "integer",
minimum: low,
maximum: high
});
};
const random = (length) => _randomString({
type: "string",
minLength: length,
maxLength: length
});
//#endregion
export { _randomFormatUrl };
//# sourceMappingURL=_randomFormatUrl.mjs.map