jostraca 0.1.2 → 0.1.4
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/jostraca.d.ts +11 -7
- package/dist/jostraca.js +115 -77
- package/dist/jostraca.js.map +1 -1
- package/package.json +2 -2
- package/src/jostraca.ts +140 -91
package/dist/jostraca.d.ts
CHANGED
|
@@ -4,13 +4,17 @@ type JostracaOptions = {
|
|
|
4
4
|
};
|
|
5
5
|
type Component = (props: any, children?: any) => void;
|
|
6
6
|
declare function Jostraca(): {
|
|
7
|
-
cmp: (component: Function) => Component;
|
|
8
|
-
each: (subject: any, apply?: any) => any;
|
|
9
7
|
generate: (opts: JostracaOptions, root: Function) => void;
|
|
10
|
-
Project: Component;
|
|
11
|
-
Code: Component;
|
|
12
|
-
File: Component;
|
|
13
|
-
Folder: Component;
|
|
14
8
|
};
|
|
9
|
+
declare const Code: Component;
|
|
10
|
+
declare const File: Component;
|
|
11
|
+
declare const Project: Component;
|
|
12
|
+
declare const Folder: Component;
|
|
13
|
+
declare function cmp(component: Function): Component;
|
|
14
|
+
declare function each(subject: any, apply?: any): any;
|
|
15
|
+
declare function select(key: any, map: Record<string, Function>): any;
|
|
16
|
+
declare function get(root: any, path: string | string[]): any;
|
|
17
|
+
declare function camelify(input: any[] | string): string;
|
|
18
|
+
declare function snakeify(input: any[] | string): string;
|
|
15
19
|
export type { JostracaOptions, Component, };
|
|
16
|
-
export { Jostraca, };
|
|
20
|
+
export { Jostraca, cmp, each, select, get, camelify, snakeify, Project, Code, File, Folder, };
|
package/dist/jostraca.js
CHANGED
|
@@ -24,11 +24,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.Folder = exports.File = exports.Code = exports.Project = void 0;
|
|
27
28
|
exports.Jostraca = Jostraca;
|
|
29
|
+
exports.cmp = cmp;
|
|
30
|
+
exports.each = each;
|
|
31
|
+
exports.select = select;
|
|
32
|
+
exports.get = get;
|
|
33
|
+
exports.camelify = camelify;
|
|
34
|
+
exports.snakeify = snakeify;
|
|
28
35
|
const Fs = __importStar(require("node:fs"));
|
|
29
36
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
37
|
+
const GLOBAL = global;
|
|
30
38
|
function Jostraca() {
|
|
31
|
-
const GLOBAL = global;
|
|
32
39
|
GLOBAL.jostraca = new node_async_hooks_1.AsyncLocalStorage();
|
|
33
40
|
function generate(opts, root) {
|
|
34
41
|
const fs = opts.fs || Fs;
|
|
@@ -38,6 +45,8 @@ function Jostraca() {
|
|
|
38
45
|
root();
|
|
39
46
|
const ctx$ = GLOBAL.jostraca.getStore();
|
|
40
47
|
const node = ctx$.node;
|
|
48
|
+
// console.log('JOSTRACA TOP')
|
|
49
|
+
// console.dir(node, { depth: null })
|
|
41
50
|
build(node, {
|
|
42
51
|
fs,
|
|
43
52
|
current: {
|
|
@@ -48,54 +57,7 @@ function Jostraca() {
|
|
|
48
57
|
});
|
|
49
58
|
});
|
|
50
59
|
}
|
|
51
|
-
function cmp(component) {
|
|
52
|
-
const cf = (props, children) => {
|
|
53
|
-
props = props || {};
|
|
54
|
-
if (null == props || 'object' !== typeof props) {
|
|
55
|
-
props = { arg: props };
|
|
56
|
-
}
|
|
57
|
-
props.ctx$ = GLOBAL.jostraca.getStore();
|
|
58
|
-
children = 'function' === typeof children ? [children] : children;
|
|
59
|
-
let node = {
|
|
60
|
-
kind: 'content',
|
|
61
|
-
children: []
|
|
62
|
-
};
|
|
63
|
-
const parent = props.ctx$.node = (props.ctx$.node || node);
|
|
64
|
-
const siblings = props.ctx$.children = (props.ctx$.children || []);
|
|
65
|
-
siblings.push(node);
|
|
66
|
-
props.ctx$.children = node.children;
|
|
67
|
-
props.ctx$.node = node;
|
|
68
|
-
let out = component(props, children);
|
|
69
|
-
props.ctx$.children = siblings;
|
|
70
|
-
props.ctx$.node = parent;
|
|
71
|
-
return out;
|
|
72
|
-
};
|
|
73
|
-
Object.defineProperty(cf, 'name', { value: component.name });
|
|
74
|
-
return cf;
|
|
75
|
-
}
|
|
76
|
-
function each(subject, apply) {
|
|
77
|
-
if (null == apply) {
|
|
78
|
-
if (Array.isArray(subject)) {
|
|
79
|
-
for (let fn of subject) {
|
|
80
|
-
fn();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
if (Array.isArray(subject)) {
|
|
86
|
-
return subject.map(apply);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const entries = Object.entries(subject);
|
|
90
|
-
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
91
|
-
entries.sort((a, b) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0);
|
|
92
|
-
}
|
|
93
|
-
return entries.map((n, ...args) => apply(n[1], [0], ...args));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
60
|
function build(topnode, ctx) {
|
|
98
|
-
// console.dir(topnode, { depth: null })
|
|
99
61
|
step(topnode, ctx);
|
|
100
62
|
}
|
|
101
63
|
function step(node, ctx) {
|
|
@@ -148,42 +110,118 @@ function Jostraca() {
|
|
|
148
110
|
},
|
|
149
111
|
content: {
|
|
150
112
|
before(node, ctx) {
|
|
151
|
-
const
|
|
152
|
-
ctx.current.file.content.push(
|
|
113
|
+
const content = ctx.current.content = node;
|
|
114
|
+
ctx.current.file.content.push(content.content);
|
|
115
|
+
},
|
|
116
|
+
after(_node, _ctx) {
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
none: {
|
|
120
|
+
before(_node, ctx) {
|
|
153
121
|
},
|
|
154
122
|
after(_node, _ctx) {
|
|
155
123
|
},
|
|
156
124
|
},
|
|
157
125
|
};
|
|
158
|
-
const Code = cmp(function Code(props) {
|
|
159
|
-
let src = props.arg;
|
|
160
|
-
props.ctx$.node.content = src;
|
|
161
|
-
});
|
|
162
|
-
const File = cmp(function File(props, children) {
|
|
163
|
-
props.ctx$.node.kind = 'file';
|
|
164
|
-
props.ctx$.node.name = props.name;
|
|
165
|
-
// Code('// FILE START: ' + props.name + '\n')
|
|
166
|
-
each(children);
|
|
167
|
-
// Code('// FILE END: ' + props.name + '\n')
|
|
168
|
-
});
|
|
169
|
-
const Project = cmp(function Project(props, children) {
|
|
170
|
-
props.ctx$.node.kind = 'project';
|
|
171
|
-
props.ctx$.node.name = props.name;
|
|
172
|
-
each(children);
|
|
173
|
-
});
|
|
174
|
-
const Folder = cmp(function Folder(props, children) {
|
|
175
|
-
props.ctx$.node.kind = 'folder';
|
|
176
|
-
props.ctx$.node.name = props.name;
|
|
177
|
-
each(children);
|
|
178
|
-
});
|
|
179
126
|
return {
|
|
180
|
-
cmp,
|
|
181
|
-
each,
|
|
182
127
|
generate,
|
|
183
|
-
Project,
|
|
184
|
-
Code,
|
|
185
|
-
File,
|
|
186
|
-
Folder,
|
|
187
128
|
};
|
|
188
129
|
}
|
|
130
|
+
const Code = cmp(function Code(props) {
|
|
131
|
+
props.ctx$.node.kind = 'content';
|
|
132
|
+
let src = props.arg;
|
|
133
|
+
props.ctx$.node.content = src;
|
|
134
|
+
});
|
|
135
|
+
exports.Code = Code;
|
|
136
|
+
const File = cmp(function File(props, children) {
|
|
137
|
+
props.ctx$.node.kind = 'file';
|
|
138
|
+
props.ctx$.node.name = props.name;
|
|
139
|
+
// Code('// FILE START: ' + props.name + '\n')
|
|
140
|
+
each(children);
|
|
141
|
+
// Code('// FILE END: ' + props.name + '\n')
|
|
142
|
+
});
|
|
143
|
+
exports.File = File;
|
|
144
|
+
const Project = cmp(function Project(props, children) {
|
|
145
|
+
props.ctx$.node.kind = 'project';
|
|
146
|
+
props.ctx$.node.name = props.name;
|
|
147
|
+
each(children);
|
|
148
|
+
});
|
|
149
|
+
exports.Project = Project;
|
|
150
|
+
const Folder = cmp(function Folder(props, children) {
|
|
151
|
+
props.ctx$.node.kind = 'folder';
|
|
152
|
+
props.ctx$.node.name = props.name;
|
|
153
|
+
each(children);
|
|
154
|
+
});
|
|
155
|
+
exports.Folder = Folder;
|
|
156
|
+
function cmp(component) {
|
|
157
|
+
const cf = (props, children) => {
|
|
158
|
+
props = props || {};
|
|
159
|
+
if (null == props || 'object' !== typeof props) {
|
|
160
|
+
props = { arg: props };
|
|
161
|
+
}
|
|
162
|
+
props.ctx$ = GLOBAL.jostraca.getStore();
|
|
163
|
+
children = 'function' === typeof children ? [children] : children;
|
|
164
|
+
let node = {
|
|
165
|
+
kind: 'none',
|
|
166
|
+
children: []
|
|
167
|
+
};
|
|
168
|
+
const parent = props.ctx$.node = (props.ctx$.node || node);
|
|
169
|
+
const siblings = props.ctx$.children = (props.ctx$.children || []);
|
|
170
|
+
siblings.push(node);
|
|
171
|
+
props.ctx$.children = node.children;
|
|
172
|
+
props.ctx$.node = node;
|
|
173
|
+
let out = component(props, children);
|
|
174
|
+
props.ctx$.children = siblings;
|
|
175
|
+
props.ctx$.node = parent;
|
|
176
|
+
return out;
|
|
177
|
+
};
|
|
178
|
+
Object.defineProperty(cf, 'name', { value: component.name });
|
|
179
|
+
return cf;
|
|
180
|
+
}
|
|
181
|
+
function each(subject, apply) {
|
|
182
|
+
if (null == apply) {
|
|
183
|
+
if (Array.isArray(subject)) {
|
|
184
|
+
for (let fn of subject) {
|
|
185
|
+
fn();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
if (Array.isArray(subject)) {
|
|
191
|
+
return subject.map(apply);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
const entries = Object.entries(subject);
|
|
195
|
+
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
196
|
+
entries.sort((a, b) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0);
|
|
197
|
+
}
|
|
198
|
+
return entries.map((n, ...args) => apply(n[1], [0], ...args));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function select(key, map) {
|
|
203
|
+
const fn = map && map[key];
|
|
204
|
+
return fn ? fn() : undefined;
|
|
205
|
+
}
|
|
206
|
+
function get(root, path) {
|
|
207
|
+
path = 'string' === typeof path ? path.split('.') : path;
|
|
208
|
+
let node = root;
|
|
209
|
+
for (let i = 0; i < path.length && null != node; i++) {
|
|
210
|
+
node = node[path[i]];
|
|
211
|
+
}
|
|
212
|
+
return node;
|
|
213
|
+
}
|
|
214
|
+
function camelify(input) {
|
|
215
|
+
let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n);
|
|
216
|
+
return parts
|
|
217
|
+
.map((p) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
|
|
218
|
+
.join('');
|
|
219
|
+
}
|
|
220
|
+
function snakeify(input) {
|
|
221
|
+
let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n);
|
|
222
|
+
return parts
|
|
223
|
+
.filter((p) => '' !== p)
|
|
224
|
+
.reduce((a, n, i) => ((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
|
|
225
|
+
.join('-');
|
|
226
|
+
}
|
|
189
227
|
//# sourceMappingURL=jostraca.js.map
|
package/dist/jostraca.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jostraca.js","sourceRoot":"","sources":["../src/jostraca.ts"],"names":[],"mappings":";AAAA,oDAAoD
|
|
1
|
+
{"version":3,"file":"jostraca.js","sourceRoot":"","sources":["../src/jostraca.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;;AAwSlD,4BAAQ;AACR,kBAAG;AAEH,oBAAI;AACJ,wBAAM;AACN,kBAAG;AACH,4BAAQ;AACR,4BAAQ;AA7SV,4CAA6B;AAE7B,uDAAoD;AAqBpD,MAAM,MAAM,GAAI,MAAc,CAAA;AAI9B,SAAS,QAAQ;IACf,MAAM,CAAC,QAAQ,GAAG,IAA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,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE,CACzC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;SACxE,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jostraca",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"main": "dist/jostraca.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/jostraca.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@hapi/code": "^9.0.3",
|
|
37
|
-
"@types/node": "22.
|
|
37
|
+
"@types/node": "22.2.0",
|
|
38
38
|
"esbuild": "^0.23.0",
|
|
39
39
|
"memfs": "^4.11.1",
|
|
40
40
|
"typescript": "^5.5.4"
|
package/src/jostraca.ts
CHANGED
|
@@ -23,9 +23,11 @@ type Node = {
|
|
|
23
23
|
type Component = (props: any, children?: any) => void
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const GLOBAL = (global as any)
|
|
27
|
+
|
|
28
|
+
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
function Jostraca() {
|
|
29
31
|
GLOBAL.jostraca = new AsyncLocalStorage()
|
|
30
32
|
|
|
31
33
|
|
|
@@ -39,6 +41,9 @@ function Jostraca() {
|
|
|
39
41
|
const ctx$ = GLOBAL.jostraca.getStore()
|
|
40
42
|
const node = ctx$.node
|
|
41
43
|
|
|
44
|
+
// console.log('JOSTRACA TOP')
|
|
45
|
+
// console.dir(node, { depth: null })
|
|
46
|
+
|
|
42
47
|
build(
|
|
43
48
|
node,
|
|
44
49
|
{
|
|
@@ -53,65 +58,7 @@ function Jostraca() {
|
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
|
|
56
|
-
function cmp(component: Function): Component {
|
|
57
|
-
const cf = (props: any, children?: any) => {
|
|
58
|
-
props = props || {}
|
|
59
|
-
if (null == props || 'object' !== typeof props) {
|
|
60
|
-
props = { arg: props }
|
|
61
|
-
}
|
|
62
|
-
props.ctx$ = GLOBAL.jostraca.getStore()
|
|
63
|
-
children = 'function' === typeof children ? [children] : children
|
|
64
|
-
|
|
65
|
-
let node = {
|
|
66
|
-
kind: 'content',
|
|
67
|
-
children: []
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const parent = props.ctx$.node = (props.ctx$.node || node)
|
|
71
|
-
const siblings = props.ctx$.children = (props.ctx$.children || [])
|
|
72
|
-
siblings.push(node)
|
|
73
|
-
|
|
74
|
-
props.ctx$.children = node.children
|
|
75
|
-
props.ctx$.node = node
|
|
76
|
-
|
|
77
|
-
let out = component(props, children)
|
|
78
|
-
|
|
79
|
-
props.ctx$.children = siblings
|
|
80
|
-
props.ctx$.node = parent
|
|
81
|
-
|
|
82
|
-
return out
|
|
83
|
-
}
|
|
84
|
-
Object.defineProperty(cf, 'name', { value: component.name })
|
|
85
|
-
return cf
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
function each(subject: any, apply?: any) {
|
|
90
|
-
if (null == apply) {
|
|
91
|
-
if (Array.isArray(subject)) {
|
|
92
|
-
for (let fn of subject) {
|
|
93
|
-
fn()
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
if (Array.isArray(subject)) {
|
|
99
|
-
return subject.map(apply)
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
const entries: any = Object.entries(subject)
|
|
103
|
-
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
104
|
-
entries.sort((a: any, b: any) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0)
|
|
105
|
-
}
|
|
106
|
-
return entries.map((n: any, ...args: any[]) =>
|
|
107
|
-
apply(n[1], [0], ...args))
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
61
|
function build(topnode: Node, ctx: any) {
|
|
114
|
-
// console.dir(topnode, { depth: null })
|
|
115
62
|
step(topnode, ctx)
|
|
116
63
|
}
|
|
117
64
|
|
|
@@ -186,70 +133,160 @@ function Jostraca() {
|
|
|
186
133
|
|
|
187
134
|
content: {
|
|
188
135
|
before(node: Node, ctx: any) {
|
|
189
|
-
const
|
|
190
|
-
ctx.current.file.content.push(
|
|
136
|
+
const content = ctx.current.content = node
|
|
137
|
+
ctx.current.file.content.push(content.content)
|
|
191
138
|
},
|
|
192
139
|
|
|
193
140
|
after(_node: Node, _ctx: any) {
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
none: {
|
|
146
|
+
before(_node: Node, ctx: any) {
|
|
147
|
+
},
|
|
194
148
|
|
|
149
|
+
after(_node: Node, _ctx: any) {
|
|
195
150
|
},
|
|
196
151
|
},
|
|
197
152
|
|
|
153
|
+
}
|
|
154
|
+
|
|
198
155
|
|
|
156
|
+
return {
|
|
157
|
+
generate,
|
|
199
158
|
}
|
|
159
|
+
}
|
|
200
160
|
|
|
201
161
|
|
|
162
|
+
const Code = cmp(function Code(props: any) {
|
|
163
|
+
props.ctx$.node.kind = 'content'
|
|
164
|
+
let src = props.arg
|
|
165
|
+
props.ctx$.node.content = src
|
|
166
|
+
})
|
|
202
167
|
|
|
203
|
-
const Code = cmp(function Code(props: any) {
|
|
204
|
-
let src = props.arg
|
|
205
|
-
props.ctx$.node.content = src
|
|
206
|
-
})
|
|
207
168
|
|
|
169
|
+
const File = cmp(function File(props: any, children: any) {
|
|
170
|
+
props.ctx$.node.kind = 'file'
|
|
171
|
+
props.ctx$.node.name = props.name
|
|
208
172
|
|
|
209
|
-
|
|
210
|
-
props.ctx$.node.kind = 'file'
|
|
211
|
-
props.ctx$.node.name = props.name
|
|
173
|
+
// Code('// FILE START: ' + props.name + '\n')
|
|
212
174
|
|
|
213
|
-
|
|
175
|
+
each(children)
|
|
214
176
|
|
|
215
|
-
|
|
177
|
+
// Code('// FILE END: ' + props.name + '\n')
|
|
178
|
+
})
|
|
216
179
|
|
|
217
|
-
// Code('// FILE END: ' + props.name + '\n')
|
|
218
|
-
})
|
|
219
180
|
|
|
181
|
+
const Project: Component = cmp(function Project(props: any, children: any) {
|
|
182
|
+
props.ctx$.node.kind = 'project'
|
|
183
|
+
props.ctx$.node.name = props.name
|
|
220
184
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
props.ctx$.node.name = props.name
|
|
185
|
+
each(children)
|
|
186
|
+
})
|
|
224
187
|
|
|
225
|
-
each(children)
|
|
226
|
-
})
|
|
227
188
|
|
|
189
|
+
const Folder = cmp(function Folder(props: any, children: any) {
|
|
190
|
+
props.ctx$.node.kind = 'folder'
|
|
191
|
+
props.ctx$.node.name = props.name
|
|
228
192
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
props.ctx$.node.name = props.name
|
|
193
|
+
each(children)
|
|
194
|
+
})
|
|
232
195
|
|
|
233
|
-
each(children)
|
|
234
|
-
})
|
|
235
196
|
|
|
197
|
+
function cmp(component: Function): Component {
|
|
198
|
+
const cf = (props: any, children?: any) => {
|
|
199
|
+
props = props || {}
|
|
200
|
+
if (null == props || 'object' !== typeof props) {
|
|
201
|
+
props = { arg: props }
|
|
202
|
+
}
|
|
203
|
+
props.ctx$ = GLOBAL.jostraca.getStore()
|
|
204
|
+
children = 'function' === typeof children ? [children] : children
|
|
236
205
|
|
|
206
|
+
let node = {
|
|
207
|
+
kind: 'none',
|
|
208
|
+
children: []
|
|
209
|
+
}
|
|
237
210
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
211
|
+
const parent = props.ctx$.node = (props.ctx$.node || node)
|
|
212
|
+
const siblings = props.ctx$.children = (props.ctx$.children || [])
|
|
213
|
+
siblings.push(node)
|
|
214
|
+
|
|
215
|
+
props.ctx$.children = node.children
|
|
216
|
+
props.ctx$.node = node
|
|
217
|
+
|
|
218
|
+
let out = component(props, children)
|
|
219
|
+
|
|
220
|
+
props.ctx$.children = siblings
|
|
221
|
+
props.ctx$.node = parent
|
|
222
|
+
|
|
223
|
+
return out
|
|
224
|
+
}
|
|
225
|
+
Object.defineProperty(cf, 'name', { value: component.name })
|
|
226
|
+
return cf
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
function each(subject: any, apply?: any) {
|
|
231
|
+
if (null == apply) {
|
|
232
|
+
if (Array.isArray(subject)) {
|
|
233
|
+
for (let fn of subject) {
|
|
234
|
+
fn()
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (Array.isArray(subject)) {
|
|
240
|
+
return subject.map(apply)
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
const entries: any = Object.entries(subject)
|
|
244
|
+
if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
|
|
245
|
+
entries.sort((a: any, b: any) => a.name < b.name ? 1 : b.name < a.name ? -1 : 0)
|
|
246
|
+
}
|
|
247
|
+
return entries.map((n: any, ...args: any[]) =>
|
|
248
|
+
apply(n[1], [0], ...args))
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
242
252
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
253
|
+
|
|
254
|
+
function select(key: any, map: Record<string, Function>) {
|
|
255
|
+
const fn = map && map[key]
|
|
256
|
+
return fn ? fn() : undefined
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
function get(root: any, path: string | string[]): any {
|
|
262
|
+
path = 'string' === typeof path ? path.split('.') : path
|
|
263
|
+
let node = root
|
|
264
|
+
for (let i = 0; i < path.length && null != node; i++) {
|
|
265
|
+
node = node[path[i]]
|
|
247
266
|
}
|
|
267
|
+
return node
|
|
268
|
+
}
|
|
248
269
|
|
|
249
270
|
|
|
271
|
+
function camelify(input: any[] | string) {
|
|
272
|
+
let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n)
|
|
273
|
+
return parts
|
|
274
|
+
.map((p: string) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
|
|
275
|
+
.join('')
|
|
250
276
|
}
|
|
251
277
|
|
|
252
278
|
|
|
279
|
+
function snakeify(input: any[] | string) {
|
|
280
|
+
let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n)
|
|
281
|
+
return parts
|
|
282
|
+
.filter((p: string) => '' !== p)
|
|
283
|
+
.reduce((a: any[], n: string, i: number) =>
|
|
284
|
+
((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
|
|
285
|
+
.join('-')
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
253
290
|
export type {
|
|
254
291
|
JostracaOptions,
|
|
255
292
|
Component,
|
|
@@ -258,4 +295,16 @@ export type {
|
|
|
258
295
|
|
|
259
296
|
export {
|
|
260
297
|
Jostraca,
|
|
298
|
+
cmp,
|
|
299
|
+
|
|
300
|
+
each,
|
|
301
|
+
select,
|
|
302
|
+
get,
|
|
303
|
+
camelify,
|
|
304
|
+
snakeify,
|
|
305
|
+
|
|
306
|
+
Project,
|
|
307
|
+
Code,
|
|
308
|
+
File,
|
|
309
|
+
Folder,
|
|
261
310
|
}
|