@itwin/frontend-devtools
Version:
Debug menu and supporting UI widgets
48 lines • 1.85 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** Given a list of arguments, parse the arguments into name-value pairs.
* Each input string is expected to be of the format "name=value".
* Argument names are converted to lower-case; values are left untouched.
* @beta
*/
export function parseArgs(args) {
const map = new Map();
for (const arg of args) {
const parts = arg.split("=");
if (2 === parts.length)
map.set(parts[0].toLowerCase(), parts[1]);
}
const findArgValue = (name) => {
name = name.toLowerCase();
for (const key of map.keys())
if (key.startsWith(name))
return map.get(key);
return undefined;
};
return {
get: (name) => findArgValue(name),
getBoolean: (name) => {
const val = findArgValue(name);
if (undefined !== val && (val === "0" || val === "1"))
return val === "1";
return undefined;
},
getInteger: (name) => {
const val = findArgValue(name);
if (undefined === val)
return undefined;
const num = Number.parseInt(val, 10);
return Number.isNaN(num) ? undefined : num;
},
getFloat: (name) => {
const val = findArgValue(name);
if (undefined === val)
return undefined;
const num = Number.parseFloat(val);
return Number.isNaN(num) ? undefined : num;
},
};
}
//# sourceMappingURL=parseArgs.js.map