@formily-djd/utils 0.0.1
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/dist/index.d.ts +75 -0
- package/dist/index.js +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/object.d.ts
|
|
2
|
+
declare function getByPath(obj: any, path: string, options?: {
|
|
3
|
+
transformKey?: (key: string) => string;
|
|
4
|
+
}): any;
|
|
5
|
+
declare function setByPath(obj: any, path: string, value: any): void;
|
|
6
|
+
/**
|
|
7
|
+
* 从路径删除节点并返回删除的值
|
|
8
|
+
* @param obj 目标对象
|
|
9
|
+
* @param path 路径(如 "username" 或 "users.properties.name")
|
|
10
|
+
* @returns 删除的值
|
|
11
|
+
*/
|
|
12
|
+
declare function deleteByPath(obj: any, path: string): any;
|
|
13
|
+
/**
|
|
14
|
+
* 在指定位置插入字段
|
|
15
|
+
* @param obj 目标对象(应该是 schema 根对象,包含 properties)
|
|
16
|
+
* @param targetPath 目标路径
|
|
17
|
+
* @param fieldName 新字段名
|
|
18
|
+
* @param value 新字段值
|
|
19
|
+
* @param position 插入位置 ('before' | 'after')
|
|
20
|
+
*/
|
|
21
|
+
declare function insertFieldByPath(obj: any, targetPath: string, fieldName: string, value: any, position?: 'before' | 'after'): void;
|
|
22
|
+
/**
|
|
23
|
+
* 获取父路径
|
|
24
|
+
* @param path 完整路径
|
|
25
|
+
* @returns 父路径,如果是根路径则返回 null
|
|
26
|
+
*/
|
|
27
|
+
declare function getParentPath(path: string): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* 从路径中提取字段名
|
|
30
|
+
* @param path 完整路径(如 "users.properties.name")
|
|
31
|
+
* @returns 字段名(如 "name")
|
|
32
|
+
*/
|
|
33
|
+
declare function getFieldNameFromPath(path: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* 递归获取所有字段名
|
|
36
|
+
* @param schema Schema 对象
|
|
37
|
+
* @param prefix 路径前缀
|
|
38
|
+
* @returns 所有字段名数组
|
|
39
|
+
*/
|
|
40
|
+
declare function getAllFieldNames(schema: any, prefix?: string): string[];
|
|
41
|
+
/**
|
|
42
|
+
* 生成唯一的字段名
|
|
43
|
+
* @param prefix 前缀(通常是组件key)
|
|
44
|
+
* @param existingNames 已存在的字段名列表
|
|
45
|
+
* @returns 唯一的字段名
|
|
46
|
+
*/
|
|
47
|
+
declare function generateUniqueFieldName(prefix: string, existingNames: string[]): string;
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/shared.d.ts
|
|
50
|
+
declare const SchemaStateMap: {
|
|
51
|
+
title: string;
|
|
52
|
+
description: string;
|
|
53
|
+
default: string;
|
|
54
|
+
enum: string;
|
|
55
|
+
readOnly: string;
|
|
56
|
+
writeOnly: string;
|
|
57
|
+
'x-content': string;
|
|
58
|
+
'x-data': string;
|
|
59
|
+
'x-value': string;
|
|
60
|
+
'x-editable': string;
|
|
61
|
+
'x-disabled': string;
|
|
62
|
+
'x-read-pretty': string;
|
|
63
|
+
'x-read-only': string;
|
|
64
|
+
'x-visible': string;
|
|
65
|
+
'x-hidden': string;
|
|
66
|
+
'x-display': string;
|
|
67
|
+
'x-pattern': string;
|
|
68
|
+
'x-validator': string;
|
|
69
|
+
'x-decorator': string;
|
|
70
|
+
'x-component': string;
|
|
71
|
+
'x-decorator-props': string;
|
|
72
|
+
'x-component-props': string;
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { SchemaStateMap, deleteByPath, generateUniqueFieldName, getAllFieldNames, getByPath, getFieldNameFromPath, getParentPath, insertFieldByPath, setByPath };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n){let{transformKey:r=e=>e}=n||{};return t.split(`.`).reduce((e,t)=>e?.[r(t)],e)}function t(e,t,n){let r=t.split(`.`),i=r.pop(),a=r.reduce((e,t)=>((!e[t]||typeof e[t]!=`object`)&&(e[t]={}),e[t]),e);a[i]=n}function n(t,n){let r=n.split(`.`),i=r.pop(),a=r.length>0?e(t,r.join(`.`)):t;if(!a||typeof a!=`object`)return;let o=a[i];return delete a[i],o}function r(t,n,r,i,a=`after`){let o=n.split(`.`),s=o.pop(),c=o.join(`.`),l=c?e(t,c):t;if(!l)return;l.properties||={};let u=l.properties,d=Object.entries(u),f=d.findIndex(([e])=>e===s);if(f===-1){u[r]=i;return}let p=a===`after`?f+1:f,m=[...d.slice(0,p),[r,i],...d.slice(p)];Object.keys(u).forEach(e=>delete u[e]),m.forEach(([e,t])=>{u[e]=t})}function i(e){let t=e.split(`.`);return t.length<=1?null:(t.pop(),t.join(`.`))}function a(e){let t=e.split(`.`);return t[t.length-1]}function o(e,t=``){let n=[];return!e||typeof e!=`object`?n:(e.properties&&typeof e.properties==`object`&&Object.keys(e.properties).forEach(r=>{let i=t?`${t}.${r}`:r;n.push(r),n.push(...o(e.properties[r],i))}),e.items?.properties&&typeof e.items.properties==`object`&&Object.keys(e.items.properties).forEach(r=>{let i=t?`${t}.items.properties.${r}`:r;n.push(r),n.push(...o(e.items.properties[r],i))}),n)}function s(e,t){let n=1,r=`${e}_${n}`;for(;t.includes(r);)n++,r=`${e}_${n}`;return r}const c={title:`title`,description:`description`,default:`initialValue`,enum:`dataSource`,readOnly:`readOnly`,writeOnly:`editable`,"x-content":`content`,"x-data":`data`,"x-value":`value`,"x-editable":`editable`,"x-disabled":`disabled`,"x-read-pretty":`readPretty`,"x-read-only":`readOnly`,"x-visible":`visible`,"x-hidden":`hidden`,"x-display":`display`,"x-pattern":`pattern`,"x-validator":`validator`,"x-decorator":`decoratorType`,"x-component":`componentType`,"x-decorator-props":`decoratorProps`,"x-component-props":`componentProps`};export{c as SchemaStateMap,n as deleteByPath,s as generateUniqueFieldName,o as getAllFieldNames,e as getByPath,a as getFieldNameFromPath,i as getParentPath,r as insertFieldByPath,t as setByPath};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@formily-djd/utils",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "utils for formily-djd",
|
|
6
|
+
"author": "gaojinsong2010@gmail.com",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"main": "./dist/index.js",
|
|
13
|
+
"module": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "export NODE_ENV=production && tsdown",
|
|
20
|
+
"dev": "export NODE_ENV=development && tsdown --watch",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"lint": "eslint",
|
|
24
|
+
"lint:fix": "eslint --fix",
|
|
25
|
+
"release": "bumpp"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@antfu/eslint-config": "^5.4.1",
|
|
29
|
+
"@types/node": "^24.9.1",
|
|
30
|
+
"bumpp": "^10.3.1",
|
|
31
|
+
"eslint": "^9.39.0",
|
|
32
|
+
"tsdown": "^0.15.9",
|
|
33
|
+
"typescript": "^5.9.3",
|
|
34
|
+
"vitest": "^4.0.1"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"registry": "https://registry.npmjs.org"
|
|
39
|
+
}
|
|
40
|
+
}
|