Socket
Socket
Sign inDemoInstall

json-to-csv-in-browser

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.5 to 1.0.6

29

lib/bundle.js

@@ -12,16 +12,15 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

var _this = this;
var str = this._headers.toString();
this._JsonArray.forEach(function (arr) {
var str = "".concat(this._headers.toString(), "\n");
this._JsonArray.forEach(function (el) {
var line = "";
_this._headers.forEach(function (head) {
var val = arr[head] == undefined ? "" : arr[head];
val = val.toString().search(",") >= 0 ? "\"" + val + "\"" : val;
if (line.length) {
line = line + ", " + val;
_this._headers.forEach(function (hl) {
var found = el[hl];
if (found) {
line = "".concat(line).concat(found, ",");
}
else {
line = "" + (val === undefined ? "" : val);
line = "".concat(line, ",");
}
});
str = str + "\n" + line;
str = "".concat(str).concat(line, "\n");
});

@@ -31,3 +30,13 @@ return str;

JsonArray.prototype.setHeaders = function () {
this._headers = Object.keys(this._JsonArray[0]).map(function (key) { return key; });
var _this = this;
// this._headers = Object.keys(this._JsonArray[0]).map((key) => key);
this._headers = [];
this._JsonArray.forEach(function (el) {
Object.keys(el).forEach(function (hl) {
if (_this._headers.indexOf(hl) < 0) {
_this._headers.push(hl);
}
});
});
console.log(this._headers);
};

@@ -34,0 +43,0 @@ return JsonArray;

@@ -11,16 +11,15 @@ "use strict";

var _this = this;
var str = this._headers.toString();
this._JsonArray.forEach(function (arr) {
var str = "".concat(this._headers.toString(), "\n");
this._JsonArray.forEach(function (el) {
var line = "";
_this._headers.forEach(function (head) {
var val = arr[head] == undefined ? "" : arr[head];
val = val.toString().search(",") >= 0 ? "\"" + val + "\"" : val;
if (line.length) {
line = line + ", " + val;
_this._headers.forEach(function (hl) {
var found = el[hl];
if (found) {
line = "".concat(line).concat(found, ",");
}
else {
line = "" + (val === undefined ? "" : val);
line = "".concat(line, ",");
}
});
str = str + "\n" + line;
str = "".concat(str).concat(line, "\n");
});

@@ -30,3 +29,13 @@ return str;

JsonArray.prototype.setHeaders = function () {
this._headers = Object.keys(this._JsonArray[0]).map(function (key) { return key; });
var _this = this;
// this._headers = Object.keys(this._JsonArray[0]).map((key) => key);
this._headers = [];
this._JsonArray.forEach(function (el) {
Object.keys(el).forEach(function (hl) {
if (_this._headers.indexOf(hl) < 0) {
_this._headers.push(hl);
}
});
});
console.log(this._headers);
};

@@ -33,0 +42,0 @@ return JsonArray;

{
"name": "json-to-csv-in-browser",
"version": "1.0.5",
"version": "1.0.6",
"description": "This converts the json array in the browser to csv file that can be stored in disc",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -12,15 +12,15 @@ export class JsonArray {

public convertToCSVstring(): string {
let str: string = this._headers.toString();
this._JsonArray.forEach((arr) => {
let line: string = "";
this._headers.forEach((head) => {
let val: string = arr[head] == undefined ? "" : arr[head];
val = val.toString().search(",") >= 0 ? `"${val}"` : val;
if (line.length) {
line = `${line}, ${val}`;
let str: string = `${this._headers.toString()}\n`;
this._JsonArray.forEach((el: any) => {
let line = "";
this._headers.forEach((hl: any) => {
const found = el[hl];
if (found) {
line = `${line}${found},`;
} else {
line = `${val === undefined ? "" : val}`;
line = `${line},`;
}
});
str = str + "\n" + line;
str = `${str}${line}\n`;
});

@@ -32,4 +32,14 @@

private setHeaders() {
this._headers = Object.keys(this._JsonArray[0]).map((key) => key);
// this._headers = Object.keys(this._JsonArray[0]).map((key) => key);
this._headers = [];
this._JsonArray.forEach((el) => {
Object.keys(el).forEach((hl) => {
if (this._headers.indexOf(hl) < 0) {
this._headers.push(hl);
}
});
});
console.log(this._headers);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc