12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- "use strict";
- function numberParser(key) {
- return function (opt) {
- const intOpt = parseInt(opt);
- if (!Number.isInteger(intOpt)) {
- throw new Error(`Key ${key} has invalid value ${opt}`);
- }
- return intOpt;
- };
- }
- function numberOrBoolParser(key) {
- return function (opt) {
- if (typeof opt === 'boolean') {
- return opt;
- }
- if (opt === 'true') {
- return true;
- }
- if (opt === 'false') {
- return false;
- }
- return numberParser(key)(opt);
- };
- }
- function numberOrStringParser(key) {
- return function (opt) {
- if (typeof opt === 'string') {
- return opt;
- }
- return numberParser(key)(opt);
- };
- }
- function objectParser(opt) {
- if (typeof opt == 'object') {
- return opt;
- }
- return JSON.parse(opt);
- }
- function arrayParser(opt) {
- if (Array.isArray(opt)) {
- return opt;
- } else if (typeof opt === 'string') {
- return opt.split(',');
- } else {
- throw new Error(`${opt} should be a comma separated string or an array`);
- }
- }
- function moduleOrObjectParser(opt) {
- if (typeof opt == 'object') {
- return opt;
- }
- try {
- return JSON.parse(opt);
- } catch (e) {
- /* */
- }
- return opt;
- }
- function booleanParser(opt) {
- if (opt == true || opt == 'true' || opt == '1') {
- return true;
- }
- return false;
- }
- function nullParser(opt) {
- if (opt == 'null') {
- return null;
- }
- return opt;
- }
- module.exports = {
- numberParser,
- numberOrBoolParser,
- numberOrStringParser,
- nullParser,
- booleanParser,
- moduleOrObjectParser,
- arrayParser,
- objectParser
- };
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJudW1iZXJQYXJzZXIiLCJrZXkiLCJvcHQiLCJpbnRPcHQiLCJwYXJzZUludCIsIk51bWJlciIsImlzSW50ZWdlciIsIkVycm9yIiwibnVtYmVyT3JCb29sUGFyc2VyIiwibnVtYmVyT3JTdHJpbmdQYXJzZXIiLCJvYmplY3RQYXJzZXIiLCJKU09OIiwicGFyc2UiLCJhcnJheVBhcnNlciIsIkFycmF5I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