@voxgig/struct 0.0.1 → 0.0.2

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,51 @@ 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): string;
55
40
  declare function stringify(val: any, maxlen?: number, pretty?: any): string;
56
41
  declare function pathify(val: any, startin?: number, endin?: number): string;
57
42
  declare function clone(val: any): any;
43
+ declare function delprop<PARENT>(parent: PARENT, key: any): PARENT;
58
44
  declare function setprop<PARENT>(parent: PARENT, key: any, val: any): PARENT;
59
45
  declare function walk(val: any, apply: WalkApply, key?: string | number, parent?: any, path?: string[]): any;
60
46
  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;
47
+ declare function getpath(store: any, path: number | string | string[], injdef?: Partial<Injection>): any;
48
+ declare function inject(val: any, store: any, injdef?: Partial<Injection>): any;
63
49
  declare function transform(data: any, // Source data to transform into new data (original not mutated)
64
50
  spec: any, // Transform specification; output follows this shape
65
- extra?: any, // Additional store of data and transforms.
66
- modify?: Modify): any;
51
+ injdef?: Partial<Injection>): any;
67
52
  declare function validate(data: any, // Source data to transform into new data (original not mutated)
68
53
  spec: any, // Transform specification; output follows this shape
69
- extra?: any, // Additional custom checks
70
- collecterrs?: any): any;
54
+ injdef?: Partial<Injection>): any;
55
+ declare function select(query: any, children: any): any[];
56
+ declare class Injection {
57
+ mode: InjectMode;
58
+ full: boolean;
59
+ keyI: number;
60
+ keys: string[];
61
+ key: string;
62
+ val: any;
63
+ parent: any;
64
+ path: string[];
65
+ nodes: any[];
66
+ handler: Injector;
67
+ errs: any[];
68
+ meta: Record<string, any>;
69
+ dparent: any;
70
+ dpath: string[];
71
+ base?: string;
72
+ modify?: Modify;
73
+ prior?: Injection;
74
+ extra?: any;
75
+ constructor(val: any, parent: any);
76
+ toString(prefix?: string): string;
77
+ descend(): any;
78
+ child(keyI: number, keys: string[]): Injection;
79
+ setval(val: any, ancestor?: number): any;
80
+ }
71
81
  declare class StructUtility {
72
82
  clone: typeof clone;
83
+ delprop: typeof delprop;
73
84
  escre: typeof escre;
74
85
  escurl: typeof escurl;
75
86
  getelem: typeof getelem;
@@ -85,10 +96,12 @@ declare class StructUtility {
85
96
  isnode: typeof isnode;
86
97
  items: typeof items;
87
98
  joinurl: typeof joinurl;
99
+ jsonify: typeof jsonify;
88
100
  keysof: typeof keysof;
89
101
  merge: typeof merge;
90
102
  pad: typeof pad;
91
103
  pathify: typeof pathify;
104
+ select: typeof select;
92
105
  setprop: typeof setprop;
93
106
  size: typeof size;
94
107
  slice: typeof slice;
@@ -99,5 +112,5 @@ declare class StructUtility {
99
112
  validate: typeof validate;
100
113
  walk: typeof walk;
101
114
  }
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, };
115
+ 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
116
  export type { Injection, Injector, WalkApply };