UNPKG

csv-to-markdown-table

Version:

JavaScript/Node.js Csv to Markdown Table Converter

3 lines (2 loc) 1.07 kB
!function(n,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(n="undefined"!=typeof globalThis?globalThis:n||self).csvToMarkdown=o()}(this,function(){"use strict";return function(n,o,t){void 0===o&&(o="\t"),void 0===t&&(t=!1),"\t"!=o&&(n=n.replace(/\t/g," "));var c=n.split(/\r?\n/),e=[],a=[],i=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=new RegExp("".concat(i,'(?![^"]*"(?:$|').concat(i,"))"));c.forEach(function(n,o){void 0===e[o]&&(e[o]=[]),n.split(r).forEach(function(n,t){void 0===a[t]&&(a[t]=0),n=n.replace(/(\||\\)/g,"\\$1"),a[t]=Math.max(a[t],n.length),e[o][t]=n})});var f="",d="";a.forEach(function(n){var o=Array(n+1+2);d+="|"+o.join("-"),f+="|"+o.join(" ")}),f+="| \n",d+="| \n",t&&(f="");var u="";return e.forEach(function(n,o){a.forEach(function(c,e){var a=void 0===n[e]?"":n[e],i=Array(c-a.length+1).join(" "),r="| ".concat(a).concat(i," ");t&&0===o?f+=r:u+=r}),t&&0===o?f+="| \n":u+="| \n"}),"".concat(f).concat(d).concat(u)}}); //# sourceMappingURL=CsvToMarkdown.min.js.map