2018-09-13 15:36:14 -04:00
|
|
|
/**
|
|
|
|
* Utility functions for parsing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a string as positive integer or NaN
|
|
|
|
*
|
|
|
|
* @param {string} value
|
|
|
|
*/
|
|
|
|
function strictParseInt(value) {
|
|
|
|
if (/^([1-9][0-9]+)$/.test(value))
|
|
|
|
return Number(value);
|
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function parseBuildingURL(url){
|
2018-09-13 15:41:42 -04:00
|
|
|
const re = /^\/building\/(.*)\/edit?.html$/;
|
|
|
|
|
2018-09-13 15:36:14 -04:00
|
|
|
const matches = re.exec(url);
|
|
|
|
if (matches && matches.length === 2) {
|
2018-09-13 15:41:42 -04:00
|
|
|
return strictParseInt(matches[1])
|
2018-09-13 15:36:14 -04:00
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { strictParseInt, parseBuildingURL };
|