UNPKG

@amaui/utils

Version:
35 lines (34 loc) 1.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const is_1 = __importDefault(require("./is")); const optionsDefault = { decode: false, decodeMethod: decodeURIComponent, }; const castParam = (value, options_ = {}) => { const options = Object.assign(Object.assign({}, optionsDefault), options_); let newValue = value; try { if ((0, is_1.default)('string', value) && options.decode && (0, is_1.default)('function', options.decodeMethod)) newValue = options.decodeMethod(value); } catch (error) { } try { if ((0, is_1.default)('string', newValue)) { if ('undefined' === newValue) return undefined; if ('NaN' === newValue) return NaN; return JSON.parse(newValue); } return newValue; } catch (error) { } return newValue; }; exports.default = castParam;