@jdeighan/coffee-utils 7.0.3 → 7.0.6

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.3",
4
+ "version": "7.0.6",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -168,7 +168,10 @@ export debug = (lArgs...) ->
168
168
  # when debugging is off
169
169
 
170
170
  [mainPre, auxPre, hEnv, type] = adjustStack(label)
171
- hOptions = {prefix: mainPre, itemPrefix: auxPre}
171
+ hOptions = {
172
+ prefix: mainPre
173
+ itemPrefix: auxPre
174
+ }
172
175
  switch type
173
176
  when 'enter'
174
177
  log label, hOptions
@@ -192,7 +192,7 @@ export withUnderScore = (path) ->
192
192
  export getSubDirs = (dir) ->
193
193
 
194
194
  return fs.readdirSync(dir, {withFileTypes: true}) \
195
- .filter((d) -> d.isDirectory()) \
195
+ .filter((d) -> d.isDirectory() && (d != '$Recycle.Bin')) \
196
196
  .map((d) -> mkpath(d.name)) \
197
197
  .sort()
198
198
 
@@ -327,34 +327,36 @@ export parseSource = (source) ->
327
327
 
328
328
  debug "enter parseSource()"
329
329
  if source == 'unit test'
330
- debug "return 'unit test' from parseSource()"
331
- return {
330
+ hSourceInfo = {
332
331
  filename: 'unit test'
333
332
  stub: 'unit test'
334
333
  }
334
+ debug "return from parseSource()", hSourceInfo
335
+ return hSourceInfo
335
336
  try
336
337
  hInfo = pathlib.parse(source)
337
- debug "return from parseSource()", hInfo
338
- if hInfo.root
338
+ if hInfo.dir
339
339
  dir = mkpath(hInfo.dir) # change \ to /
340
- return {
341
- dir: dir
340
+ hSourceInfo = {
341
+ dir
342
342
  fullpath: mkpath(dir, hInfo.base)
343
343
  filename: hInfo.base
344
344
  stub: hInfo.name
345
345
  ext: hInfo.ext
346
346
  }
347
347
  else
348
- return {
349
- dir: mkpath(hInfo.dir) # change \ to /
348
+ hSourceInfo = {
350
349
  filename: hInfo.base
351
350
  stub: hInfo.name
352
351
  ext: hInfo.ext
353
352
  }
353
+ debug "return from parseSource()", hSourceInfo
354
+ return hSourceInfo
354
355
  catch err
355
- debug "return '#{err.message} from parseSource()"
356
- return {
356
+ hSourceInfo = {
357
357
  filename: source
358
358
  stub: source
359
359
  error: err.message
360
360
  }
361
+ debug "return '#{err.message} from parseSource()", hSourceInfo
362
+ return hSourceInfo
package/src/fs_utils.js CHANGED
@@ -223,7 +223,7 @@ export var getSubDirs = function(dir) {
223
223
  return fs.readdirSync(dir, {
224
224
  withFileTypes: true
225
225
  }).filter(function(d) {
226
- return d.isDirectory();
226
+ return d.isDirectory() && (d !== '$Recycle.Bin');
227
227
  }).map(function(d) {
228
228
  return mkpath(d.name);
229
229
  }).sort();
@@ -372,7 +372,7 @@ export var shortenPath = function(path) {
372
372
 
373
373
  // ---------------------------------------------------------------------------
374
374
  export var parseSource = function(source) {
375
- var dir, err, hInfo;
375
+ var dir, err, hInfo, hSourceInfo;
376
376
  // --- returns {
377
377
  // dir
378
378
  // filename # only this is guaranteed to be set
@@ -381,39 +381,41 @@ export var parseSource = function(source) {
381
381
  // }
382
382
  debug("enter parseSource()");
383
383
  if (source === 'unit test') {
384
- debug("return 'unit test' from parseSource()");
385
- return {
384
+ hSourceInfo = {
386
385
  filename: 'unit test',
387
386
  stub: 'unit test'
388
387
  };
388
+ debug("return from parseSource()", hSourceInfo);
389
+ return hSourceInfo;
389
390
  }
390
391
  try {
391
392
  hInfo = pathlib.parse(source);
392
- debug("return from parseSource()", hInfo);
393
- if (hInfo.root) {
393
+ if (hInfo.dir) {
394
394
  dir = mkpath(hInfo.dir); // change \ to /
395
- return {
396
- dir: dir,
395
+ hSourceInfo = {
396
+ dir,
397
397
  fullpath: mkpath(dir, hInfo.base),
398
398
  filename: hInfo.base,
399
399
  stub: hInfo.name,
400
400
  ext: hInfo.ext
401
401
  };
402
402
  } else {
403
- return {
404
- dir: mkpath(hInfo.dir), // change \ to /
403
+ hSourceInfo = {
405
404
  filename: hInfo.base,
406
405
  stub: hInfo.name,
407
406
  ext: hInfo.ext
408
407
  };
409
408
  }
409
+ debug("return from parseSource()", hSourceInfo);
410
+ return hSourceInfo;
410
411
  } catch (error1) {
411
412
  err = error1;
412
- debug(`return '${err.message} from parseSource()`);
413
- return {
413
+ hSourceInfo = {
414
414
  filename: source,
415
415
  stub: source,
416
416
  error: err.message
417
417
  };
418
+ debug(`return '${err.message} from parseSource()`, hSourceInfo);
419
+ return hSourceInfo;
418
420
  }
419
421
  };
@@ -130,22 +130,6 @@ export tabify = (str, numSpaces=undef) ->
130
130
  lLines.push '\t'.repeat(prefixLen) + theRest
131
131
  return arrayToBlock(lLines)
132
132
 
133
- # ---------------------------------------------------------------------------
134
- # untabify - convert leading TABs to spaces
135
-
136
- untabify_old = (str, numSpaces=3) ->
137
-
138
- oneIndent = ' '.repeat(numSpaces)
139
- lLines = []
140
- for str in blockToArray(str)
141
- lMatches = str.match(/^(\t*)(.*)$/)
142
- [_, prefix, theRest] = lMatches
143
- if prefix == ''
144
- lLines.push theRest
145
- else
146
- lLines.push oneIndent.repeat(prefix.length) + theRest
147
- return arrayToBlock(lLines)
148
-
149
133
  # ---------------------------------------------------------------------------
150
134
  # untabify - convert ALL TABs to spaces
151
135
 
@@ -1,7 +1,5 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
- // indent_utils.coffee
3
- var untabify_old;
4
-
2
+ // indent_utils.coffee
5
3
  import {
6
4
  assert,
7
5
  undef,
@@ -162,26 +160,6 @@ export var tabify = function(str, numSpaces = undef) {
162
160
  return arrayToBlock(lLines);
163
161
  };
164
162
 
165
- // ---------------------------------------------------------------------------
166
- // untabify - convert leading TABs to spaces
167
- untabify_old = function(str, numSpaces = 3) {
168
- var _, i, lLines, lMatches, len, oneIndent, prefix, ref, theRest;
169
- oneIndent = ' '.repeat(numSpaces);
170
- lLines = [];
171
- ref = blockToArray(str);
172
- for (i = 0, len = ref.length; i < len; i++) {
173
- str = ref[i];
174
- lMatches = str.match(/^(\t*)(.*)$/);
175
- [_, prefix, theRest] = lMatches;
176
- if (prefix === '') {
177
- lLines.push(theRest);
178
- } else {
179
- lLines.push(oneIndent.repeat(prefix.length) + theRest);
180
- }
181
- }
182
- return arrayToBlock(lLines);
183
- };
184
-
185
163
  // ---------------------------------------------------------------------------
186
164
  // untabify - convert ALL TABs to spaces
187
165
  export var untabify = function(str, numSpaces = 3) {
@@ -134,17 +134,15 @@ export log = (str, hOptions={}) ->
134
134
 
135
135
  export logItem = (label, item, hOptions={}) ->
136
136
  # --- valid options:
137
- # prefix
138
- # itemPrefix
137
+ # prefix - not used
138
+ # itemPrefix - always used
139
139
 
140
140
  assert isFunction(putstr), "putstr not properly set"
141
141
  assert !label || isString(label), "label a non-string"
142
142
  assert isHash(hOptions), "arg 3 not a hash"
143
143
 
144
144
  label = fixStr(label)
145
- prefix = fixStr(hOptions.prefix)
146
- itemPrefix = fixStr(hOptions.itemPrefix || prefix)
147
-
145
+ prefix = fixStr(hOptions.itemPrefix || hOptions.prefix)
148
146
  labelStr = if label then "#{label} = " else ""
149
147
 
150
148
  if (item == undef)
@@ -155,16 +153,16 @@ export logItem = (label, item, hOptions={}) ->
155
153
  else
156
154
  if label
157
155
  putstr "#{prefix}#{label}:"
158
- putBlock item, itemPrefix
156
+ putBlock item, prefix
159
157
  else if isNumber(item)
160
158
  putstr "#{prefix}#{labelStr}#{item}"
161
159
  else
162
- putstr "#{itemPrefix}#{sep_dash}"
160
+ putstr "#{prefix}#{sep_dash}"
163
161
  if label
164
162
  putstr "#{prefix}#{label}:"
165
163
  for str in blockToArray(stringify(item, true)) # escape special chars
166
- putstr "#{itemPrefix}#{indentation(1)}#{fixStr(str)}"
167
- putstr "#{itemPrefix}#{sep_dash}"
164
+ putstr "#{prefix}#{indentation(1)}#{fixStr(str)}"
165
+ putstr "#{prefix}#{sep_dash}"
168
166
 
169
167
  return
170
168
 
package/src/log_utils.js CHANGED
@@ -151,16 +151,15 @@ export var log = function(str, hOptions = {}) {
151
151
 
152
152
  // ---------------------------------------------------------------------------
153
153
  export var logItem = function(label, item, hOptions = {}) {
154
- var i, itemPrefix, labelStr, len, prefix, ref, str;
154
+ var i, labelStr, len, prefix, ref, str;
155
155
  // --- valid options:
156
- // prefix
157
- // itemPrefix
156
+ // prefix - not used
157
+ // itemPrefix - always used
158
158
  assert(isFunction(putstr), "putstr not properly set");
159
159
  assert(!label || isString(label), "label a non-string");
160
160
  assert(isHash(hOptions), "arg 3 not a hash");
161
161
  label = fixStr(label);
162
- prefix = fixStr(hOptions.prefix);
163
- itemPrefix = fixStr(hOptions.itemPrefix || prefix);
162
+ prefix = fixStr(hOptions.itemPrefix || hOptions.prefix);
164
163
  labelStr = label ? `${label} = ` : "";
165
164
  if (item === undef) {
166
165
  putstr(`${prefix}${labelStr}undef`);
@@ -171,12 +170,12 @@ export var logItem = function(label, item, hOptions = {}) {
171
170
  if (label) {
172
171
  putstr(`${prefix}${label}:`);
173
172
  }
174
- putBlock(item, itemPrefix);
173
+ putBlock(item, prefix);
175
174
  }
176
175
  } else if (isNumber(item)) {
177
176
  putstr(`${prefix}${labelStr}${item}`);
178
177
  } else {
179
- putstr(`${itemPrefix}${sep_dash}`);
178
+ putstr(`${prefix}${sep_dash}`);
180
179
  if (label) {
181
180
  putstr(`${prefix}${label}:`);
182
181
  }
@@ -184,9 +183,9 @@ export var logItem = function(label, item, hOptions = {}) {
184
183
  // escape special chars
185
184
  for (i = 0, len = ref.length; i < len; i++) {
186
185
  str = ref[i];
187
- putstr(`${itemPrefix}${indentation(1)}${fixStr(str)}`);
186
+ putstr(`${prefix}${indentation(1)}${fixStr(str)}`);
188
187
  }
189
- putstr(`${itemPrefix}${sep_dash}`);
188
+ putstr(`${prefix}${sep_dash}`);
190
189
  }
191
190
  };
192
191