@jdeighan/coffee-utils 7.0.0 → 7.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.0",
4
+ "version": "7.0.3",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -49,7 +49,7 @@
49
49
  "js-yaml": "^4.1.0",
50
50
  "n-readlines": "^1.0.1",
51
51
  "readline-sync": "^1.4.10",
52
- "svelte": "^3.46.4"
52
+ "svelte": "^3.46.6"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@jdeighan/unit-tester": "^1.0.5"
@@ -93,13 +93,13 @@ export class CallStack
93
93
  auxPre = getPrefix(@level, 'returnVal')
94
94
 
95
95
  if @lStack.length == 0
96
- LOG "returnFrom('#{fName}') but stack is empty"
96
+ LOG "returnFrom('#{funcName}') but stack is empty"
97
97
  return [mainPre, auxPre, undef]
98
98
 
99
99
  hInfo = @removeCall(funcName)
100
100
  if doDebugStack
101
101
  prefix = ' '.repeat(@lStack.length)
102
- LOG "#{prefix}[<-- BACK #{fName}]"
102
+ LOG "#{prefix}[<-- BACK #{funcName}]"
103
103
 
104
104
  return [mainPre, auxPre, hInfo]
105
105
 
package/src/call_stack.js CHANGED
@@ -99,13 +99,13 @@ export var CallStack = class CallStack {
99
99
  mainPre = getPrefix(this.level, 'withArrow');
100
100
  auxPre = getPrefix(this.level, 'returnVal');
101
101
  if (this.lStack.length === 0) {
102
- LOG(`returnFrom('${fName}') but stack is empty`);
102
+ LOG(`returnFrom('${funcName}') but stack is empty`);
103
103
  return [mainPre, auxPre, undef];
104
104
  }
105
105
  hInfo = this.removeCall(funcName);
106
106
  if (doDebugStack) {
107
107
  prefix = ' '.repeat(this.lStack.length);
108
- LOG(`${prefix}[<-- BACK ${fName}]`);
108
+ LOG(`${prefix}[<-- BACK ${funcName}]`);
109
109
  }
110
110
  return [mainPre, auxPre, hInfo];
111
111
  }
@@ -239,21 +239,26 @@ export pathTo = (fname, dir, direction="down") ->
239
239
 
240
240
  debug "enter pathTo('#{fname}','#{dir}','#{direction}')"
241
241
  assert fs.existsSync(dir), "Directory #{dir} does not exist"
242
- if fs.existsSync("#{dir}/#{fname}")
243
- debug "return from pathTo: #{dir}/#{fname} - file exists"
244
- return mkpath("#{dir}/#{fname}")
242
+ filepath = mkpath(dir, fname)
243
+ if fs.existsSync(filepath)
244
+ debug "return from pathTo: #{filepath} - file exists"
245
+ return filepath
245
246
  else if (direction == 'down')
246
247
  # --- Search all directories in this directory
248
+ # getSubDirs() returns dirs sorted alphabetically
247
249
  for subdir in getSubDirs(dir)
248
- if fpath = pathTo(fname, "#{dir}/#{subdir}")
250
+ dirpath = mkpath(dir, subdir)
251
+ debug "check #{dirpath}"
252
+ if fpath = pathTo(fname, dirpath)
249
253
  debug "return from pathTo: #{fpath}"
250
254
  return fpath
251
255
  else if (direction == 'up')
252
- while dir = getParentDir(dir)
253
- debug "check #{dir}"
254
- if fs.existsSync("#{dir}/#{fname}")
255
- debug "return from pathTo(): #{dir}/#{fname}"
256
- return "#{dir}/#{fname}"
256
+ while dirpath = getParentDir(dir)
257
+ debug "check #{dirpath}"
258
+ filepath = mkpath(dirpath, fname)
259
+ if fs.existsSync(filepath)
260
+ debug "return from pathTo(): #{filepath}"
261
+ return filepath
257
262
  else
258
263
  error "pathTo(): Invalid direction '#{direction}'"
259
264
  debug "return undef from pathTo - file not found"
package/src/fs_utils.js CHANGED
@@ -281,28 +281,33 @@ export var forEachFile = function(dir, cb, filt = undef, level = 0) {
281
281
 
282
282
  // ---------------------------------------------------------------------------
283
283
  export var pathTo = function(fname, dir, direction = "down") {
284
- var fpath, i, len, ref, subdir;
284
+ var dirpath, filepath, fpath, i, len, ref, subdir;
285
285
  debug(`enter pathTo('${fname}','${dir}','${direction}')`);
286
286
  assert(fs.existsSync(dir), `Directory ${dir} does not exist`);
287
- if (fs.existsSync(`${dir}/${fname}`)) {
288
- debug(`return from pathTo: ${dir}/${fname} - file exists`);
289
- return mkpath(`${dir}/${fname}`);
287
+ filepath = mkpath(dir, fname);
288
+ if (fs.existsSync(filepath)) {
289
+ debug(`return from pathTo: ${filepath} - file exists`);
290
+ return filepath;
290
291
  } else if (direction === 'down') {
291
292
  ref = getSubDirs(dir);
292
293
  // --- Search all directories in this directory
294
+ // getSubDirs() returns dirs sorted alphabetically
293
295
  for (i = 0, len = ref.length; i < len; i++) {
294
296
  subdir = ref[i];
295
- if (fpath = pathTo(fname, `${dir}/${subdir}`)) {
297
+ dirpath = mkpath(dir, subdir);
298
+ debug(`check ${dirpath}`);
299
+ if (fpath = pathTo(fname, dirpath)) {
296
300
  debug(`return from pathTo: ${fpath}`);
297
301
  return fpath;
298
302
  }
299
303
  }
300
304
  } else if (direction === 'up') {
301
- while (dir = getParentDir(dir)) {
302
- debug(`check ${dir}`);
303
- if (fs.existsSync(`${dir}/${fname}`)) {
304
- debug(`return from pathTo(): ${dir}/${fname}`);
305
- return `${dir}/${fname}`;
305
+ while (dirpath = getParentDir(dir)) {
306
+ debug(`check ${dirpath}`);
307
+ filepath = mkpath(dirpath, fname);
308
+ if (fs.existsSync(filepath)) {
309
+ debug(`return from pathTo(): ${filepath}`);
310
+ return filepath;
306
311
  }
307
312
  }
308
313
  } else {
@@ -41,7 +41,7 @@ export indentLevel = (str) ->
41
41
  # ---------------------------------------------------------------------------
42
42
  # indented - add indentation to each string in a block
43
43
 
44
- export indented = (input, level=0) ->
44
+ export indented = (input, level=1) ->
45
45
 
46
46
  assert (level >= 0), "indented(): negative level"
47
47
  if level == 0
@@ -53,7 +53,7 @@ export var indentLevel = function(str) {
53
53
 
54
54
  // ---------------------------------------------------------------------------
55
55
  // indented - add indentation to each string in a block
56
- export var indented = function(input, level = 0) {
56
+ export var indented = function(input, level = 1) {
57
57
  var lInputLines, lLines, line, toAdd;
58
58
  assert(level >= 0, "indented(): negative level");
59
59
  if (level === 0) {