@innoways/utils 3.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,184 @@
1
+ # Change Log
2
+
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Initial version
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - Initial changelog
14
+
15
+ ## 1.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - Initial changelog
20
+
21
+ All notable changes to this project will be documented in this file.
22
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
23
+
24
+ ### [0.8.2](https://github.com/jdfed/drip-form/compare/v0.8.1...v0.8.2) (2022-07-15)
25
+
26
+ ### Bug Fixes
27
+
28
+ - inaccurate width calculation when margin contains extra spaces ([#233](https://github.com/jdfed/drip-form/issues/233)) ([22f4eeb](https://github.com/jdfed/drip-form/commit/22f4eeb96f5a0f2b39eae69705f0a2e65e1e8ee1))
29
+
30
+ ### [0.8.1](https://github.com/jdfed/drip-form/compare/v0.8.0...v0.8.1) (2022-06-29)
31
+
32
+ ### Bug Fixes
33
+
34
+ - **generator:** compatibility with old data ([#217](https://github.com/jdfed/drip-form/issues/217)) ([ece5bfc](https://github.com/jdfed/drip-form/commit/ece5bfc9755d53c598ad2a577100a79abd4119d9))
35
+ - **utils:** handleMargin function cannot properly handle the width when margin is set to 4 values ([#222](https://github.com/jdfed/drip-form/issues/222)) ([70f9a4c](https://github.com/jdfed/drip-form/commit/70f9a4cfeb28aa232e6ef3aad5779bca27d8c4f2))
36
+
37
+ ## [0.8.0](https://github.com/jdfed/drip-form/compare/v0.7.0...v0.8.0) (2022-06-01)
38
+
39
+ ### Features
40
+
41
+ - **form:** array container supports sorting ([#206](https://github.com/jdfed/drip-form/issues/206)) ([7a60b0b](https://github.com/jdfed/drip-form/commit/7a60b0b3e2eb9af8d6b479356ceee659bba86947))
42
+ - **generator:** support the same type for different themes ([#211](https://github.com/jdfed/drip-form/issues/211)) ([23cf581](https://github.com/jdfed/drip-form/commit/23cf581dca35b93b6d33640f67250fcd37c32009))
43
+ - combine method supports configuring the configuration to transform fieldkeys ([f3fef68](https://github.com/jdfed/drip-form/commit/f3fef681cccc7f5b900e65fa796e995090d316b2))
44
+ - title add showColon configuration ([#199](https://github.com/jdfed/drip-form/issues/199)) ([d8d32ef](https://github.com/jdfed/drip-form/commit/d8d32ef06f77015a4c76a37254daae5eedb28379))
45
+ - **utils:** parseUnitedSchema supports transparent DataSchema keywords ([#190](https://github.com/jdfed/drip-form/issues/190)) ([a1062c3](https://github.com/jdfed/drip-form/commit/a1062c3195bf9000d1c7e0016131965d55d6d77d))
46
+ - customize component fontSize and fontColor ([#178](https://github.com/jdfed/drip-form/issues/178)) ([3199e29](https://github.com/jdfed/drip-form/commit/3199e29e7338cb78cd8c6d702b3c55df9562c157))
47
+ - title support fontSize、color configuration ([#177](https://github.com/jdfed/drip-form/issues/177)) ([d83836c](https://github.com/jdfed/drip-form/commit/d83836ce1827bf0af082e345e0710391b6f963ff))
48
+
49
+ ### Bug Fixes
50
+
51
+ - margin affect the number of layout columns ([#210](https://github.com/jdfed/drip-form/issues/210)) ([e5ebb44](https://github.com/jdfed/drip-form/commit/e5ebb44591ccea9bccd261becac251737dce6b8e))
52
+ - **generator:** default configuration is not effective ([7e97006](https://github.com/jdfed/drip-form/commit/7e9700633a66b8221bbe43782fc998b564e044a4))
53
+
54
+ ## [0.7.0](https://github.com/jdfed/drip-form/compare/v0.6.0...v0.7.0) (2022-03-14)
55
+
56
+ ### Features
57
+
58
+ - **generator:** datepicker add default configuration ([a238424](https://github.com/jdfed/drip-form/commit/a238424c1aed9382735d1e2de1ec60890dd851c4))
59
+ - containerStyle configuration add padding prop ([27cefed](https://github.com/jdfed/drip-form/commit/27cefeda6cf880cc1d113a70624eea6789683937))
60
+ - unitedSchema JSON add requiredMode configuration ([#150](https://github.com/jdfed/drip-form/issues/150)) ([7e717ef](https://github.com/jdfed/drip-form/commit/7e717ef9431228809fd5f2d3908a274f181225ec))
61
+ - **generator:** support change fieldKey in the property configuration panel ([#144](https://github.com/jdfed/drip-form/issues/144)) ([9681f62](https://github.com/jdfed/drip-form/commit/9681f62083c8c4feba7c4b1538b3ae99838545a3))
62
+
63
+ ## [0.6.0](https://github.com/jdfed/drip-form/compare/v0.5.0...v0.6.0) (2022-01-24)
64
+
65
+ ### Bug Fixes
66
+
67
+ - reset 导致 visbleFieldKey 清空,错误信息无法展示 ([c4d839c](https://github.com/jdfed/drip-form/commit/c4d839c6cf9199459c7c90244f75d29c687b326b))
68
+ - 修复 errorMessage 在对象数组未透传问题 ([d69d1d6](https://github.com/jdfed/drip-form/commit/d69d1d6b98bf73a630d78c47537e154ace7d2616))
69
+ - 数组内部子元素校验失效 ([#126](https://github.com/jdfed/drip-form/issues/126)) ([6f0a89e](https://github.com/jdfed/drip-form/commit/6f0a89e20c276c35699607956668152100b28e45))
70
+ - 数组容器组件 key 兜底使用数组下标导致删除错乱 ([#131](https://github.com/jdfed/drip-form/issues/131)) ([cc73d8d](https://github.com/jdfed/drip-form/commit/cc73d8d558114eb5ed339a9a6e98cc37fe435332))
71
+ - 校验配置 0,错误文案配置不展示 ([5f0f211](https://github.com/jdfed/drip-form/commit/5f0f2118488df32f1d579ca024a3556e4f91e049))
72
+
73
+ ## [0.5.0](https://github.com/jdfed/drip-form/compare/v0.4.0...v0.5.0) (2022-01-13)
74
+
75
+ ### Features
76
+
77
+ - setError 支持配置 action.ignore ([#125](https://github.com/jdfed/drip-form/issues/125)) ([b84aa5e](https://github.com/jdfed/drip-form/commit/b84aa5eead2b3f384d70bb45ce2961fcb1afbd1d))
78
+
79
+ ## 0.4.0 (2022-01-11)
80
+
81
+ ### Features
82
+
83
+ - upload support img size limit ([#102](https://github.com/jdfed/drip-form/issues/102)) ([acbd278](https://github.com/jdfed/drip-form/commit/acbd27861a44004abf3afb7ae5ca5d210c70c28d))
84
+ - 数组容器样式优化 & 支持序号文案自定义 ([#109](https://github.com/jdfed/drip-form/issues/109)) ([2ca6f67](https://github.com/jdfed/drip-form/commit/2ca6f67a2b894fc0152230f3bee69f279bce640c))
85
+
86
+ ### Bug Fixes
87
+
88
+ - custom keyword duplicate error ([#84](https://github.com/jdfed/drip-form/issues/84)) ([afcaa7d](https://github.com/jdfed/drip-form/commit/afcaa7df4d0a2255de1685e37c59962d192c2b7e))
89
+ - provide a default key for dynamic children ([#53](https://github.com/jdfed/drip-form/issues/53)) ([3abe606](https://github.com/jdfed/drip-form/commit/3abe6068e20d2d567426eb7ee637e2b6a0c93af5))
90
+ - 修复元祖无数据不展示问题 ([#112](https://github.com/jdfed/drip-form/issues/112)) ([a67ae0e](https://github.com/jdfed/drip-form/commit/a67ae0e441d06d26812d257e34f82a245c9a84ea))
91
+ - **utils:** 修复 parse 无法解析顶层$:xxx 自定义属性的问题 ([36235e5](https://github.com/jdfed/drip-form/commit/36235e56f477461c49b4f59149c6da7e6ede99d9))
92
+
93
+ ## 0.3.0 (2022-01-11)
94
+
95
+ ### Features
96
+
97
+ - upload support img size limit ([#102](https://github.com/jdfed/drip-form/issues/102)) ([acbd278](https://github.com/jdfed/drip-form/commit/acbd27861a44004abf3afb7ae5ca5d210c70c28d))
98
+ - 数组容器样式优化 & 支持序号文案自定义 ([#109](https://github.com/jdfed/drip-form/issues/109)) ([2ca6f67](https://github.com/jdfed/drip-form/commit/2ca6f67a2b894fc0152230f3bee69f279bce640c))
99
+
100
+ ### Bug Fixes
101
+
102
+ - custom keyword duplicate error ([#84](https://github.com/jdfed/drip-form/issues/84)) ([afcaa7d](https://github.com/jdfed/drip-form/commit/afcaa7df4d0a2255de1685e37c59962d192c2b7e))
103
+ - provide a default key for dynamic children ([#53](https://github.com/jdfed/drip-form/issues/53)) ([3abe606](https://github.com/jdfed/drip-form/commit/3abe6068e20d2d567426eb7ee637e2b6a0c93af5))
104
+ - 修复元祖无数据不展示问题 ([#112](https://github.com/jdfed/drip-form/issues/112)) ([a67ae0e](https://github.com/jdfed/drip-form/commit/a67ae0e441d06d26812d257e34f82a245c9a84ea))
105
+ - **utils:** 修复 parse 无法解析顶层$:xxx 自定义属性的问题 ([36235e5](https://github.com/jdfed/drip-form/commit/36235e56f477461c49b4f59149c6da7e6ede99d9))
106
+
107
+ ## 0.2.0 (2022-01-07)
108
+
109
+ ### Features
110
+
111
+ - upload support img size limit ([#102](https://github.com/jdfed/drip-form/issues/102)) ([acbd278](https://github.com/jdfed/drip-form/commit/acbd27861a44004abf3afb7ae5ca5d210c70c28d))
112
+
113
+ ### Bug Fixes
114
+
115
+ - custom keyword duplicate error ([#84](https://github.com/jdfed/drip-form/issues/84)) ([afcaa7d](https://github.com/jdfed/drip-form/commit/afcaa7df4d0a2255de1685e37c59962d192c2b7e))
116
+ - provide a default key for dynamic children ([#53](https://github.com/jdfed/drip-form/issues/53)) ([3abe606](https://github.com/jdfed/drip-form/commit/3abe6068e20d2d567426eb7ee637e2b6a0c93af5))
117
+ - **utils:** 修复 parse 无法解析顶层$:xxx 自定义属性的问题 ([36235e5](https://github.com/jdfed/drip-form/commit/36235e56f477461c49b4f59149c6da7e6ede99d9))
118
+
119
+ **Note:** Version bump only for package @jdfed/utils
120
+
121
+ ## 0.1.0 (2021-11-24)
122
+
123
+ ### Features
124
+
125
+ - 打包&文档 ([a65b57e](https://github.com/jdfed/drip-form/commit/a65b57e1fa390dc38d1bd3d9a5cb2c98f446744f))
126
+ - 关键字插件化处理 ([591d492](https://github.com/jdfed/drip-form/commit/591d492018cc6dcb092dec533d9d078ed8810b83))
127
+ - 关键字插件化处理 ([b560f22](https://github.com/jdfed/drip-form/commit/b560f220bd7bda8614a8f94a60cf5a2a3417e584))
128
+ - 迁移 babel-form 至 drip-form ([7687505](https://github.com/jdfed/drip-form/commit/768750518a8fdd9de93234fb8fbd5fc1cbd555b6))
129
+ - 嵌套表单 ([b939eed](https://github.com/jdfed/drip-form/commit/b939eed9bf23db5efa9a6c8177a24b397f4e8ba8))
130
+ - 删除 Spin loading ([1a6d7df](https://github.com/jdfed/drip-form/commit/1a6d7df9e638d49bb3b938c2bbc46fb274bb6ea3))
131
+ - 升级 ajv ([1708e2c](https://github.com/jdfed/drip-form/commit/1708e2c8ad8581a78be9923f194c494e2f970a4c))
132
+ - 添加自定义 export 函数,测试 iframe 外部控制导出逻辑 ([de01461](https://github.com/jdfed/drip-form/commit/de014610c37d43959a3311148e27b0bf7ec49d27))
133
+ - 添加 combine & 修复 addField 类型引用错误的问题 ([cd5fb7d](https://github.com/jdfed/drip-form/commit/cd5fb7d73704739073f734dcd1ca384299ba2f67))
134
+ - 添加 typePath 入参 reducer ([22d9af6](https://github.com/jdfed/drip-form/commit/22d9af63b4a218ccb20971a6ac0ebda3916647e1))
135
+ - 拖拽优化 ([90e2251](https://github.com/jdfed/drip-form/commit/90e22517082fe2a432bb443fc1961451da7b2ba0))
136
+ - 完成嵌套解析 ([f98dca4](https://github.com/jdfed/drip-form/commit/f98dca4a27999a3839bb9721a3e83b114799fb05))
137
+ - 完善拖拽区操作 ([08cc07a](https://github.com/jdfed/drip-form/commit/08cc07ab74260d233ece26051142680ae89e8c03))
138
+ - 文件结构优化 & 添加 combine 和 parse 的 errMsg 单测数据 ([108a6e4](https://github.com/jdfed/drip-form/commit/108a6e456782ca6f8cfe242520a34aa540af943f))
139
+ - 支持跨表单获取数据 ([ff9eecb](https://github.com/jdfed/drip-form/commit/ff9eecbfcbf7b87527e060cb6637e7b8a009137c))
140
+ - 支持配置底部按钮&优化属性配置 ([db07029](https://github.com/jdfed/drip-form/commit/db070296f612a2ff3394424f319f0e27b2734fae))
141
+ - 支持拖拽 ([45bba5c](https://github.com/jdfed/drip-form/commit/45bba5c4f75a268b06310105b6865bb42f3eca39))
142
+ - **generator:** 支持校验 ([93367c5](https://github.com/jdfed/drip-form/commit/93367c5d965007638b51653459f1faeff9d637c5))
143
+ - **generator:** 支持校验联动 ([ed519f5](https://github.com/jdfed/drip-form/commit/ed519f559ea5ceb0524787f6a8e343fbe845024b))
144
+ - 支持 set、get、merge ([dc267b6](https://github.com/jdfed/drip-form/commit/dc267b6a23d7d9a8b5bf3edff303adfed7a98056))
145
+ - babel-form 初始化 ([51fd2af](https://github.com/jdfed/drip-form/commit/51fd2af04a66c1d84970a8060174e20b0d859746))
146
+ - container 外部封装高阶拖拽组件 ([45f8427](https://github.com/jdfed/drip-form/commit/45f842764601aaa44b267a39f3530827be11c0a3))
147
+ - generator 可视化拖拽区域进度 80% ([b999cfd](https://github.com/jdfed/drip-form/commit/b999cfde748d98ee6cac457636893a7a7f74ee02))
148
+ - jest 单元测试&&utils 单测&&fix: seetDeepProp ([30748ee](https://github.com/jdfed/drip-form/commit/30748eea8f48260184a92c0bf300b7033b33cb8f))
149
+ - merge master ([1f5d45c](https://github.com/jdfed/drip-form/commit/1f5d45ce1cdd7b86a80cd049631eb9d46a6310e7))
150
+ - setDeepProp typeMap 未定义,默认未对象 ([312db6e](https://github.com/jdfed/drip-form/commit/312db6e073b574e9ad292373bd4dde9591d14e28))
151
+ - upload 支持 maxFileNumber 和 customUpload ([54c3611](https://github.com/jdfed/drip-form/commit/54c361148e66e65ea0ec505b2bf6cb059048eba2))
152
+
153
+ ### Bug Fixes
154
+
155
+ - 必填校验失效 ([393e65a](https://github.com/jdfed/drip-form/commit/393e65a964594430a5f856e6cbba605cbe414693))
156
+ - 修复导出包无法被 vite 或 snowpack 使用的问题 ([37f6636](https://github.com/jdfed/drip-form/commit/37f6636124ecd3223eac7152fb19a4accf2c5ca8))
157
+ - 修复合并冲突 ([2fcc913](https://github.com/jdfed/drip-form/commit/2fcc9132017b121ad849a5d7f6186ba7cd628673))
158
+ - 修复如时间选择器这类一个 fieldKey 对应多个值的组件,在 parse 和 combine 中子项被错误解析的问题 ([e11e0e1](https://github.com/jdfed/drip-form/commit/e11e0e1d55c4aaf90405a6c3387a8bb5fbbd2843))
159
+ - 修复样式包的问题 ([7a87bdf](https://github.com/jdfed/drip-form/commit/7a87bdf9e7364493e541fe60f653067336bef9a0))
160
+ - 修复一系列问题 ([52d3e42](https://github.com/jdfed/drip-form/commit/52d3e4258f962958189f1c8ced9b8c20dcf24653))
161
+ - 修复因 ajv 版本不一致导致的报错问题 ([ecf0901](https://github.com/jdfed/drip-form/commit/ecf09018d51c66c2e9d328c0696a7cb15ff45188))
162
+ - 修复元组类型解析错误问题 ([b4ada65](https://github.com/jdfed/drip-form/commit/b4ada65f857184c7a3c15012ea5d5d385aac89d4))
163
+ - 修复 combine theme 丢失问题 ([f9979f1](https://github.com/jdfed/drip-form/commit/f9979f168e5f15bbbae27d6c3a8f49c3cbc6b409))
164
+ - 修复 combine 未针对 errorMessage 处理的问题 ([46b3027](https://github.com/jdfed/drip-form/commit/46b30273fbbefcf38fae1bbccdcfdc2a3dec2503))
165
+ - 修复 common.ts ([86c0d9a](https://github.com/jdfed/drip-form/commit/86c0d9a3f3b7a68f0b212dd030fea84f6ea0381f))
166
+ - 修复 dataSchema 中包含$container 的问题 ([044ee44](https://github.com/jdfed/drip-form/commit/044ee44d71c27b3ab83328797c2131d20ea2c4da))
167
+ - 修复 errMsg 在 combine 中丢失的问题 ([f106ab6](https://github.com/jdfed/drip-form/commit/f106ab6c0463913b4e636aeb2d7d4c310f30623a))
168
+ - 修复 errorMessage parse 时放置位置错误的问题 ([82d77a2](https://github.com/jdfed/drip-form/commit/82d77a2d69646864287302e8c88ac166236795da))
169
+ - 修复 exports 被删除后无法打包的问题 ([9d54151](https://github.com/jdfed/drip-form/commit/9d54151a8445fd0b7849b1ce2f806f4db8ef07a1))
170
+ - 修复 typePath 没有动态生成的问题 ([f338118](https://github.com/jdfed/drip-form/commit/f338118011f394e74975a73d09f7168ef4e7692a))
171
+ - 修复 usefield 删除校验状态异常&number 为 0 非空判断 ([242d503](https://github.com/jdfed/drip-form/commit/242d50319875eb007440e36800e08158aef8022b))
172
+ - 修复 viewport 无法更新 schema 的问题 & parse 对于无 fieldKey 状态的兜底处理逻辑 ([007cd89](https://github.com/jdfed/drip-form/commit/007cd897855c8b680d16823c5dca6a6f3e6afa05))
173
+ - 一系列问题 ([52f612a](https://github.com/jdfed/drip-form/commit/52f612a37c20c55ae5957365aa249e9ffff96db3))
174
+ - 移除多余 console & 调整代码结构 ([bc17f1a](https://github.com/jdfed/drip-form/commit/bc17f1aca8e9e5dfdbca23ea01d51af869dfd056))
175
+ - combine 方法中的判空处理 ([97c8f45](https://github.com/jdfed/drip-form/commit/97c8f454ea176edfa1c38c7c0f00f819c0032295))
176
+ - fieldKey 第一层级为数字索引时,typeMap 正则解析错误 ([069aabc](https://github.com/jdfed/drip-form/commit/069aabcb6d365ed2e414be9181d92d6828554394))
177
+ - isEmpty 传布尔值,返回 false ([2d5624b](https://github.com/jdfed/drip-form/commit/2d5624bf326cb2ef204fdd9b54595211d08f93eb))
178
+ - ts 声明 ([7800503](https://github.com/jdfed/drip-form/commit/7800503addeaf8b2a75ac8fd205934d00a0c8479))
179
+ - ts 支持 ([f75b705](https://github.com/jdfed/drip-form/commit/f75b705eaa00890bcd9c7f442c5521e770b16849))
180
+
181
+ ### Performance Improvements
182
+
183
+ - 优化右侧面板联动渲染区的逻辑 ([2233a14](https://github.com/jdfed/drip-form/commit/2233a1472d630df83da6984fcdba0f52a93ccfaa))
184
+ - parse 移除 delete null 操作 ([aae5528](https://github.com/jdfed/drip-form/commit/aae55288b99f778c6d2cad86749acf0ea73927e8))
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@drip/utils`
2
+
3
+ > drip-form 通用方法
4
+
5
+ - 持续更新
6
+
7
+ | 函数名 | 函数说明 | 参数类型 | 返回值类型 |
8
+ | :---------- | :------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------- | :--------- |
9
+ | typeCheck | 基本数据类型检测 | `any` | `string` |
10
+ | isEmpty | 判断变量是否为空 | `any` | `boolean` |
11
+ | setDeepProp | 设置 data.a.b.c = value,若 data 没有 a.b 则依次赋值空对象,最后再将 a.b.c 设为 value | `{keys: string[], data: {[ key:string ]: any}, value: string | number | boolean}` | `any` |
@@ -0,0 +1,102 @@
1
+ import { combine } from '../src/index'
2
+ import {
3
+ parsedSchema as test1,
4
+ unitedSchema as verify1,
5
+ } from '../__testsdata__/multinest.schema'
6
+ import {
7
+ parsedSchema as test2,
8
+ unitedSchema as verify2,
9
+ } from '../__testsdata__/nest.schema'
10
+ import {
11
+ parsedSchema as test3,
12
+ unitedSchema as verify3,
13
+ } from '../__testsdata__/nestObject.schema'
14
+ import {
15
+ unitedSchema as verify4,
16
+ parsedSchema as test4,
17
+ } from '../__testsdata__/errMsg.schema'
18
+ import {
19
+ unitedSchema as verify5,
20
+ parsedSchema as test5,
21
+ } from '../__testsdata__/errMsg2.schema'
22
+ import {
23
+ unitedSchema as verify6,
24
+ parsedSchema as test6,
25
+ } from '../__testsdata__/errMsg3.schema'
26
+ import {
27
+ unitedSchema as verify7,
28
+ parsedSchema as test7,
29
+ } from '../__testsdata__/datePicker.schema'
30
+ import {
31
+ unitedSchema as verify8,
32
+ parsedSchema as test8,
33
+ } from '../__testsdata__/array.schema'
34
+ import {
35
+ unitedSchema as verify9,
36
+ parsedSchema as test9,
37
+ } from '../__testsdata__/test$fieldKey.schema'
38
+ import {
39
+ unitedSchema as verify10,
40
+ parsedSchema as test10,
41
+ } from '../__testsdata__/root.schema'
42
+ import {
43
+ unitedSchema as verify11,
44
+ parsedSchema as test11,
45
+ } from '../__testsdata__/test.schema'
46
+
47
+ describe('combine', () => {
48
+ test('test dataPicker.schema', () => {
49
+ const data = combine(test7.dataSchema, test7.uiSchema)
50
+ // fs.writeFileSync('./data.json', JSON.stringify(data))
51
+ expect(data).toStrictEqual(verify7)
52
+ })
53
+
54
+ test('test multinest.schema', () => {
55
+ const data = combine(test1.dataSchema, test1.uiSchema)
56
+ // fs.writeFileSync('./data.json', JSON.stringify(data))
57
+ expect(data).toStrictEqual(verify1)
58
+ })
59
+
60
+ test('test nest.schema', () => {
61
+ const data = combine(test2.dataSchema, test2.uiSchema)
62
+ // fs.writeFileSync('./data.json', JSON.stringify(data))
63
+ expect(data).toStrictEqual(verify2)
64
+ })
65
+
66
+ test('test nestObject.schema', () => {
67
+ const data = combine(test3.dataSchema, test3.uiSchema)
68
+ // fs.writeFileSync('./data.json', JSON.stringify(data))
69
+ expect(data).toStrictEqual(verify3)
70
+ })
71
+
72
+ test('test errMsg.schema.js', () => {
73
+ const data = combine(test4.dataSchema, test4.uiSchema)
74
+ expect(data).toStrictEqual(verify4)
75
+ })
76
+
77
+ test('test errMsg2.schema.js', () => {
78
+ const data = combine(test5.dataSchema, test5.uiSchema)
79
+ expect(data).toStrictEqual(verify5)
80
+ })
81
+
82
+ test('test errMsg3.schema.js', () => {
83
+ const data = combine(test6.dataSchema, test6.uiSchema)
84
+ expect(data).toStrictEqual(verify6)
85
+ })
86
+ test('test array.schema.js', () => {
87
+ const data = combine(test8.dataSchema, test8.uiSchema)
88
+ expect(data).toStrictEqual(verify8)
89
+ })
90
+ test('test errMsg4.schema.js', () => {
91
+ const data = combine(test9.dataSchema, test9.uiSchema, { $fieldKey: true })
92
+ expect(data).toStrictEqual(verify9)
93
+ })
94
+ test('test root.schema.js', () => {
95
+ const data = combine(test10.dataSchema, test10.uiSchema)
96
+ expect(data).toStrictEqual(verify10)
97
+ })
98
+ test('test test.schema.js', () => {
99
+ const data = combine(test11.dataSchema, test11.uiSchema)
100
+ expect(data).toStrictEqual(verify11)
101
+ })
102
+ })
@@ -0,0 +1,155 @@
1
+ /* eslint-disable quotes */
2
+ import {
3
+ generateReg,
4
+ typeCheck,
5
+ isEmpty,
6
+ setDeepProp,
7
+ deleteDeepProp,
8
+ judgeAndRegister,
9
+ parseHrefParam,
10
+ } from '../src/index'
11
+
12
+ describe('generateReg', () => {
13
+ test('generateReg(["a"])===/^a$/ig', () => {
14
+ expect(generateReg(['a'])).toStrictEqual(/^a$/gi)
15
+ })
16
+ test('generateReg(["0"])===/^(0|\\$container)$/ig', () => {
17
+ expect(generateReg(['0'])).toStrictEqual(/^(0|\$container)$/gi)
18
+ })
19
+ test('generateReg(["a","0"])===/^a\\.(\\d+|\\$container)$/ig', () => {
20
+ expect(generateReg(['a', '0'])).toStrictEqual(/^a\.(0|\$container)$/gi)
21
+ })
22
+ test('generateReg(["a","0","b"])===/^a\\.(\\d+|\\$container)\\.b$/ig', () => {
23
+ expect(generateReg(['a', '0', 'b'])).toStrictEqual(
24
+ /^a\.(0|\$container)\.b$/gi
25
+ )
26
+ })
27
+ test('generateReg(["common","$required"])===/^common\\.\\$requiredb$/ig', () => {
28
+ expect(generateReg(['common', '$required'])).toStrictEqual(
29
+ /^common\.\$required$/gi
30
+ )
31
+ })
32
+ })
33
+
34
+ describe('typeCheck', () => {
35
+ test('typeCheck(1) === "Number"', () => {
36
+ expect(typeCheck(1)).toBe('Number')
37
+ })
38
+ test('typeCheck("1") === "String"', () => {
39
+ expect(typeCheck('1')).toBe('String')
40
+ })
41
+ test('typeCheck(null) === "Null"', () => {
42
+ expect(typeCheck(null)).toBe('Null')
43
+ })
44
+ test('typeCheck(undefined) === "Undefined"', () => {
45
+ expect(typeCheck(undefined)).toBe('Undefined')
46
+ })
47
+ test('typeCheck(false) or typeCheck(true) === "Boolean"', () => {
48
+ expect(typeCheck(false)).toBe('Boolean')
49
+ expect(typeCheck(true)).toBe('Boolean')
50
+ })
51
+ test('typeCheck({}) === "Object"', () => {
52
+ expect(typeCheck({})).toBe('Object')
53
+ })
54
+ test('typeCheck([]) === "Array"', () => {
55
+ expect(typeCheck([])).toBe('Array')
56
+ })
57
+ })
58
+
59
+ describe('isEmpty', () => {
60
+ test('arg is a number、array.length>0、string.length>0、boolean,isEmpty return false', () => {
61
+ expect(isEmpty(0)).toBeFalsy()
62
+ expect(isEmpty([1])).toBeFalsy()
63
+ expect(isEmpty('1')).toBeFalsy()
64
+ expect(isEmpty(false)).toBeFalsy()
65
+ })
66
+ test('arg is null、undefined、[]、""、,isEmpty return true', () => {
67
+ expect(isEmpty(null)).toBeTruthy()
68
+ expect(isEmpty(undefined)).toBeTruthy()
69
+ expect(isEmpty([])).toBeTruthy()
70
+ expect(isEmpty('')).toBeTruthy()
71
+ })
72
+ test('arg is a object,isEmpty return !Object.keys(object).length>0', () => {
73
+ expect(isEmpty({})).toBeTruthy()
74
+ expect(isEmpty({ a: 1 })).toBeFalsy()
75
+ })
76
+ })
77
+ // TODO 针对typeMap做优化
78
+ describe('setDeepProp', () => {
79
+ test('setDeepProp([a],{},1) can set args[1] === {a:1}', () => {
80
+ const data = {}
81
+ setDeepProp(['a'], data, 1)
82
+ expect(data).toStrictEqual({ a: 1 })
83
+ })
84
+ test('setDeepProp([a,b,c],{},1) can set args[1] === {a:{b:{c:1}}}', () => {
85
+ const data = {}
86
+ setDeepProp(['a', 'b', 'c'], data, 1)
87
+ expect(data).toStrictEqual({ a: { b: { c: 1 } } })
88
+ })
89
+ test('setDeepProp([a,b,c],{a:{b:{}}},1) can set args[1] === {a:{b:{c:1}}}', () => {
90
+ const data = { a: { b: {} } }
91
+ setDeepProp(['a', 'b', 'c'], data, 1)
92
+ expect(data).toStrictEqual({
93
+ a: { b: { c: 1 } },
94
+ })
95
+ })
96
+ test('setDeepProp([],{},1)', () => {
97
+ const data = {}
98
+ setDeepProp([], data, 1)
99
+ expect(data).toStrictEqual({})
100
+ })
101
+ })
102
+ // 针对数组做优化
103
+ describe('deleteDeepProp', () => {
104
+ test('deleteDeepProp([],{a:1}) === {a:1}', () => {
105
+ const data = { a: 1 }
106
+ deleteDeepProp([], data)
107
+ expect(data).toStrictEqual({ a: 1 })
108
+ })
109
+ test('deleteDeepProp([a,b],{c:1}) === {c:1}', () => {
110
+ const data = { c: 1 }
111
+ deleteDeepProp(['a', 'b'], data)
112
+ expect(data).toStrictEqual({ c: 1 })
113
+ })
114
+ test('deleteDeepProp([a,b],{a:1}) === {a:1}', () => {
115
+ const data = { a: 1 }
116
+ deleteDeepProp(['a', 'b'], data)
117
+ expect(data).toStrictEqual({ a: 1 })
118
+ })
119
+ test('deleteDeepProp([a,b],{a:{b:1}}) === {a:{}}', () => {
120
+ const data = { a: { b: 1 } }
121
+ deleteDeepProp(['a', 'b'], data)
122
+ expect(data).toStrictEqual({ a: {} })
123
+ })
124
+ })
125
+
126
+ describe('judgeAndRegister', () => {
127
+ test("judgeAndRegister({}, 'object', 'properties', 'item') === {}", () => {
128
+ const data = judgeAndRegister({}, 'object', 'properties', 'item')
129
+ expect(data).toStrictEqual({})
130
+ })
131
+
132
+ test("judgeAndRegister({}, 'array', 'order') === []", () => {
133
+ const data = judgeAndRegister({}, 'array', 'order')
134
+ expect(data).toStrictEqual([])
135
+ })
136
+ })
137
+
138
+ describe('parseHrefParam', () => {
139
+ test("parseHrefParam('babel.m.jd.com/manage/index?manage_type=myprojects&projectId=2740440')", () => {
140
+ const data = parseHrefParam(
141
+ 'www.iconfont.cn/manage/index?manage_type=myprojects&projectId=2740440'
142
+ )
143
+ expect(data).toStrictEqual({
144
+ manage_type: 'myprojects',
145
+ projectId: '2740440',
146
+ })
147
+ })
148
+
149
+ test("parseHrefParam('babel.m.jd.com/manage/index?manage_type=myprojects&projectId')", () => {
150
+ const data = parseHrefParam(
151
+ 'www.iconfont.cn/manage/index?manage_type=myprojects&projectId'
152
+ )
153
+ expect(data).toStrictEqual({ manage_type: 'myprojects', projectId: true })
154
+ })
155
+ })
@@ -0,0 +1,16 @@
1
+ import {
2
+ flowCondintion,
3
+ flowEffectTestData,
4
+ } from '../__testsdata__/controlFlow'
5
+ import { parseFlow } from '../src'
6
+
7
+ describe.skip('parseFlow', () => {
8
+ test('controlFlow', () => {
9
+ expect(parseFlow(flowCondintion)).toBe(
10
+ "const {get,set,merge,setDeepProp,changeKey}=props;if((get('a').uiSchema?.disabled===true)&&(get('b').uiSchema?.a!==\"c\")&&(get('c').dataSchema?.default===\"c\")||(get('c').data?.d===\"c\")||(get('c').dataSchema?.default===\"c\")&&(get('a.a1').uiSchema?.disabled===true)||(get('b.b1').uiSchema?.a!==\"c\")&&(get('c.c1').dataSchema?.default===\"c\")&&(get('c.c1').data?.d===\"c\")||(get('c.c1').dataSchema?.default===\"c\")){set('b','data',\"\");};"
11
+ )
12
+ expect(parseFlow(flowEffectTestData)).toBe(
13
+ "const {get,set,merge,setDeepProp,changeKey}=props;if((get('b').undefined!==\"c\")){set('a','data',\"b\");set('a','uiSchema',(oldValue)=>{setDeepProp([\"vcontrol\"],oldValue,\"const {get}=props;return (get('b').undefined!==\"c\")\")});set('b','dataSchema',(oldValue)=>{setDeepProp([\"default\"],oldValue,\"1\")});set('c','data',(oldValue)=>{setDeepProp([\"property\"],oldValue,\"1\")});set('a1.a2','uiSchema',(oldValue)=>{setDeepProp([\"vcontrol\"],oldValue,\"const {get}=props;return (get('b').undefined!==\"c\")\")});set('b1.b2','dataSchema',(oldValue)=>{setDeepProp([\"default\"],oldValue,\"1\")});set('c1.c2','data',(oldValue)=>{setDeepProp([\"property\"],oldValue,\"1\")});};"
14
+ )
15
+ })
16
+ })
@@ -0,0 +1,109 @@
1
+ import { parseUnitedSchema, UnitedSchema } from '../src/index'
2
+ import {
3
+ unitedSchema as test1,
4
+ parsedSchema as verify1,
5
+ } from '../__testsdata__/multinest.schema'
6
+ import {
7
+ unitedSchema as test2,
8
+ parsedSchema as verify2,
9
+ } from '../__testsdata__/nest.schema'
10
+ import {
11
+ unitedSchema as test3,
12
+ parsedSchema as verify3,
13
+ } from '../__testsdata__/nestObject.schema'
14
+ import {
15
+ unitedSchema as test4,
16
+ parsedSchema as verify4,
17
+ } from '../__testsdata__/errMsg.schema'
18
+ import {
19
+ unitedSchema as test5,
20
+ parsedSchema as verify5,
21
+ } from '../__testsdata__/errMsg2.schema'
22
+ import {
23
+ unitedSchema as test6,
24
+ parsedSchema as verify6,
25
+ } from '../__testsdata__/errMsg3.schema'
26
+ import {
27
+ unitedSchema as test7,
28
+ parsedSchema as verify7,
29
+ } from '../__testsdata__/datePicker.schema'
30
+ import {
31
+ unitedSchema as test8,
32
+ parsedSchema as verify8,
33
+ } from '../__testsdata__/array.schema'
34
+ import {
35
+ unitedSchema as test9,
36
+ parsedSchema as verify9,
37
+ } from '../__testsdata__/errMsg4.schema'
38
+ import {
39
+ unitedSchema as test10,
40
+ parsedSchema as verify10,
41
+ } from '../__testsdata__/root.schema'
42
+ import {
43
+ unitedSchema as test11,
44
+ parsedSchema as verify11,
45
+ } from '../__testsdata__/test.schema'
46
+ import {
47
+ unitedSchema as test12,
48
+ parsedSchema as verify12,
49
+ } from '../__testsdata__/repeatField.schema'
50
+
51
+ describe('parseUnitedSchema', () => {
52
+ test('test datePicker.schema.js', () => {
53
+ const data = parseUnitedSchema(test7 as UnitedSchema)
54
+ expect(data).toStrictEqual(verify7)
55
+ })
56
+
57
+ test('test multinest.schema.js', () => {
58
+ const data = parseUnitedSchema(test1 as UnitedSchema)
59
+ expect(data).toStrictEqual(verify1)
60
+ })
61
+
62
+ test('test nest.schema.js', () => {
63
+ const data = parseUnitedSchema(test2 as UnitedSchema)
64
+ expect(data).toStrictEqual(verify2)
65
+ })
66
+
67
+ test('test nestObject.schema.js', () => {
68
+ const data = parseUnitedSchema(test3 as UnitedSchema)
69
+ expect(data).toStrictEqual(verify3)
70
+ })
71
+
72
+ test('test errMsg.schema.js', () => {
73
+ const data = parseUnitedSchema(test4 as UnitedSchema)
74
+ expect(data).toStrictEqual(verify4)
75
+ })
76
+
77
+ test('test errMsg.schema2.js', () => {
78
+ const data = parseUnitedSchema(test5 as UnitedSchema)
79
+ expect(data).toStrictEqual(verify5)
80
+ })
81
+
82
+ test('test errMsg.schema3.js', () => {
83
+ const data = parseUnitedSchema(test6 as UnitedSchema)
84
+ expect(data).toStrictEqual(verify6)
85
+ })
86
+
87
+ test('test errMsg4.schema.js', () => {
88
+ const data = parseUnitedSchema(test9 as UnitedSchema)
89
+ expect(data).toStrictEqual(verify9)
90
+ })
91
+
92
+ test('test array.schema.js', () => {
93
+ const data = parseUnitedSchema(test8 as UnitedSchema)
94
+ expect(data).toStrictEqual(verify8)
95
+ })
96
+ test('test root.schema.js', () => {
97
+ const data = parseUnitedSchema(test10 as UnitedSchema)
98
+ expect(data).toStrictEqual(verify10)
99
+ })
100
+
101
+ test('test test.schema.js', () => {
102
+ const data = parseUnitedSchema(test11 as UnitedSchema)
103
+ expect(data).toStrictEqual(verify11)
104
+ })
105
+ test('test repeatField.schema.js', () => {
106
+ const data = parseUnitedSchema(test12 as UnitedSchema)
107
+ expect(data).toStrictEqual(verify12)
108
+ })
109
+ })