Skip to content

Commit 90f672a

Browse files
docs(samples): modernize the samples (#838)
1 parent 75a9b53 commit 90f672a

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
rules:
33
no-console: off
4+
node/no-unsupported-features/node-builtins: off

packages/google-cloud-vision/samples/package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "nodejs-docs-samples-vision",
33
"private": true,
44
"license": "Apache-2.0",
5-
"author": "Google Inc.",
5+
"author": "Google LLC",
66
"engines": {
7-
"node": ">=8"
7+
"node": ">=10.17.0"
88
},
99
"files": [
1010
"*.js"
@@ -14,7 +14,6 @@
1414
},
1515
"dependencies": {
1616
"@google-cloud/vision": "^2.1.2",
17-
"mathjs": "^7.0.0",
1817
"natural": "^2.0.0",
1918
"pureimage": "^0.2.1",
2019
"redis": "^3.0.0",

packages/google-cloud-vision/samples/quickstart.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,33 @@
1414

1515
'use strict';
1616

17-
// [START vision_quickstart]
18-
async function quickstart() {
19-
// Imports the Google Cloud client library
20-
const vision = require('@google-cloud/vision');
17+
// sample-metadata:
18+
// title: Cloud Vision Quickstart
19+
// description: Performs label detection of an image with a cat.
20+
// usage: node quickstart.js
2121

22-
// Creates a client
23-
const client = new vision.ImageAnnotatorClient();
22+
function main() {
23+
// [START vision_quickstart]
24+
async function quickstart() {
25+
// Imports the Google Cloud client library
26+
const vision = require('@google-cloud/vision');
2427

25-
// Performs label detection on the image file
26-
const [result] = await client.labelDetection('./resources/wakeupcat.jpg');
27-
const labels = result.labelAnnotations;
28-
console.log('Labels:');
29-
labels.forEach(label => console.log(label.description));
28+
// Creates a client
29+
const client = new vision.ImageAnnotatorClient();
30+
31+
// Performs label detection on the image file
32+
const [result] = await client.labelDetection('./resources/wakeupcat.jpg');
33+
const labels = result.labelAnnotations;
34+
console.log('Labels:');
35+
labels.forEach(label => console.log(label.description));
36+
}
37+
quickstart();
38+
// [END vision_quickstart]
3039
}
31-
// [END vision_quickstart]
3240

33-
quickstart().catch(console.error);
41+
process.on('unhandledRejection', err => {
42+
console.error(err.message);
43+
process.exitCode = 1;
44+
});
45+
46+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)