Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="drop_zone">Drop CSV file here</div>
<output id="list"></output>
<a id="downloadAnchorElem"></a>
              * {
  box-sizing: border-box;
  font-family: Helvetica, Arial, sans-serif;
body {
  background: #f0f0f0;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
#drop_zone {
  font-size: 1.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
  width: 300px;
  height: 300px;
  border: 10px dashed gray;
  padding: 10px;
  background: white;
  box-shadow: 6px 6px 32px rgba(0,0,0,0.25);
  opacity: 0.5;
  transition: all 400ms ease;


// Pad numbers with zeros: number:1, padding:2 becomes: 02
function padNumber( number, padding ){
  let str = number.toString();
  let padded = str;
  if ( str.length < padding ){
    for ( let i = 0; i < (padding-str.length); i++ ){
      // str = "0" + str; // [ FAIL ]
      padded = "0" + padded;
  return padded;

function csvToJson( csv ) {

  let split = csv.split(/\r?\n/);
  let headers = split[0];
  let headerCols = headers.split(",");
  let colsCount = headerCols.length;
  let rows = split.slice(1);
  let rowsCount = rows.length;

  let levelCounter1 = 1;
  let levelCounter2 = 1;
  let levelCounter3 = 1;
  let levelCounter4 = 1;

  // Level Index:
  let levels = Array(colsCount).fill({});
  let json = []; => {

    let row = rowStr.split(",");
    let level1 = row[0] && row[0].trim();
    let level2 = row[1] && row[1].trim();
    let level3 = row[2] && row[2].trim();
    let level4 = row[3] && row[3].trim();

    // LEVEL 1
    if (level1 && !levels[0][level1]) {
      let output = {
        id: padNumber(levelCounter1, 2),
        position: levelCounter1,
        label: level1,
        value: level1,
        title: level1,
        parentID: null
      levels[0][level1] = levelCounter1++;
    // LEVEL 2
    if (level2 && !levels[1][level2]) {
      let output = {
        id: `${padNumber(levels[0][level1],2)}${padNumber(levelCounter2,4)}`,
        position: levelCounter2,
        label: level2,
        value: `${level1} > ${level2}`,
        title: level2,
        parentID: levels[0][level1]
      levels[1][level2] = levelCounter2++;
    // LEVEL 3
    if (level3 && !levels[2][level3]) {
      let output = {
        id: `${padNumber(levels[0][level1],2)}${padNumber(levels[1][level2],4)}${padNumber(levelCounter3,4)}`,
        position: levelCounter3,
        label: level3,
        value: `${level1} > ${level2} > ${level3}`,
        title: level3,
        parentID: levels[1][level2]
      levels[2][level3] = levelCounter3++;
    // LEVEL 4
    if (level4 && !levels[3][level4]) {
      let output = {
        id: `${padNumber(levels[0][level1],2)}${padNumber(levels[1][level2],4)}${padNumber(levels[2][level3],4)}${padNumber(levelCounter4,4)}`,
        position: levelCounter4,
        label: level4,
        value: `${level1} > ${level2} > ${level3} > ${level4}`,
        title: level4,
        parentID: levels[2][level3]
      levels[3][level4] = levelCounter4++;


  return json;


function handleFileSelect(e) {

    let file = e.dataTransfer.files[0]; // FileList object.
    let reader = new FileReader();
    reader.onload = function(e) {
      let json = csvToJson( reader.result );
      // Download:
      let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(json, null, 2));
      let dlAnchorElem = document.getElementById('downloadAnchorElem');
      dlAnchorElem.setAttribute("href",     dataStr     );
      dlAnchorElem.setAttribute("download", "data.json");;

function handleDragOver(e) {
  e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. = 1;

function handleDragLeave(e) { = 0.5;

let dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('dragleave', handleDragLeave, false);
dropZone.addEventListener('drop', handleFileSelect, false);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.