jostraca 0.5.0 → 0.7.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.
Files changed (55) hide show
  1. package/dist/cmp/Content.d.ts +2 -0
  2. package/dist/cmp/Content.js +12 -0
  3. package/dist/cmp/Content.js.map +1 -0
  4. package/dist/cmp/Copy.d.ts +1 -1
  5. package/dist/cmp/Copy.js +6 -19
  6. package/dist/cmp/Copy.js.map +1 -1
  7. package/dist/cmp/File.d.ts +2 -0
  8. package/dist/cmp/File.js +13 -0
  9. package/dist/cmp/File.js.map +1 -0
  10. package/dist/cmp/Folder.d.ts +2 -0
  11. package/dist/cmp/Folder.js +12 -0
  12. package/dist/cmp/Folder.js.map +1 -0
  13. package/dist/cmp/Project.d.ts +2 -0
  14. package/dist/cmp/Project.js +13 -0
  15. package/dist/cmp/Project.js.map +1 -0
  16. package/dist/jostraca.d.ts +8 -40
  17. package/dist/jostraca.js +98 -290
  18. package/dist/jostraca.js.map +1 -1
  19. package/dist/op/ContentOp.d.ts +6 -0
  20. package/dist/op/ContentOp.js +12 -0
  21. package/dist/op/ContentOp.js.map +1 -0
  22. package/dist/op/CopyOp.d.ts +1 -1
  23. package/dist/op/CopyOp.js +115 -14
  24. package/dist/op/CopyOp.js.map +1 -1
  25. package/dist/op/FileOp.d.ts +6 -0
  26. package/dist/op/FileOp.js +43 -0
  27. package/dist/op/FileOp.js.map +1 -0
  28. package/dist/op/FolderOp.d.ts +6 -0
  29. package/dist/op/FolderOp.js +23 -0
  30. package/dist/op/FolderOp.js.map +1 -0
  31. package/dist/op/NoneOp.d.ts +6 -0
  32. package/dist/op/NoneOp.js +9 -0
  33. package/dist/op/NoneOp.js.map +1 -0
  34. package/dist/op/ProjectOp.d.ts +6 -0
  35. package/dist/op/ProjectOp.js +24 -0
  36. package/dist/op/ProjectOp.js.map +1 -0
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/dist/utility.d.ts +45 -0
  39. package/dist/utility.js +486 -0
  40. package/dist/utility.js.map +1 -0
  41. package/package.json +4 -4
  42. package/src/cmp/Content.ts +19 -0
  43. package/src/cmp/Copy.ts +9 -22
  44. package/src/cmp/File.ts +21 -0
  45. package/src/cmp/Folder.ts +21 -0
  46. package/src/cmp/Project.ts +22 -0
  47. package/src/jostraca.ts +115 -385
  48. package/src/op/ContentOp.ts +18 -0
  49. package/src/op/CopyOp.ts +144 -16
  50. package/src/op/FileOp.ts +58 -0
  51. package/src/op/FolderOp.ts +31 -0
  52. package/src/op/NoneOp.ts +14 -0
  53. package/src/op/ProjectOp.ts +33 -0
  54. package/src/utility.ts +582 -0
  55. package/src/op/CopyOp.ts~ +0 -12
