dingtalk-qr-code 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # DingTalk QR Code
2
+
3
+ 钉钉风格的二维码生成器
4
+
5
+ ## 使用方法
6
+
7
+ ### node.js
8
+
9
+ ```js
10
+ import { createCanvas, loadImage } from '@napi-rs/canvas';
11
+ import qr from 'dingtalk-qr-code';
12
+ import fs from 'fs/promises';
13
+
14
+ async function main() {
15
+ const url = 'https://www.dingtalk.com';
16
+ const defaultImgUrl =
17
+ 'https://gw.alicdn.com/imgextra/i4/O1CN01djwPhA29ICfjOWcA1_!!6000000008044-2-tps-192-192.png';
18
+ const canvas = createCanvas(1, 1);
19
+ const ctx = (canvas.getContext('2d') as any) as CanvasRenderingContext2D;
20
+ const logo = ((await loadImage(defaultImgUrl)) as any) as HTMLImageElement;
21
+
22
+ qr.generate(ctx, url, { logo, });
23
+
24
+ const data = canvas.toBuffer('image/png');
25
+ await fs.writeFile('./qrcode.test.png', data);
26
+ }
27
+
28
+ main();
29
+ ```
30
+
31
+ ### 前端
32
+
33
+ ```js
34
+ import qr from 'dingtalk-qr-code';
35
+
36
+ async function main() {
37
+ const url = 'https://www.dingtalk.com';
38
+ const defaultImgUrl =
39
+ 'https://gw.alicdn.com/imgextra/i4/O1CN01djwPhA29ICfjOWcA1_!!6000000008044-2-tps-192-192.png';
40
+ const logo = document.createElement('img');
41
+ logo.src = defaultImgUrl;
42
+ await new Promise(r=>logo.onload = r);
43
+
44
+ const canvas = document.createElement('canvas');
45
+ const ctx = canvas.getContext('2d');
46
+
47
+ qr.generate(ctx, url, { logo, });
48
+
49
+ document.body.appendChild(canvas);
50
+ }
51
+
52
+ main();
53
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dingtalk-qr-code",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/types/index.d.ts CHANGED
@@ -13,7 +13,7 @@ ctx: CanvasRenderingContext2D,
13
13
  /**
14
14
  * 二维码的内容,通常为一个 url
15
15
  */
16
- text: string, params: {
16
+ text: string, params?: {
17
17
  /**
18
18
  * 二维码中间显示的图像
19
19
  */