@jdeighan/coffee-utils 11.0.0 → 11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/call_stack.coffee +5 -6
- package/src/call_stack.js +5 -9
- package/src/log_utils.coffee +7 -23
- package/src/log_utils.js +11 -29
- package/src/taml.coffee +18 -3
- package/src/taml.js +22 -6
package/package.json
CHANGED
package/src/call_stack.coffee
CHANGED
@@ -5,7 +5,6 @@ import {
|
|
5
5
|
undef, defined, OL, escapeStr, deepCopy,
|
6
6
|
isArray, isBoolean,
|
7
7
|
} from '@jdeighan/coffee-utils'
|
8
|
-
import {LOG} from '@jdeighan/coffee-utils/log'
|
9
8
|
|
10
9
|
doDebugStack = false
|
11
10
|
|
@@ -29,7 +28,7 @@ export class CallStack
|
|
29
28
|
reset: () ->
|
30
29
|
|
31
30
|
if doDebugStack
|
32
|
-
|
31
|
+
console.log "RESET STACK"
|
33
32
|
@lStack = []
|
34
33
|
return
|
35
34
|
|
@@ -48,7 +47,7 @@ export class CallStack
|
|
48
47
|
assert isBoolean(isLogged), "missing isLogged"
|
49
48
|
|
50
49
|
if doDebugStack
|
51
|
-
|
50
|
+
console.log @indent() + "[--> ENTER #{funcName}]"
|
52
51
|
|
53
52
|
lMatches = funcName.match(///^
|
54
53
|
([A-Za-z_][A-Za-z0-9_]*)
|
@@ -101,13 +100,13 @@ export class CallStack
|
|
101
100
|
returnFrom: (fName) ->
|
102
101
|
|
103
102
|
if @lStack.length == 0
|
104
|
-
|
103
|
+
console.log "ERROR: returnFrom('#{fName}') but stack is empty"
|
105
104
|
return
|
106
105
|
{fullName, isLogged} = @lStack.pop()
|
107
106
|
if doDebugStack
|
108
|
-
|
107
|
+
console.log @indent() + "[<-- BACK #{fName}]"
|
109
108
|
if (fullName != fName)
|
110
|
-
|
109
|
+
console.log "ERROR: returnFrom('#{fName}') but TOS is #{fullName}"
|
111
110
|
return
|
112
111
|
|
113
112
|
return
|
package/src/call_stack.js
CHANGED
@@ -17,10 +17,6 @@ import {
|
|
17
17
|
isBoolean
|
18
18
|
} from '@jdeighan/coffee-utils';
|
19
19
|
|
20
|
-
import {
|
21
|
-
LOG
|
22
|
-
} from '@jdeighan/coffee-utils/log';
|
23
|
-
|
24
20
|
doDebugStack = false;
|
25
21
|
|
26
22
|
// ---------------------------------------------------------------------------
|
@@ -37,7 +33,7 @@ export var CallStack = class CallStack {
|
|
37
33
|
// ........................................................................
|
38
34
|
reset() {
|
39
35
|
if (doDebugStack) {
|
40
|
-
|
36
|
+
console.log("RESET STACK");
|
41
37
|
}
|
42
38
|
this.lStack = [];
|
43
39
|
}
|
@@ -54,7 +50,7 @@ export var CallStack = class CallStack {
|
|
54
50
|
assert(isArray(lArgs), "missing lArgs");
|
55
51
|
assert(isBoolean(isLogged), "missing isLogged");
|
56
52
|
if (doDebugStack) {
|
57
|
-
|
53
|
+
console.log(this.indent() + `[--> ENTER ${funcName}]`);
|
58
54
|
}
|
59
55
|
lMatches = funcName.match(/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?$/);
|
60
56
|
assert(defined(lMatches), `Bad funcName: ${OL(funcName)}`);
|
@@ -106,15 +102,15 @@ export var CallStack = class CallStack {
|
|
106
102
|
returnFrom(fName) {
|
107
103
|
var fullName, isLogged;
|
108
104
|
if (this.lStack.length === 0) {
|
109
|
-
|
105
|
+
console.log(`ERROR: returnFrom('${fName}') but stack is empty`);
|
110
106
|
return;
|
111
107
|
}
|
112
108
|
({fullName, isLogged} = this.lStack.pop());
|
113
109
|
if (doDebugStack) {
|
114
|
-
|
110
|
+
console.log(this.indent() + `[<-- BACK ${fName}]`);
|
115
111
|
}
|
116
112
|
if (fullName !== fName) {
|
117
|
-
|
113
|
+
console.log(`ERROR: returnFrom('${fName}') but TOS is ${fullName}`);
|
118
114
|
return;
|
119
115
|
}
|
120
116
|
}
|
package/src/log_utils.coffee
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# log_utils.coffee
|
2
2
|
|
3
|
-
import yaml from 'js-yaml'
|
4
|
-
|
5
3
|
import {assert, error, croak} from '@jdeighan/unit-tester/utils'
|
6
4
|
import {
|
7
5
|
undef, isNumber, isInteger, isString, isHash, isFunction,
|
@@ -11,6 +9,7 @@ import {blockToArray} from '@jdeighan/coffee-utils/block'
|
|
11
9
|
import {
|
12
10
|
tabify, untabify, indentation, indented,
|
13
11
|
} from '@jdeighan/coffee-utils/indent'
|
12
|
+
import {toTAML} from '@jdeighan/coffee-utils/taml'
|
14
13
|
|
15
14
|
# --- This logger only ever gets passed a single string argument
|
16
15
|
putstr = undef
|
@@ -96,39 +95,24 @@ export resetLogger = () ->
|
|
96
95
|
|
97
96
|
# ---------------------------------------------------------------------------
|
98
97
|
|
99
|
-
escReplacer = (name, value) ->
|
100
|
-
|
101
|
-
if ! isString(value)
|
102
|
-
return value
|
103
|
-
return escapeStr(value)
|
104
|
-
|
105
|
-
# ---------------------------------------------------------------------------
|
106
|
-
|
107
98
|
export tamlStringify = (obj, escape=false) ->
|
108
99
|
|
109
|
-
|
110
|
-
|
111
|
-
indent: 1
|
100
|
+
return toTAML(obj, {
|
101
|
+
useTabs: false
|
112
102
|
sortKeys: false
|
113
|
-
|
114
|
-
replacer: if escape then escReplacer else (name,value) -> value
|
103
|
+
escape
|
115
104
|
})
|
116
|
-
return "---\n" + str
|
117
105
|
|
118
106
|
# ---------------------------------------------------------------------------
|
119
107
|
|
120
108
|
export orderedStringify = (obj, escape=false) ->
|
121
109
|
|
122
|
-
|
123
|
-
|
124
|
-
indent: 1
|
110
|
+
return toTAML(obj, {
|
111
|
+
useTabs: false
|
125
112
|
sortKeys: true
|
126
|
-
|
127
|
-
replacer: if escape then escReplacer else (name,value) -> value
|
113
|
+
escape
|
128
114
|
})
|
129
115
|
|
130
|
-
return "---\n" + str
|
131
|
-
|
132
116
|
# ---------------------------------------------------------------------------
|
133
117
|
|
134
118
|
maxOneLine = 32
|
package/src/log_utils.js
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
2
|
// log_utils.coffee
|
3
|
-
var doDebugLog,
|
4
|
-
|
5
|
-
import yaml from 'js-yaml';
|
3
|
+
var doDebugLog, fixForTerminal, fourSpaces, loaded, maxOneLine, putBlock, putstr;
|
6
4
|
|
7
5
|
import {
|
8
6
|
assert,
|
@@ -35,6 +33,10 @@ import {
|
|
35
33
|
indented
|
36
34
|
} from '@jdeighan/coffee-utils/indent';
|
37
35
|
|
36
|
+
import {
|
37
|
+
toTAML
|
38
|
+
} from '@jdeighan/coffee-utils/taml';
|
39
|
+
|
38
40
|
// --- This logger only ever gets passed a single string argument
|
39
41
|
putstr = undef;
|
40
42
|
|
@@ -122,42 +124,22 @@ export var resetLogger = function() {
|
|
122
124
|
return setLogger(console.log);
|
123
125
|
};
|
124
126
|
|
125
|
-
// ---------------------------------------------------------------------------
|
126
|
-
escReplacer = function(name, value) {
|
127
|
-
if (!isString(value)) {
|
128
|
-
return value;
|
129
|
-
}
|
130
|
-
return escapeStr(value);
|
131
|
-
};
|
132
|
-
|
133
127
|
// ---------------------------------------------------------------------------
|
134
128
|
export var tamlStringify = function(obj, escape = false) {
|
135
|
-
|
136
|
-
|
137
|
-
skipInvalid: true,
|
138
|
-
indent: 1,
|
129
|
+
return toTAML(obj, {
|
130
|
+
useTabs: false,
|
139
131
|
sortKeys: false,
|
140
|
-
|
141
|
-
replacer: escape ? escReplacer : function(name, value) {
|
142
|
-
return value;
|
143
|
-
}
|
132
|
+
escape
|
144
133
|
});
|
145
|
-
return "---\n" + str;
|
146
134
|
};
|
147
135
|
|
148
136
|
// ---------------------------------------------------------------------------
|
149
137
|
export var orderedStringify = function(obj, escape = false) {
|
150
|
-
|
151
|
-
|
152
|
-
skipInvalid: true,
|
153
|
-
indent: 1,
|
138
|
+
return toTAML(obj, {
|
139
|
+
useTabs: false,
|
154
140
|
sortKeys: true,
|
155
|
-
|
156
|
-
replacer: escape ? escReplacer : function(name, value) {
|
157
|
-
return value;
|
158
|
-
}
|
141
|
+
escape
|
159
142
|
});
|
160
|
-
return "---\n" + str;
|
161
143
|
};
|
162
144
|
|
163
145
|
// ---------------------------------------------------------------------------
|
package/src/taml.coffee
CHANGED
@@ -4,7 +4,7 @@ import yaml from 'js-yaml'
|
|
4
4
|
|
5
5
|
import {assert, error, croak} from '@jdeighan/unit-tester/utils'
|
6
6
|
import {
|
7
|
-
undef, oneline, isString, chomp,
|
7
|
+
undef, oneline, isString, chomp, escapeStr,
|
8
8
|
} from '@jdeighan/coffee-utils'
|
9
9
|
import {untabify, tabify, splitLine} from '@jdeighan/coffee-utils/indent'
|
10
10
|
import {slurp} from '@jdeighan/coffee-utils/fs'
|
@@ -64,9 +64,24 @@ export fromTAML = taml
|
|
64
64
|
|
65
65
|
# ---------------------------------------------------------------------------
|
66
66
|
|
67
|
-
|
67
|
+
escReplacer = (name, value) ->
|
68
68
|
|
69
|
-
|
69
|
+
if ! isString(value)
|
70
|
+
return value
|
71
|
+
return escapeStr(value)
|
72
|
+
|
73
|
+
# ---------------------------------------------------------------------------
|
74
|
+
|
75
|
+
export toTAML = (obj, hOptions={}) ->
|
76
|
+
|
77
|
+
{useTabs, sortKeys, escape} = hOptions
|
78
|
+
str = yaml.dump(obj, {
|
79
|
+
skipInvalid: true
|
80
|
+
indent: 3
|
81
|
+
sortKeys: !!sortKeys
|
82
|
+
lineWidth: -1
|
83
|
+
replacer: if !!escape then escReplacer else (name,value) -> value
|
84
|
+
})
|
70
85
|
if useTabs
|
71
86
|
str = str.replace(/ /g, "\t")
|
72
87
|
return "---\n" + chomp(str)
|
package/src/taml.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
2
|
// taml.coffee
|
3
|
-
var squote;
|
3
|
+
var escReplacer, squote;
|
4
4
|
|
5
5
|
import yaml from 'js-yaml';
|
6
6
|
|
@@ -14,7 +14,8 @@ import {
|
|
14
14
|
undef,
|
15
15
|
oneline,
|
16
16
|
isString,
|
17
|
-
chomp
|
17
|
+
chomp,
|
18
|
+
escapeStr
|
18
19
|
} from '@jdeighan/coffee-utils';
|
19
20
|
|
20
21
|
import {
|
@@ -89,10 +90,25 @@ export var taml = function(text) {
|
|
89
90
|
export var fromTAML = taml;
|
90
91
|
|
91
92
|
// ---------------------------------------------------------------------------
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
escReplacer = function(name, value) {
|
94
|
+
if (!isString(value)) {
|
95
|
+
return value;
|
96
|
+
}
|
97
|
+
return escapeStr(value);
|
98
|
+
};
|
99
|
+
|
100
|
+
// ---------------------------------------------------------------------------
|
101
|
+
export var toTAML = function(obj, hOptions = {}) {
|
102
|
+
var escape, sortKeys, str, useTabs;
|
103
|
+
({useTabs, sortKeys, escape} = hOptions);
|
104
|
+
str = yaml.dump(obj, {
|
105
|
+
skipInvalid: true,
|
106
|
+
indent: 3,
|
107
|
+
sortKeys: !!sortKeys,
|
108
|
+
lineWidth: -1,
|
109
|
+
replacer: !!escape ? escReplacer : function(name, value) {
|
110
|
+
return value;
|
111
|
+
}
|
96
112
|
});
|
97
113
|
if (useTabs) {
|
98
114
|
str = str.replace(/ /g, "\t");
|