Skip to content

Alternative non-eval implementation for objectConverter() #108

@jobisoft

Description

@jobisoft

The current implementation for objectConvert() is using eval (new Function) which is blocked by CSP in many environments.

function objectConverter(columns) {
  return new Function("d", "return {" + columns.map(function(name, i) {
    return JSON.stringify(name) + ": d[" + i + "] || \"\"";
  }).join(",") + "}");
}

An alternative implementation could be:

function objectConverter(columns) {
  return function (d) {
    const obj = {};
    for (let i = 0; i < columns.length; i++) {
      obj[columns[i]] = d[i] ?? "";
    }
    return obj;
  };
}

Would that be an option?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions