Skip to content

Commit aee6ab6

Browse files
committed
⚡😁
1 parent 5208c74 commit aee6ab6

File tree

4 files changed

+135
-133
lines changed

4 files changed

+135
-133
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chart.js-image",
3-
"version": "5.6.0",
3+
"version": "5.6.2",
44
"description": "Render Chart.JS as Image (or URL of Image)",
55
"main": "lib.js",
66
"types": "types.d.ts",

test.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("ChartJSImage", () => {
9494
describe("toBuffer", () => {
9595
it("rejects if a chs is not defined", () =>
9696
expect(ChartJSImage().toBuffer()).rejects.toMatchInlineSnapshot(
97-
`[Error: Bad Request]`
97+
`[Error: "value" must contain at least one of [c, chart]]`
9898
));
9999

100100
it("rejects if a icac is defined without ichm", () =>
@@ -109,7 +109,9 @@ describe("ChartJSImage", () => {
109109
})
110110
.icac("test_fixture")
111111
.toBuffer()
112-
).rejects.toMatchInlineSnapshot(`[Error: Bad Request]`));
112+
).rejects.toMatchInlineSnapshot(
113+
`[Error: The \`icac\` (ACCOUNT_ID) and \`ichm\` (HMAC-SHA256 request signature) query parameters must both be defined if specified. [Learn more](https://bit.ly/HMACENT)]`
114+
));
113115

114116
it("rejects if timeout is reached", () =>
115117
expect(
@@ -195,7 +197,7 @@ describe("ChartJSImage", () => {
195197
describe("toDataURI", () => {
196198
it("rejects if there was an error", () =>
197199
expect(ChartJSImage().toDataURI()).rejects.toMatchInlineSnapshot(
198-
`[Error: Bad Request]`
200+
`[Error: "value" must contain at least one of [c, chart]]`
199201
));
200202

201203
it("works", () =>
@@ -239,7 +241,9 @@ describe("ChartJSImage", () => {
239241
it("rejects if there was an error", () =>
240242
expect(
241243
ChartJSImage().toFile("/tmp/chart.png")
242-
).rejects.toMatchInlineSnapshot(`[Error: Bad Request]`));
244+
).rejects.toMatchInlineSnapshot(
245+
`[Error: "value" must contain at least one of [c, chart]]`
246+
));
243247

244248
it("rejects when the path is invalid", () => {
245249
const file_path = "/__invalid_path/chart.png";

types.d.ts

+125-127
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,146 @@
1-
declare module 'chart.js-image' {
2-
export default class ChartJSImage {
3-
constructor(options?: {
4-
timeout?: number;
5-
secret?: string;
6-
host?: string;
7-
protocol?: string;
8-
port?: number;
9-
pathname?: string;
10-
})
1+
export default class ChartJSImage {
2+
constructor(options?: {
3+
timeout?: number;
4+
secret?: string;
5+
host?: string;
6+
protocol?: string;
7+
port?: number;
8+
pathname?: string;
9+
})
1110

12-
13-
/**
14-
* Javascript/JSON definition of the chart. Use a Chart.js configuration object.
15-
* [Reference documentation]{@link }
16-
* @example
11+
12+
/**
13+
* Javascript/JSON definition of the chart. Use a Chart.js configuration object.
14+
* [Reference documentation]{@link }
15+
* @example
1716
* const chart = ImageCharts().c("{type:'bar',data:{labels:['Q1','Q2','Q3','Q4'],datasets:[{label:'Users',data:[50,60,70,180]},{label:'Revenue',data:[100,200,300,400]}]}}");
18-
*
19-
* @param {string} value - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
20-
* @return {ImageCharts.constructor}
21-
*/
22-
c(value: string): this;
23-
24-
/**
25-
* Javascript/JSON definition of the chart. Use a Chart.js configuration object.
26-
* [Reference documentation]{@link }
27-
* @example
17+
*
18+
* @param {string} value - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
19+
* @return {ImageCharts.constructor}
20+
*/
21+
c(value: string): this;
22+
23+
/**
24+
* Javascript/JSON definition of the chart. Use a Chart.js configuration object.
25+
* [Reference documentation]{@link }
26+
* @example
2827
* const chart = ImageCharts().chart("{type:'bar',data:{labels:['Q1','Q2','Q3','Q4'],datasets:[{label:'Users',data:[50,60,70,180]},{label:'Revenue',data:[100,200,300,400]}]}}");
29-
*
30-
* @param {string} value - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
31-
* @return {ImageCharts.constructor}
32-
*/
33-
chart(value: string): this;
34-
35-
/**
36-
* Width of the chart
37-
* [Reference documentation]{@link }
38-
* @example
28+
*
29+
* @param {string} value - Javascript/JSON definition of the chart. Use a Chart.js configuration object.
30+
* @return {ImageCharts.constructor}
31+
*/
32+
chart(value: string): this;
33+
34+
/**
35+
* Width of the chart
36+
* [Reference documentation]{@link }
37+
* @example
3938
* const chart = ImageCharts().width("400");
40-
* @default "500"
41-
* @param {integer} value - Width of the chart
42-
* @return {ImageCharts.constructor}
43-
*/
44-
width(value: string): this;
45-
46-
/**
47-
* Height of the chart
48-
* [Reference documentation]{@link }
49-
* @example
39+
* @default "500"
40+
* @param {integer} value - Width of the chart
41+
* @return {ImageCharts.constructor}
42+
*/
43+
width(value: string): this;
44+
45+
/**
46+
* Height of the chart
47+
* [Reference documentation]{@link }
48+
* @example
5049
* const chart = ImageCharts().height("300");
51-
* @default "300"
52-
* @param {integer} value - Height of the chart
53-
* @return {ImageCharts.constructor}
54-
*/
55-
height(value: string): this;
56-
57-
/**
58-
* Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
59-
* [Reference documentation]{@link }
60-
* @example
50+
* @default "300"
51+
* @param {integer} value - Height of the chart
52+
* @return {ImageCharts.constructor}
53+
*/
54+
height(value: string): this;
55+
56+
/**
57+
* Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
58+
* [Reference documentation]{@link }
59+
* @example
6160
* const chart = ImageCharts().backgroundColor("black");
6261
* const chart = ImageCharts().backgroundColor("rgb(255,255,120)");
6362
* const chart = ImageCharts().backgroundColor("%23ff00ff");
64-
*
65-
* @param {string} value - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
66-
* @return {ImageCharts.constructor}
67-
*/
68-
backgroundColor(value: string): this;
69-
70-
/**
71-
* Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
72-
* [Reference documentation]{@link }
73-
* @example
63+
*
64+
* @param {string} value - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
65+
* @return {ImageCharts.constructor}
66+
*/
67+
backgroundColor(value: string): this;
68+
69+
/**
70+
* Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
71+
* [Reference documentation]{@link }
72+
* @example
7473
* const chart = ImageCharts().bkg("black");
7574
* const chart = ImageCharts().bkg("rgb(255,255,120)");
7675
* const chart = ImageCharts().bkg("%23ff00ff");
77-
*
78-
* @param {string} value - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
79-
* @return {ImageCharts.constructor}
80-
*/
81-
bkg(value: string): this;
82-
83-
/**
84-
* Encoding of your "chart" parameter. Accepted values are url and base64.
85-
* [Reference documentation]{@link }
86-
* @example
76+
*
77+
* @param {string} value - Background of the chart canvas. Accepts rgb (rgb(255,255,120)), colors (red), and url-encoded hex values (%23ff00ff). Abbreviated as "bkg"
78+
* @return {ImageCharts.constructor}
79+
*/
80+
bkg(value: string): this;
81+
82+
/**
83+
* Encoding of your "chart" parameter. Accepted values are url and base64.
84+
* [Reference documentation]{@link }
85+
* @example
8786
* const chart = ImageCharts().encoding("url");
8887
* const chart = ImageCharts().encoding("base64");
89-
* @default "url"
90-
* @param {string} value - Encoding of your "chart" parameter. Accepted values are url and base64.
91-
* @return {ImageCharts.constructor}
92-
*/
93-
encoding(value: string): this;
94-
95-
/**
96-
* image-charts enterprise `account_id`
97-
* [Reference documentation]{@link https://documentation.image-charts.com/enterprise/}
98-
* @example
88+
* @default "url"
89+
* @param {string} value - Encoding of your "chart" parameter. Accepted values are url and base64.
90+
* @return {ImageCharts.constructor}
91+
*/
92+
encoding(value: string): this;
93+
94+
/**
95+
* image-charts enterprise `account_id`
96+
* [Reference documentation]{@link https://documentation.image-charts.com/enterprise/}
97+
* @example
9998
* const chart = ImageCharts().icac("accountId");
100-
*
101-
* @param {string} value - image-charts enterprise `account_id`
102-
* @return {ImageCharts.constructor}
103-
*/
104-
icac(value: string): this;
105-
106-
/**
107-
* HMAC-SHA256 signature required to activate paid features
108-
* [Reference documentation]{@link https://documentation.image-charts.com/enterprise/}
109-
* @example
99+
*
100+
* @param {string} value - image-charts enterprise `account_id`
101+
* @return {ImageCharts.constructor}
102+
*/
103+
icac(value: string): this;
104+
105+
/**
106+
* HMAC-SHA256 signature required to activate paid features
107+
* [Reference documentation]{@link https://documentation.image-charts.com/enterprise/}
108+
* @example
110109
* const chart = ImageCharts().ichm("0785cf22a0381c2e0239e27c126de4181f501d117c2c81745611e9db928b0376");
111-
*
112-
* @param {string} value - HMAC-SHA256 signature required to activate paid features
113-
* @return {ImageCharts.constructor}
114-
*/
115-
ichm(value: string): this;
116-
117-
/**
118-
* Retina is a marketing term coined by Apple that refers to devices and monitors that have a resolution and pixel density so high — roughly 300 or more pixels per inch – that a person is unable to discern the individual pixels at a normal viewing distance.
110+
*
111+
* @param {string} value - HMAC-SHA256 signature required to activate paid features
112+
* @return {ImageCharts.constructor}
113+
*/
114+
ichm(value: string): this;
115+
116+
/**
117+
* Retina is a marketing term coined by Apple that refers to devices and monitors that have a resolution and pixel density so high — roughly 300 or more pixels per inch – that a person is unable to discern the individual pixels at a normal viewing distance.
119118
* In order to generate beautiful charts for these Retina displays, Image-Charts supports a retina mode that can be activated through the icretina=1 parameter
120-
* [Reference documentation]{@link https://documentation.image-charts.com/reference/retina/}
121-
* @example
119+
* [Reference documentation]{@link https://documentation.image-charts.com/reference/retina/}
120+
* @example
122121
* const chart = ImageCharts().icretina("1");
123-
*
124-
* @param {string} value - retina mode
125-
* @return {ImageCharts.constructor}
126-
*/
127-
icretina(value: string): this;
128-
122+
*
123+
* @param {string} value - retina mode
124+
* @return {ImageCharts.constructor}
125+
*/
126+
icretina(value: string): this;
127+
129128

130-
/**
131-
* Get the full Image-Charts API url (signed and encoded if necessary)
132-
* @return full generated url
133-
*/
134-
toURL(): string;
129+
/**
130+
* Get the full Image-Charts API url (signed and encoded if necessary)
131+
* @return full generated url
132+
*/
133+
toURL(): string;
135134

136-
/**
137-
* Do a request to Image-Charts API with current configuration and yield a promise of a NodeJS buffer
138-
* @return binary image represented as a NodeJS Buffer wrapped inside a promise
139-
*/
140-
toBuffer(): Promise<Buffer>;
135+
/**
136+
* Do a request to Image-Charts API with current configuration and yield a promise of a NodeJS buffer
137+
* @return binary image represented as a NodeJS Buffer wrapped inside a promise
138+
*/
139+
toBuffer(): Promise<Buffer>;
141140

142-
/**
143-
* Do a request to Image-Charts API with current configuration and yield a promise of a base64 encoded data URI
144-
* @return base64 data URI wrapped inside a promise
145-
*/
146-
toDataURI(): Promise<string>;
147-
}
141+
/**
142+
* Do a request to Image-Charts API with current configuration and yield a promise of a base64 encoded data URI
143+
* @return base64 data URI wrapped inside a promise
144+
*/
145+
toDataURI(): Promise<string>;
148146
}

0 commit comments

Comments
 (0)