Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/router / dist / deps / parseObjWithSerializedValues.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const exotic_1 = require("exotic");
const chain_able_lego_1 = require("chain-able-lego");
const chain_able_deps_1 = require("chain-able-deps");
const stringMagic_1 = require("./stringMagic");
/**
 * @param parsed @mutates
 * @note these are not if-else
 */
function parseObjWithSerializedValues(parsed) {
    Object.keys(parsed).forEach(key => {
        // remove undefined
        if (exotic_1.isNil(parsed[key]) === true) {
            delete parsed[key];
        }
        if (exotic_1.isStringPrimitive(parsed[key]) === false) {
            return;
        }
        // @note - typescript isn't recognizing the `if isString` above
        if (stringMagic_1.isURIEncoded(parsed[key]) === true) {
            parsed[key] = decodeURIComponent(parsed[key]);
        }
        if (exotic_1.isValidJSON(parsed[key]) === true) {
            parsed[key] = stringMagic_1.parseJSON(parsed[key]);
            /**
             * make it serializable
             *
             * @todo @@perf the `toString` is probably not needed
             */
            if (exotic_1.isObj(parsed[key])) {
                const toJSON = () => chain_able_lego_1.stringify(parsed[key]);
                chain_able_deps_1.defineFinal(parsed[key], 'toString', toJSON);
                chain_able_deps_1.defineFinal(parsed[key], Symbol.toPrimitive, toJSON);
            }
        }
    });
}
exports.parseObjWithSerializedValues = parseObjWithSerializedValues;
//# sourceMappingURL=parseObjWithSerializedValues.js.map