json-to-csv-in-browser
Advanced tools
| (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){ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.JsonArray = void 0; | ||
| var JsonArray = /** @class */ (function () { | ||
| function JsonArray(JsonArray) { | ||
| this._JsonArray = JsonArray; | ||
| this.setHeaders(); | ||
| } | ||
| JsonArray.prototype.convertToCSVstring = function () { | ||
| var _this = this; | ||
| var str = this._headers.toString(); | ||
| this._JsonArray.forEach(function (arr) { | ||
| 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; | ||
| } | ||
| else { | ||
| line = "" + (val === undefined ? "" : val); | ||
| } | ||
| }); | ||
| str = str + "\n" + line; | ||
| }); | ||
| return str; | ||
| }; | ||
| JsonArray.prototype.setHeaders = function () { | ||
| this._headers = Object.keys(this._JsonArray[0]).map(function (key) { return key; }); | ||
| }; | ||
| return JsonArray; | ||
| }()); | ||
| exports.JsonArray = JsonArray; | ||
| },{}],2:[function(require,module,exports){ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.download = void 0; | ||
| function download(filename, text) { | ||
| var element = document.createElement('a'); | ||
| element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | ||
| element.setAttribute('download', filename); | ||
| element.style.display = 'none'; | ||
| document.body.appendChild(element); | ||
| element.click(); | ||
| document.body.removeChild(element); | ||
| } | ||
| exports.download = download; | ||
| // Start file download. | ||
| // download("hello.txt","This is the content of my file :)"); | ||
| },{}],3:[function(require,module,exports){ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.download = exports.JsonArray = void 0; | ||
| var JsonArray_1 = require("./JsonArray"); | ||
| Object.defineProperty(exports, "JsonArray", { enumerable: true, get: function () { return JsonArray_1.JsonArray; } }); | ||
| var download_1 = require("./download"); | ||
| Object.defineProperty(exports, "download", { enumerable: true, get: function () { return download_1.download; } }); | ||
| },{"./JsonArray":1,"./download":2}]},{},[3]); |
+5
-1
@@ -1,2 +0,5 @@ | ||
| export function download(filename, text) { | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.download = void 0; | ||
| function download(filename, text) { | ||
| var element = document.createElement('a'); | ||
@@ -10,4 +13,5 @@ element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | ||
| } | ||
| exports.download = download; | ||
| // Start file download. | ||
| // download("hello.txt","This is the content of my file :)"); | ||
| //# sourceMappingURL=download.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"download.js","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,QAAe,EAAE,IAAQ;IAC9C,IAAI,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE3C,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,uBAAuB;AACzB,+DAA+D"} | ||
| {"version":3,"file":"download.js","sourceRoot":"","sources":["../src/download.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,QAAe,EAAE,IAAQ;IAC9C,IAAI,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC1C,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,gCAAgC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1F,OAAO,CAAC,YAAY,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE3C,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEnC,OAAO,CAAC,KAAK,EAAE,CAAC;IAEhB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC;AAXH,4BAWG;AAED,uBAAuB;AACzB,+DAA+D"} |
+2
-2
@@ -1,4 +0,4 @@ | ||
| import { JsonArray } from "./JsonArray.js"; | ||
| import { download } from "./download.js"; | ||
| import { JsonArray } from "./JsonArray"; | ||
| import { download } from "./download"; | ||
| export { JsonArray, download }; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AACrC,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAA;AAEnC,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,CAAA"} |
+7
-3
@@ -1,4 +0,8 @@ | ||
| import { JsonArray } from "./JsonArray.js"; | ||
| import { download } from "./download.js"; | ||
| export { JsonArray, download }; | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.download = exports.JsonArray = void 0; | ||
| var JsonArray_1 = require("./JsonArray"); | ||
| Object.defineProperty(exports, "JsonArray", { enumerable: true, get: function () { return JsonArray_1.JsonArray; } }); | ||
| var download_1 = require("./download"); | ||
| Object.defineProperty(exports, "download", { enumerable: true, get: function () { return download_1.download; } }); | ||
| //# sourceMappingURL=index.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAA;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AAEtC,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,CAAA"} | ||
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAAqC;AAG7B,0FAHA,qBAAS,OAGA;AAFjB,uCAAmC;AAEhB,yFAFX,mBAAQ,OAEW"} |
+22
-16
@@ -1,18 +0,22 @@ | ||
| export class JsonArray { | ||
| constructor(JsonArray) { | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.JsonArray = void 0; | ||
| var JsonArray = /** @class */ (function () { | ||
| function JsonArray(JsonArray) { | ||
| this._JsonArray = JsonArray; | ||
| this.setHeaders(); | ||
| } | ||
| convertToCSVstring() { | ||
| let str = this._headers.toString(); | ||
| this._JsonArray.forEach(arr => { | ||
| let line = ""; | ||
| this._headers.forEach(head => { | ||
| let val = arr[head] === undefined ? "" : arr[head]; | ||
| val = val.toString().search(",") >= 0 ? `"${val}"` : val; | ||
| JsonArray.prototype.convertToCSVstring = function () { | ||
| var _this = this; | ||
| var str = this._headers.toString(); | ||
| this._JsonArray.forEach(function (arr) { | ||
| 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}`; | ||
| line = line + ", " + val; | ||
| } | ||
| else { | ||
| line = `${val === undefined ? "" : val}`; | ||
| line = "" + (val === undefined ? "" : val); | ||
| } | ||
@@ -23,7 +27,9 @@ }); | ||
| return str; | ||
| } | ||
| setHeaders() { | ||
| this._headers = Object.keys(this._JsonArray[0]).map(key => key); | ||
| } | ||
| } | ||
| }; | ||
| JsonArray.prototype.setHeaders = function () { | ||
| this._headers = Object.keys(this._JsonArray[0]).map(function (key) { return key; }); | ||
| }; | ||
| return JsonArray; | ||
| }()); | ||
| exports.JsonArray = JsonArray; | ||
| //# sourceMappingURL=JsonArray.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"JsonArray.js","sourceRoot":"","sources":["../src/JsonArray.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAS;IAKlB,YAAY,SAAe;QACvB,IAAI,CAAC,UAAU,GAAE,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,EAAE,CAAC;IACrB,CAAC;IAEM,kBAAkB;QACrB,IAAI,GAAG,GAAU,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAA,EAAE;YACzB,IAAI,IAAI,GAAQ,EAAE,CAAA;YAClB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAA,EAAE;gBACxB,IAAI,GAAG,GAAU,GAAG,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG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C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC1D,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAE,CAAC,CAAC,OAAI,GAAG,OAAG,CAAC,CAAC,CAAC,GAAG,CAAA;gBACzD,IAAG,IAAI,CAAC,MAAM,EAAC;oBAEX,IAAI,GAAI,IAAI,UAAK,GAAK,CAAC;iBAC1B;qBAAI;oBACD,IAAI,GAAC,MAAG,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAE,CAAA;iBACzC;YAEL,CAAC,CAAC,CAAA;YACF,GAAG,GAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;QAC3B,CAAC,CAAC,CAAA;QAEN,OAAO,GAAG,CAAC;IAEf,CAAC;IAEO,8BAAU,GAAlB;QACI,IAAI,CAAC,QAAQ,GAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAA,GAAG,IAAE,OAAA,GAAG,EAAH,CAAG,CAAC,CAAA;IAChE,CAAC;IACL,gBAAC;AAAD,CAAC,AAnCD,IAmCC;AAnCY,8BAAS"} |
+2
-2
| { | ||
| "name": "json-to-csv-in-browser", | ||
| "version": "1.0.2", | ||
| "version": "1.0.3", | ||
| "description": "This converts the json array in the browser to csv file that can be stored in disc", | ||
| "main": "lib/index.js", | ||
| "scripts": { | ||
| "dev" : "tsc -p ." | ||
| "dev" : "tsc -p . && cd lib && browserify index.js -o bundle.js && cd ../ && yalc publish && cd test && yalc update json-to-csv-in-browser && browserify client.js -o bundle.js" | ||
| }, | ||
@@ -9,0 +9,0 @@ "repository": { |
+2
-2
@@ -1,5 +0,5 @@ | ||
| import {JsonArray} from "./JsonArray.js" | ||
| import {download} from "./download.js" | ||
| import {JsonArray} from "./JsonArray" | ||
| import {download} from "./download" | ||
| export {JsonArray, download} | ||
+2
-2
@@ -7,4 +7,4 @@ { | ||
| // "incremental": true, /* Enable incremental compilation */ | ||
| "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
| "module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
| "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
| "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
| // "lib": [], /* Specify library files to be included in the compilation. */ | ||
@@ -11,0 +11,0 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ |
19634
24.18%20
5.26%234
46.25%