@voxgig/struct 0.0.1 → 0.0.3

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/struct.d.ts CHANGED
@@ -1,46 +1,30 @@
1
1
  type PropKey = string | number;
2
+ type Indexable = {
3
+ [key: string]: any;
4
+ } & {
5
+ [key: number]: any;
6
+ };
2
7
  type InjectMode = 'key:pre' | 'key:post' | 'val';
3
8
  type Injector = (inj: Injection, // Injection state.
4
9
  val: any, // Injection value specification.
5
- current: any, // Current source parent value.
6
10
  ref: string, // Original injection reference string.
7
11
  store: any) => any;
8
- declare class Injection {
9
- mode: InjectMode;
10
- full: boolean;
11
- keyI: number;
12
- keys: string[];
13
- key: string;
14
- val: any;
15
- parent: any;
16
- path: string[];
17
- nodes: any[];
18
- handler: Injector;
19
- errs: any[];
20
- meta: Record<string, any>;
21
- base?: string;
22
- modify?: Modify;
23
- prior?: Injection;
24
- constructor(val: any, parent: any, modify?: Modify, errs?: any[]);
25
- toString(prefix?: string): string;
26
- child(keyI: number, keys: string[]): Injection;
27
- setval(val: any, ancestor?: number): any;
28
- }
29
12
  type Modify = (val: any, // Value.
30
13
  key?: PropKey, // Value key, if any,
31
14
  parent?: any, // Parent node, if any.
32
15
  inj?: Injection, // Injection state, if any.
33
- current?: any, // Current value in store (matches path).
34
16
  store?: any) => void;
35
17
  type WalkApply = (key: string | number | undefined, val: any, parent: any, path: string[]) => any;
36
- declare function isnode(val: any): boolean;
37
- declare function ismap(val: any): boolean;
18
+ declare function isnode(val: any): val is Indexable;
19
+ declare function ismap(val: any): val is {
20
+ [key: string]: any;
21
+ };
38
22
  declare function islist(val: any): val is any[];
39
- declare function iskey(key: any): boolean;
23
+ declare function iskey(key: any): key is PropKey;
40
24
  declare function isempty(val: any): boolean;
41
- declare function isfunc(val: any): boolean;
25
+ declare function isfunc(val: any): val is Function;
42
26
  declare function size(val: any): number;
43
- declare function slice<V extends any>(val: V, start: number, end?: number): V;
27
+ declare function slice<V extends any>(val: V, start?: number, end?: number): V;
44
28
  declare function pad(str: any, padding?: number, padchar?: string): string;
45
29
  declare function typify(value: any): string;
46
30
  declare function getelem(val: any, key: any, alt?: any): any;
@@ -52,24 +36,54 @@ declare function items(val: any): [number | string, any][];
52
36
  declare function escre(s: string): string;
53
37
  declare function escurl(s: string): string;
54
38
  declare function joinurl(sarr: any[]): string;
39
+ declare function jsonify(val: any, flags?: {
40
+ indent?: number;
41
+ offset?: number;
42
+ }): string;
55
43
  declare function stringify(val: any, maxlen?: number, pretty?: any): string;
56
44
  declare function pathify(val: any, startin?: number, endin?: number): string;
57
45
  declare function clone(val: any): any;
46
+ declare function delprop<PARENT>(parent: PARENT, key: any): PARENT;
58
47
  declare function setprop<PARENT>(parent: PARENT, key: any, val: any): PARENT;
59
48
  declare function walk(val: any, apply: WalkApply, key?: string | number, parent?: any, path?: string[]): any;
60
49
  declare function merge(val: any): any;
61
- declare function getpath(path: string | string[], store: any, current?: any, inj?: Injection): any;
62
- declare function inject(val: any, store: any, modify?: Modify, current?: any, inj?: Injection): any;
50
+ declare function getpath(store: any, path: number | string | string[], injdef?: Partial<Injection>): any;
51
+ declare function inject(val: any, store: any, injdef?: Partial<Injection>): any;
63
52
  declare function transform(data: any, // Source data to transform into new data (original not mutated)
64
53
  spec: any, // Transform specification; output follows this shape
65
- extra?: any, // Additional store of data and transforms.
66
- modify?: Modify): any;
54
+ injdef?: Partial<Injection>): any;
67
55
  declare function validate(data: any, // Source data to transform into new data (original not mutated)
68
56
  spec: any, // Transform specification; output follows this shape
69
- extra?: any, // Additional custom checks
70
- collecterrs?: any): any;
57
+ injdef?: Partial<Injection>): any;
58
+ declare function select(query: any, children: any): any[];
59
+ declare class Injection {
60
+ mode: InjectMode;
61
+ full: boolean;
62
+ keyI: number;
63
+ keys: string[];
64
+ key: string;
65
+ val: any;
66
+ parent: any;
67
+ path: string[];
68
+ nodes: any[];
69
+ handler: Injector;
70
+ errs: any[];
71
+ meta: Record<string, any>;
72
+ dparent: any;
73
+ dpath: string[];
74
+ base?: string;
75
+ modify?: Modify;
76
+ prior?: Injection;
77
+ extra?: any;
78
+ constructor(val: any, parent: any);
79
+ toString(prefix?: string): string;
80
+ descend(): any;
81
+ child(keyI: number, keys: string[]): Injection;
82
+ setval(val: any, ancestor?: number): any;
83
+ }
71
84
  declare class StructUtility {
72
85
  clone: typeof clone;
86
+ delprop: typeof delprop;
73
87
  escre: typeof escre;
74
88
  escurl: typeof escurl;
75
89
  getelem: typeof getelem;
@@ -85,10 +99,12 @@ declare class StructUtility {
85
99
  isnode: typeof isnode;
86
100
  items: typeof items;
87
101
  joinurl: typeof joinurl;
102
+ jsonify: typeof jsonify;
88
103
  keysof: typeof keysof;
89
104
  merge: typeof merge;
90
105
  pad: typeof pad;
91
106
  pathify: typeof pathify;
107
+ select: typeof select;
92
108
  setprop: typeof setprop;
93
109
  size: typeof size;
94
110
  slice: typeof slice;
@@ -99,5 +115,5 @@ declare class StructUtility {
99
115
  validate: typeof validate;
100
116
  walk: typeof walk;
101
117
  }
102
- export { StructUtility, clone, escre, escurl, getelem, getpath, getprop, haskey, inject, isempty, isfunc, iskey, islist, ismap, isnode, items, joinurl, keysof, merge, pad, pathify, setprop, size, slice, strkey, stringify, transform, typify, validate, walk, };
118
+ export { StructUtility, clone, delprop, escre, escurl, getelem, getpath, getprop, haskey, inject, isempty, isfunc, iskey, islist, ismap, isnode, items, joinurl, jsonify, keysof, merge, pad, pathify, select, setprop, size, slice, strkey, stringify, transform, typify, validate, walk, };
103
119
  export type { Injection, Injector, WalkApply };