@jdeighan/coffee-utils 7.0.66 → 7.0.69
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -1
- package/src/call_stack.coffee +8 -2
- package/src/call_stack.js +7 -2
- package/src/placeholders.coffee +25 -0
- package/src/placeholders.js +31 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "7.0.
|
4
|
+
"version": "7.0.69",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -18,6 +18,7 @@
|
|
18
18
|
"./svelte": "./src/svelte_utils.js",
|
19
19
|
"./store": "./src/DataStores.js",
|
20
20
|
"./taml": "./src/taml.js",
|
21
|
+
"./placeholders": "./src/placeholders.js",
|
21
22
|
"./package.json": "./package.json"
|
22
23
|
},
|
23
24
|
"engines": {
|
package/src/call_stack.coffee
CHANGED
@@ -34,6 +34,12 @@ export class CallStack
|
|
34
34
|
|
35
35
|
# ........................................................................
|
36
36
|
|
37
|
+
indent: () ->
|
38
|
+
|
39
|
+
return ' '.repeat(@lStack.length)
|
40
|
+
|
41
|
+
# ........................................................................
|
42
|
+
|
37
43
|
enter: (funcName, lArgs=[], isLogged) ->
|
38
44
|
# --- funcName might be <object>.<method>
|
39
45
|
|
@@ -41,7 +47,7 @@ export class CallStack
|
|
41
47
|
assert isBoolean(isLogged), "missing isLogged"
|
42
48
|
|
43
49
|
if doDebugStack
|
44
|
-
LOG "[--> ENTER #{funcName}]"
|
50
|
+
LOG @indent() + "[--> ENTER #{funcName}]"
|
45
51
|
|
46
52
|
lMatches = funcName.match(///^
|
47
53
|
([A-Za-z_][A-Za-z0-9_]*)
|
@@ -94,7 +100,7 @@ export class CallStack
|
|
94
100
|
returnFrom: (fName) ->
|
95
101
|
|
96
102
|
if doDebugStack
|
97
|
-
LOG "[<-- BACK #{fName}]"
|
103
|
+
LOG @indent() + "[<-- BACK #{fName}]"
|
98
104
|
|
99
105
|
if @lStack.length == 0
|
100
106
|
LOG "ERROR: returnFrom('#{fName}') but stack is empty"
|
package/src/call_stack.js
CHANGED
@@ -39,6 +39,11 @@ export var CallStack = class CallStack {
|
|
39
39
|
this.lStack = [];
|
40
40
|
}
|
41
41
|
|
42
|
+
// ........................................................................
|
43
|
+
indent() {
|
44
|
+
return ' '.repeat(this.lStack.length);
|
45
|
+
}
|
46
|
+
|
42
47
|
// ........................................................................
|
43
48
|
enter(funcName, lArgs = [], isLogged) {
|
44
49
|
var _, hStackItem, ident1, ident2, lMatches;
|
@@ -46,7 +51,7 @@ export var CallStack = class CallStack {
|
|
46
51
|
assert(isArray(lArgs), "missing lArgs");
|
47
52
|
assert(isBoolean(isLogged), "missing isLogged");
|
48
53
|
if (doDebugStack) {
|
49
|
-
LOG(`[--> ENTER ${funcName}]`);
|
54
|
+
LOG(this.indent() + `[--> ENTER ${funcName}]`);
|
50
55
|
}
|
51
56
|
lMatches = funcName.match(/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?$/);
|
52
57
|
assert(defined(lMatches), `Bad funcName: ${OL(funcName)}`);
|
@@ -98,7 +103,7 @@ export var CallStack = class CallStack {
|
|
98
103
|
returnFrom(fName) {
|
99
104
|
var fullName, isLogged;
|
100
105
|
if (doDebugStack) {
|
101
|
-
LOG(`[<-- BACK ${fName}]`);
|
106
|
+
LOG(this.indent() + `[<-- BACK ${fName}]`);
|
102
107
|
}
|
103
108
|
if (this.lStack.length === 0) {
|
104
109
|
LOG(`ERROR: returnFrom('${fName}') but stack is empty`);
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# placeholders.coffee
|
2
|
+
|
3
|
+
import {assert, undef, defined, croak} from '@jdeighan/coffee-utils'
|
4
|
+
|
5
|
+
hDefOptions = {
|
6
|
+
pre: '__'
|
7
|
+
post: '__'
|
8
|
+
}
|
9
|
+
|
10
|
+
# ---------------------------------------------------------------------------
|
11
|
+
|
12
|
+
export phStr = (name, hOptions=hDefOptions) ->
|
13
|
+
|
14
|
+
{pre, post} = hOptions
|
15
|
+
return "#{pre}#{name}#{post}"
|
16
|
+
|
17
|
+
# ---------------------------------------------------------------------------
|
18
|
+
|
19
|
+
export phReplace = (str, hValues, hOptions=hDefOptions) ->
|
20
|
+
|
21
|
+
{pre, post} = hOptions
|
22
|
+
return str.replace(
|
23
|
+
/// #{pre} ([A-Za-z_][A-Za-z0-9_]*) #{post} ///g,
|
24
|
+
(_, name) -> hValues[name]
|
25
|
+
)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// Generated by CoffeeScript 2.7.0
|
2
|
+
// placeholders.coffee
|
3
|
+
var hDefOptions;
|
4
|
+
|
5
|
+
import {
|
6
|
+
assert,
|
7
|
+
undef,
|
8
|
+
defined,
|
9
|
+
croak
|
10
|
+
} from '@jdeighan/coffee-utils';
|
11
|
+
|
12
|
+
hDefOptions = {
|
13
|
+
pre: '__',
|
14
|
+
post: '__'
|
15
|
+
};
|
16
|
+
|
17
|
+
// ---------------------------------------------------------------------------
|
18
|
+
export var phStr = function(name, hOptions = hDefOptions) {
|
19
|
+
var post, pre;
|
20
|
+
({pre, post} = hOptions);
|
21
|
+
return `${pre}${name}${post}`;
|
22
|
+
};
|
23
|
+
|
24
|
+
// ---------------------------------------------------------------------------
|
25
|
+
export var phReplace = function(str, hValues, hOptions = hDefOptions) {
|
26
|
+
var post, pre;
|
27
|
+
({pre, post} = hOptions);
|
28
|
+
return str.replace(RegExp(`${pre}([A-Za-z_][A-Za-z0-9_]*)${post}`, "g"), function(_, name) {
|
29
|
+
return hValues[name];
|
30
|
+
});
|
31
|
+
};
|