Skip to content

Commit 853c34d

Browse files
Modernize variable declarations
1 parent 54cca08 commit 853c34d

File tree

3 files changed

+63
-68
lines changed

3 files changed

+63
-68
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The third usage option is with downloaded or CDN dist files
5858
<script src="jspdf.min.js"></script>
5959
<script src="jspdf.plugin.autotable.min.js"></script>
6060
<script>
61-
var doc = new jsPDF()
61+
const doc = new jsPDF()
6262
doc.autoTable({ html: '#my-table' })
6363
doc.save('table.pdf')
6464
</script>
@@ -226,7 +226,7 @@ To see what is included in the `Table`, `Row`, `Column` and `Cell` types, either
226226
autoTable(doc, {
227227
didDrawCell: (data) => {
228228
if (data.section === 'body' && data.column.index === 0) {
229-
var base64Img = 'data:image/jpeg;base64,iVBORw0KGgoAAAANS...'
229+
const base64Img = 'data:image/jpeg;base64,iVBORw0KGgoAAAANS...'
230230
doc.addImage(base64Img, 'JPEG', data.cell.x + 2, data.cell.y + 2, 10, 10)
231231
}
232232
},

examples/examples.js

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
| for a minimal example.
1313
*/
1414

15-
var faker = window.faker
15+
const faker = window.faker
1616

17-
var examples = {}
17+
const examples = {}
1818
window.examples = examples
1919

2020
// Basic - shows what a default table looks like
2121
examples.basic = function () {
22-
var doc = new jsPDF()
22+
const doc = new jsPDF()
2323

2424
// From HTML
2525
doc.autoTable({ html: '.table' })
2626

2727
// From Javascript
28-
var finalY = doc.lastAutoTable.finalY || 10
28+
let finalY = doc.lastAutoTable.finalY || 10
2929
doc.text('From javascript arrays', 14, finalY + 15)
3030
doc.autoTable({
3131
startY: finalY + 20,
@@ -59,7 +59,7 @@ examples.basic = function () {
5959

6060
// Minimal - shows how compact tables can be drawn
6161
examples.minimal = function () {
62-
var doc = new jsPDF()
62+
const doc = new jsPDF()
6363
doc.autoTable({
6464
html: '.table',
6565
tableWidth: 'wrap',
@@ -70,11 +70,11 @@ examples.minimal = function () {
7070

7171
// Long data - shows how the overflow features looks and can be used
7272
examples.long = function () {
73-
var doc = new jsPDF('l')
73+
const doc = new jsPDF('l')
7474

75-
var head = headRows()
75+
const head = headRows()
7676
head[0]['text'] = 'Text'
77-
var body = bodyRows(4)
77+
const body = bodyRows(4)
7878
body.forEach(function (row) {
7979
row['text'] = faker.lorem.sentence(100)
8080
})
@@ -107,17 +107,17 @@ examples.long = function () {
107107

108108
// Content - shows how tables can be integrated with any other pdf content
109109
examples.content = function () {
110-
var doc = new jsPDF()
110+
const doc = new jsPDF()
111111

112112
doc.setFontSize(18)
113113
doc.text('With content', 14, 22)
114114
doc.setFontSize(11)
115115
doc.setTextColor(100)
116116

117117
// jsPDF 1.4+ uses getWidth, <1.4 uses .width
118-
var pageSize = doc.internal.pageSize
119-
var pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth()
120-
var text = doc.splitTextToSize(faker.lorem.sentence(45), pageWidth - 35, {})
118+
const pageSize = doc.internal.pageSize
119+
const pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth()
120+
const text = doc.splitTextToSize(faker.lorem.sentence(45), pageWidth - 35, {})
121121
doc.text(text, 14, 30)
122122

123123
doc.autoTable({
@@ -134,12 +134,12 @@ examples.content = function () {
134134

135135
// Multiple - shows how multiple tables can be drawn both horizontally and vertically
136136
examples.multiple = function () {
137-
var doc = new jsPDF()
137+
const doc = new jsPDF()
138138
doc.text('Multiple tables', 14, 20)
139139

140140
doc.autoTable({ startY: 30, head: headRows(), body: bodyRows(25) })
141141

142-
var pageNumber = doc.internal.getNumberOfPages()
142+
const pageNumber = doc.internal.getNumberOfPages()
143143

144144
doc.autoTable({
145145
columns: [
@@ -169,7 +169,7 @@ examples.multiple = function () {
169169
margin: { left: 107 },
170170
})
171171

172-
for (var j = 0; j < 3; j++) {
172+
for (let j = 0; j < 3; j++) {
173173
doc.autoTable({
174174
head: headRows(),
175175
body: bodyRows(),
@@ -183,8 +183,8 @@ examples.multiple = function () {
183183

184184
// Header and footers - shows how header and footers can be drawn
185185
examples['header-footer'] = function () {
186-
var doc = new jsPDF()
187-
var totalPagesExp = '{total_pages_count_string}'
186+
const doc = new jsPDF()
187+
const totalPagesExp = '{total_pages_count_string}'
188188

189189
doc.autoTable({
190190
head: headRows(),
@@ -200,16 +200,18 @@ examples['header-footer'] = function () {
200200
},
201201
didDrawPage: function (data) {
202202
// Footer
203-
var str = 'Page ' + doc.internal.getNumberOfPages()
203+
let str = 'Page ' + doc.internal.getNumberOfPages()
204204
// Total page number plugin only available in jspdf v1.0+
205205
if (typeof doc.putTotalPages === 'function') {
206206
str = str + ' of ' + totalPagesExp
207207
}
208208
doc.setFontSize(10)
209209

210210
// jsPDF 1.4+ uses getHeight, <1.4 uses .height
211-
var pageSize = doc.internal.pageSize
212-
var pageHeight = pageSize.height ? pageSize.height : pageSize.getHeight()
211+
const pageSize = doc.internal.pageSize
212+
const pageHeight = pageSize.height
213+
? pageSize.height
214+
: pageSize.getHeight()
213215
doc.text(str, data.settings.margin.left, pageHeight - 10)
214216
},
215217
margin: { top: 30 },
@@ -231,7 +233,7 @@ examples.defaults = function () {
231233
headStyles: { fillColor: 0 },
232234
})
233235

234-
var doc = new jsPDF()
236+
const doc = new jsPDF()
235237

236238
doc.text('Global options (black header)', 15, 20)
237239
doc.autoTable({ head: headRows(), body: bodyRows(5), startY: 25 })
@@ -241,22 +243,22 @@ examples.defaults = function () {
241243
{
242244
headStyles: { fillColor: [155, 89, 182] }, // Purple
243245
didDrawPage: function (data) {
244-
var finalY = doc.lastAutoTable.finalY + 15
245-
var leftMargin = data.settings.margin.left
246+
const finalY = doc.lastAutoTable.finalY + 15
247+
const leftMargin = data.settings.margin.left
246248
doc.text('Default options (purple header)', leftMargin, finalY)
247249
},
248250
},
249251
doc,
250252
)
251253

252-
var startY = doc.lastAutoTable.finalY + 20
254+
const startY = doc.lastAutoTable.finalY + 20
253255
doc.autoTable({ head: headRows(), body: bodyRows(5), startY: startY })
254256

255257
// Reset defaults
256258
doc.autoTableSetDefaults(null)
257259
jsPDF.autoTableSetDefaults(null)
258260

259-
var finalY = doc.lastAutoTable.finalY
261+
const finalY = doc.lastAutoTable.finalY
260262
doc.text('After reset (blue header)', 15, finalY + 15)
261263
doc.autoTable({ head: headRows(), body: bodyRows(5), startY: finalY + 20 })
262264

@@ -265,7 +267,7 @@ examples.defaults = function () {
265267

266268
// Column styles - shows how tables can be drawn with specific column styles
267269
examples.colstyles = function () {
268-
var doc = new jsPDF()
270+
const doc = new jsPDF()
269271
doc.autoTable({
270272
head: headRows(),
271273
body: bodyRows(),
@@ -283,15 +285,15 @@ examples.colstyles = function () {
283285

284286
// Col spans and row spans
285287
examples.spans = function () {
286-
var doc = new jsPDF('p', 'pt')
288+
const doc = new jsPDF('p', 'pt')
287289
doc.text('Rowspan and colspan', 40, 50)
288290

289-
var raw = bodyRows(40)
290-
var body = []
291+
const raw = bodyRows(40)
292+
const body = []
291293

292-
for (var i = 0; i < raw.length; i++) {
293-
var row = []
294-
for (var key in raw[i]) {
294+
for (let i = 0; i < raw.length; i++) {
295+
const row = []
296+
for (let key in raw[i]) {
295297
row.push(raw[i][key])
296298
}
297299
if (i % 5 === 0) {
@@ -323,7 +325,7 @@ examples.spans = function () {
323325

324326
// Themes - shows how the different themes looks
325327
examples.themes = function () {
326-
var doc = new jsPDF()
328+
const doc = new jsPDF()
327329

328330
doc.text('Theme "striped"', 14, 16)
329331
doc.autoTable({ head: headRows(), body: bodyRows(5), startY: 20 })
@@ -349,11 +351,11 @@ examples.themes = function () {
349351

350352
// Nested tables
351353
examples.nested = function () {
352-
var doc = new jsPDF()
354+
const doc = new jsPDF()
353355
doc.text('Nested tables', 14, 16)
354356

355-
var nestedTableHeight = 100
356-
var nestedTableCell = {
357+
const nestedTableHeight = 100
358+
const nestedTableCell = {
357359
content: '',
358360
// Dynamic height of nested tables are not supported right now
359361
// so we need to define height of the parent cell
@@ -390,7 +392,7 @@ examples.nested = function () {
390392

391393
// Custom style - shows how custom styles can be applied
392394
examples.custom = function () {
393-
var doc = new jsPDF()
395+
const doc = new jsPDF()
394396
doc.autoTable({
395397
head: headRows(),
396398
body: bodyRows(),
@@ -505,7 +507,7 @@ examples.custom = function () {
505507

506508
// Custom style - shows how custom styles can be applied
507509
examples.borders = function () {
508-
var doc = new jsPDF()
510+
const doc = new jsPDF()
509511
doc.autoTable({
510512
head: headRows(),
511513
body: bodyRows(3),
@@ -635,16 +637,16 @@ examples.borders = function () {
635637

636638
// Split columns - shows how the overflowed columns split into pages
637639
examples.horizontalPageBreak = function () {
638-
var doc = new jsPDF('l')
640+
const doc = new jsPDF('l')
639641

640-
var head = headRows()
642+
const head = headRows()
641643
head[0].region = 'Region'
642644
head[0].country = 'Country'
643645
head[0].zipcode = 'Zipcode'
644646
head[0].phone = 'Phone'
645647
// head[0].timeZone = 'Timezone';
646648
head[0]['text'] = 'Text'
647-
var body = bodyRows(4)
649+
const body = bodyRows(4)
648650
body.forEach(function (row) {
649651
row['text'] = faker.lorem.sentence(100)
650652
row['zipcode'] = faker.address.zipCode()
@@ -669,16 +671,16 @@ examples.horizontalPageBreak = function () {
669671

670672
// Split columns - shows how the overflowed columns split into pages with a given column repeated
671673
examples.horizontalPageBreakRepeat = function () {
672-
var doc = new jsPDF('l')
674+
const doc = new jsPDF('l')
673675

674-
var head = headRows()
676+
const head = headRows()
675677
head[0].region = 'Region'
676678
head[0].country = 'Country'
677679
head[0].zipcode = 'Zipcode'
678680
head[0].phone = 'Phone'
679681
// head[0].timeZone = 'Timezone';
680682
head[0]['text'] = 'Text'
681-
var body = bodyRows(4)
683+
const body = bodyRows(4)
682684
body.forEach(function (row) {
683685
row['text'] = faker.lorem.sentence(15)
684686
row['zipcode'] = faker.address.zipCode()
@@ -707,16 +709,16 @@ examples.horizontalPageBreakRepeat = function () {
707709

708710
// Split columns - shows how to alter the behaviour of columns that split into pages
709711
examples.horizontalPageBreakBehaviour = function () {
710-
var doc = new jsPDF('l')
712+
const doc = new jsPDF('l')
711713

712-
var head = headRows()
714+
const head = headRows()
713715
head[0].region = 'Region'
714716
head[0].country = 'Country'
715717
head[0].zipcode = 'Zipcode'
716718
head[0].phone = 'Phone'
717719
head[0].datetime = 'DateTime'
718720
head[0].text = 'Text'
719-
var body = bodyRows(50)
721+
const body = bodyRows(50)
720722
body.forEach(function (row) {
721723
row['text'] = faker.lorem.sentence(10)
722724
row['zipcode'] = faker.address.zipCode()
@@ -774,8 +776,8 @@ function columns() {
774776

775777
function data(rowCount) {
776778
rowCount = rowCount || 10
777-
var body = []
778-
for (var j = 1; j <= rowCount; j++) {
779+
const body = []
780+
for (let j = 1; j <= rowCount; j++) {
779781
body.push({
780782
id: j,
781783
name: faker.name.findName(),
@@ -789,8 +791,8 @@ function data(rowCount) {
789791

790792
function bodyRows(rowCount) {
791793
rowCount = rowCount || 10
792-
var body = []
793-
for (var j = 1; j <= rowCount; j++) {
794+
const body = []
795+
for (let j = 1; j <= rowCount; j++) {
794796
body.push({
795797
id: j,
796798
name: faker.name.findName(),

0 commit comments

Comments
 (0)