package/src/utility.ts ADDED
@@ -0,0 +1,582 @@
1
+ /* Copyright (c) 2024 Richard Rodger, MIT License */
2
+
3
+
4
+ type JostracaOptions = {
5
+ folder?: string
6
+ fs?: any
7
+ meta?: any
8
+ }
9
+
10
+
11
+ type Node = {
12
+ kind: string
13
+ children?: Node[]
14
+ name?: string
15
+ path: string[]
16
+ from?: string
17
+ content?: any[]
18
+ folder?: string
19
+ after?: any
20
+ exclude?: boolean
21
+ }
22
+
23
+
24
+ type OpStep = (node: Node, ctx$: any, buildctx: any) => void
25
+
26
+ type OpDef = {
27
+ before: OpStep,
28
+ after: OpStep,
29
+ }
30
+
31
+
32
+ type Component = (props: any, children?: any) => void
33
+
34
+
35
+
36
+
37
+ function each(subject?: any, apply?: any) {
38
+ if (null == apply) {
39
+ let out = []
40
+ if (Array.isArray(subject)) {
41
+ for (let fn of subject) {
42
+ out.push('function' === typeof fn ? fn() : fn)
43
+ }
44
+ return out.sort()
45
+ }
46
+ else if (null == subject || 'object' !== typeof subject) {
47
+ return []
48
+ }
49
+ }
50
+ else if (Array.isArray(subject)) {
51
+ return subject.map(apply)
52
+ }
53
+
54
+ if (null == subject || 'object' !== typeof subject) {
55
+ return []
56
+ }
57
+
58
+ const entries: any = Object.entries(subject).map((n: any[], _: any) =>
59
+ (_ = typeof n[1],
60
+ (null != n[1] && 'object' === _) ? (n[1].key$ = n[0]) :
61
+ (n[1] = { name: n[0], key$: n[0], val$: n[1] }), n))
62
+
63
+ if (1 < entries.length) {
64
+ if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].name) {
65
+ entries.sort((a: any, b: any) =>
66
+ a[1].name < b[1].name ? -1 : b[1].name < a[1].name ? 1 : 0)
67
+ }
68
+ else if (entries[0] && entries[0][1] && 'string' === typeof entries[0][1].key$) {
69
+ entries.sort((a: any, b: any) =>
70
+ a[1].key$ < b[1].key$ ? -1 : b[1].key$ < a[1].key$ ? 1 : 0)
71
+ }
72
+ }
73
+
74
+ apply = 'function' === typeof apply ? apply : (x: any) => x
75
+
76
+ return entries.map((n: any, ...args: any[]) =>
77
+ apply(n[1], n[0], ...args))
78
+ }
79
+
80
+
81
+
82
+ function select(key: any, map: Record<string, Function>) {
83
+ const fn = map && map[key]
84
+ return fn ? fn() : undefined
85
+ }
86
+
87
+
88
+
89
+ function getx(root: any, path: string | string[]): any {
90
+ path = ('string' === typeof path ? path.split(/[.\s\r\n\t]/) : path).filter(part => '' != part)
91
+ let node = root
92
+ let parents = []
93
+
94
+ partloop:
95
+ for (let i = 0; i < path.length && null != node; i++) {
96
+ let part = String(path[i]).trim()
97
+
98
+ if ('*' === part) {
99
+ // console.log('STAR', each(node), path.slice(i + 1))
100
+ return getx(each(node), path.slice(i + 1))
101
+ }
102
+
103
+ let m = part.match(/^([^<=>~^?!]*)([<=>~^?!]+)(.*)$/)
104
+
105
+ if (m) {
106
+ part = m[1]
107
+ let op = m[2]
108
+ let arg: any = m[3]
109
+
110
+ let val = '' === part ? node : node[part]
111
+
112
+ const argtype = typeof arg
113
+ arg =
114
+ 'true' === arg ? true :
115
+ 'false' === arg ? false :
116
+ 'string' === argtype ?
117
+ (arg.match(/^"[^"]+"$/) ? arg.substring(1, arg.length - 1) : arg) : arg
118
+
119
+ // console.log('GETX-M', val, part, op, arg)
120
+
121
+ if ('=' === op && 'null' === arg) {
122
+ parents.push(node)
123
+ node = {} // virtual node so that ^ works consistently
124
+ continue partloop
125
+ }
126
+ else if ('^' === op && '' === part && '' !== arg) {
127
+ node = parents[parents.length - Number(arg)]
128
+ continue partloop
129
+ }
130
+ else if ('?' === op[0]) {
131
+ // no property name
132
+ arg = (1 < op.length ? op.substring(1) : '') + arg
133
+
134
+ node = Array.isArray(val) ?
135
+ each(val).filter((n: any) => (
136
+ null != getx(n, arg))) :
137
+ each(val).filter((n: any) => (
138
+ null != getx(n, arg)))
139
+ .reduce((a: any, n: any) => (a[n.key$] = n, delete n.key$, a), {})
140
+
141
+ continue partloop
142
+ }
143
+
144
+ if (null == val) return undefined
145
+
146
+ // const valtype = typeof val
147
+
148
+ val = Array.isArray(val) ? val.length :
149
+ 'object' === typeof val ? Object.keys(val).filter(k => !k.includes('$')).length :
150
+ val
151
+
152
+ switch (op) {
153
+ case '<':
154
+ if (!(val < arg)) return undefined
155
+ break
156
+ case '<=':
157
+ if (!(val <= arg)) return undefined
158
+ break
159
+ case '>':
160
+ if (!(val > arg)) return undefined
161
+ break
162
+ case '>=':
163
+ if (!(val >= arg)) return undefined
164
+ break
165
+ case '=':
166
+ if (!(val == arg)) return undefined
167
+ break
168
+ case '==':
169
+ if (!(val === arg)) return undefined
170
+ break
171
+ case '!=':
172
+ if (!(val != arg)) return undefined
173
+ break
174
+ case '~':
175
+ if (!(String(val).match(RegExp(arg)))) return undefined
176
+ break
177
+ case '^':
178
+ node = parents[parents.length - Number(arg)]
179
+ continue partloop
180
+ default:
181
+ return undefined
182
+ }
183
+ }
184
+
185
+ parents.push(node)
186
+ node = '' === part ? node : node[part]
187
+ }
188
+ return node
189
+ }
190
+
191
+
192
+ function get(root: any, path: string | string[]): any {
193
+ path = 'string' === typeof path ? path.split('.') : path
194
+ let node = root
195
+ for (let i = 0; i < path.length && null != node; i++) {
196
+ node = node[path[i]]
197
+ }
198
+ return node
199
+ }
200
+
201
+
202
+ function camelify(input: any[] | string) {
203
+ let parts = 'string' == typeof input ? input.split('-') : input.map(n => '' + n)
204
+ return parts
205
+ .map((p: string) => ('' === p ? '' : (p[0].toUpperCase() + p.substring(1))))
206
+ .join('')
207
+ }
208
+
209
+
210
+ function kebabify(input: any[] | string) {
211
+ let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n)
212
+ return parts
213
+ .filter((p: string) => '' !== p)
214
+ .reduce((a: any[], n: string, i: number) =>
215
+ ((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
216
+ .join('-')
217
+ }
218
+
219
+
220
+ function snakify(input: any[] | string) {
221
+ let parts = 'string' == typeof input ? input.split(/([A-Z])/) : input.map(n => '' + n)
222
+ return parts
223
+ .filter((p: string) => '' !== p)
224
+ .reduce((a: any[], n: string, i: number) =>
225
+ ((0 === i % 2 ? a.push(n.toLowerCase()) : a[(i / 2) | 0] += n), a), [])
226
+ .join('_')
227
+ }
228
+
229
+
230
+ function names(base: any, name: string, prop = 'name') {
231
+ base.name$ = name
232
+ base[prop.toLowerCase()] = name.toLowerCase()
233
+ base[camelify(prop)] = camelify(name)
234
+ base[snakify(prop)] = snakify(name)
235
+ base[kebabify(prop)] = kebabify(name)
236
+ base[prop.toUpperCase()] = name.toUpperCase()
237
+ }
238
+
239
+
240
+
241
+ // Map child objects to new child objects
242
+ function cmap(o: any, p: any) {
243
+ return Object
244
+ .entries(o)
245
+ .reduce((r: any, n: any, _: any) => (_ = Object
246
+ .entries(p)
247
+ .reduce((s: any, m: any) => (cmap.FILTER === s ? s : (s[m[0]] = (
248
+ // transfom(val,key,current,parentkey,parent)
249
+ 'function' === typeof m[1] ? m[1](n[1][m[0]], {
250
+ skey: m[0], self: n[1], key: n[0], parent: o
251
+ }) : m[1]
252
+ ), (cmap.FILTER === s[m[0]] ? cmap.FILTER : s))), {})
253
+ , (cmap.FILTER === _ ? 0 : r[n[0]] = _), r), {})
254
+ }
255
+
256
+ cmap.COPY = (x: any) => x
257
+ // keep self if x is truthy, or function returning truthy-new-value or [truthy,new-value]
258
+ cmap.FILTER = (x: any) => 'function' === typeof x ? ((y: any, p: any, _: any) =>
259
+ (_ = x(y, p), Array.isArray(_) ? !_[0] ? _[1] : cmap.FILTER : _)) : (x ? x : cmap.FILTER)
260
+ cmap.KEY = (_: any, p: any) => p.key
261
+
262
+
263
+ // Map child objects to a list of child objects
264
+ function vmap(o: any, p: any) {
265
+ return Object
266
+ .entries(o)
267
+ .reduce((r: any, n: any, _: any) => (_ = Object
268
+ .entries(p)
269
+ .reduce((s: any, m: any) => (vmap.FILTER === s ? s : (s[m[0]] = (
270
+ // transfom(val,key,current,parentkey,parent)
271
+ // 'function' === typeof m[1] ? m[1](n[1][m[0]], m[0], n[1], n[0], o) : m[1]
272
+ 'function' === typeof m[1] ? m[1](n[1][m[0]], {
273
+ skey: m[0], self: n[1], key: n[0], parent: o
274
+ }) : m[1]
275
+ ), (vmap.FILTER === s[m[0]] ? vmap.FILTER : s))), {})
276
+ , (vmap.FILTER === _ ? 0 : r.push(_)), r), [])
277
+
278
+ }
279
+ vmap.COPY = (x: any) => x
280
+ vmap.FILTER = (x: any) => 'function' === typeof x ? ((y: any, p: any, _: any) =>
281
+ (_ = x(y, p), Array.isArray(_) ? !_[0] ? _[1] : vmap.FILTER : _)) : (x ? x : vmap.FILTER)
282
+ vmap.KEY = (_: any, p: any) => p.key
283
+
284
+
285
+
286
+
287
+ /*
288
+ MIT License
289
+
290
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
291
+ Copyright (c) Paul Miller (https://paulmillr.com)
292
+
293
+ Thank You!
294
+ */
295
+ const BINARY_EXT = [
296
+ "3dm",
297
+ "3ds",
298
+ "3g2",
299
+ "3gp",
300
+ "7z",
301
+ "a",
302
+ "aac",
303
+ "adp",
304
+ "afdesign",
305
+ "afphoto",
306
+ "afpub",
307
+ "ai",
308
+ "aif",
309
+ "aiff",
310
+ "alz",
311
+ "ape",
312
+ "apk",
313
+ "appimage",
314
+ "ar",
315
+ "arj",
316
+ "asf",
317
+ "au",
318
+ "avi",
319
+ "bak",
320
+ "baml",
321
+ "bh",
322
+ "bin",
323
+ "bk",
324
+ "bmp",
325
+ "btif",
326
+ "bz2",
327
+ "bzip2",
328
+ "cab",
329
+ "caf",
330
+ "cgm",
331
+ "class",
332
+ "cmx",
333
+ "cpio",
334
+ "cr2",
335
+ "cur",
336
+ "dat",
337
+ "dcm",
338
+ "deb",
339
+ "dex",
340
+ "djvu",
341
+ "dll",
342
+ "dmg",
343
+ "dng",
344
+ "doc",
345
+ "docm",
346
+ "docx",
347
+ "dot",
348
+ "dotm",
349
+ "dra",
350
+ "DS_Store",
351
+ "dsk",
352
+ "dts",
353
+ "dtshd",
354
+ "dvb",
355
+ "dwg",
356
+ "dxf",
357
+ "ecelp4800",
358
+ "ecelp7470",
359
+ "ecelp9600",
360
+ "egg",
361
+ "eol",
362
+ "eot",
363
+ "epub",
364
+ "exe",
365
+ "f4v",
366
+ "fbs",
367
+ "fh",
368
+ "fla",
369
+ "flac",
370
+ "flatpak",
371
+ "fli",
372
+ "flv",
373
+ "fpx",
374
+ "fst",
375
+ "fvt",
376
+ "g3",
377
+ "gh",
378
+ "gif",
379
+ "graffle",
380
+ "gz",
381
+ "gzip",
382
+ "h261",
383
+ "h263",
384
+ "h264",
385
+ "icns",
386
+ "ico",
387
+ "ief",
388
+ "img",
389
+ "ipa",
390
+ "iso",
391
+ "jar",
392
+ "jpeg",
393
+ "jpg",
394
+ "jpgv",
395
+ "jpm",
396
+ "jxr",
397
+ "key",
398
+ "ktx",
399
+ "lha",
400
+ "lib",
401
+ "lvp",
402
+ "lz",
403
+ "lzh",
404
+ "lzma",
405
+ "lzo",
406
+ "m3u",
407
+ "m4a",
408
+ "m4v",
409
+ "mar",
410
+ "mdi",
411
+ "mht",
412
+ "mid",
413
+ "midi",
414
+ "mj2",
415
+ "mka",
416
+ "mkv",
417
+ "mmr",
418
+ "mng",
419
+ "mobi",
420
+ "mov",
421
+ "movie",
422
+ "mp3",
423
+ "mp4",
424
+ "mp4a",
425
+ "mpeg",
426
+ "mpg",
427
+ "mpga",
428
+ "mxu",
429
+ "nef",
430
+ "npx",
431
+ "numbers",
432
+ "nupkg",
433
+ "o",
434
+ "odp",
435
+ "ods",
436
+ "odt",
437
+ "oga",
438
+ "ogg",
439
+ "ogv",
440
+ "otf",
441
+ "ott",
442
+ "pages",
443
+ "pbm",
444
+ "pcx",
445
+ "pdb",
446
+ "pdf",
447
+ "pea",
448
+ "pgm",
449
+ "pic",
450
+ "png",
451
+ "pnm",
452
+ "pot",
453
+ "potm",
454
+ "potx",
455
+ "ppa",
456
+ "ppam",
457
+ "ppm",
458
+ "pps",
459
+ "ppsm",
460
+ "ppsx",
461
+ "ppt",
462
+ "pptm",
463
+ "pptx",
464
+ "psd",
465
+ "pya",
466
+ "pyc",
467
+ "pyo",
468
+ "pyv",
469
+ "qt",
470
+ "rar",
471
+ "ras",
472
+ "raw",
473
+ "resources",
474
+ "rgb",
475
+ "rip",
476
+ "rlc",
477
+ "rmf",
478
+ "rmvb",
479
+ "rpm",
480
+ "rtf",
481
+ "rz",
482
+ "s3m",
483
+ "s7z",
484
+ "scpt",
485
+ "sgi",
486
+ "shar",
487
+ "snap",
488
+ "sil",
489
+ "sketch",
490
+ "slk",
491
+ "smv",
492
+ "snk",
493
+ "so",
494
+ "stl",
495
+ "suo",
496
+ "sub",
497
+ "swf",
498
+ "tar",
499
+ "tbz",
500
+ "tbz2",
501
+ "tga",
502
+ "tgz",
503
+ "thmx",
504
+ "tif",
505
+ "tiff",
506
+ "tlz",
507
+ "ttc",
508
+ "ttf",
509
+ "txz",
510
+ "udf",
511
+ "uvh",
512
+ "uvi",
513
+ "uvm",
514
+ "uvp",
515
+ "uvs",
516
+ "uvu",
517
+ "viv",
518
+ "vob",
519
+ "war",
520
+ "wav",
521
+ "wax",
522
+ "wbmp",
523
+ "wdp",
524
+ "weba",
525
+ "webm",
526
+ "webp",
527
+ "whl",
528
+ "wim",
529
+ "wm",
530
+ "wma",
531
+ "wmv",
532
+ "wmx",
533
+ "woff",
534
+ "woff2",
535
+ "wrm",
536
+ "wvx",
537
+ "xbm",
538
+ "xif",
539
+ "xla",
540
+ "xlam",
541
+ "xls",
542
+ "xlsb",
543
+ "xlsm",
544
+ "xlsx",
545
+ "xlt",
546
+ "xltm",
547
+ "xltx",
548
+ "xm",
549
+ "xmind",
550
+ "xpi",
551
+ "xpm",
552
+ "xwd",
553
+ "xz",
554
+ "z",
555
+ "zip",
556
+ "zipx"
557
+ ]
558
+
559
+
560
+
561
+ export type {
562
+ JostracaOptions,
563
+ Node,
564
+ OpStep,
565
+ OpDef,
566
+ Component,
567
+ }
568
+
569
+
570
+ export {
571
+ each,
572
+ select,
573
+ get,
574
+ getx,
575
+ camelify,
576
+ snakify,
577
+ kebabify,
578
+ cmap,
579
+ vmap,
580
+ names,
581
+ BINARY_EXT,
582
+ }
package/src/op/CopyOp.ts~ DELETED
@@ -1,12 +0,0 @@
1
-
2
-
3
-
4
- const CopyOp = {
5
-
6
-
7
- }
8
-
9
-
10
- export {
11
- CopyOp
12
- }