Nouvelles versions compilées en JS des scripts.
This commit is contained in:
parent
b12ae3d8e3
commit
b2d5f75065
216
public/JS/exampleWithCSV.app.js
Normal file
216
public/JS/exampleWithCSV.app.js
Normal file
File diff suppressed because one or more lines are too long
216
public/JS/exampleWithHTML.app.js
Normal file
216
public/JS/exampleWithHTML.app.js
Normal file
File diff suppressed because one or more lines are too long
216
public/JS/exampleWithJSON.app.js
Normal file
216
public/JS/exampleWithJSON.app.js
Normal file
File diff suppressed because one or more lines are too long
120
src/build/exampleWithCSV.js
Normal file
120
src/build/exampleWithCSV.js
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
import { FreeDatas2HTML, Pagination, Render, Selector, SortingField } from "./freeDatas2HTML";
|
||||||
|
var initialise = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
|
var mySort, converter, myRender, pagination, filtre1, filtre2, filtre3, sortingField1, sortingField2, sortingField3, sortingField4, e_1;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
_a.trys.push([0, 3, , 4]);
|
||||||
|
mySort = function (a, b, order) {
|
||||||
|
if (order === void 0) { order = "asc"; }
|
||||||
|
var values = ["> 100000", "> 1 et < 100 000", "≤ 1", "Traces", "Inexistant"];
|
||||||
|
if (order === "desc")
|
||||||
|
values.reverse();
|
||||||
|
if (values.indexOf(a) > values.indexOf(b))
|
||||||
|
return -1;
|
||||||
|
else if (values.indexOf(a) < values.indexOf(b))
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
converter = new FreeDatas2HTML("CSV");
|
||||||
|
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/elements-chimiques.csv" });
|
||||||
|
converter.datasViewElt = { id: "datas" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
myRender = new Render(converter);
|
||||||
|
if (window.innerWidth < 800) {
|
||||||
|
myRender.settings =
|
||||||
|
{
|
||||||
|
allBegining: "<h4>Affichage petits écrans !</h4>",
|
||||||
|
allEnding: "",
|
||||||
|
linesBegining: "<ul>",
|
||||||
|
linesEnding: "</ul>",
|
||||||
|
lineBegining: "<li><ul>",
|
||||||
|
lineEnding: "</ul></li>",
|
||||||
|
dataDisplaying: "<li><b>#FIELDNAME :</b> #VALUE</li>",
|
||||||
|
};
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
myRender.settings.allBegining = "<table class='table-hover'>";
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
converter.datasSortingFunctions = [{ datasFieldNb: 4, sort: mySort }];
|
||||||
|
pagination = new Pagination(converter, { id: "pages" }, "Page à afficher :");
|
||||||
|
pagination.options = { displayElement: { id: "paginationOptions" }, values: [10, 20, 50, 500], name: "Choix de pagination :" };
|
||||||
|
pagination.selectedValue = 10;
|
||||||
|
converter.pagination = pagination;
|
||||||
|
pagination.rend2HTML();
|
||||||
|
converter.datasCounter = { id: "compteur" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 2:
|
||||||
|
_a.sent();
|
||||||
|
filtre1 = new Selector(converter, 3, { id: "filtre1" });
|
||||||
|
filtre1.selector2HTML();
|
||||||
|
filtre2 = new Selector(converter, 4, { id: "filtre2" });
|
||||||
|
filtre2.selector2HTML();
|
||||||
|
filtre3 = new Selector(converter, 5, { id: "filtre3" });
|
||||||
|
filtre3.separator = ",";
|
||||||
|
filtre3.selector2HTML();
|
||||||
|
converter.datasSelectors = [filtre1, filtre2, filtre3];
|
||||||
|
if (window.innerWidth >= 800) {
|
||||||
|
sortingField1 = new SortingField(converter, 0);
|
||||||
|
sortingField1.field2HTML();
|
||||||
|
sortingField2 = new SortingField(converter, 1);
|
||||||
|
sortingField2.field2HTML();
|
||||||
|
sortingField3 = new SortingField(converter, 2);
|
||||||
|
sortingField3.field2HTML();
|
||||||
|
sortingField4 = new SortingField(converter, 4);
|
||||||
|
sortingField4.field2HTML();
|
||||||
|
converter.datasSortingFields = [sortingField1, sortingField2, sortingField3, sortingField4];
|
||||||
|
}
|
||||||
|
return [3, 4];
|
||||||
|
case 3:
|
||||||
|
e_1 = _a.sent();
|
||||||
|
console.error(e_1);
|
||||||
|
if (document.getElementById("datas") !== null)
|
||||||
|
document.getElementById("datas").innerHTML = "<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>";
|
||||||
|
return [3, 4];
|
||||||
|
case 4: return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); };
|
||||||
|
initialise();
|
97
src/build/exampleWithHTML.js
Normal file
97
src/build/exampleWithHTML.js
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
import { FreeDatas2HTML, Pagination, Render, Selector, SortingField } from "./freeDatas2HTML";
|
||||||
|
var initialise = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
|
var converter, myRender, pagination, filtre1, sortingField1, sortingField2, e_1;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
_a.trys.push([0, 3, , 4]);
|
||||||
|
converter = new FreeDatas2HTML("HTML");
|
||||||
|
converter.datasViewElt = { id: "datas" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
myRender = new Render(converter);
|
||||||
|
if (window.innerWidth < 800) {
|
||||||
|
myRender.settings =
|
||||||
|
{
|
||||||
|
allBegining: "<h4>Affichage petits écrans !</h4>",
|
||||||
|
allEnding: "",
|
||||||
|
linesBegining: "<ul>",
|
||||||
|
linesEnding: "</ul>",
|
||||||
|
lineBegining: "<li><ul>",
|
||||||
|
lineEnding: "</ul></li>",
|
||||||
|
dataDisplaying: "<li><b>#FIELDNAME :</b> #VALUE</li>",
|
||||||
|
};
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
myRender.settings.allBegining = "<table class='table-hover'>";
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
pagination = new Pagination(converter, { id: "pages" }, "Page à afficher :");
|
||||||
|
pagination.options = { displayElement: { id: "paginationOptions" }, values: [15, 30, 50, 100], name: "Nombre de lignes par page :" };
|
||||||
|
pagination.selectedValue = 15;
|
||||||
|
converter.pagination = pagination;
|
||||||
|
pagination.rend2HTML();
|
||||||
|
converter.datasCounter = { id: "compteur" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 2:
|
||||||
|
_a.sent();
|
||||||
|
filtre1 = new Selector(converter, 3, { id: "filtre1" });
|
||||||
|
filtre1.selector2HTML();
|
||||||
|
converter.datasSelectors = [filtre1];
|
||||||
|
if (window.innerWidth >= 800) {
|
||||||
|
sortingField1 = new SortingField(converter, 2);
|
||||||
|
sortingField1.field2HTML();
|
||||||
|
sortingField2 = new SortingField(converter, 3);
|
||||||
|
sortingField2.field2HTML();
|
||||||
|
converter.datasSortingFields = [sortingField1, sortingField2];
|
||||||
|
}
|
||||||
|
return [3, 4];
|
||||||
|
case 3:
|
||||||
|
e_1 = _a.sent();
|
||||||
|
console.error(e_1);
|
||||||
|
if (document.getElementById("datas") !== null)
|
||||||
|
document.getElementById("datas").innerHTML = "<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>";
|
||||||
|
return [3, 4];
|
||||||
|
case 4: return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); };
|
||||||
|
initialise();
|
100
src/build/exampleWithJSON.js
Normal file
100
src/build/exampleWithJSON.js
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
import { FreeDatas2HTML, Pagination, Render, Selector, SortingField } from "./freeDatas2HTML";
|
||||||
|
var initialise = function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
|
var converter, myRender, pagination, filtre1, sortingField1, sortingField2, sortingField3, e_1;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
_a.trys.push([0, 3, , 4]);
|
||||||
|
converter = new FreeDatas2HTML("JSON");
|
||||||
|
converter.parser.setRemoteSource({ url: "http://localhost:8080/datas/posts.json", withCredentials: true, headers: [{ key: "Authorization", value: "Token YWxhZGRpbjpvcGVuc2VzYW1l" }] });
|
||||||
|
converter.datasViewElt = { id: "datas" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
myRender = new Render(converter);
|
||||||
|
if (window.innerWidth < 800) {
|
||||||
|
myRender.settings =
|
||||||
|
{
|
||||||
|
allBegining: "<h4>Affichage petits écrans !</h4>",
|
||||||
|
allEnding: "",
|
||||||
|
linesBegining: "<ul>",
|
||||||
|
linesEnding: "</ul>",
|
||||||
|
lineBegining: "<li><ul>",
|
||||||
|
lineEnding: "</ul></li>",
|
||||||
|
dataDisplaying: "<li><b>#FIELDNAME :</b> #VALUE</li>",
|
||||||
|
};
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
myRender.settings.allBegining = "<table class='table-hover'>";
|
||||||
|
converter.datasRender = myRender;
|
||||||
|
}
|
||||||
|
pagination = new Pagination(converter, { id: "pages" }, "Page à afficher :");
|
||||||
|
pagination.options = { displayElement: { id: "paginationOptions" }, values: [15, 30, 50, 100], name: "Nombre de lignes par page :" };
|
||||||
|
pagination.selectedValue = 15;
|
||||||
|
converter.pagination = pagination;
|
||||||
|
pagination.rend2HTML();
|
||||||
|
converter.datasCounter = { id: "compteur" };
|
||||||
|
return [4, converter.run()];
|
||||||
|
case 2:
|
||||||
|
_a.sent();
|
||||||
|
filtre1 = new Selector(converter, 0, { id: "filtre1" });
|
||||||
|
filtre1.selector2HTML();
|
||||||
|
converter.datasSelectors = [filtre1];
|
||||||
|
if (window.innerWidth >= 800) {
|
||||||
|
sortingField1 = new SortingField(converter, 0);
|
||||||
|
sortingField1.field2HTML();
|
||||||
|
sortingField2 = new SortingField(converter, 1);
|
||||||
|
sortingField2.field2HTML();
|
||||||
|
sortingField3 = new SortingField(converter, 2);
|
||||||
|
sortingField3.field2HTML();
|
||||||
|
converter.datasSortingFields = [sortingField1, sortingField2, sortingField3];
|
||||||
|
}
|
||||||
|
return [3, 4];
|
||||||
|
case 3:
|
||||||
|
e_1 = _a.sent();
|
||||||
|
console.error(e_1);
|
||||||
|
if (document.getElementById("datas") !== null)
|
||||||
|
document.getElementById("datas").innerHTML = "<strong>Désolé, mais un problème technique empêche l'affichage des données.</strong>";
|
||||||
|
return [3, 4];
|
||||||
|
case 4: return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); };
|
||||||
|
initialise();
|
166
src/build/freeDatas2HTMLParserForCSV.js
Normal file
166
src/build/freeDatas2HTMLParserForCSV.js
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var Papa = require("papaparse");
|
||||||
|
var errors = require("./errors.js");
|
||||||
|
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
|
||||||
|
var ParserForCSV = (function () {
|
||||||
|
function ParserForCSV(datasRemoteSource) {
|
||||||
|
this._datas2Parse = "";
|
||||||
|
this._parseResults = undefined;
|
||||||
|
this.options = {
|
||||||
|
delimiter: "",
|
||||||
|
newline: "",
|
||||||
|
quoteChar: '"',
|
||||||
|
escapeChar: '"',
|
||||||
|
transformHeader: function (field, index) { return field.trim(); },
|
||||||
|
preview: 0,
|
||||||
|
comments: "",
|
||||||
|
fastMode: undefined,
|
||||||
|
transform: undefined
|
||||||
|
};
|
||||||
|
this._privateOptions = {
|
||||||
|
header: true,
|
||||||
|
download: false,
|
||||||
|
downloadRequestHeaders: undefined,
|
||||||
|
skipEmptyLines: "greedy",
|
||||||
|
withCredentials: undefined
|
||||||
|
};
|
||||||
|
if (datasRemoteSource !== undefined)
|
||||||
|
this._datasRemoteSource = datasRemoteSource;
|
||||||
|
else
|
||||||
|
this._datasRemoteSource = new RemoteSources({ url: "" });
|
||||||
|
}
|
||||||
|
ParserForCSV.prototype.setRemoteSource = function (source) {
|
||||||
|
this._datasRemoteSource = new RemoteSources(source);
|
||||||
|
};
|
||||||
|
Object.defineProperty(ParserForCSV.prototype, "datasRemoteSource", {
|
||||||
|
get: function () {
|
||||||
|
return this._datasRemoteSource;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForCSV.prototype, "datas2Parse", {
|
||||||
|
get: function () {
|
||||||
|
return this._datas2Parse;
|
||||||
|
},
|
||||||
|
set: function (datas) {
|
||||||
|
if (datas.trim().length === 0)
|
||||||
|
throw new Error(errors.parserNeedDatas);
|
||||||
|
else
|
||||||
|
this._datas2Parse = datas.trim();
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForCSV.prototype, "parseResults", {
|
||||||
|
get: function () {
|
||||||
|
return this._parseResults;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForCSV.prototype, "privateOptions", {
|
||||||
|
get: function () {
|
||||||
|
return this._privateOptions;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
ParserForCSV.prototype.parse = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var parser, options, parseContent, i;
|
||||||
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
parser = this, options = this.options;
|
||||||
|
parseContent = "";
|
||||||
|
if (parser._datasRemoteSource.url !== "") {
|
||||||
|
parseContent = parser._datasRemoteSource.url;
|
||||||
|
this._privateOptions.download = true;
|
||||||
|
this._privateOptions.withCredentials = parser._datasRemoteSource.withCredentials;
|
||||||
|
if (parser._datasRemoteSource.headers !== undefined) {
|
||||||
|
this._privateOptions.downloadRequestHeaders = {};
|
||||||
|
for (i = 0; i < parser._datasRemoteSource.headers.length; i++)
|
||||||
|
this._privateOptions.downloadRequestHeaders[parser._datasRemoteSource.headers[i].key] = parser._datasRemoteSource.headers[i].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (parser._datas2Parse !== "")
|
||||||
|
parseContent = parser._datas2Parse;
|
||||||
|
else
|
||||||
|
throw new Error(errors.parserNeedSource);
|
||||||
|
return [2, new Promise(function (resolve, reject) {
|
||||||
|
Papa.parse(parseContent, {
|
||||||
|
delimiter: options.delimiter,
|
||||||
|
newline: options.newline,
|
||||||
|
quoteChar: options.quoteChar,
|
||||||
|
escapeChar: options.escapeChar,
|
||||||
|
header: true,
|
||||||
|
transformHeader: options.transformHeader,
|
||||||
|
preview: options.preview,
|
||||||
|
comments: options.comments,
|
||||||
|
complete: function (results) {
|
||||||
|
var realFields = [];
|
||||||
|
for (var _i = 0, _a = results.meta.fields; _i < _a.length; _i++) {
|
||||||
|
var field = _a[_i];
|
||||||
|
if (field.trim() !== "")
|
||||||
|
realFields.push(field);
|
||||||
|
}
|
||||||
|
if (realFields.length === 0)
|
||||||
|
reject(new Error(errors.parserFail));
|
||||||
|
else {
|
||||||
|
parser._parseResults = {
|
||||||
|
datas: results.data,
|
||||||
|
errors: results.errors,
|
||||||
|
fields: realFields,
|
||||||
|
};
|
||||||
|
resolve(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
download: _this._privateOptions.download,
|
||||||
|
downloadRequestHeaders: _this._privateOptions.downloadRequestHeaders,
|
||||||
|
skipEmptyLines: "greedy",
|
||||||
|
fastMode: options.fastMode,
|
||||||
|
withCredentials: _this._privateOptions.withCredentials,
|
||||||
|
transform: options.transform
|
||||||
|
});
|
||||||
|
})];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return ParserForCSV;
|
||||||
|
}());
|
||||||
|
export { ParserForCSV };
|
174
src/build/freeDatas2HTMLParserForHTML.js
Normal file
174
src/build/freeDatas2HTMLParserForHTML.js
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var errors = require("./errors.js");
|
||||||
|
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
|
||||||
|
var ParserForHTML = (function () {
|
||||||
|
function ParserForHTML(datasRemoteSource) {
|
||||||
|
this._document2Parse = document;
|
||||||
|
this._parseResults = undefined;
|
||||||
|
this._fieldsSelector = "table > thead > tr > th";
|
||||||
|
this._rowsSelector = "table > tbody > tr";
|
||||||
|
this._datasSelector = "tr > td";
|
||||||
|
if (datasRemoteSource !== undefined)
|
||||||
|
this._datasRemoteSource = datasRemoteSource;
|
||||||
|
else
|
||||||
|
this._datasRemoteSource = new RemoteSources({ url: "" });
|
||||||
|
}
|
||||||
|
ParserForHTML.prototype.setRemoteSource = function (source) {
|
||||||
|
this._datasRemoteSource = new RemoteSources(source);
|
||||||
|
};
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "datasRemoteSource", {
|
||||||
|
get: function () {
|
||||||
|
return this._datasRemoteSource;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "document2Parse", {
|
||||||
|
get: function () {
|
||||||
|
return this._document2Parse;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "fieldsSelector", {
|
||||||
|
get: function () {
|
||||||
|
return this._fieldsSelector;
|
||||||
|
},
|
||||||
|
set: function (selector) {
|
||||||
|
if (selector.trim() === "")
|
||||||
|
throw new Error(errors.parserSelectorsIsEmpty);
|
||||||
|
else
|
||||||
|
this._fieldsSelector = selector.trim();
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "rowsSelector", {
|
||||||
|
get: function () {
|
||||||
|
return this._rowsSelector;
|
||||||
|
},
|
||||||
|
set: function (selector) {
|
||||||
|
if (selector.trim() === "")
|
||||||
|
throw new Error(errors.parserSelectorsIsEmpty);
|
||||||
|
else
|
||||||
|
this._rowsSelector = selector.trim();
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "datasSelector", {
|
||||||
|
get: function () {
|
||||||
|
return this._datasSelector;
|
||||||
|
},
|
||||||
|
set: function (selector) {
|
||||||
|
if (selector.trim() === "")
|
||||||
|
throw new Error(errors.parserSelectorsIsEmpty);
|
||||||
|
else
|
||||||
|
this._datasSelector = selector.trim();
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForHTML.prototype, "parseResults", {
|
||||||
|
get: function () {
|
||||||
|
return this._parseResults;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
ParserForHTML.prototype.parse = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var parser, realFields, datas, parseErrors, settings, response, responseHTML, parserDOM, fields, i, checkField, rows, datasElts, i, dataObject, j;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
parser = this;
|
||||||
|
realFields = [], datas = [], parseErrors = [];
|
||||||
|
if (!(parser._datasRemoteSource.url !== "")) return [3, 3];
|
||||||
|
settings = parser._datasRemoteSource.getFetchSettings();
|
||||||
|
return [4, fetch(parser._datasRemoteSource.url, settings)];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
if (!response.ok)
|
||||||
|
throw new Error(errors.parserRemoteFail);
|
||||||
|
return [4, response.text()];
|
||||||
|
case 2:
|
||||||
|
responseHTML = _a.sent();
|
||||||
|
parserDOM = new DOMParser();
|
||||||
|
this._document2Parse = parserDOM.parseFromString(responseHTML, "text/html");
|
||||||
|
_a.label = 3;
|
||||||
|
case 3:
|
||||||
|
fields = this._document2Parse.querySelectorAll(this._fieldsSelector);
|
||||||
|
if (fields.length === 0)
|
||||||
|
throw new Error(errors.parserElementsNotFound + this._fieldsSelector);
|
||||||
|
for (i = 0; i < fields.length; i++) {
|
||||||
|
checkField = (fields[i].textContent + "").trim();
|
||||||
|
if (checkField !== "" && realFields.indexOf(checkField) === -1)
|
||||||
|
realFields.push(checkField);
|
||||||
|
else
|
||||||
|
console.error(errors.parserFieldNameFail);
|
||||||
|
}
|
||||||
|
if (realFields.length === 0)
|
||||||
|
throw new Error(errors.parserFieldsNotFound);
|
||||||
|
rows = this._document2Parse.querySelectorAll(this._rowsSelector);
|
||||||
|
for (i = 0; i < rows.length; i++) {
|
||||||
|
datasElts = rows[i].querySelectorAll(this._datasSelector);
|
||||||
|
if (datasElts.length !== realFields.length)
|
||||||
|
parseErrors.push({ row: i, message: errors.parserMeetErrors });
|
||||||
|
dataObject = {};
|
||||||
|
for (j = 0; j < datasElts.length && j < realFields.length; j++)
|
||||||
|
dataObject[realFields[j]] = datasElts[j].textContent + "";
|
||||||
|
if (Object.keys(dataObject).length !== 0)
|
||||||
|
datas.push(dataObject);
|
||||||
|
else
|
||||||
|
parseErrors.push({ row: i, message: errors.parserMeetErrors });
|
||||||
|
}
|
||||||
|
parser._parseResults =
|
||||||
|
{
|
||||||
|
datas: datas,
|
||||||
|
errors: parseErrors,
|
||||||
|
fields: realFields,
|
||||||
|
};
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return ParserForHTML;
|
||||||
|
}());
|
||||||
|
export { ParserForHTML };
|
171
src/build/freeDatas2HTMLParserForJSON.js
Normal file
171
src/build/freeDatas2HTMLParserForJSON.js
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var errors = require("./errors.js");
|
||||||
|
import { RemoteSources } from "./freeDatas2HTMLRemoteSources";
|
||||||
|
var ParserForJSON = (function () {
|
||||||
|
function ParserForJSON(datasRemoteSource) {
|
||||||
|
this._datas2Parse = "";
|
||||||
|
this._parseResults = undefined;
|
||||||
|
if (datasRemoteSource !== undefined)
|
||||||
|
this._datasRemoteSource = datasRemoteSource;
|
||||||
|
else
|
||||||
|
this._datasRemoteSource = new RemoteSources({ url: "" });
|
||||||
|
}
|
||||||
|
ParserForJSON.prototype.setRemoteSource = function (source) {
|
||||||
|
this._datasRemoteSource = new RemoteSources(source);
|
||||||
|
};
|
||||||
|
Object.defineProperty(ParserForJSON.prototype, "datasRemoteSource", {
|
||||||
|
get: function () {
|
||||||
|
return this._datasRemoteSource;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForJSON.prototype, "datas2Parse", {
|
||||||
|
get: function () {
|
||||||
|
return this._datas2Parse;
|
||||||
|
},
|
||||||
|
set: function (datas) {
|
||||||
|
if (datas.trim().length === 0)
|
||||||
|
throw new Error(errors.parserNeedDatas);
|
||||||
|
else
|
||||||
|
this._datas2Parse = datas.trim();
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(ParserForJSON.prototype, "parseResults", {
|
||||||
|
get: function () {
|
||||||
|
return this._parseResults;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
ParserForJSON.trimAllFields = function (fields) {
|
||||||
|
var nb = fields.length, goodFields = [];
|
||||||
|
for (var i = 0; i < nb; i++) {
|
||||||
|
if (typeof fields[i] === "string")
|
||||||
|
goodFields.push(fields[i].trim());
|
||||||
|
}
|
||||||
|
return goodFields;
|
||||||
|
};
|
||||||
|
ParserForJSON.prototype.parse = function () {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var parser, parseContent, settings, response, datasParsed, typesOkForValue, fields, datas, parseErrors, nbFields, nbDatas, i, dataObject, nbObjFields, j, i, _i, datasParsed_1, data, dataObject, field;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
parser = this;
|
||||||
|
parseContent = "";
|
||||||
|
if (!(parser._datasRemoteSource.url !== "")) return [3, 3];
|
||||||
|
settings = parser._datasRemoteSource.getFetchSettings();
|
||||||
|
return [4, fetch(parser._datasRemoteSource.url, settings)];
|
||||||
|
case 1:
|
||||||
|
response = _a.sent();
|
||||||
|
if (!response.ok)
|
||||||
|
throw new Error(errors.parserRemoteFail);
|
||||||
|
return [4, response.text()];
|
||||||
|
case 2:
|
||||||
|
parseContent = _a.sent();
|
||||||
|
return [3, 4];
|
||||||
|
case 3:
|
||||||
|
if (parser._datas2Parse !== "")
|
||||||
|
parseContent = parser._datas2Parse;
|
||||||
|
else
|
||||||
|
throw new Error(errors.parserNeedSource);
|
||||||
|
_a.label = 4;
|
||||||
|
case 4:
|
||||||
|
try {
|
||||||
|
datasParsed = JSON.parse(parseContent);
|
||||||
|
typesOkForValue = ["boolean", "number", "string"];
|
||||||
|
fields = [], datas = [], parseErrors = [];
|
||||||
|
if (datasParsed.fields !== undefined && Array.isArray(datasParsed.fields) && datasParsed.datas !== undefined && Array.isArray(datasParsed.datas)) {
|
||||||
|
fields = ParserForJSON.trimAllFields(datasParsed.fields);
|
||||||
|
nbFields = fields.length, nbDatas = datasParsed.datas.length;
|
||||||
|
for (i = 0; i < nbDatas; i++) {
|
||||||
|
dataObject = {}, nbObjFields = datasParsed.datas[i].length;
|
||||||
|
for (j = 0; j < nbObjFields && j < nbFields; j++) {
|
||||||
|
if (typesOkForValue.indexOf(typeof datasParsed.datas[i][j]) === -1)
|
||||||
|
parseErrors.push({ row: i, message: errors.parserTypeError + typeof datasParsed.datas[i][j] });
|
||||||
|
else
|
||||||
|
dataObject[fields[j]] = datasParsed.datas[i][j] + "";
|
||||||
|
}
|
||||||
|
if (Object.keys(dataObject).length !== 0)
|
||||||
|
datas.push(dataObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i = 0;
|
||||||
|
for (_i = 0, datasParsed_1 = datasParsed; _i < datasParsed_1.length; _i++) {
|
||||||
|
data = datasParsed_1[_i];
|
||||||
|
dataObject = {};
|
||||||
|
for (field in data) {
|
||||||
|
if (typesOkForValue.indexOf(typeof data[field]) !== -1) {
|
||||||
|
field = field.trim();
|
||||||
|
if (field !== "" && fields.indexOf(field) === -1)
|
||||||
|
fields.push(field);
|
||||||
|
dataObject[field] = data[field] + "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
parseErrors.push({ row: i, message: errors.parserTypeError + typeof data[field] });
|
||||||
|
}
|
||||||
|
if (Object.keys(dataObject).length !== 0)
|
||||||
|
datas.push(dataObject);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fields.length === 0)
|
||||||
|
throw new Error(errors.parserFail);
|
||||||
|
parser._parseResults =
|
||||||
|
{
|
||||||
|
datas: datas,
|
||||||
|
errors: parseErrors,
|
||||||
|
fields: fields,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
throw new Error(errors.parserFail);
|
||||||
|
}
|
||||||
|
return [2];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
return ParserForJSON;
|
||||||
|
}());
|
||||||
|
export { ParserForJSON };
|
76
src/build/freeDatas2HTMLRemoteSources.js
Normal file
76
src/build/freeDatas2HTMLRemoteSources.js
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
var errors = require("./errors.js");
|
||||||
|
var RemoteSources = (function () {
|
||||||
|
function RemoteSources(RemoteSettings) {
|
||||||
|
this.allowedUrlProtocol = ["https:", "http:"];
|
||||||
|
this._headers = [];
|
||||||
|
this._withCredentials = false;
|
||||||
|
this._url = RemoteSettings.url;
|
||||||
|
if (RemoteSettings.headers !== undefined)
|
||||||
|
this.headers = RemoteSettings.headers;
|
||||||
|
if (RemoteSettings.withCredentials !== undefined)
|
||||||
|
this.withCredentials = RemoteSettings.withCredentials;
|
||||||
|
}
|
||||||
|
Object.defineProperty(RemoteSources.prototype, "url", {
|
||||||
|
get: function () {
|
||||||
|
return this._url;
|
||||||
|
},
|
||||||
|
set: function (url) {
|
||||||
|
if (url.trim().length === 0)
|
||||||
|
throw new Error(errors.remoteSourceNeedUrl);
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
var checkUrl = new URL(url);
|
||||||
|
if (this.allowedUrlProtocol.indexOf(checkUrl.protocol) === -1)
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
throw new Error(errors.remoteSourceUrlFail);
|
||||||
|
}
|
||||||
|
this._url = url.trim();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(RemoteSources.prototype, "headers", {
|
||||||
|
get: function () {
|
||||||
|
return this._headers;
|
||||||
|
},
|
||||||
|
set: function (headers) {
|
||||||
|
var forbiddenHeadersNames = ["Accept-Charset", "Accept-Encoding", "Access-Control-Request-Headers", "Access-Control-Request-Method", "Connection", "Content-Length", "Cookie", "Cookie2", "Date", "DNT", "Expect", "Host", "Keep-Alive", "Origin", "Referer", "TE", "Trailer", "Transfer-Encoding", "Upgrade", "Via"];
|
||||||
|
for (var _i = 0, headers_1 = headers; _i < headers_1.length; _i++) {
|
||||||
|
var header = headers_1[_i];
|
||||||
|
header.key = header.key.trim();
|
||||||
|
if (header.key.startsWith("Sec-") || header.key.startsWith("Proxy-") || forbiddenHeadersNames.indexOf(header.key) !== -1)
|
||||||
|
console.error(errors.remoteSourceHeaderIsUnallowed);
|
||||||
|
else
|
||||||
|
this._headers.push({ key: header.key, value: header.value.trim() });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(RemoteSources.prototype, "withCredentials", {
|
||||||
|
get: function () {
|
||||||
|
return this._withCredentials;
|
||||||
|
},
|
||||||
|
set: function (credentials) {
|
||||||
|
this._withCredentials = credentials;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
RemoteSources.prototype.getFetchSettings = function () {
|
||||||
|
var headers = new Headers();
|
||||||
|
if (this._headers !== undefined) {
|
||||||
|
for (var _i = 0, _a = this._headers; _i < _a.length; _i++) {
|
||||||
|
var header = _a[_i];
|
||||||
|
headers.append(header.key, header.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var credentials = (this._withCredentials) ? "include" : "omit";
|
||||||
|
return { method: "GET", headers: headers, credentials: credentials };
|
||||||
|
};
|
||||||
|
return RemoteSources;
|
||||||
|
}());
|
||||||
|
export { RemoteSources };
|
Loading…
Reference in New Issue
Block a user