How to use sanitizeHead method in wpt

Best JavaScript code snippet using wpt

fonts.js

Source:fonts.js Github

copy

Full Screen

...1154 dest.set(glyf, destStart);1155 glyphProfile.length = glyf.length;1156 return glyphProfile;1157 }1158 function sanitizeHead(head, numGlyphs, locaLength) {1159 var data = head.data;1160 var version = int32(data[0], data[1], data[2], data[3]);1161 if (version >> 16 !== 1) {1162 (0, _util.info)('Attempting to fix invalid version in head table: ' + version);1163 data[0] = 0;1164 data[1] = 1;1165 data[2] = 0;1166 data[3] = 0;1167 }1168 var indexToLocFormat = int16(data[50], data[51]);1169 if (indexToLocFormat < 0 || indexToLocFormat > 1) {1170 (0, _util.info)('Attempting to fix invalid indexToLocFormat in head table: ' + indexToLocFormat);1171 var numGlyphsPlusOne = numGlyphs + 1;1172 if (locaLength === numGlyphsPlusOne << 1) {1173 data[50] = 0;1174 data[51] = 0;1175 } else if (locaLength === numGlyphsPlusOne << 2) {1176 data[50] = 0;1177 data[51] = 1;1178 } else {1179 throw new _util.FormatError('Could not fix indexToLocFormat: ' + indexToLocFormat);1180 }1181 }1182 }1183 function sanitizeGlyphLocations(loca, glyf, numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions) {1184 var itemSize, itemDecode, itemEncode;1185 if (isGlyphLocationsLong) {1186 itemSize = 4;1187 itemDecode = function fontItemDecodeLong(data, offset) {1188 return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3];1189 };1190 itemEncode = function fontItemEncodeLong(data, offset, value) {1191 data[offset] = value >>> 24 & 0xFF;1192 data[offset + 1] = value >> 16 & 0xFF;1193 data[offset + 2] = value >> 8 & 0xFF;1194 data[offset + 3] = value & 0xFF;1195 };1196 } else {1197 itemSize = 2;1198 itemDecode = function fontItemDecode(data, offset) {1199 return data[offset] << 9 | data[offset + 1] << 1;1200 };1201 itemEncode = function fontItemEncode(data, offset, value) {1202 data[offset] = value >> 9 & 0xFF;1203 data[offset + 1] = value >> 1 & 0xFF;1204 };1205 }1206 var locaData = loca.data;1207 var locaDataSize = itemSize * (1 + numGlyphs);1208 if (locaData.length !== locaDataSize) {1209 locaData = new Uint8Array(locaDataSize);1210 locaData.set(loca.data.subarray(0, locaDataSize));1211 loca.data = locaData;1212 }1213 var oldGlyfData = glyf.data;1214 var oldGlyfDataLength = oldGlyfData.length;1215 var newGlyfData = new Uint8Array(oldGlyfDataLength);1216 var startOffset = itemDecode(locaData, 0);1217 var writeOffset = 0;1218 var missingGlyphs = Object.create(null);1219 itemEncode(locaData, 0, writeOffset);1220 var i, j;1221 var locaCount = dupFirstEntry ? numGlyphs - 1 : numGlyphs;1222 for (i = 0, j = itemSize; i < locaCount; i++, j += itemSize) {1223 var endOffset = itemDecode(locaData, j);1224 if (endOffset > oldGlyfDataLength && (oldGlyfDataLength + 3 & ~3) === endOffset) {1225 endOffset = oldGlyfDataLength;1226 }1227 if (endOffset > oldGlyfDataLength) {1228 startOffset = endOffset;1229 }1230 var glyphProfile = sanitizeGlyph(oldGlyfData, startOffset, endOffset, newGlyfData, writeOffset, hintsValid);1231 var newLength = glyphProfile.length;1232 if (newLength === 0) {1233 missingGlyphs[i] = true;1234 }1235 if (glyphProfile.sizeOfInstructions > maxSizeOfInstructions) {1236 maxSizeOfInstructions = glyphProfile.sizeOfInstructions;1237 }1238 writeOffset += newLength;1239 itemEncode(locaData, j, writeOffset);1240 startOffset = endOffset;1241 }1242 if (writeOffset === 0) {1243 var simpleGlyph = new Uint8Array([0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);1244 for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {1245 itemEncode(locaData, j, simpleGlyph.length);1246 }1247 glyf.data = simpleGlyph;1248 } else if (dupFirstEntry) {1249 var firstEntryLength = itemDecode(locaData, itemSize);1250 if (newGlyfData.length > firstEntryLength + writeOffset) {1251 glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);1252 } else {1253 glyf.data = new Uint8Array(firstEntryLength + writeOffset);1254 glyf.data.set(newGlyfData.subarray(0, writeOffset));1255 }1256 glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);1257 itemEncode(loca.data, locaData.length - itemSize, writeOffset + firstEntryLength);1258 } else {1259 glyf.data = newGlyfData.subarray(0, writeOffset);1260 }1261 return {1262 missingGlyphs: missingGlyphs,1263 maxSizeOfInstructions: maxSizeOfInstructions1264 };1265 }1266 function readPostScriptTable(post, properties, maxpNumGlyphs) {1267 var start = (font.start ? font.start : 0) + post.offset;1268 font.pos = start;1269 var length = post.length,1270 end = start + length;1271 var version = font.getInt32();1272 font.getBytes(28);1273 var glyphNames;1274 var valid = true;1275 var i;1276 switch (version) {1277 case 0x00010000:1278 glyphNames = MacStandardGlyphOrdering;1279 break;1280 case 0x00020000:1281 var numGlyphs = font.getUint16();1282 if (numGlyphs !== maxpNumGlyphs) {1283 valid = false;1284 break;1285 }1286 var glyphNameIndexes = [];1287 for (i = 0; i < numGlyphs; ++i) {1288 var index = font.getUint16();1289 if (index >= 32768) {1290 valid = false;1291 break;1292 }1293 glyphNameIndexes.push(index);1294 }1295 if (!valid) {1296 break;1297 }1298 var customNames = [];1299 var strBuf = [];1300 while (font.pos < end) {1301 var stringLength = font.getByte();1302 strBuf.length = stringLength;1303 for (i = 0; i < stringLength; ++i) {1304 strBuf[i] = String.fromCharCode(font.getByte());1305 }1306 customNames.push(strBuf.join(''));1307 }1308 glyphNames = [];1309 for (i = 0; i < numGlyphs; ++i) {1310 var j = glyphNameIndexes[i];1311 if (j < 258) {1312 glyphNames.push(MacStandardGlyphOrdering[j]);1313 continue;1314 }1315 glyphNames.push(customNames[j - 258]);1316 }1317 break;1318 case 0x00030000:1319 break;1320 default:1321 (0, _util.warn)('Unknown/unsupported post table version ' + version);1322 valid = false;1323 if (properties.defaultEncoding) {1324 glyphNames = properties.defaultEncoding;1325 }1326 break;1327 }1328 properties.glyphNames = glyphNames;1329 return valid;1330 }1331 function readNameTable(nameTable) {1332 var start = (font.start ? font.start : 0) + nameTable.offset;1333 font.pos = start;1334 var names = [[], []];1335 var length = nameTable.length,1336 end = start + length;1337 var format = font.getUint16();1338 var FORMAT_0_HEADER_LENGTH = 6;1339 if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {1340 return names;1341 }1342 var numRecords = font.getUint16();1343 var stringsStart = font.getUint16();1344 var records = [];1345 var NAME_RECORD_LENGTH = 12;1346 var i, ii;1347 for (i = 0; i < numRecords && font.pos + NAME_RECORD_LENGTH <= end; i++) {1348 var r = {1349 platform: font.getUint16(),1350 encoding: font.getUint16(),1351 language: font.getUint16(),1352 name: font.getUint16(),1353 length: font.getUint16(),1354 offset: font.getUint16()1355 };1356 if (r.platform === 1 && r.encoding === 0 && r.language === 0 || r.platform === 3 && r.encoding === 1 && r.language === 0x409) {1357 records.push(r);1358 }1359 }1360 for (i = 0, ii = records.length; i < ii; i++) {1361 var record = records[i];1362 if (record.length <= 0) {1363 continue;1364 }1365 var pos = start + stringsStart + record.offset;1366 if (pos + record.length > end) {1367 continue;1368 }1369 font.pos = pos;1370 var nameIndex = record.name;1371 if (record.encoding) {1372 var str = '';1373 for (var j = 0, jj = record.length; j < jj; j += 2) {1374 str += String.fromCharCode(font.getUint16());1375 }1376 names[1][nameIndex] = str;1377 } else {1378 names[0][nameIndex] = (0, _util.bytesToString)(font.getBytes(record.length));1379 }1380 }1381 return names;1382 }1383 var TTOpsStackDeltas = [0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1, 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1, 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2, 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1, -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];1384 function sanitizeTTProgram(table, ttContext) {1385 var data = table.data;1386 var i = 0,1387 j,1388 n,1389 b,1390 funcId,1391 pc,1392 lastEndf = 0,1393 lastDeff = 0;1394 var stack = [];1395 var callstack = [];1396 var functionsCalled = [];1397 var tooComplexToFollowFunctions = ttContext.tooComplexToFollowFunctions;1398 var inFDEF = false,1399 ifLevel = 0,1400 inELSE = 0;1401 for (var ii = data.length; i < ii;) {1402 var op = data[i++];1403 if (op === 0x40) {1404 n = data[i++];1405 if (inFDEF || inELSE) {1406 i += n;1407 } else {1408 for (j = 0; j < n; j++) {1409 stack.push(data[i++]);1410 }1411 }1412 } else if (op === 0x41) {1413 n = data[i++];1414 if (inFDEF || inELSE) {1415 i += n * 2;1416 } else {1417 for (j = 0; j < n; j++) {1418 b = data[i++];1419 stack.push(b << 8 | data[i++]);1420 }1421 }1422 } else if ((op & 0xF8) === 0xB0) {1423 n = op - 0xB0 + 1;1424 if (inFDEF || inELSE) {1425 i += n;1426 } else {1427 for (j = 0; j < n; j++) {1428 stack.push(data[i++]);1429 }1430 }1431 } else if ((op & 0xF8) === 0xB8) {1432 n = op - 0xB8 + 1;1433 if (inFDEF || inELSE) {1434 i += n * 2;1435 } else {1436 for (j = 0; j < n; j++) {1437 b = data[i++];1438 stack.push(b << 8 | data[i++]);1439 }1440 }1441 } else if (op === 0x2B && !tooComplexToFollowFunctions) {1442 if (!inFDEF && !inELSE) {1443 funcId = stack[stack.length - 1];1444 ttContext.functionsUsed[funcId] = true;1445 if (funcId in ttContext.functionsStackDeltas) {1446 stack.length += ttContext.functionsStackDeltas[funcId];1447 } else if (funcId in ttContext.functionsDefined && functionsCalled.indexOf(funcId) < 0) {1448 callstack.push({1449 data: data,1450 i: i,1451 stackTop: stack.length - 11452 });1453 functionsCalled.push(funcId);1454 pc = ttContext.functionsDefined[funcId];1455 if (!pc) {1456 (0, _util.warn)('TT: CALL non-existent function');1457 ttContext.hintsValid = false;1458 return;1459 }1460 data = pc.data;1461 i = pc.i;1462 }1463 }1464 } else if (op === 0x2C && !tooComplexToFollowFunctions) {1465 if (inFDEF || inELSE) {1466 (0, _util.warn)('TT: nested FDEFs not allowed');1467 tooComplexToFollowFunctions = true;1468 }1469 inFDEF = true;1470 lastDeff = i;1471 funcId = stack.pop();1472 ttContext.functionsDefined[funcId] = {1473 data: data,1474 i: i1475 };1476 } else if (op === 0x2D) {1477 if (inFDEF) {1478 inFDEF = false;1479 lastEndf = i;1480 } else {1481 pc = callstack.pop();1482 if (!pc) {1483 (0, _util.warn)('TT: ENDF bad stack');1484 ttContext.hintsValid = false;1485 return;1486 }1487 funcId = functionsCalled.pop();1488 data = pc.data;1489 i = pc.i;1490 ttContext.functionsStackDeltas[funcId] = stack.length - pc.stackTop;1491 }1492 } else if (op === 0x89) {1493 if (inFDEF || inELSE) {1494 (0, _util.warn)('TT: nested IDEFs not allowed');1495 tooComplexToFollowFunctions = true;1496 }1497 inFDEF = true;1498 lastDeff = i;1499 } else if (op === 0x58) {1500 ++ifLevel;1501 } else if (op === 0x1B) {1502 inELSE = ifLevel;1503 } else if (op === 0x59) {1504 if (inELSE === ifLevel) {1505 inELSE = 0;1506 }1507 --ifLevel;1508 } else if (op === 0x1C) {1509 if (!inFDEF && !inELSE) {1510 var offset = stack[stack.length - 1];1511 if (offset > 0) {1512 i += offset - 1;1513 }1514 }1515 }1516 if (!inFDEF && !inELSE) {1517 var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] : op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;1518 if (op >= 0x71 && op <= 0x75) {1519 n = stack.pop();1520 if (!isNaN(n)) {1521 stackDelta = -n * 2;1522 }1523 }1524 while (stackDelta < 0 && stack.length > 0) {1525 stack.pop();1526 stackDelta++;1527 }1528 while (stackDelta > 0) {1529 stack.push(NaN);1530 stackDelta--;1531 }1532 }1533 }1534 ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;1535 var content = [data];1536 if (i > data.length) {1537 content.push(new Uint8Array(i - data.length));1538 }1539 if (lastDeff > lastEndf) {1540 (0, _util.warn)('TT: complementing a missing function tail');1541 content.push(new Uint8Array([0x22, 0x2D]));1542 }1543 foldTTTable(table, content);1544 }1545 function checkInvalidFunctions(ttContext, maxFunctionDefs) {1546 if (ttContext.tooComplexToFollowFunctions) {1547 return;1548 }1549 if (ttContext.functionsDefined.length > maxFunctionDefs) {1550 (0, _util.warn)('TT: more functions defined than expected');1551 ttContext.hintsValid = false;1552 return;1553 }1554 for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {1555 if (j > maxFunctionDefs) {1556 (0, _util.warn)('TT: invalid function id: ' + j);1557 ttContext.hintsValid = false;1558 return;1559 }1560 if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {1561 (0, _util.warn)('TT: undefined function: ' + j);1562 ttContext.hintsValid = false;1563 return;1564 }1565 }1566 }1567 function foldTTTable(table, content) {1568 if (content.length > 1) {1569 var newLength = 0;1570 var j, jj;1571 for (j = 0, jj = content.length; j < jj; j++) {1572 newLength += content[j].length;1573 }1574 newLength = newLength + 3 & ~3;1575 var result = new Uint8Array(newLength);1576 var pos = 0;1577 for (j = 0, jj = content.length; j < jj; j++) {1578 result.set(content[j], pos);1579 pos += content[j].length;1580 }1581 table.data = result;1582 table.length = newLength;1583 }1584 }1585 function sanitizeTTPrograms(fpgm, prep, cvt, maxFunctionDefs) {1586 var ttContext = {1587 functionsDefined: [],1588 functionsUsed: [],1589 functionsStackDeltas: [],1590 tooComplexToFollowFunctions: false,1591 hintsValid: true1592 };1593 if (fpgm) {1594 sanitizeTTProgram(fpgm, ttContext);1595 }1596 if (prep) {1597 sanitizeTTProgram(prep, ttContext);1598 }1599 if (fpgm) {1600 checkInvalidFunctions(ttContext, maxFunctionDefs);1601 }1602 if (cvt && cvt.length & 1) {1603 var cvtData = new Uint8Array(cvt.length + 1);1604 cvtData.set(cvt.data);1605 cvt.data = cvtData;1606 }1607 return ttContext.hintsValid;1608 }1609 font = new _stream.Stream(new Uint8Array(font.getBytes()));1610 var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp', 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];1611 var header = readOpenTypeHeader(font);1612 var numTables = header.numTables;1613 var cff, cffFile;1614 var tables = Object.create(null);1615 tables['OS/2'] = null;1616 tables['cmap'] = null;1617 tables['head'] = null;1618 tables['hhea'] = null;1619 tables['hmtx'] = null;1620 tables['maxp'] = null;1621 tables['name'] = null;1622 tables['post'] = null;1623 var table;1624 for (var i = 0; i < numTables; i++) {1625 table = readTableEntry(font);1626 if (VALID_TABLES.indexOf(table.tag) < 0) {1627 continue;1628 }1629 if (table.length === 0) {1630 continue;1631 }1632 tables[table.tag] = table;1633 }1634 var isTrueType = !tables['CFF '];1635 if (!isTrueType) {1636 if (header.version === 'OTTO' && !(properties.composite && properties.cidToGidMap) || !tables['head'] || !tables['hhea'] || !tables['maxp'] || !tables['post']) {1637 cffFile = new _stream.Stream(tables['CFF '].data);1638 cff = new CFFFont(cffFile, properties);1639 adjustWidths(properties);1640 return this.convert(name, cff, properties);1641 }1642 delete tables['glyf'];1643 delete tables['loca'];1644 delete tables['fpgm'];1645 delete tables['prep'];1646 delete tables['cvt '];1647 this.isOpenType = true;1648 } else {1649 if (!tables['loca']) {1650 throw new _util.FormatError('Required "loca" table is not found');1651 }1652 if (!tables['glyf']) {1653 (0, _util.warn)('Required "glyf" table is not found -- trying to recover.');1654 tables['glyf'] = {1655 tag: 'glyf',1656 data: new Uint8Array(0)1657 };1658 }1659 this.isOpenType = false;1660 }1661 if (!tables['maxp']) {1662 throw new _util.FormatError('Required "maxp" table is not found');1663 }1664 font.pos = (font.start || 0) + tables['maxp'].offset;1665 var version = font.getInt32();1666 var numGlyphs = font.getUint16();1667 var maxFunctionDefs = 0;1668 var maxSizeOfInstructions = 0;1669 if (version >= 0x00010000 && tables['maxp'].length >= 22) {1670 font.pos += 8;1671 var maxZones = font.getUint16();1672 if (maxZones > 2) {1673 tables['maxp'].data[14] = 0;1674 tables['maxp'].data[15] = 2;1675 }1676 font.pos += 4;1677 maxFunctionDefs = font.getUint16();1678 font.pos += 6;1679 maxSizeOfInstructions = font.getUint16();1680 }1681 var dupFirstEntry = false;1682 if (properties.type === 'CIDFontType2' && properties.toUnicode && properties.toUnicode.get(0) > '\0') {1683 dupFirstEntry = true;1684 numGlyphs++;1685 tables['maxp'].data[4] = numGlyphs >> 8;1686 tables['maxp'].data[5] = numGlyphs & 255;1687 }1688 var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'], tables['cvt '], maxFunctionDefs);1689 if (!hintsValid) {1690 delete tables['fpgm'];1691 delete tables['prep'];1692 delete tables['cvt '];1693 }1694 sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);1695 if (!tables['head']) {1696 throw new _util.FormatError('Required "head" table is not found');1697 }1698 sanitizeHead(tables['head'], numGlyphs, isTrueType ? tables['loca'].length : 0);1699 var missingGlyphs = Object.create(null);1700 if (isTrueType) {1701 var isGlyphLocationsLong = int16(tables['head'].data[50], tables['head'].data[51]);1702 var glyphsInfo = sanitizeGlyphLocations(tables['loca'], tables['glyf'], numGlyphs, isGlyphLocationsLong, hintsValid, dupFirstEntry, maxSizeOfInstructions);1703 missingGlyphs = glyphsInfo.missingGlyphs;1704 if (version >= 0x00010000 && tables['maxp'].length >= 22) {1705 tables['maxp'].data[26] = glyphsInfo.maxSizeOfInstructions >> 8;1706 tables['maxp'].data[27] = glyphsInfo.maxSizeOfInstructions & 255;1707 }1708 }1709 if (!tables['hhea']) {1710 throw new _util.FormatError('Required "hhea" table is not found');1711 }1712 if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {...

Full Screen

Full Screen

Dashboard.js

Source:Dashboard.js Github

copy

Full Screen

1import React, { useState, useEffect } from 'react';2import DOMParserReact, { parse } from 'dom-parser-react';3import sanitizeHtml from 'sanitize-html';4import { Button, Card, CardBody, CardTitle, CardSubtitle, Container,Row,Col, Badge, Form, FormGroup, FormText, Label, Input, ListGroup, ListGroupItem, Dropdown, DropdownItem, DropdownToggle, DropdownMenu } from 'reactstrap';5const axios = require('axios');6export default function Dashboard() {7 const [uploaded, setUploaded] = useState([]);8 const [refresh, setRefresh] = useState(false);9 const [tableHead, setTableHead] = useState();10 const [summary, setSummary] = useState();11 const [csvSelected, setCsvSelected] = useState();12 useEffect(() => {13 axios.get('http://localhost:8000/csv')14 .then((res) => {15 if (res.data) {16 // let names = res.data17 // console.log('resData', res.data)18 const temp = res.data.map((item) => {19 item.csv_file = item.csv_file.slice(19)20 return item;21 })22 console.log('csv response: ', temp)23 setUploaded(temp);24 }25 })26 .catch((err) => {27 console.log('Csv error: ', err)28 })29 }, [refresh])30 const formData = new FormData();31 const [csv, setCsv] = useState();32 const [dropOpen, setDropOpen] = useState(false);33 const handleCsvDrop=()=>{34 setDropOpen(!dropOpen);35 }36 const onButton = () => {37 const start = new Date(Date.now())38 formData.append('csv_file', csv);39 axios.post('http://localhost:8000/csv',40 formData,41 {42 headers: {43 'Content-Type': 'multipart/form-data'44 }45 }46 )47 .then((data) => {48 console.log('Received: ', data);49 setRefresh(true);50 const end = new Date(Date.now())51 console.log('time required in ', end - start)52 })53 .catch((err) => {54 console.log('err:', err);55 })56 }57 const handleItemClick = (e, i) => {58 console.log("click", i);59 const start = new Date(Date.now())60 setCsvSelected(i);61 axios.get(`http://localhost:8000/csvDetails/${i.id}`)62 .then((res) => {63 if (res.data) {64 // let names = res.data65 console.log('resData', res.data)66 // const doc = new DOMParser().parseFromString(res.data.head, "text/html");67 // const htmlSections = doc.childNodes[0].childNodes[1].childNodes68 // console.log(doc.childNodes[0].childNodes[1].childNodes)69 // const sections = Object.keys(htmlSections).map((key, i) => {70 // const el = htmlSections[key];71 // const contents = [el.innerHTML];72 // return <div key={i}>{contents}</div>73 // })74 const sanitizeHead = sanitizeHtml(res.data.head,{ allowedTags: ['table', 'thead', 'tr', 'th', 'td'], }75 );76 setTableHead(sanitizeHead);77 const sanitize = sanitizeHtml(res.data.summary);78 setSummary(sanitize);79 const end = new Date(Date.now())80 console.log('time required in ', end - start)81 }82 })83 .catch((err) => {84 const end = new Date(Date.now())85 console.log('time required in ', end - start)86 console.log('Csv error: ', err)87 })88 }89 const fileChangeHandler = (file) => {90 if (!file) {91 setCsv('');92 return;93 }94 setCsv(file);95 console.log('CsvFIle:', typeof (file));96 }97 return (98 <Container>99 <Row className="d-flex">100 <Col xs="3" className="bg-light border">101 <div className="p-2 flex"><Card102 >103 <CardBody>104 <CardTitle tag="h5">105 Upload File106 </CardTitle>107 108 <Form>109 <FormGroup>110 {/* <Label for="exampleFile">111 File112 </Label> */}113 <Input114 id="exampleFile"115 name="file"116 type="file"117 onChange={(event) => { fileChangeHandler(event.target.files[0] || null) }}118 />119 </FormGroup>120 </Form>121 <Button color='primary' onClick={onButton}>122 Upload123 </Button>124 </CardBody>125 </Card></div>126 <div className="p-2 flex"><Card127 >128 <CardBody>129 <CardTitle tag="h5">130 Uploaded Files131 </CardTitle>132 {/* <ListGroup>133 {134 uploaded.map((item) => (135 <ListGroupItem action tag="button" onClick={(e) => handleItemClick(e, item)} key={item.id} href='#'>136 {item.csv_file}137 </ListGroupItem>138 ))139 }140 </ListGroup> */}141 <Dropdown isOpen={dropOpen} toggle={handleCsvDrop}>142 {143 csvSelected ?144 <DropdownToggle caret> 145 {csvSelected.csv_file}146 </DropdownToggle>147 :148 <DropdownToggle caret> 149 Select 150 </DropdownToggle>151 }152 <DropdownMenu color='primary' container="body">153 {154 uploaded.map((item) => (155 <DropdownItem onClick={(e) => handleItemClick(e, item)} key={item.id}>156 {item.csv_file}157 </DropdownItem>158 ))159 }160 161 </DropdownMenu>162 </Dropdown>163 </CardBody>164 </Card></div>165 166 </Col>167 <Col xs="9">168 <div className="w-100 m-3 p-2">169 <h5>Head</h5>170 {/* {171 tableHead && <DOMParserReact source={tableHead} />172 } */}173 <div dangerouslySetInnerHTML={{__html:tableHead}} />174 </div>175 <div className="w-100 m-3 p-2">176 <h5>Summary</h5>177 {178 // summary && <DOMParserReact source={summary} />179 180 }181 <div dangerouslySetInnerHTML={{__html:summary}} />182 </div>183 </Col>184 </Row>185 </Container>186 );...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 wpt.getTestStatus(data.data.testId, function(err, data) {4 if (data.statusCode == 200) {5 wpt.sanitizeHead(data.data.testId, function(err, data) {6 if (data.statusCode == 200) {7 console.log(data.data);8 }9 });10 }11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.sanitizeHead(options, function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.getLocations(function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.getBrowsers(function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.getTesters(function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.getTesters(function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.getTesters(function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.getTesters(function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var wpt = require('wpt');58wpt.getTesters(function(err, data) {59 if (err) {60 console.log(err);61 } else {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.sanitizeHead(url, function(err, data) {3 if (err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9});10var wpt = require('wpt');11wpt.getLocations(function(err, data) {12 if (err) {13 console.log(err);14 }15 else {16 console.log(data);17 }18});19var wpt = require('wpt');20wpt.getTesters(function(err, data) {21 if (err) {22 console.log(err);23 }24 else {25 console.log(data);26 }27});28var wpt = require('wpt');29wpt.getTesters(function(err, data) {30 if (err) {31 console.log(err);32 }33 else {34 console.log(data);35 }36});37var wpt = require('wpt');38wpt.getHAR('123456', function(err, data) {39 if (err) {40 console.log(err);41 }42 else {43 console.log(data);44 }45});46var wpt = require('wpt');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var options = {url: url};3wpt.sanitizeHead(options, function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org');12var wpt = new WebPageTest('www.webpagetest.org', 'A.1234567890abcdef1234567890abcdef');13module.exports = {14 sanitizeHead: function(options, callback) {15 wpt.sanitizeHead(options, function(err, data) {16 if (err) {17 callback(err);18 } else {19 callback(null, data);20 }21 });22 }23};24I am using the following code to import the module in my application:25var wpt = require('webpagetest');26I have also tried using the following code to import the module:27var wpt = require('./node_modules/webpagetest');28I have also tried using the following code to import the module:29var wpt = require('./node_modules/webpagetest/lib/webpagetest.js');30Google Chrome Version 39.0.2171.95 (64-bit)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt-api');2var url = "www.google.com";3var wptApi = new wpt();4wptApi.sanitizeHead(url, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var request = require('request');12function wpt() {13 this.sanitizeHead = function(url, callback) {14 var url = base_url + 'runtest.php?url=' + url + '&f=json&k=' + 'A.6b4d2d2e6c4e4e4c6c4d6d3f6b4d6d3f' + '&location=ec2-ap-southeast-1:Chrome&runs=1';15 request(url, function(error, response, body) {16 if (!error && response.statusCode == 200) {17 callback(null, body);18 } else {19 callback(error, null);20 }21 });22 }23}24module.exports = wpt;

Full Screen

Using AI Code Generation

copy

Full Screen

1wpt.sanitizeHead(url, options)2 .then((response) => {3 console.log(response);4 })5 .catch((error) => {6 console.log(error);7 });8wpt.getLocations(options)9 .then((response) => {10 console.log(response);11 })12 .catch((error) => {13 console.log(error);14 });15wpt.getTesters(options)16 .then((response) => {17 console.log(response);18 })19 .catch((error) => {20 console.log(error);21 });22wpt.getTestersByLocation(location, options)23 .then((response) => {24 console.log(response);25 })26 .catch((error) => {27 console.log(error);28 });29wpt.getTestersByLocation(location, options)30 .then((response) => {31 console.log(response);32 })33 .catch((error) => {34 console.log(error);35 });36wpt.getTestersByLocation(location, options)37 .then((response) => {38 console.log(response);39 })40 .catch((error) => {41 console.log(error);42 });43wpt.getTestersByLocation(location, options)44 .then((response) => {45 console.log(response);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful