mirror of
https://github.com/glenndehaan/unifi-voucher-site.git
synced 2026-03-31 06:24:00 -04:00
21 lines
714 B
JavaScript
21 lines
714 B
JavaScript
/**
|
|
* Returns an array or object of voucher type(s)
|
|
*
|
|
* @param string
|
|
* @param single
|
|
* @returns {*}
|
|
*/
|
|
module.exports = (string, single = false) => {
|
|
if(single) {
|
|
const match = string.match(/^(?<expiration>\d+)?,(?<usage>\d+)?,(?<upload>\d+)?,(?<download>\d+)?,(?<megabytes>\d+)?/);
|
|
return match.groups.expiration ? {...match.groups, raw: string} : undefined;
|
|
}
|
|
|
|
const types = string.split(';');
|
|
|
|
return types.filter(n => n).map((type) => {
|
|
const match = type.match(/^(?<expiration>\d+)?,(?<usage>\d+)?,(?<upload>\d+)?,(?<download>\d+)?,(?<megabytes>\d+)?/);
|
|
return match.groups.expiration ? {...match.groups, raw: type} : undefined;
|
|
}).filter(n => n);
|
|
}
|