Skip to content

Commit 47bc245

Browse files
alexander-fensterbcoexiaozhenliu-gg5
authored
feat!: drop node8 support, support for async iterators (#568)
* feat!: drop node8 support, support for async iterators BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration. * fix tests & linter Co-authored-by: Benjamin E. Coe <[email protected]> Co-authored-by: Xiaozhen Liu <[email protected]>
1 parent 2cc70bb commit 47bc245

24 files changed

+203
-211
lines changed

vision/samples/async-batch-annotate-images.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,20 @@ function main(
3636
async function asyncBatchAnnotateImages() {
3737
// Set the type of annotation you want to perform on the image
3838
// https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.Feature.Type
39-
const features = [
40-
{type: 'LABEL_DETECTION'},
41-
];
39+
const features = [{type: 'LABEL_DETECTION'}];
4240

4341
// Build the image request object for that one image. Note: for additional images you have to create
44-
// additional image request objects and store them in a list to be used below.
42+
// additional image request objects and store them in a list to be used below.
4543
const imageRequest = {
4644
image: {
4745
source: {
4846
imageUri: inputImageUri,
4947
},
5048
},
5149
features: features,
52-
}
50+
};
5351

54-
// Set where to store the results for the images that will be annotated.
52+
// Set where to store the results for the images that will be annotated.
5553
const outputConfig = {
5654
gcsDestination: {
5755
uri: outputUri,

vision/samples/batch-annotate-files-gcs.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ function main(
6161

6262
// Add each `AnnotateFileRequest` object to the batch request.
6363
const request = {
64-
requests: [
65-
fileRequest,
66-
],
64+
requests: [fileRequest],
6765
};
6866

6967
// Make the synchronous batch request.
@@ -74,7 +72,7 @@ function main(
7472
const responses = result.responses[0].responses;
7573

7674
for (const response of responses) {
77-
console.log(`Full text: ${response.fullTextAnnotation.text}`)
75+
console.log(`Full text: ${response.fullTextAnnotation.text}`);
7876
for (const page of response.fullTextAnnotation.pages) {
7977
for (const block of page.blocks) {
8078
console.log(`Block confidence: ${block.confidence}`);

vision/samples/batch-annotate-files.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
'use strict';
1616

17-
function main(
18-
fileName = 'path/to/your/file.pdf'
19-
) {
17+
function main(fileName = 'path/to/your/file.pdf') {
2018
// [START vision_batch_annotate_files]
2119
/**
2220
* TODO(developer): Uncomment these variables before running the sample.
@@ -62,9 +60,7 @@ function main(
6260

6361
// Add each `AnnotateFileRequest` object to the batch request.
6462
const request = {
65-
requests: [
66-
fileRequest,
67-
],
63+
requests: [fileRequest],
6864
};
6965

7066
// Make the synchronous batch request.
@@ -75,7 +71,7 @@ function main(
7571
const responses = result.responses[0].responses;
7672

7773
for (const response of responses) {
78-
console.log(`Full text: ${response.fullTextAnnotation.text}`)
74+
console.log(`Full text: ${response.fullTextAnnotation.text}`);
7975
for (const page of response.fullTextAnnotation.pages) {
8076
for (const block of page.blocks) {
8177
console.log(`Block confidence: ${block.confidence}`);

vision/samples/detect.js

+75-75
Original file line numberDiff line numberDiff line change
@@ -742,179 +742,179 @@ async function localizeObjectsGCS(gcsUri) {
742742
require(`yargs`) // eslint-disable-line
743743
.demand(1)
744744
.command(
745-
`faces <fileName>`,
746-
`Detects faces in a local image file.`,
745+
'faces <fileName>',
746+
'Detects faces in a local image file.',
747747
{},
748748
opts => detectFaces(opts.fileName)
749749
)
750750
.command(
751-
`faces-gcs <bucketName> <fileName>`,
752-
`Detects faces in an image in Google Cloud Storage.`,
751+
'faces-gcs <bucketName> <fileName>',
752+
'Detects faces in an image in Google Cloud Storage.',
753753
{},
754754
opts => detectFacesGCS(opts.bucketName, opts.fileName)
755755
)
756756
.command(
757-
`labels <fileName>`,
758-
`Detects labels in a local image file.`,
757+
'labels <fileName>',
758+
'Detects labels in a local image file.',
759759
{},
760760
opts => detectLabels(opts.fileName)
761761
)
762762
.command(
763-
`labels-gcs <bucketName> <fileName>`,
764-
`Detects labels in an image in Google Cloud Storage.`,
763+
'labels-gcs <bucketName> <fileName>',
764+
'Detects labels in an image in Google Cloud Storage.',
765765
{},
766766
opts => detectLabelsGCS(opts.bucketName, opts.fileName)
767767
)
768768
.command(
769-
`landmarks <fileName>`,
770-
`Detects landmarks in a local image file.`,
769+
'landmarks <fileName>',
770+
'Detects landmarks in a local image file.',
771771
{},
772772
opts => detectLandmarks(opts.fileName)
773773
)
774774
.command(
775-
`landmarks-gcs <bucketName> <fileName>`,
776-
`Detects landmarks in an image in Google Cloud Storage.`,
775+
'landmarks-gcs <bucketName> <fileName>',
776+
'Detects landmarks in an image in Google Cloud Storage.',
777777
{},
778778
opts => detectLandmarksGCS(opts.bucketName, opts.fileName)
779779
)
780-
.command(`text <fileName>`, `Detects text in a local image file.`, {}, opts =>
780+
.command('text <fileName>', 'Detects text in a local image file.', {}, opts =>
781781
detectText(opts.fileName)
782782
)
783783
.command(
784-
`text-gcs <bucketName> <fileName>`,
785-
`Detects text in an image in Google Cloud Storage.`,
784+
'text-gcs <bucketName> <fileName>',
785+
'Detects text in an image in Google Cloud Storage.',
786786
{},
787787
opts => detectTextGCS(opts.bucketName, opts.fileName)
788788
)
789789
.command(
790-
`logos <fileName>`,
791-
`Detects logos in a local image file.`,
790+
'logos <fileName>',
791+
'Detects logos in a local image file.',
792792
{},
793793
opts => detectLogos(opts.fileName)
794794
)
795795
.command(
796-
`logos-gcs <bucketName> <fileName>`,
797-
`Detects logos in an image in Google Cloud Storage.`,
796+
'logos-gcs <bucketName> <fileName>',
797+
'Detects logos in an image in Google Cloud Storage.',
798798
{},
799799
opts => detectLogosGCS(opts.bucketName, opts.fileName)
800800
)
801801
.command(
802-
`properties <fileName>`,
803-
`Detects image properties in a local image file.`,
802+
'properties <fileName>',
803+
'Detects image properties in a local image file.',
804804
{},
805805
opts => detectProperties(opts.fileName)
806806
)
807807
.command(
808-
`properties-gcs <bucketName> <fileName>`,
809-
`Detects image properties in an image in Google Cloud Storage.`,
808+
'properties-gcs <bucketName> <fileName>',
809+
'Detects image properties in an image in Google Cloud Storage.',
810810
{},
811811
opts => detectPropertiesGCS(opts.bucketName, opts.fileName)
812812
)
813813
.command(
814-
`safe-search <fileName>`,
815-
`Detects safe search properties in a local image file.`,
814+
'safe-search <fileName>',
815+
'Detects safe search properties in a local image file.',
816816
{},
817817
opts => detectSafeSearch(opts.fileName)
818818
)
819819
.command(
820-
`safe-search-gcs <bucketName> <fileName>`,
821-
`Detects safe search properties in an image in Google Cloud Storage.`,
820+
'safe-search-gcs <bucketName> <fileName>',
821+
'Detects safe search properties in an image in Google Cloud Storage.',
822822
{},
823823
opts => detectSafeSearchGCS(opts.bucketName, opts.fileName)
824824
)
825825
.command(
826-
`crops <fileName>`,
827-
`Detects crop hints in a local image file.`,
826+
'crops <fileName>',
827+
'Detects crop hints in a local image file.',
828828
{},
829829
opts => detectCropHints(opts.fileName)
830830
)
831831
.command(
832-
`crops-gcs <bucketName> <fileName>`,
833-
`Detects crop hints in an image in Google Cloud Storage.`,
832+
'crops-gcs <bucketName> <fileName>',
833+
'Detects crop hints in an image in Google Cloud Storage.',
834834
{},
835835
opts => detectCropHintsGCS(opts.bucketName, opts.fileName)
836836
)
837837
.command(
838-
`web <fileName>`,
839-
`Finds similar photos on the web for a local image file.`,
838+
'web <fileName>',
839+
'Finds similar photos on the web for a local image file.',
840840
{},
841841
opts => detectWeb(opts.fileName)
842842
)
843843
.command(
844-
`web-gcs <bucketName> <fileName>`,
845-
`Finds similar photos on the web for an image in Google Cloud Storage.`,
844+
'web-gcs <bucketName> <fileName>',
845+
'Finds similar photos on the web for an image in Google Cloud Storage.',
846846
{},
847847
opts => detectWebGCS(opts.bucketName, opts.fileName)
848848
)
849849
.command(
850-
`web-geo <fileName>`,
851-
`Detects web entities with improved results using geographic metadata`,
850+
'web-geo <fileName>',
851+
'Detects web entities with improved results using geographic metadata',
852852
{},
853853
opts => detectWebGeo(opts.fileName)
854854
)
855855
.command(
856-
`web-geo-gcs <bucketName> <fileName>`,
857-
`Detects web entities with improved results using geographic metadata`,
856+
'web-geo-gcs <bucketName> <fileName>',
857+
'Detects web entities with improved results using geographic metadata',
858858
{},
859859
opts => detectWebGeoGCS(opts.bucketName, opts.fileName)
860860
)
861861
.command(
862-
`fulltext <fileName>`,
863-
`Extracts full text from a local image file.`,
862+
'fulltext <fileName>',
863+
'Extracts full text from a local image file.',
864864
{},
865865
opts => detectFulltext(opts.fileName)
866866
)
867867
.command(
868-
`fulltext-gcs <bucketName> <fileName>`,
869-
`Extracts full text from an image in Google Cloud Storage.`,
868+
'fulltext-gcs <bucketName> <fileName>',
869+
'Extracts full text from an image in Google Cloud Storage.',
870870
{},
871871
opts => detectFulltextGCS(opts.bucketName, opts.fileName)
872872
)
873873
.command(
874-
`pdf <bucketName> <fileName> <outputPrefix>`,
875-
`Extracts full text from a pdf file`,
874+
'pdf <bucketName> <fileName> <outputPrefix>',
875+
'Extracts full text from a pdf file',
876876
{},
877877
opts => detectPdfText(opts.bucketName, opts.fileName, opts.outputPrefix)
878878
)
879879
.command(
880-
`localize-objects <fileName>`,
881-
`Detects Objects in a local image file`,
880+
'localize-objects <fileName>',
881+
'Detects Objects in a local image file',
882882
{},
883883
opts => localizeObjects(opts.fileName)
884884
)
885885
.command(
886-
`localize-objects-gcs <gcsUri>`,
887-
`Detects Objects Google Cloud Storage Bucket`,
886+
'localize-objects-gcs <gcsUri>',
887+
'Detects Objects Google Cloud Storage Bucket',
888888
{},
889889
opts => localizeObjectsGCS(opts.gcsUri)
890890
)
891-
.example(`node $0 faces ./resources/face_no_surprise.jpg`)
892-
.example(`node $0 faces-gcs my-bucket your-image.jpg`)
893-
.example(`node $0 labels ./resources/wakeupcat.jpg`)
894-
.example(`node $0 labels-gcs my-bucket your-image.jpg`)
895-
.example(`node $0 landmarks ./resources/landmark.jpg`)
896-
.example(`node $0 landmarks-gcs my-bucket your-image.jpg`)
897-
.example(`node $0 text ./resources/wakeupcat.jpg`)
898-
.example(`node $0 text-gcs my-bucket your-image.jpg`)
899-
.example(`node $0 logos ./resources/logos.png`)
900-
.example(`node $0 logos-gcs my-bucket your-image.jpg.png`)
901-
.example(`node $0 properties ./resources/landmark.jpg`)
902-
.example(`node $0 properties-gcs my-bucket your-image.jpg`)
903-
.example(`node $0 safe-search ./resources/wakeupcat.jpg`)
904-
.example(`node $0 safe-search-gcs my-bucket your-image.jpg`)
905-
.example(`node $0 crops ./resources/wakeupcat.jpg`)
906-
.example(`node $0 crops-gcs my-bucket your-image.jpg`)
907-
.example(`node $0 web ./resources/wakeupcat.jpg`)
908-
.example(`node $0 web-gcs my-bucket your-image.jpg`)
909-
.example(`node $0 web-geo ./resources/city.jpg`)
910-
.example(`node $0 web-geo-gcs my-bucket your-image.jpg`)
911-
.example(`node $0 fulltext ./resources/wakeupcat.jpg`)
912-
.example(`node $0 fulltext-gcs my-bucket your-image.jpg`)
913-
.example(`node $0 pdf my-bucket my-pdf.pdf results`)
914-
.example(`node $0 localize-objects ./resources/duck_and_truck.jpg`)
915-
.example(`node $0 localize-objects-gcs gs://bucket/bucketImage.png`)
891+
.example('node $0 faces ./resources/face_no_surprise.jpg')
892+
.example('node $0 faces-gcs my-bucket your-image.jpg')
893+
.example('node $0 labels ./resources/wakeupcat.jpg')
894+
.example('node $0 labels-gcs my-bucket your-image.jpg')
895+
.example('node $0 landmarks ./resources/landmark.jpg')
896+
.example('node $0 landmarks-gcs my-bucket your-image.jpg')
897+
.example('node $0 text ./resources/wakeupcat.jpg')
898+
.example('node $0 text-gcs my-bucket your-image.jpg')
899+
.example('node $0 logos ./resources/logos.png')
900+
.example('node $0 logos-gcs my-bucket your-image.jpg.png')
901+
.example('node $0 properties ./resources/landmark.jpg')
902+
.example('node $0 properties-gcs my-bucket your-image.jpg')
903+
.example('node $0 safe-search ./resources/wakeupcat.jpg')
904+
.example('node $0 safe-search-gcs my-bucket your-image.jpg')
905+
.example('node $0 crops ./resources/wakeupcat.jpg')
906+
.example('node $0 crops-gcs my-bucket your-image.jpg')
907+
.example('node $0 web ./resources/wakeupcat.jpg')
908+
.example('node $0 web-gcs my-bucket your-image.jpg')
909+
.example('node $0 web-geo ./resources/city.jpg')
910+
.example('node $0 web-geo-gcs my-bucket your-image.jpg')
911+
.example('node $0 fulltext ./resources/wakeupcat.jpg')
912+
.example('node $0 fulltext-gcs my-bucket your-image.jpg')
913+
.example('node $0 pdf my-bucket my-pdf.pdf results')
914+
.example('node $0 localize-objects ./resources/duck_and_truck.jpg')
915+
.example('node $0 localize-objects-gcs gs://bucket/bucketImage.png')
916916
.wrap(120)
917917
.recommendCommands()
918-
.epilogue(`For more information, see https://cloud.google.com/vision/docs`)
918+
.epilogue('For more information, see https://cloud.google.com/vision/docs')
919919
.help()
920920
.strict().argv;

vision/samples/detect.v1p1beta1.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,35 @@ async function detectWebEntitiesIncludingGeoResults(fileName) {
210210
require(`yargs`) // eslint-disable-line
211211
.demand(1)
212212
.command(
213-
`web-entities-geo <fileName>`,
214-
`Detects web entities with improved results using geographic metadata`,
213+
'web-entities-geo <fileName>',
214+
'Detects web entities with improved results using geographic metadata',
215215
{},
216216
opts => detectWebEntitiesIncludingGeoResults(opts.fileName)
217217
)
218218
.command(
219-
`safe-search <fileName>`,
220-
`Detects safe search properties including additional racy category`,
219+
'safe-search <fileName>',
220+
'Detects safe search properties including additional racy category',
221221
{},
222222
opts => detectSafeSearch(opts.fileName)
223223
)
224224
.command(
225-
`web <fileName>`,
226-
`Detects web entities including new best guess labels describing content`,
225+
'web <fileName>',
226+
'Detects web entities including new best guess labels describing content',
227227
{},
228228
opts => detectWeb(opts.fileName)
229229
)
230230
.command(
231-
`fulltext <fileName>`,
232-
`Extracts full text from an image file including new confidence scores`,
231+
'fulltext <fileName>',
232+
'Extracts full text from an image file including new confidence scores',
233233
{},
234234
opts => detectFulltext(opts.fileName)
235235
)
236-
.example(`node $0 safe-search ./resources/wakeupcat.jpg`)
237-
.example(`node $0 web-entities-geo ./resources/city.jpg`)
238-
.example(`node $0 web ./resources/wakeupcat.jpg`)
239-
.example(`node $0 fulltext ./resources/wakeupcat.jpg`)
236+
.example('node $0 safe-search ./resources/wakeupcat.jpg')
237+
.example('node $0 web-entities-geo ./resources/city.jpg')
238+
.example('node $0 web ./resources/wakeupcat.jpg')
239+
.example('node $0 fulltext ./resources/wakeupcat.jpg')
240240
.wrap(120)
241241
.recommendCommands()
242-
.epilogue(`For more information, see https://cloud.google.com/vision/docs`)
242+
.epilogue('For more information, see https://cloud.google.com/vision/docs')
243243
.help()
244244
.strict().argv;

vision/samples/productSearch/addProductToProductSet.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function main(projectId, location, productId, productSetId) {
4242
};
4343

4444
await client.addProductToProductSet(request);
45-
console.log(`Product added to product set.`);
45+
console.log('Product added to product set.');
4646
}
4747
// [END vision_product_search_add_product_to_product_set]
4848
addProductToProductSet();

vision/samples/productSearch/deleteReferenceImage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function main(projectId, location, productId, referenceImageId) {
4141
};
4242

4343
await client.deleteReferenceImage(request);
44-
console.log(`Reference image deleted from product.`);
44+
console.log('Reference image deleted from product.');
4545
}
4646
// [END vision_product_search_delete_reference_image]
4747
deleteReferenceImage();

0 commit comments

Comments
 (0)