How to use the krl-stdlib.encode function in krl-stdlib

To help you get started, we’ve selected a few krl-stdlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Picolab / pico-engine / packages / pico-engine / src / startCore.js View on Github external
var toKRLjson = function(val, indent){
    var message = krl_stdlib.encode({}, val, indent);
    if(message === "\"[JSObject]\""){
        message = val + "";
    }
    return message;
};
github Picolab / pico-engine / packages / node-pico-engine-core / src / cleanEvent.js View on Github external
if(isBlank(event_orig && event_orig.eci)){
        throw new Error("missing event.eci");
    }
    if(isBlank(event_orig.domain)){
        throw new Error("missing event.domain");
    }
    if(isBlank(event_orig.type)){
        throw new Error("missing event.type");
    }

    var attrs = {};
    if(_.has(event_orig, "attrs")){
        //we want to make sure only json-able values are in the attrs
        //also want to clone it as to not mutate the original copy
        var attrs_json = krl_stdlib.encode({}, event_orig.attrs);
        //only if it's a map or array do we consider it valid
        if(attrs_json[0] === "{" || attrs_json[0] === "["){
            attrs = krl_stdlib.decode({}, attrs_json);
        }
    }

    var eid = ktypes.toString(event_orig.eid).trim();
    if(eid.length === 0 || eid === "null"){
        eid = "none";
    }

    return {

        eci: event_orig.eci.trim(),

        eid: eid,