Skip to content

Commit 8ceacb3

Browse files
author
StringKE
committed
feat: allow user custom merge options
1 parent c55f7e5 commit 8ceacb3

File tree

8 files changed

+4528
-3022
lines changed

8 files changed

+4528
-3022
lines changed

CHANGELOG.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,43 @@ All notable changes to this project will be documented in this file. See [standa
66

77
## [1.4.0](https://github.com/stringke/simple-qrbtf/compare/v1.3.0...v1.4.0) (2024-03-15)
88

9-
109
### Features
1110

12-
* docs update and refersh deps ([bd686d2](https://github.com/stringke/simple-qrbtf/commit/bd686d28f305d4b5d14e8f779b4a78b699ec51f0))
13-
* update ([bdede52](https://github.com/stringke/simple-qrbtf/commit/bdede524e12fa64027ef8e80e949b692141c609b))
14-
* Update package.json ([30d1ee4](https://github.com/stringke/simple-qrbtf/commit/30d1ee42d4956f8aa91d65aa736db5ccc142e0ed))
15-
11+
- docs update and refersh deps ([bd686d2](https://github.com/stringke/simple-qrbtf/commit/bd686d28f305d4b5d14e8f779b4a78b699ec51f0))
12+
- update ([bdede52](https://github.com/stringke/simple-qrbtf/commit/bdede524e12fa64027ef8e80e949b692141c609b))
13+
- Update package.json ([30d1ee4](https://github.com/stringke/simple-qrbtf/commit/30d1ee42d4956f8aa91d65aa736db5ccc142e0ed))
1614

1715
## [1.3.0](https://github.com/ifrps/simple-qrbtf/compare/v1.2.1...v1.3.0) (2021-04-01)
1816

19-
2017
### Features
2118

22-
* move type ([240bb0b](https://github.com/ifrps/simple-qrbtf/commit/240bb0b74b7de75940d97339f20592588ee92ca1))
19+
- move type ([240bb0b](https://github.com/ifrps/simple-qrbtf/commit/240bb0b74b7de75940d97339f20592588ee92ca1))
2320

2421
### [1.2.1](https://github.com/ifrps/simple-qrbtf/compare/v1.2.0...v1.2.1) (2021-03-31)
2522

26-
2723
### Bug Fixes
2824

29-
* add export ([b7ca95f](https://github.com/ifrps/simple-qrbtf/commit/b7ca95f0bc5185d37a98114cb0ee8ce36f4dad9f))
25+
- add export ([b7ca95f](https://github.com/ifrps/simple-qrbtf/commit/b7ca95f0bc5185d37a98114cb0ee8ce36f4dad9f))
3026

3127
## [1.2.0](https://github.com/ifrps/simple-qrbtf/compare/v1.1.1...v1.2.0) (2021-03-31)
3228

33-
3429
### Features
3530

36-
* 添加 圆形 二维码 ([91b5b27](https://github.com/ifrps/simple-qrbtf/commit/91b5b273ce0ac255d3baf5c81919a2eadb47264c))
37-
* 添加几个二维码支持 ([7203e3b](https://github.com/ifrps/simple-qrbtf/commit/7203e3bc72ab19384332fea471b60d4ec042c18e))
38-
* 完善单元测试,增加 2.5D 展示效果 ([d7bacdf](https://github.com/ifrps/simple-qrbtf/commit/d7bacdf8f4c0017e14119235d8473ce4194312f2))
39-
31+
- 添加 圆形 二维码 ([91b5b27](https://github.com/ifrps/simple-qrbtf/commit/91b5b273ce0ac255d3baf5c81919a2eadb47264c))
32+
- 添加几个二维码支持 ([7203e3b](https://github.com/ifrps/simple-qrbtf/commit/7203e3bc72ab19384332fea471b60d4ec042c18e))
33+
- 完善单元测试,增加 2.5D 展示效果 ([d7bacdf](https://github.com/ifrps/simple-qrbtf/commit/d7bacdf8f4c0017e14119235d8473ce4194312f2))
4034

4135
### Bug Fixes
4236

43-
* 降低 typedoc 版本 ([bddc5e0](https://github.com/ifrps/simple-qrbtf/commit/bddc5e06dd9eb0d33a3ead8f8798bd2c44fd7bd0))
44-
* 移除图片处理 ([52e9052](https://github.com/ifrps/simple-qrbtf/commit/52e90527a40f0344b33d4d0603a609a94d506dd3))
37+
- 降低 typedoc 版本 ([bddc5e0](https://github.com/ifrps/simple-qrbtf/commit/bddc5e06dd9eb0d33a3ead8f8798bd2c44fd7bd0))
38+
- 移除图片处理 ([52e9052](https://github.com/ifrps/simple-qrbtf/commit/52e90527a40f0344b33d4d0603a609a94d506dd3))
4539

4640
### [1.1.1](https://github.com/ifrps/simple-qrbtf/compare/v1.1.0...v1.1.1) (2021-03-30)
4741

4842
## 1.1.0 (2021-03-30)
4943

50-
5144
### Features
5245

53-
* **base qr:** 完善基础封装,以及测试代码 ([ddb0c28](https://github.com/ifrps/simple-qrbtf/commit/ddb0c2837f8ada4c8d1b5bde63edbcfb75304e13))
54-
* **base qrcode:** 基础二维码生存完成 ([7e37b95](https://github.com/ifrps/simple-qrbtf/commit/7e37b950d1aa54a76b2e96c96d8f6129a2f873db))
55-
* **init:** 初始化项目 ([4a10732](https://github.com/ifrps/simple-qrbtf/commit/4a107323de0d3013e77a92ec45a69240b3a12c86))
46+
- **base qr:** 完善基础封装,以及测试代码 ([ddb0c28](https://github.com/ifrps/simple-qrbtf/commit/ddb0c2837f8ada4c8d1b5bde63edbcfb75304e13))
47+
- **base qrcode:** 基础二维码生存完成 ([7e37b95](https://github.com/ifrps/simple-qrbtf/commit/7e37b950d1aa54a76b2e96c96d8f6129a2f873db))
48+
- **init:** 初始化项目 ([4a10732](https://github.com/ifrps/simple-qrbtf/commit/4a107323de0d3013e77a92ec45a69240b3a12c86))

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,27 @@ of `node` and `browser` in environments.
1111
# preview
1212

1313
| base | circle | dsj |
14-
|----------------------------------------------------------|------------------------------------------------------------|---------------------------------------------------------|
14+
| -------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------- |
1515
| <img src="./assets/base.png" width="80px" height="80px"> | <img src="./assets/circle.png" width="80px" height="80px"> | <img src="./assets/dsj.png" width="80px" height="80px"> |
1616

1717
| func | image | imagefill |
18-
|---------------------------------------------------------|-----------------------------------------------------------|---------------------------------------------------------------|
18+
| ------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------- |
1919
| <img src="./assets/fun.png" width="80px" height="80px"> | <img src="./assets/image.png" width="80px" height="80px"> | <img src="./assets/imagefill.png" width="80px" height="80px"> |
2020

2121
| line | rand-rect | solid(2.5D) |
22-
|----------------------------------------------------------|--------------------------------------------------------------|-----------------------------------------------------------|
22+
| -------------------------------------------------------- | ------------------------------------------------------------ | --------------------------------------------------------- |
2323
| <img src="./assets/line.png" width="80px" height="80px"> | <img src="./assets/randrect.png" width="80px" height="80px"> | <img src="./assets/solid.png" width="80px" height="80px"> |
2424

2525
# install
2626

2727
```bash
2828
npm i simple-qrbtf
2929
```
30+
3031
```bash
3132
yarn add simple-qrbtf
3233
```
34+
3335
```bash
3436
pnpm add simple-qrbtf
3537
```

README_CN.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
# 预览
1010

1111
| base | circle | dsj |
12-
|----------------------------------------------------------|------------------------------------------------------------|---------------------------------------------------------|
12+
| -------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------- |
1313
| <img src="./assets/base.png" width="80px" height="80px"> | <img src="./assets/circle.png" width="80px" height="80px"> | <img src="./assets/dsj.png" width="80px" height="80px"> |
1414

1515
| func | image | imagefill |
16-
|---------------------------------------------------------|-----------------------------------------------------------|---------------------------------------------------------------|
16+
| ------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------------------------------- |
1717
| <img src="./assets/fun.png" width="80px" height="80px"> | <img src="./assets/image.png" width="80px" height="80px"> | <img src="./assets/imagefill.png" width="80px" height="80px"> |
1818

1919
| line | rand-rect | solid(2.5D) |
20-
|----------------------------------------------------------|--------------------------------------------------------------|-----------------------------------------------------------|
20+
| -------------------------------------------------------- | ------------------------------------------------------------ | --------------------------------------------------------- |
2121
| <img src="./assets/line.png" width="80px" height="80px"> | <img src="./assets/randrect.png" width="80px" height="80px"> | <img src="./assets/solid.png" width="80px" height="80px"> |
2222

2323
# 安装
@@ -40,20 +40,24 @@ pnpm add simple-qrbtf
4040

4141
es6
4242

43-
```javascript
43+
```javascript
4444
import SimpleQr from 'simple-qrbtf';
4545

46-
console.log(SimpleQr.base({
47-
"content": "Hello, world!",
48-
}));
46+
console.log(
47+
SimpleQr.base({
48+
content: 'Hello, world!',
49+
}),
50+
);
4951
```
5052

5153
node
5254

5355
```javascript
5456
const SimpleQr = require('simple-qrbtf');
5557

56-
console.log(SimpleQr.base({
57-
"content": "Hello, world!",
58-
}));
58+
console.log(
59+
SimpleQr.base({
60+
content: 'Hello, world!',
61+
}),
62+
);
5963
```

index.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<!doctype html>
22
<html lang="zh-CN">
3-
<head>
4-
<meta charset="UTF-8"/>
5-
<meta
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta
66
name="viewport"
77
content="width=device-width, initial-scale=1.0"
8-
/>
9-
<title>Vite App</title>
10-
</head>
11-
<body>
12-
<div id="app"></div>
13-
<script
14-
type="module"
15-
src="/src/main.ts"
16-
></script>
17-
</body>
8+
/>
9+
<title>Vite App</title>
10+
</head>
11+
<body>
12+
<div id="app"></div>
13+
<script
14+
type="module"
15+
src="/src/main.ts"
16+
></script>
17+
</body>
1818
</html>

lib/renderer.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,30 @@ export interface Renderer<T> {
228228
defaultProps: T;
229229
}
230230

231+
export function defaultMergeOptions<T>(
232+
renderer: Renderer<T>,
233+
props?: DeepPartial<RendererOptions<T>>,
234+
): RendererOptions<T> {
235+
const newProps = merge(
236+
{
237+
level: 'H',
238+
icon: {
239+
enabled: 0,
240+
scale: 100,
241+
src: '',
242+
},
243+
opacity: 100,
244+
size: 100,
245+
},
246+
renderer.defaultProps,
247+
props,
248+
) as RendererOptions<T>;
249+
250+
newProps.content = newProps.content || '无二维码内容';
251+
newProps.level = newProps.icon ? 'H' : newProps.level;
252+
return newProps;
253+
}
254+
231255
export function createRenderer<T>(rendererProps: Renderer<T>) {
232256
const renderer = merge(
233257
{
@@ -243,24 +267,12 @@ export function createRenderer<T>(rendererProps: Renderer<T>) {
243267
rendererProps,
244268
) as Required<Renderer<T>>;
245269

246-
return (props?: DeepPartial<RendererOptions<T>>) => {
247-
const newProps = merge(
248-
{
249-
level: 'H',
250-
icon: {
251-
enabled: 0,
252-
scale: 100,
253-
src: '',
254-
},
255-
opacity: 100,
256-
size: 100,
257-
},
258-
rendererProps.defaultProps,
259-
props,
260-
) as RendererOptions<T>;
261-
262-
newProps.content = newProps.content || '无二维码内容';
263-
newProps.level = newProps.icon ? 'H' : newProps.level;
270+
return (
271+
props?: DeepPartial<RendererOptions<T>>,
272+
mergeOptions?: (renderer: Renderer<T>, props?: DeepPartial<RendererOptions<T>>) => RendererOptions<T>,
273+
) => {
274+
const fn = mergeOptions || defaultMergeOptions;
275+
const newProps = fn(renderer, props);
264276
newProps.qrcode =
265277
newProps.qrcode ||
266278
encodeData({

package.json

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
{
2-
"name": "simple-qrbtf",
3-
"description": "this is simple create a svg qrcode library",
4-
"private": false,
5-
"version": "1.4.1",
6-
"type": "module",
7-
"homepage": "https://github.com/stringke/simple-qrbtf/",
8-
"repository": {
9-
"type": "git",
10-
"url": "git+https://github.com/stringke/simple-qrbtf.git"
11-
},
12-
"license": "MIT",
13-
"files": [
14-
"dist"
15-
],
16-
"main": "./dist/index.umd.cjs",
17-
"module": "./dist/index.js",
18-
"types": "./dist/index.d.ts",
19-
"exports": {
2+
"name": "simple-qrbtf",
3+
"description": "this is simple create a svg qrcode library",
4+
"private": false,
5+
"version": "1.4.1",
6+
"type": "module",
7+
"homepage": "https://github.com/stringke/simple-qrbtf/",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/stringke/simple-qrbtf.git"
11+
},
12+
"license": "MIT",
13+
"files": [
14+
"dist"
15+
],
16+
"main": "./dist/index.umd.cjs",
17+
"module": "./dist/index.js",
2018
"types": "./dist/index.d.ts",
21-
"import": "./dist/index.js",
22-
"require": "./dist/index.umd.cjs",
23-
"node": "./dist/index.cjs"
24-
},
25-
"scripts": {
26-
"dev": "vite",
27-
"build": "DEBUG=\"vite-plugin-dts:bundle\" vite build",
28-
"commit": "git-cz",
29-
"release": "standard-version"
30-
},
31-
"author": {
32-
"name": "StringKe",
33-
"email": "stringke@126.com",
34-
"url": "https://github.com/stringke"
35-
},
36-
"keywords": [
37-
"qrcode",
38-
"svg",
39-
"library",
40-
"qrbtf",
41-
"simple"
42-
],
43-
"devDependencies": {
44-
"@types/node": "^20.11.27",
45-
"cz-conventional-changelog": "^3.3.0",
46-
"prettier": "^3.2.5",
47-
"standard-version": "^9.5.0",
48-
"typescript": "5.3.3",
49-
"vite": "^5.1.6",
50-
"vite-plugin-dts": "^3.7.3"
51-
},
52-
"config": {
53-
"commitizen": {
54-
"path": "./node_modules/cz-conventional-changelog"
19+
"exports": {
20+
"types": "./dist/index.d.ts",
21+
"import": "./dist/index.js",
22+
"require": "./dist/index.umd.cjs",
23+
"node": "./dist/index.cjs"
24+
},
25+
"scripts": {
26+
"dev": "vite",
27+
"build": "DEBUG=\"vite-plugin-dts:bundle\" vite build",
28+
"commit": "git-cz",
29+
"release": "standard-version"
30+
},
31+
"author": {
32+
"name": "StringKe",
33+
"email": "stringke@126.com",
34+
"url": "https://github.com/stringke"
35+
},
36+
"keywords": [
37+
"qrcode",
38+
"svg",
39+
"library",
40+
"qrbtf",
41+
"simple"
42+
],
43+
"devDependencies": {
44+
"@types/node": "^20.11.27",
45+
"cz-conventional-changelog": "^3.3.0",
46+
"prettier": "^3.2.5",
47+
"standard-version": "^9.5.0",
48+
"typescript": "5.3.3",
49+
"vite": "^5.1.6",
50+
"vite-plugin-dts": "^3.7.3"
51+
},
52+
"config": {
53+
"commitizen": {
54+
"path": "./node_modules/cz-conventional-changelog"
55+
}
5556
}
56-
}
5757
}

0 commit comments

Comments
 (0)