@@ -20,29 +20,93 @@ npm install --save conversiontools
2020
2121To use REST API - get API Token from the Profile page at https://conversiontools.io/profile .
2222
23+ ### Using Promises
24+
2325``` javascript
2426const ConversionClient = require (' conversiontools' );
2527
2628// API Token from your Profile page at https://conversiontools.io/profile
2729const apiToken = ' put the api token here' ;
2830
29- const conversion = new ConversionClient (apiToken);
31+ const conversionClient = new ConversionClient (apiToken);
32+ const conversionOptions = {
33+ filename: ' test.xml' ,
34+ timeout: 4000 ,
35+ outputFilename: ' test.xml.csv' ,
36+ options: {
37+ delimiter: ' tab' ,
38+ },
39+ };
40+
41+ conversionClient
42+ .run (' convert.xml_to_csv' , conversionOptions)
43+ .then ((filename ) => {
44+ console .log (' File downloaded to' , filename);
45+ })
46+ .catch (err => {
47+ console .error (' Conversion error' , err);
48+ });
49+ ```
50+
51+ ### Using async/await
52+
53+ ``` javascript
54+ const ConversionClient = require (' conversiontools' );
55+
56+ // API Token from your Profile page at https://conversiontools.io/profile
57+ const apiToken = ' put the api token here' ;
3058
31- conversion
32- .run (' convert.xml_to_csv' , {
59+ const convert = async () => {
60+ const conversionClient = new ConversionClient (apiToken);
61+ const conversionOptions = {
3362 filename: ' test.xml' ,
3463 timeout: 4000 ,
3564 outputFilename: ' test.xml.csv' ,
3665 options: {
3766 delimiter: ' tab' ,
3867 },
39- })
40- .then ((filename ) => {
68+ };
69+ try {
70+ const filename = await conversionClient .run (' convert.xml_to_csv' , conversionOptions);
4171 console .log (' File downloaded to' , filename);
42- })
43- .catch (err => {
44- console .log (' Conversion error' , err);
45- });
72+ } catch (err) {
73+ console .error (' Conversion error' , err);
74+ }
75+ };
76+
77+ convert ();
78+ ```
79+
80+ ### Conversion with URL
81+
82+ The following example saving website page provided by the URL to JPG image.
83+
84+ ``` javascript
85+ const ConversionClient = require (' conversiontools' );
86+
87+ // API Token from your Profile page at https://conversiontools.io/profile
88+ const apiToken = ' put the api token here' ;
89+
90+ const convert = async () => {
91+ const conversionClient = new ConversionClient (apiToken);
92+ const conversionOptions = {
93+ url: ' https://en.wikipedia.org/wiki/Main_Page' ,
94+ timeout: 4000 ,
95+ outputFilename: ' wiki.jpg' ,
96+ options: {
97+ images: ' yes' ,
98+ javascript: ' yes' ,
99+ },
100+ };
101+ try {
102+ const filename = await conversionClient .run (' convert.website_to_jpg' , conversionOptions);
103+ console .log (' File downloaded to' , filename);
104+ } catch (err) {
105+ console .error (' Conversion error' , err);
106+ }
107+ };
108+
109+ convert ();
46110```
47111
48112## Documentation
@@ -53,4 +117,4 @@ List of available Conversion Types and corresponding conversion options can be f
53117
54118Licensed under [ MIT] ( ./LICENSE ) .
55119
56- Copyright (c) 2020 [ Conversion Tools] ( https://conversiontools.io )
120+ Copyright (c) 2020-2021 [ Conversion Tools] ( https://conversiontools.io )
0 commit comments