@fable-org/fable-library-js
Version:
Core library used by F# projects compiled with fable.io
23 lines (22 loc) • 629 B
JavaScript
import { FSharpRef } from "./Types.js";
import { Exception } from "./Util.js";
export function tryParse(str, defValue) {
if (str != null && str.match(/^\s*true\s*$/i)) {
defValue.contents = true;
return true;
}
else if (str != null && str.match(/^\s*false\s*$/i)) {
defValue.contents = false;
return true;
}
return false;
}
export function parse(str) {
const defValue = new FSharpRef(false);
if (tryParse(str, defValue)) {
return defValue.contents;
}
else {
throw new Exception(`String '${str}' was not recognized as a valid Boolean.`);
}
}