"use strict"

export function morphBoard( board, boardID ) {
    var img = 'https://i.4cdn.org/' + boardID + '/';
    var threads = [];

    console.log("parsing 4chan board");
    console.log("type of board = ", typeof board);

    for (let page in board) {
        if (!board.hasOwnProperty(page)) return false;
        let threads = board[page]['threads'];
        console.log("Threads length is", threads.length)
		for (let i = 0; i < threads.length; i++) {
		    formatThread(threads[i]);
		}
    }

    if (!threads.length) throw new Error("No threads extracted");
    return threads;

    function formatThread(threadObj) {
        console.log("Creating thread #"+threads.length);
        var thread = {
        	id: threadObj['no'],
        	date: threadObj['now'],
            title: threadObj['sub'] || "",
            comment: threadObj['com'],
            imgsrc: {
                sm: img + threadObj['tim'] + "s.jpg",
                lg: img + threadObj['tim'] + ".jpg",
            },
            replies: {
                textCount: threadObj['replies'],
                imgCount: threadObj['images']
            }
        }
        threads.push(thread);
    }
}

export function morphThread( posts, boardID ) {
    let img = 'https://i.4cdn.org/' + boardID + '/';

    if (!posts.length) throw new Error("No threads extracted");
    let thread = [];
    posts.map( post => {
        thread.push({
            id: post['no'],
            date: post['now'],
            title: post['sub'] || "",
            comment: post['com'],
            imgsrc: !!post['ext'] ? {
                sm: img + post['tim'] + "s.jpg",
                lg: img + post['tim'] + post['ext']
            } : undefined,
            ext: post['ext'],
            replies: {
                textCount: post['replies'],
                imgCount: post['images'],
                ipCount: post['unique_ips']
            }
        })
    });

    console.log(`Created ${thread.length} 4chan posts`);
    return thread
}


export function extractBoardList( boardList ) {
    let boards = []
    boardList.map( board => {
        boards.push({
            board: board.board, 
            title: board.title
        })
    });
    return boards
}
@@ -116,22 +116,21 @@
    var t
-hreads
+arget
  = %5B%5D;%0A%0A
@@ -146,17 +146,17 @@
 le.log(%22
-p
+P
 arsing 4
@@ -172,59 +172,8 @@
 d%22);
-%0A    console.log(%22type of board = %22, typeof board);
 %0A%0A  
@@ -305,65 +305,8 @@
 '%5D;%0A
-        console.log(%22Threads length is%22, threads.length)%0A
 %09%09fo
@@ -399,22 +399,21 @@
   if (!t
-hreads
+arget
 .length)
@@ -462,132 +462,127 @@
     
-return threads;%0A%0A    function formatThread(threadObj) %7B%0A        console.log(%22Creating thread #%22+threads.length);%0A        var
+console.log(%60Created $%7Btarget.length%7D threads%60);%0A    return target;%0A%0A    function formatThread(threadObj) %7B%0A        let
  thr
@@ -1029,22 +1029,21 @@
        t
-hreads
+arget
 .push(th
@@ -1381,32 +1381,63 @@
 t%5B'sub'%5D %7C%7C %22%22,%0A
+            time: post%5B'tim'%5D,%0A
             comm

Add time to morphThread function in morph-4chan + logging cleanup