Skip to content

Commit dd9cdfd

Browse files
committed
pref: import default config
1 parent 5a8074a commit dd9cdfd

14 files changed

+61
-50
lines changed

.markdownlint.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"blanks-around-fences": false
2+
"blanks-around-fences": false,
3+
"line_length": false
34
}

package.json

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@axolo/tree-array",
3-
"version": "0.5.3",
3+
"version": "0.5.4",
44
"description": "An array have children key and parentId key like tree.",
55
"author": "Yueming Fang",
66
"license": "MIT",
@@ -9,6 +9,23 @@
99
"files": [
1010
"dist"
1111
],
12+
"scripts": {
13+
"dev": "vite",
14+
"build": "vite build",
15+
"preview": "vite preview",
16+
"build:npm": "vite build --config npm.config.js",
17+
"dev:docs": "vitepress dev docs",
18+
"build:docs": "vitepress build docs"
19+
},
20+
"devDependencies": {
21+
"@vitejs/plugin-vue": "^5.1.4",
22+
"lodash.clonedeep": "^4.5.0",
23+
"sass": "^1.79.4",
24+
"vite": "^5.4.8",
25+
"vitepress": "^1.3.4",
26+
"vue": "^3.5.10",
27+
"vue-json-pretty": "^2.4.0"
28+
},
1229
"keywords": [
1330
"random id",
1431
"random key",
@@ -29,23 +46,5 @@
2946
"repository": {
3047
"type": "git",
3148
"url": "git+https://github.com/axolo/tree-array.git"
32-
},
33-
"scripts": {
34-
"dev": "vite",
35-
"build": "vite build",
36-
"preview": "vite preview",
37-
"build:npm": "vite build --config npm.config.js",
38-
"dev:docs": "vitepress dev docs",
39-
"build:docs": "vitepress build docs"
40-
},
41-
"devDependencies": {
42-
"@babel/core": "^7.24.4",
43-
"@vitejs/plugin-vue": "^5.0.4",
44-
"lodash.clonedeep": "^4.5.0",
45-
"sass": "^1.74.1",
46-
"vite": "^5.2.8",
47-
"vitepress": "^1.1.4",
48-
"vue": "^3.4.21",
49-
"vue-json-pretty": "^2.4.0"
5049
}
5150
}

src/lib/array-deep.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const arrayDeep = (array, options, deep = 1) => {
2-
options = { idKey: 'id', parentKey: 'parentId', ...options }
4+
options = { ...config, ...options }
35
const { idKey, parentKey } = options
46
let temp = [...array]
57
temp = array.filter(a => temp.some(b => b[parentKey] === a[idKey]))

src/lib/array-node.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const arrayNode = (array, id, options, parents = []) => {
2-
options = { idKey: 'id', parentKey: 'parentId', ...options }
4+
options = { ...config, ...options }
35
const { idKey, parentKey } = options
46
const item = array.find(a => a[idKey] === id)
57
if (!item || !item[idKey]) return parents

src/lib/array-parents.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const arrayParents = (id, array = [], options, parents = []) => {
2-
options = { idKey: 'id', parentKey: 'parentId', ...options }
4+
options = { ...config, ...options }
35
const { idKey, parentKey } = options
46
const item = array.find(a => a[idKey] === id)
57
if (!item || !item[idKey]) return parents

src/lib/array-trace.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const arrayTrace = (array, id, options, parents = []) => {
2-
options = { idKey: 'id', parentKey: 'parentId', ...options }
4+
options = { ...config, ...options }
35
const { idKey, parentKey } = options
46
const item = array.find(a => a[idKey] === id)
57
if (!item || !item[idKey]) return parents

src/lib/array2tree.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1+
import config from './config'
2+
13
const array2tree = (array, options) => {
24
if (!Array.isArray(array)) return array
3-
4-
options = {
5-
idKey: 'id',
6-
parentKey: 'parentId',
7-
childrenKey: 'children',
8-
leafKey: 'leaf',
9-
leafValue: true,
10-
deepKey: 'deep',
11-
deepValue: 0,
12-
...options
13-
}
14-
5+
options = { ...config, ...options }
156
const { parentKey, idKey, childrenKey, leafKey, leafValue, deepKey, deepValue } = options
167
const roots = array.filter(a => !a[parentKey] || !array.some(b => b[idKey] === a[parentKey]))
178

src/lib/config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
idKey: 'id',
3+
parentKey: 'parentId',
4+
childrenKey: 'children',
5+
leafKey: 'leaf',
6+
leafValue: true,
7+
deepKey: 'deep',
8+
deepValue: 0
9+
}

src/lib/tree-deep.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const treeDeep = (tree, options, deep = 1) => {
2-
options = { childrenKey: 'children', ...options }
4+
options = { ...config, ...options }
35
const { childrenKey } = options
46
let has = false
57
let temp = []

src/lib/tree-filter.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const filterTree = (tree, condition, options) => {
2-
options = { childrenKey: 'children', ...options }
4+
options = { ...config, ...options }
35
const { childrenKey } = options
46

57
return tree.filter(node => {

src/lib/tree-node.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const treeNode = (tree, targetId, options, currentPath = []) => {
2-
options = { idKey: 'id', childrenKey: 'children', ...options }
4+
options = { ...config, ...options }
35
const { idKey, childrenKey } = options
46

57
for (let node of tree) {

src/lib/tree-path.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const treePath = (tree, targetId, options, currentPath = []) => {
2-
options = { idKey: 'id', childrenKey: 'children', ...options }
4+
options = { ...config, ...options }
35
const { idKey, childrenKey } = options
46

57
for (let i = 0; i < tree.length; i++) {

src/lib/tree-sub.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import config from './config'
2+
13
const treeSub = (tree, id, options) => {
2-
options = { idKey: 'id', childrenKey: 'children', ...options }
4+
options = { ...config, ...options }
35
const { idKey, childrenKey } = options
46

57
for (let i = 0; i < tree.length; i++) {

src/lib/tree2array.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1+
import config from './config'
12
import randomId from "./random-id"
23

34
const tree2array = (tree, options, parentId = null) => {
45
if (!Array.isArray(tree)) return tree
5-
6-
options = {
7-
idKey: 'id',
8-
childrenKey: 'children',
9-
parentKey: 'parentId',
10-
leafKey: 'leaf',
11-
leafValue: true,
12-
...options
13-
}
6+
options = { ...config, ...options }
147
const { idKey, childrenKey, parentKey, leafKey, leafValue } = options
158

169
let result = []

0 commit comments

Comments
 (0)