Skip to content

Commit

Permalink
docs: replace var in with let/const
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn committed Apr 12, 2024
1 parent 41cc568 commit ac4fcbd
Show file tree
Hide file tree
Showing 42 changed files with 182 additions and 181 deletions.
16 changes: 8 additions & 8 deletions docs/_guides/attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ db.put({
}).then(function () {
return db.getAttachment('meowth', 'meowth.png');
}).then(function (blob) {
var url = URL.createObjectURL(blob);
var img = document.createElement('img');
const url = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img);
}).catch(function (err) {
Expand Down Expand Up @@ -150,16 +150,16 @@ For instance, we can read the image data from an `<img>` tag using a `canvas` el

```js
function convertImgToBlob(img, callback) {
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0);

// Warning: toBlob() isn't supported by every browser.
// You may want to use blob-util.
canvas.toBlob(callback, 'image/png');
}

var catImage = document.getElementById('cat');
const catImage = document.getElementById('cat');
convertImgToBlob(catImage, function (blob) {
db.putAttachment('meowth', 'meowth.png', blob, 'image/png').then(function () {
return db.get('meowth', {attachments: true});
Expand Down Expand Up @@ -196,9 +196,9 @@ Here is an example of allowing a user to choose a file from their filesystem:
And then "uploading" that file directly into PouchDB:

```js
var input = document.querySelector('input');
const input = document.querySelector('input');
input.addEventListener('change', function () {
var file = input.files[0]; // file is a Blob
const file = input.files[0]; // file is a Blob

db.put({
_id: 'mydoc',
Expand Down Expand Up @@ -285,7 +285,7 @@ The other "read" APIs, such as `get()`, `allDocs()`, `changes()`, and `query()`
Blobs have their own `type`, but there is also a `content_type` that you specify when you store it in PouchDB:

```js
var myBlob = new Blob(['I am plain text!'], {type: 'text/plain'});
const myBlob = new Blob(['I am plain text!'], {type: 'text/plain'});
console.log(myBlob.type); // 'text/plain'

db.put({
Expand Down
4 changes: 2 additions & 2 deletions docs/_guides/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Also notice the option `{include_docs: true}`. By default, the documents themsel
If you expect this to be a very large number of changes, you can also use the `limit` option to do pagination:

```js
var pageSize = 10;
var lastSeq = 0;
const pageSize = 10;
let lastSeq = 0;
function fetchNextPage() {
return db.changes({
since: lastSeq,
Expand Down
2 changes: 1 addition & 1 deletion docs/_guides/compact-and-destroy.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ However, if that's not a concern, then compaction is a harmless operation. In fa
If you really want to go all-in on compaction, then you can even put your database in `auto_compaction` mode. This means that it will automatically perform a `compact()` operation after every write.

```js
var db = new PouchDB('mydb', {auto_compaction: true});
const db = new PouchDB('mydb', {auto_compaction: true});
db.put({_id: 'foo', version: 1}).then(function () {
return db.get('foo');
}).then(function (doc) {
Expand Down
2 changes: 1 addition & 1 deletion docs/_guides/conflicts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ In CouchDB, conflicts can occur in two places: immediately, when you try to comm
**Immediate conflicts** can occur with any API that takes a `rev` or a document with `_rev` as input &ndash; `put()`, `post()`, `remove()`, `bulkDocs()`, and `putAttachment()`. They manifest as a `409` (conflict) error:

```js
var myDoc = {
const myDoc = {
_id: 'someid',
_rev: '1-somerev'
};
Expand Down
4 changes: 2 additions & 2 deletions docs/_guides/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PouchDB databases come in two flavors: local and remote.
To create a local database, you simply call `new PouchDB` and give it a name:

```js
var db = new PouchDB('kittens');
const db = new PouchDB('kittens');
```

You can see a **[live example](http://bl.ocks.org/nolanlawson/bddac54b92c2d8d39241)** of this code.
Expand All @@ -37,7 +37,7 @@ Now the site is up and running at <a href='http://localhost:8000'>http://localho
To create a remote database, you call `new PouchDB` and give it a path to a database in CouchDB.

```js
var db = new PouchDB('http://localhost:5984/kittens');
const db = new PouchDB('http://localhost:5984/kittens');
```

{% include alert/start.html variant="info" %}
Expand Down
2 changes: 1 addition & 1 deletion docs/_guides/documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ We'll discuss these concepts later on.
To store a document, you simply `put` it:

```js
var doc = {
const doc = {
"_id": "mittens",
"name": "Mittens",
"occupation": "kitten",
Expand Down
2 changes: 1 addition & 1 deletion docs/_guides/mango-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you are using Node, Browserify, Webpack, Rollup, etc., then you can install i
Then in code:

```js
var PouchDB = require('pouchdb');
const PouchDB = require('pouchdb');
PouchDB.plugin(require('pouchdb-find'));
```

Expand Down
4 changes: 2 additions & 2 deletions docs/_guides/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ First, you create a **design document**, which describes the `map` function you
```js
// document that tells PouchDB/CouchDB
// to build up an index on doc.name
var ddoc = {
const ddoc = {
_id: '_design/my_index',
views: {
by_name: {
Expand Down Expand Up @@ -203,7 +203,7 @@ As for _reduce_ functions, there are a few handy built-ins that do aggregate ope

```js
// emit the first letter of each pokemon's name
var myMapReduceFun = {
const myMapReduceFun = {
map: function (doc) {
emit(doc.name.charAt(0));
},
Expand Down
8 changes: 4 additions & 4 deletions docs/_guides/replication.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ In this way, CouchDB replication "just works."
As you already know, you can create either local PouchDBs:

```js
var localDB = new PouchDB('mylocaldb')
const localDB = new PouchDB('mylocaldb')
```

or remote PouchDBs:

```js
var remoteDB = new PouchDB('http://localhost:5984/myremotedb')
const remoteDB = new PouchDB('http://localhost:5984/myremotedb')
```

This pattern comes in handy when you want to share data between the two.
Expand Down Expand Up @@ -132,7 +132,7 @@ This is ideal for scenarios where the user may be flitting in and out of connect
Sometimes, you may want to manually cancel replication &ndash; for instance, because the user logged out. You can do so by calling `cancel()` and then waiting for the `'complete'` event:

```js
var syncHandler = localDB.sync(remoteDB, {
const syncHandler = localDB.sync(remoteDB, {
live: true,
retry: true
});
Expand All @@ -147,7 +147,7 @@ syncHandler.cancel(); // <-- this cancels it
The `replicate` API also supports canceling:

```js
var replicationHandler = localDB.replicate.to(remoteDB, {
const replicationHandler = localDB.replicate.to(remoteDB, {
live: true,
retry: true
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_guides/setup-pouchdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ npm install pouchdb
Then in your JavaScript:

```js
var PouchDB = require('pouchdb');
const PouchDB = require('pouchdb');
```

{% include anchor.html title="With TypeScript" hash="typescript" %}
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/api/active_tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#### Example Usage:

{% highlight js %}
var tasks = PouchDB.activeTasks.list()
const tasks = PouchDB.activeTasks.list()
{% endhighlight %}

#### Example Result:
Expand Down
8 changes: 4 additions & 4 deletions docs/_includes/api/batch_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% include code/start.html id="bulk_docs_1" type="async" %}
{% highlight js %}
try {
var result = await db.bulkDocs([
const result = await db.bulkDocs([
{title : 'Lisa Says', _id: 'doc1'},
{title : 'Space Oddity', _id: 'doc2'}
]);
Expand Down Expand Up @@ -67,7 +67,7 @@
{% include code/start.html id="bulk_docs_2" type="async" %}
{% highlight js %}
try {
var result = await db.bulkDocs([
const result = await db.bulkDocs([
{title : 'Lisa Says'},
{title : 'Space Oddity'}
]);
Expand Down Expand Up @@ -155,7 +155,7 @@
{% include code/start.html id="bulk_docs3" type="async" %}
{% highlight js %}
try {
var result = await db.bulkDocs([
const result = await db.bulkDocs([
{
title : 'Lisa Says',
artist : 'Velvet Underground',
Expand Down Expand Up @@ -225,7 +225,7 @@
{% include code/start.html id="bulk_docs_4" type="async" %}
{% highlight js %}
try {
var result = await db.bulkDocs([
const result = await db.bulkDocs([
{
title : 'Lisa Says',
_deleted : true,
Expand Down
6 changes: 3 additions & 3 deletions docs/_includes/api/batch_fetch.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{% include code/start.html id="all_docs" type="async" %}
{% highlight js %}
try {
var result = await db.allDocs({
const result = await db.allDocs({
include_docs: true,
attachments: true
});
Expand Down Expand Up @@ -125,7 +125,7 @@
{% include code/start.html id="all_docs_2" type="async" %}
{% highlight js %}
try {
var result = await db.allDocs({
const result = await db.allDocs({
include_docs: true,
attachments: true,
startkey: 'bar',
Expand Down Expand Up @@ -175,7 +175,7 @@
{% include code/start.html id="all_docs_3" type="async" %}
{% highlight js %}
try {
var result = await db.allDocs({
const result = await db.allDocs({
include_docs: true,
attachments: true,
startkey: 'foo',
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/api/bulk_get.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% include code/start.html id="bulkget1" type="async" %}
{% highlight js %}
try {
var result = await db.bulkGet({
const result = await db.bulkGet({
docs: [
{ id: "doc-that-exists", rev: "1-967a00dff5e02add41819138abb3284d"},
{ id: "doc-that-does-not-exist", rev: "1-3a24009a9525bde9e4bfa8a99046b00d"},
Expand Down
4 changes: 2 additions & 2 deletions docs/_includes/api/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#### Example Usage:

{% highlight js %}
var changes = db.changes({
const changes = db.changes({
since: 'now',
live: true,
include_docs: true
Expand Down Expand Up @@ -161,7 +161,7 @@
{% include code/start.html id="changes1" type="async" %}
{% highlight js %}
try {
var result = await db.changes({
const result = await db.changes({
limit: 10,
since: 0
});
Expand Down
2 changes: 1 addition & 1 deletion docs/_includes/api/compaction.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% include code/start.html id="compact" type="async" %}
{% highlight js %}
try {
var result = await db.compact();
const result = await db.compact();
} catch (err) {
console.log(err);
}
Expand Down
8 changes: 4 additions & 4 deletions docs/_includes/api/create_database.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@

#### Example Usage:
{% highlight js %}
var db = new PouchDB('dbname');
const db = new PouchDB('dbname');
// or
var db = new PouchDB('http://localhost:5984/dbname');
const db = new PouchDB('http://localhost:5984/dbname');
{% endhighlight %}

Create an in-memory Pouch (must install `pouchdb-adapter-memory` first):

{% highlight js %}
var db = new PouchDB('dbname', {adapter: 'memory'});
const db = new PouchDB('dbname', {adapter: 'memory'});
{% endhighlight %}

Create a remote PouchDB with special fetch options:

{% highlight js %}
var db = new PouchDB('http://example.com/dbname', {
const db = new PouchDB('http://example.com/dbname', {
fetch: function (url, opts) {
opts.headers.set('X-Some-Special-Header', 'foo');
return PouchDB.fetch(url, opts);
Expand Down
8 changes: 4 additions & 4 deletions docs/_includes/api/create_document.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% include code/start.html id="newDoc" type="async" %}
{% highlight js %}
try {
var response = await db.put({
const response = await db.put({
_id: 'mydoc',
title: 'Heroes'
});
Expand Down Expand Up @@ -74,8 +74,8 @@
{% include code/start.html id="updateDoc" type="async" %}
{% highlight js %}
try {
var doc = await db.get('mydoc');
var response = await db.put({
const doc = await db.get('mydoc');
const response = await db.put({
_id: 'mydoc',
_rev: doc._rev,
title: "Let's Dance"
Expand Down Expand Up @@ -139,7 +139,7 @@
{% include code/start.html id="post_doc" type="async" %}
{% highlight js %}
try {
var response = await db.post({
const response = await db.post({
title: 'Ziggy Stardust'
});
} catch (err) {
Expand Down
12 changes: 6 additions & 6 deletions docs/_includes/api/create_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% include code/start.html id="create_idx" type="async" %}
{% highlight js %}
try {
var result = await db.createIndex({
const result = await db.createIndex({
index: {
fields: ['foo']
}
Expand Down Expand Up @@ -90,7 +90,7 @@
{% include code/start.html id="create_idx2" type="async" %}
{% highlight js %}
try {
var result = await db.createIndex({
const result = await db.createIndex({
index: {
fields: ['foo', 'bar', 'baz']
}
Expand Down Expand Up @@ -133,7 +133,7 @@
{% include code/start.html id="create_idx3" type="async" %}
{% highlight js %}
try {
var result = await db.createIndex({
const result = await db.createIndex({
index: {
fields: ['person.address.zipcode']
}
Expand Down Expand Up @@ -179,7 +179,7 @@
{% include code/start.html id="create_idx4" type="async" %}
{% highlight js %}
try {
var result = await db.createIndex({
const result = await db.createIndex({
index: {
fields: ['foo', 'bar'],
name: 'myindex',
Expand Down Expand Up @@ -242,7 +242,7 @@
{% include code/start.html id="create_idx5" type="async" %}
{% highlight js %}
try {
var result = db.createIndex({
const result = db.createIndex({
index: {
fields: ['year', 'title'],
partial_filter_selector: {
Expand Down Expand Up @@ -284,7 +284,7 @@
When a PouchDB instance updates an index, it emits `indexing` events that include information about the progress of the index update task.

{% highlight js %}
var db = new PouchDB('my-docs');
const db = new PouchDB('my-docs');

db.on('indexing', function (event) {
// called when indexes are updated
Expand Down
Loading

0 comments on commit ac4fcbd

Please sign in to comment.