Skip to content

Commit

Permalink
Enable no-var in eslint (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and alexander-fenster committed Sep 18, 2018
1 parent 4db80be commit f789569
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
24 changes: 12 additions & 12 deletions vision/samples/faceDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var vision = require('@google-cloud/vision');
let vision = require('@google-cloud/vision');
// [END vision_face_detection_tutorial_imports]
// [START vision_face_detection_tutorial_client]
// Creates a client
var client = new vision.ImageAnnotatorClient();
let client = new vision.ImageAnnotatorClient();

var fs = require('fs');
let fs = require('fs');
// [END vision_face_detection_tutorial_client]

/**
Expand All @@ -40,7 +40,7 @@ function detectFaces(inputFile, callback) {
.faceDetection(request)
.then(results => {
const faces = results[0].faceAnnotations;
var numFaces = faces.length;
let numFaces = faces.length;
console.log('Found ' + numFaces + (numFaces === 1 ? ' face' : ' faces'));
callback(null, faces);
})
Expand All @@ -61,12 +61,12 @@ function highlightFaces(inputFile, faces, outputFile, Canvas, callback) {
return callback(err);
}

var Image = Canvas.Image;
let Image = Canvas.Image;
// Open the original image into a canvas
var img = new Image();
let img = new Image();
img.src = image;
var canvas = new Canvas(img.width, img.height);
var context = canvas.getContext('2d');
let canvas = new Canvas(img.width, img.height);
let context = canvas.getContext('2d');
context.drawImage(img, 0, 0, img.width, img.height);

// Now draw boxes around all the faces
Expand All @@ -90,8 +90,8 @@ function highlightFaces(inputFile, faces, outputFile, Canvas, callback) {

// Write the result to a file
console.log('Writing to file ' + outputFile);
var writeStream = fs.createWriteStream(outputFile);
var pngStream = canvas.pngStream();
let writeStream = fs.createWriteStream(outputFile);
let pngStream = canvas.pngStream();

pngStream.on('data', chunk => {
writeStream.write(chunk);
Expand Down Expand Up @@ -131,7 +131,7 @@ if (module === require.main) {
// eslint-disable-next-line no-process-exit
process.exit(1);
}
var inputFile = process.argv[2];
var outputFile = process.argv[3];
let inputFile = process.argv[2];
let outputFile = process.argv[3];
exports.main(inputFile, outputFile, require('canvas'), console.log);
}
58 changes: 29 additions & 29 deletions vision/samples/textDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@

'use strict';

var async = require('async');
var fs = require('fs');
var path = require('path');
let async = require('async');
let fs = require('fs');
let path = require('path');

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var vision = require('@google-cloud/vision');
var natural = require('natural');
var redis = require('redis');
let vision = require('@google-cloud/vision');
let natural = require('natural');
let redis = require('redis');

// Instantiate a vision client
var client = new vision.ImageAnnotatorClient();
let client = new vision.ImageAnnotatorClient();

function Index() {
// Connect to a redis server.
var TOKEN_DB = 0;
var DOCS_DB = 1;
var PORT = process.env.REDIS_PORT || '6379';
var HOST = process.env.REDIS_HOST || '127.0.0.1';
let TOKEN_DB = 0;
let DOCS_DB = 1;
let PORT = process.env.REDIS_PORT || '6379';
let HOST = process.env.REDIS_HOST || '127.0.0.1';

this.tokenClient = redis
.createClient(PORT, HOST, {
Expand All @@ -59,12 +59,12 @@ Index.prototype.quit = function() {
};

Index.prototype.add = function(filename, document, callback) {
var self = this;
var PUNCTUATION = ['.', ',', ':', ''];
var tokenizer = new natural.WordTokenizer();
var tokens = tokenizer.tokenize(document);
let self = this;
let PUNCTUATION = ['.', ',', ':', ''];
let tokenizer = new natural.WordTokenizer();
let tokens = tokenizer.tokenize(document);

var tasks = tokens
let tasks = tokens
.filter(function(token) {
return PUNCTUATION.indexOf(token) === -1;
})
Expand All @@ -82,8 +82,8 @@ Index.prototype.add = function(filename, document, callback) {
};

Index.prototype.lookup = function(words, callback) {
var self = this;
var tasks = words.map(function(word) {
let self = this;
let tasks = words.map(function(word) {
word = word.toLowerCase();
return function(cb) {
self.tokenClient.smembers(word, cb);
Expand Down Expand Up @@ -114,7 +114,7 @@ Index.prototype.setContainsNoText = function(filename, callback) {
};

function lookup(words, callback) {
var index = new Index();
let index = new Index();
index.lookup(words, function(err, hits) {
index.quit();
if (err) {
Expand All @@ -128,7 +128,7 @@ function lookup(words, callback) {
}

function extractDescription(texts) {
var document = '';
let document = '';
texts.forEach(function(text) {
document += text.description || '';
});
Expand Down Expand Up @@ -158,10 +158,10 @@ function getTextFromFiles(index, inputFiles, callback) {
.batchAnnotateImages({requests: requests})
.then(results => {
let detections = results[0].responses;
var textResponse = {};
var tasks = [];
let textResponse = {};
let tasks = [];
inputFiles.forEach(function(filename, i) {
var response = detections[i];
let response = detections[i];
if (response.error) {
console.log('API Error for ' + filename, response.error);
return;
Expand All @@ -186,7 +186,7 @@ function getTextFromFiles(index, inputFiles, callback) {

// Run the example
function main(inputDir, callback) {
var index = new Index();
let index = new Index();

async.waterfall(
[
Expand All @@ -198,7 +198,7 @@ function main(inputDir, callback) {
function(files, cb) {
async.parallel(
files.map(function(file) {
var filename = path.join(inputDir, file);
let filename = path.join(inputDir, file);
return function(cb) {
fs.stat(filename, function(err, stats) {
if (err) {
Expand All @@ -216,7 +216,7 @@ function main(inputDir, callback) {
},
// Figure out which files have already been processed
function(allImageFiles, cb) {
var tasks = allImageFiles
let tasks = allImageFiles
.filter(function(filename) {
return filename;
})
Expand Down Expand Up @@ -256,16 +256,16 @@ function main(inputDir, callback) {
}

if (module === require.main) {
var generalError =
let generalError =
'Usage: node textDetection <command> <arg> ...\n\n' +
'\tCommands: analyze, lookup';
if (process.argv.length < 3) {
console.log(generalError);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
var args = process.argv.slice(2);
var command = args.shift();
let args = process.argv.slice(2);
let command = args.shift();
if (command === 'analyze') {
if (!args.length) {
console.log('Usage: node textDetection analyze <dir>');
Expand Down

0 comments on commit f789569

Please sign in to comment.