@jdeighan/coffee-utils 4.0.11 → 4.0.15

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": "4.0.11",
4
+ "version": "4.0.15",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -1,10 +1,9 @@
1
1
  # UnitTester.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
3
  import test from 'ava'
5
4
 
6
5
  import {
7
- undef, pass, error, croak,
6
+ assert, undef, pass, error, croak,
8
7
  isString, isFunction, isInteger, isArray,
9
8
  } from '@jdeighan/coffee-utils'
10
9
  import {blockToArray} from '@jdeighan/coffee-utils/block'
@@ -103,7 +102,7 @@ export class UnitTester
103
102
 
104
103
  fails: (lineNum, func, expected) ->
105
104
 
106
- assert not expected?, "UnitTester: fails doesn't allow expected"
105
+ assert ! expected?, "UnitTester: fails doesn't allow expected"
107
106
  assert isFunction(func), "UnitTester: fails requires a function"
108
107
 
109
108
  # --- disable logging
@@ -123,7 +122,7 @@ export class UnitTester
123
122
 
124
123
  succeeds: (lineNum, func, expected) ->
125
124
 
126
- assert not expected?, "UnitTester: succeeds doesn't allow expected"
125
+ assert ! expected?, "UnitTester: succeeds doesn't allow expected"
127
126
  assert isFunction(func), "UnitTester: succeeds requires a function"
128
127
  try
129
128
  func()
@@ -137,8 +136,8 @@ export class UnitTester
137
136
  # ........................................................................
138
137
 
139
138
  same_list: (lineNum, list, expected) ->
140
- assert not list? || isArray(list), "UnitTester: not an array"
141
- assert not expected? || isArray(expected),
139
+ assert ! list? || isArray(list), "UnitTester: not an array"
140
+ assert ! expected? || isArray(expected),
142
141
  "UnitTester: expected is not an array"
143
142
 
144
143
  @setWhichTest 'deepEqual'
@@ -148,8 +147,8 @@ export class UnitTester
148
147
  # ........................................................................
149
148
 
150
149
  not_same_list: (lineNum, list, expected) ->
151
- assert not list? || isArray(list), "UnitTester: not an array"
152
- assert not expected? || isArray(expected),
150
+ assert ! list? || isArray(list), "UnitTester: not an array"
151
+ assert ! expected? || isArray(expected),
153
152
  "UnitTester: expected is not an array"
154
153
 
155
154
  @setWhichTest 'notDeepEqual'
@@ -182,7 +181,7 @@ export class UnitTester
182
181
  if (lineNum < 0) && process.env.FINALTEST
183
182
  error "Negative line numbers not allowed in FINALTEST"
184
183
 
185
- if not @testing || (@maxLineNum && (lineNum > @maxLineNum))
184
+ if ! @testing || (@maxLineNum && (lineNum > @maxLineNum))
186
185
  return
187
186
 
188
187
  if lineNum < -100000
package/src/UnitTester.js CHANGED
@@ -1,12 +1,9 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
- // UnitTester.coffee
3
- import {
4
- strict as assert
5
- } from 'assert';
6
-
2
+ // UnitTester.coffee
7
3
  import test from 'ava';
8
4
 
9
5
  import {
6
+ assert,
10
7
  undef,
11
8
  pass,
12
9
  error,
@@ -1,13 +1,10 @@
1
1
  # block_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
- import {
5
- existsSync, readFileSync, createReadStream,
6
- } from 'fs'
7
- import {createInterface} from 'readline'
3
+ import fs from 'fs'
4
+ import readline from 'readline'
8
5
 
9
6
  import {
10
- isEmpty, isString, nonEmpty, error, isComment, rtrim,
7
+ assert, isEmpty, isString, nonEmpty, error, isComment, rtrim,
11
8
  } from '@jdeighan/coffee-utils'
12
9
  import {log} from '@jdeighan/coffee-utils/log'
13
10
 
@@ -98,8 +95,8 @@ export joinBlocks = (lBlocks...) ->
98
95
  ```
99
96
  export async function forEachLine(filepath, func) {
100
97
 
101
- const fileStream = createReadStream(filepath);
102
- const rl = createInterface({
98
+ const fileStream = fs.createReadStream(filepath);
99
+ const rl = readline.createInterface({
103
100
  input: fileStream,
104
101
  crlfDelay: Infinity
105
102
  });
@@ -141,7 +138,7 @@ export forEachBlock = (filepath, func, regexp = /^-{16,}$/) ->
141
138
  return
142
139
 
143
140
  await forEachLine filepath, callback
144
- if not earlyExit
141
+ if ! earlyExit
145
142
  func(lLines.join('\n'), firstLineNum)
146
143
  return
147
144
 
@@ -176,7 +173,7 @@ export forEachSetOfBlocks = (filepath, func,
176
173
  return
177
174
 
178
175
  await forEachLine filepath, callback
179
- if not earlyExit
176
+ if ! earlyExit
180
177
  lBlocks.push(lLines.join('\n'))
181
178
  func(lBlocks, firstLineNum)
182
179
  return
@@ -1,20 +1,11 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
- // block_utils.coffee
3
- import {
4
- strict as assert
5
- } from 'assert';
6
-
7
- import {
8
- existsSync,
9
- readFileSync,
10
- createReadStream
11
- } from 'fs';
2
+ // block_utils.coffee
3
+ import fs from 'fs';
12
4
 
13
- import {
14
- createInterface
15
- } from 'readline';
5
+ import readline from 'readline';
16
6
 
17
7
  import {
8
+ assert,
18
9
  isEmpty,
19
10
  isString,
20
11
  nonEmpty,
@@ -129,8 +120,8 @@ export var joinBlocks = function(...lBlocks) {
129
120
 
130
121
  export async function forEachLine(filepath, func) {
131
122
 
132
- const fileStream = createReadStream(filepath);
133
- const rl = createInterface({
123
+ const fileStream = fs.createReadStream(filepath);
124
+ const rl = readline.createInterface({
134
125
  input: fileStream,
135
126
  crlfDelay: Infinity
136
127
  });
@@ -1,7 +1,5 @@
1
1
  # coffee_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
-
5
3
  import {log} from '@jdeighan/coffee-utils/log'
6
4
 
7
5
  export sep_dash = '-'.repeat(42)
@@ -20,6 +18,15 @@ export error = (message) ->
20
18
 
21
19
  throw new Error(message)
22
20
 
21
+ # ---------------------------------------------------------------------------
22
+ # assert - mimic nodejs's assert
23
+
24
+ export assert = (cond, msg) ->
25
+
26
+ if ! cond
27
+ error(msg)
28
+ return
29
+
23
30
  # ---------------------------------------------------------------------------
24
31
  # croak - throws an error after possibly printing useful info
25
32
 
@@ -75,10 +82,10 @@ export isNumber = (x) ->
75
82
  export isObject = (x) ->
76
83
 
77
84
  return (typeof x == 'object') \
78
- && not isString(x) \
79
- && not isArray(x) \
80
- && not isHash(x) \
81
- && not isNumber(x)
85
+ && ! isString(x) \
86
+ && ! isArray(x) \
87
+ && ! isHash(x) \
88
+ && ! isNumber(x)
82
89
 
83
90
  # ---------------------------------------------------------------------------
84
91
 
@@ -98,7 +105,7 @@ export isHash = (x) ->
98
105
 
99
106
  export isEmpty = (x) ->
100
107
 
101
- if not x?
108
+ if ! x?
102
109
  return true
103
110
  if isString(x)
104
111
  return x.match(/^\s*$/)
@@ -115,10 +122,10 @@ export isEmpty = (x) ->
115
122
 
116
123
  export nonEmpty = (x) ->
117
124
 
118
- if not x?
125
+ if ! x?
119
126
  return false
120
127
  if isString(x)
121
- return not x.match(/^\s*$/)
128
+ return ! x.match(/^\s*$/)
122
129
  if isArray(x)
123
130
  return x.length > 0
124
131
  if isHash(x)
@@ -153,10 +160,10 @@ export words = (str) ->
153
160
 
154
161
  export isArrayOfHashes = (lItems) ->
155
162
 
156
- if not isArray(lItems)
163
+ if ! isArray(lItems)
157
164
  return false
158
165
  for item in lItems
159
- if not isHash(item)
166
+ if ! isHash(item)
160
167
  return false
161
168
  return true
162
169
 
@@ -164,10 +171,10 @@ export isArrayOfHashes = (lItems) ->
164
171
 
165
172
  export isArrayOfStrings = (lItems) ->
166
173
 
167
- if not isArray(lItems)
174
+ if ! isArray(lItems)
168
175
  return false
169
176
  for item in lItems
170
- if not isString(item)
177
+ if ! isString(item)
171
178
  return false
172
179
  return true
173
180
 
@@ -223,7 +230,7 @@ export ask = (prompt) ->
223
230
  export titleLine = (title, char='=', padding=2, linelen=42) ->
224
231
  # --- used in logger
225
232
 
226
- if not title
233
+ if ! title
227
234
  return char.repeat(linelen)
228
235
 
229
236
  titleLen = title.length + 2 * padding
@@ -272,7 +279,7 @@ export deepCopy = (obj) ->
272
279
 
273
280
  export escapeStr = (str) ->
274
281
 
275
- if not str?
282
+ if ! str?
276
283
  return 'undef'
277
284
  if typeof str != 'string'
278
285
  croak "escapeStr(): not a string", str, 'STRING'
@@ -2,10 +2,6 @@
2
2
  // coffee_utils.coffee
3
3
  var commentRegExp;
4
4
 
5
- import {
6
- strict as assert
7
- } from 'assert';
8
-
9
5
  import {
10
6
  log
11
7
  } from '@jdeighan/coffee-utils/log';
@@ -26,6 +22,14 @@ export var error = function(message) {
26
22
  throw new Error(message);
27
23
  };
28
24
 
25
+ // ---------------------------------------------------------------------------
26
+ // assert - mimic nodejs's assert
27
+ export var assert = function(cond, msg) {
28
+ if (!cond) {
29
+ error(msg);
30
+ }
31
+ };
32
+
29
33
  // ---------------------------------------------------------------------------
30
34
  // croak - throws an error after possibly printing useful info
31
35
  export var croak = function(err, label, obj) {
@@ -227,7 +231,6 @@ export var ask = function(prompt) {
227
231
  // ---------------------------------------------------------------------------
228
232
  export var titleLine = function(title, char = '=', padding = 2, linelen = 42) {
229
233
  var nLeft, nRight, strLeft, strMiddle, strRight, titleLen;
230
- // --- used in logger
231
234
  if (!title) {
232
235
  return char.repeat(linelen);
233
236
  }
@@ -1,9 +1,7 @@
1
1
  # debug_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
-
5
3
  import {
6
- undef, error, croak, warn, words, isString, isFunction,
4
+ assert, undef, error, croak, warn, words, isString, isFunction,
7
5
  oneline, escapeStr, isNumber, isArray,
8
6
  } from '@jdeighan/coffee-utils'
9
7
  import {blockToArray} from '@jdeighan/coffee-utils/block'
@@ -148,7 +146,7 @@ export debug = (lArgs...) ->
148
146
  if entering && lDebugFuncs && funcMatch(curFunc)
149
147
  setDebugging true
150
148
 
151
- if debugging && (not ifMatches? || str.match(ifMatches))
149
+ if debugging && (! ifMatches? || str.match(ifMatches))
152
150
 
153
151
  # --- set the prefix, i.e. indentation to use
154
152
  if returning
@@ -202,7 +200,7 @@ export funcMatch = (curFunc) ->
202
200
  # ---------------------------------------------------------------------------
203
201
 
204
202
  export checkTrace = (block) ->
205
- # --- export only to allow unit tests
203
+ # --- export only to allow unit tests
206
204
 
207
205
  lStack = []
208
206
 
@@ -3,10 +3,7 @@
3
3
  var arrow, arrowhead, corner, debugLevel, getPrefix, hbar, ifMatches, indent, lDebugFuncs, lDebugStack, reMethod, restoreDebugEnv, saveDebugEnv, stripArrow, vbar;
4
4
 
5
5
  import {
6
- strict as assert
7
- } from 'assert';
8
-
9
- import {
6
+ assert,
10
7
  undef,
11
8
  error,
12
9
  croak,
@@ -1,17 +1,11 @@
1
1
  # fs_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
- import {
5
- dirname, resolve, parse as parsePath,
6
- } from 'path'
7
- import {fileURLToPath} from 'url'
8
- import {
9
- existsSync, copyFileSync, readFileSync, writeFileSync, readdirSync,
10
- createReadStream, mkdirSync, renameSync, statSync,
11
- } from 'fs'
3
+ import pathlib from 'path'
4
+ import urllib from 'url'
5
+ import fs from 'fs'
12
6
 
13
7
  import {
14
- undef, pass, rtrim, error, nonEmpty,
8
+ assert, undef, pass, rtrim, error, nonEmpty,
15
9
  isRegExp, isFunction, croak,
16
10
  } from '@jdeighan/coffee-utils'
17
11
  import {log} from '@jdeighan/coffee-utils/log'
@@ -35,7 +29,7 @@ export parseSource = (source) ->
35
29
  stub: 'unit test'
36
30
  }
37
31
  try
38
- hInfo = parsePath(source)
32
+ hInfo = pathlib.parse(source)
39
33
  debug "return from parseSource()", hInfo
40
34
  if hInfo.root
41
35
  dir = mkpath(hInfo.dir) # change \ to /
@@ -67,7 +61,8 @@ export parseSource = (source) ->
67
61
 
68
62
  export mydir = (url) ->
69
63
 
70
- return mkpath(dirname(fileURLToPath(url.replace(/\@/g, '%40'))))
64
+ dir = pathlib.dirname(urllib.fileURLToPath(url))
65
+ return mkpath(dir)
71
66
 
72
67
  # ---------------------------------------------------------------------------
73
68
 
@@ -84,7 +79,7 @@ export mkpath = (lParts...) ->
84
79
 
85
80
  export getFullPath = (filepath) ->
86
81
 
87
- return mkpath(resolve(filepath))
82
+ return mkpath(pathlib.resolve(filepath))
88
83
 
89
84
  # ---------------------------------------------------------------------------
90
85
  # backup - back up a file
@@ -98,13 +93,13 @@ export backup = (file, from, to, report=false) ->
98
93
  dest = mkpath(to, file)
99
94
 
100
95
  if report
101
- if existsSync(src)
96
+ if fs.existsSync(src)
102
97
  console.log "OK #{file}"
103
- copyFileSync(src, dest)
98
+ fs.copyFileSync(src, dest)
104
99
  else
105
100
  console.log "MISSING #{src}"
106
101
  else
107
- copyFileSync(src, dest)
102
+ fs.copyFileSync(src, dest)
108
103
 
109
104
  # ---------------------------------------------------------------------------
110
105
  # slurp - read an entire file into a string
@@ -113,7 +108,7 @@ export slurp = (filepath) ->
113
108
 
114
109
  debug "enter slurp('#{filepath}')"
115
110
  filepath = filepath.replace(/\//g, "\\")
116
- contents = readFileSync(filepath, 'utf8').toString()
111
+ contents = fs.readFileSync(filepath, 'utf8').toString()
117
112
  debug "return from slurp()", contents
118
113
  return contents
119
114
 
@@ -124,10 +119,7 @@ export barf = (filepath, contents) ->
124
119
 
125
120
  debug "enter barf('#{filepath}')", contents
126
121
  contents = rtrim(contents) + "\n"
127
- try
128
- writeFileSync(filepath, contents, {encoding: 'utf8'})
129
- catch err
130
- log "barf(): write failed: #{err.message}"
122
+ fs.writeFileSync(filepath, contents, {encoding: 'utf8'})
131
123
  debug "return from barf()"
132
124
  return
133
125
 
@@ -150,7 +142,7 @@ export withExt = (filename, newExt) ->
150
142
 
151
143
  withUnderScore = (path) ->
152
144
 
153
- h = parsePath(path)
145
+ h = pathlib.parse(path)
154
146
  return mkpath(h.dir, "_#{h.base}")
155
147
 
156
148
  # ---------------------------------------------------------------------------
@@ -158,7 +150,7 @@ withUnderScore = (path) ->
158
150
 
159
151
  export getSubDirs = (dir) ->
160
152
 
161
- return readdirSync(dir, {withFileTypes: true}) \
153
+ return fs.readdirSync(dir, {withFileTypes: true}) \
162
154
  .filter((d) -> d.isDirectory()) \
163
155
  .map((d) -> mkpath(d.name)) \
164
156
  .sort()
@@ -168,10 +160,10 @@ export getSubDirs = (dir) ->
168
160
 
169
161
  export getParentDir = (dir) ->
170
162
 
171
- hParts = parsePath(dir)
163
+ hParts = pathlib.parse(dir)
172
164
  if (hParts.dir == hParts.root)
173
165
  return undef
174
- return mkpath(resolve(dir, '..'))
166
+ return mkpath(pathlib.resolve(dir, '..'))
175
167
 
176
168
  # ---------------------------------------------------------------------------
177
169
 
@@ -181,7 +173,7 @@ export forEachFile = (dir, cb, filt=undef, level=0) ->
181
173
  # callback will get parms (filename, dir, level)
182
174
 
183
175
  lSubDirectories = []
184
- for ent in readdirSync(dir, {withFileTypes: true})
176
+ for ent in fs.readdirSync(dir, {withFileTypes: true})
185
177
  if ent.isDirectory()
186
178
  lSubDirectories.push ent
187
179
  else if ent.isFile()
@@ -205,8 +197,8 @@ export forEachFile = (dir, cb, filt=undef, level=0) ->
205
197
  export pathTo = (fname, dir, direction="down") ->
206
198
 
207
199
  debug "enter pathTo('#{fname}','#{dir}','#{direction}')"
208
- assert existsSync(dir), "Directory #{dir} does not exist"
209
- if existsSync("#{dir}/#{fname}")
200
+ assert fs.existsSync(dir), "Directory #{dir} does not exist"
201
+ if fs.existsSync("#{dir}/#{fname}")
210
202
  debug "return from pathTo: #{dir}/#{fname} - file exists"
211
203
  return mkpath("#{dir}/#{fname}")
212
204
  else if (direction == 'down')
@@ -218,7 +210,7 @@ export pathTo = (fname, dir, direction="down") ->
218
210
  else if (direction == 'up')
219
211
  while dir = getParentDir(dir)
220
212
  debug "check #{dir}"
221
- if existsSync("#{dir}/#{fname}")
213
+ if fs.existsSync("#{dir}/#{fname}")
222
214
  debug "return from pathTo(): #{dir}/#{fname}"
223
215
  return "#{dir}/#{fname}"
224
216
  else
@@ -235,8 +227,8 @@ export allPathsTo = (fname, searchDir) ->
235
227
  if path?
236
228
  lPaths = [path] # --- build an array of paths
237
229
  # --- search upward for files, but return ordered top down
238
- while (h = parsePath(path)) \
239
- && (path = pathTo(fname, resolve(h.dir, '..'), "up"))
230
+ while (h = pathlib.parse(path)) \
231
+ && (path = pathTo(fname, pathlib.resolve(h.dir, '..'), "up"))
240
232
  lPaths.unshift path
241
233
  return lPaths
242
234
  else
@@ -247,11 +239,11 @@ export allPathsTo = (fname, searchDir) ->
247
239
  export newerDestFileExists = (srcPath, destPath) ->
248
240
 
249
241
  debug "enter newerDestFileExists()"
250
- if ! existsSync(destPath)
242
+ if ! fs.existsSync(destPath)
251
243
  debug "return false from newerDestFileExists() - no file"
252
244
  return false
253
- srcModTime = statSync(srcPath).mtimeMs
254
- destModTime = statSync(destPath).mtimeMs
245
+ srcModTime = fs.statSync(srcPath).mtimeMs
246
+ destModTime = fs.statSync(destPath).mtimeMs
255
247
  debug "srcModTime = #{srcModTime}"
256
248
  debug "destModTime = #{destModTime}"
257
249
  if destModTime >= srcModTime
package/src/fs_utils.js CHANGED
@@ -2,33 +2,14 @@
2
2
  // fs_utils.coffee
3
3
  var withUnderScore;
4
4
 
5
- import {
6
- strict as assert
7
- } from 'assert';
5
+ import pathlib from 'path';
8
6
 
9
- import {
10
- dirname,
11
- resolve,
12
- parse as parsePath
13
- } from 'path';
7
+ import urllib from 'url';
14
8
 
15
- import {
16
- fileURLToPath
17
- } from 'url';
18
-
19
- import {
20
- existsSync,
21
- copyFileSync,
22
- readFileSync,
23
- writeFileSync,
24
- readdirSync,
25
- createReadStream,
26
- mkdirSync,
27
- renameSync,
28
- statSync
29
- } from 'fs';
9
+ import fs from 'fs';
30
10
 
31
11
  import {
12
+ assert,
32
13
  undef,
33
14
  pass,
34
15
  rtrim,
@@ -65,7 +46,7 @@ export var parseSource = function(source) {
65
46
  };
66
47
  }
67
48
  try {
68
- hInfo = parsePath(source);
49
+ hInfo = pathlib.parse(source);
69
50
  debug("return from parseSource()", hInfo);
70
51
  if (hInfo.root) {
71
52
  dir = mkpath(hInfo.dir); // change \ to /
@@ -99,7 +80,9 @@ export var parseSource = function(source) {
99
80
  // mydir() - pass argument `import.meta.url` and it will return
100
81
  // the directory your file is in
101
82
  export var mydir = function(url) {
102
- return mkpath(dirname(fileURLToPath(url.replace(/\@/g, '%40'))));
83
+ var dir;
84
+ dir = pathlib.dirname(urllib.fileURLToPath(url));
85
+ return mkpath(dir);
103
86
  };
104
87
 
105
88
  // ---------------------------------------------------------------------------
@@ -116,7 +99,7 @@ export var mkpath = function(...lParts) {
116
99
 
117
100
  // ---------------------------------------------------------------------------
118
101
  export var getFullPath = function(filepath) {
119
- return mkpath(resolve(filepath));
102
+ return mkpath(pathlib.resolve(filepath));
120
103
  };
121
104
 
122
105
  // ---------------------------------------------------------------------------
@@ -130,14 +113,14 @@ export var backup = function(file, from, to, report = false) {
130
113
  src = mkpath(from, file);
131
114
  dest = mkpath(to, file);
132
115
  if (report) {
133
- if (existsSync(src)) {
116
+ if (fs.existsSync(src)) {
134
117
  console.log(`OK ${file}`);
135
- return copyFileSync(src, dest);
118
+ return fs.copyFileSync(src, dest);
136
119
  } else {
137
120
  return console.log(`MISSING ${src}`);
138
121
  }
139
122
  } else {
140
- return copyFileSync(src, dest);
123
+ return fs.copyFileSync(src, dest);
141
124
  }
142
125
  };
143
126
 
@@ -147,7 +130,7 @@ export var slurp = function(filepath) {
147
130
  var contents;
148
131
  debug(`enter slurp('${filepath}')`);
149
132
  filepath = filepath.replace(/\//g, "\\");
150
- contents = readFileSync(filepath, 'utf8').toString();
133
+ contents = fs.readFileSync(filepath, 'utf8').toString();
151
134
  debug("return from slurp()", contents);
152
135
  return contents;
153
136
  };
@@ -155,17 +138,11 @@ export var slurp = function(filepath) {
155
138
  // ---------------------------------------------------------------------------
156
139
  // barf - write a string to a file
157
140
  export var barf = function(filepath, contents) {
158
- var err;
159
141
  debug(`enter barf('${filepath}')`, contents);
160
142
  contents = rtrim(contents) + "\n";
161
- try {
162
- writeFileSync(filepath, contents, {
163
- encoding: 'utf8'
164
- });
165
- } catch (error1) {
166
- err = error1;
167
- log(`barf(): write failed: ${err.message}`);
168
- }
143
+ fs.writeFileSync(filepath, contents, {
144
+ encoding: 'utf8'
145
+ });
169
146
  debug("return from barf()");
170
147
  };
171
148
 
@@ -189,14 +166,14 @@ export var withExt = function(filename, newExt) {
189
166
  // withUnderScore - add '_' to file name
190
167
  withUnderScore = function(path) {
191
168
  var h;
192
- h = parsePath(path);
169
+ h = pathlib.parse(path);
193
170
  return mkpath(h.dir, `_${h.base}`);
194
171
  };
195
172
 
196
173
  // ---------------------------------------------------------------------------
197
174
  // Get all subdirectories of a directory
198
175
  export var getSubDirs = function(dir) {
199
- return readdirSync(dir, {
176
+ return fs.readdirSync(dir, {
200
177
  withFileTypes: true
201
178
  }).filter(function(d) {
202
179
  return d.isDirectory();
@@ -209,11 +186,11 @@ export var getSubDirs = function(dir) {
209
186
  // Get path to parent directory of a directory
210
187
  export var getParentDir = function(dir) {
211
188
  var hParts;
212
- hParts = parsePath(dir);
189
+ hParts = pathlib.parse(dir);
213
190
  if (hParts.dir === hParts.root) {
214
191
  return undef;
215
192
  }
216
- return mkpath(resolve(dir, '..'));
193
+ return mkpath(pathlib.resolve(dir, '..'));
217
194
  };
218
195
 
219
196
  // ---------------------------------------------------------------------------
@@ -223,7 +200,7 @@ export var forEachFile = function(dir, cb, filt = undef, level = 0) {
223
200
  // (filename, dir, level)
224
201
  // callback will get parms (filename, dir, level)
225
202
  lSubDirectories = [];
226
- ref = readdirSync(dir, {
203
+ ref = fs.readdirSync(dir, {
227
204
  withFileTypes: true
228
205
  });
229
206
  for (i = 0, len = ref.length; i < len; i++) {
@@ -259,8 +236,8 @@ export var forEachFile = function(dir, cb, filt = undef, level = 0) {
259
236
  export var pathTo = function(fname, dir, direction = "down") {
260
237
  var fpath, i, len, ref, subdir;
261
238
  debug(`enter pathTo('${fname}','${dir}','${direction}')`);
262
- assert(existsSync(dir), `Directory ${dir} does not exist`);
263
- if (existsSync(`${dir}/${fname}`)) {
239
+ assert(fs.existsSync(dir), `Directory ${dir} does not exist`);
240
+ if (fs.existsSync(`${dir}/${fname}`)) {
264
241
  debug(`return from pathTo: ${dir}/${fname} - file exists`);
265
242
  return mkpath(`${dir}/${fname}`);
266
243
  } else if (direction === 'down') {
@@ -276,7 +253,7 @@ export var pathTo = function(fname, dir, direction = "down") {
276
253
  } else if (direction === 'up') {
277
254
  while (dir = getParentDir(dir)) {
278
255
  debug(`check ${dir}`);
279
- if (existsSync(`${dir}/${fname}`)) {
256
+ if (fs.existsSync(`${dir}/${fname}`)) {
280
257
  debug(`return from pathTo(): ${dir}/${fname}`);
281
258
  return `${dir}/${fname}`;
282
259
  }
@@ -296,7 +273,7 @@ export var allPathsTo = function(fname, searchDir) {
296
273
  if (path != null) {
297
274
  lPaths = [path]; // --- build an array of paths
298
275
  // --- search upward for files, but return ordered top down
299
- while ((h = parsePath(path)) && (path = pathTo(fname, resolve(h.dir, '..'), "up"))) {
276
+ while ((h = pathlib.parse(path)) && (path = pathTo(fname, pathlib.resolve(h.dir, '..'), "up"))) {
300
277
  lPaths.unshift(path);
301
278
  }
302
279
  return lPaths;
@@ -309,12 +286,12 @@ export var allPathsTo = function(fname, searchDir) {
309
286
  export var newerDestFileExists = function(srcPath, destPath) {
310
287
  var destModTime, srcModTime;
311
288
  debug("enter newerDestFileExists()");
312
- if (!existsSync(destPath)) {
289
+ if (!fs.existsSync(destPath)) {
313
290
  debug("return false from newerDestFileExists() - no file");
314
291
  return false;
315
292
  }
316
- srcModTime = statSync(srcPath).mtimeMs;
317
- destModTime = statSync(destPath).mtimeMs;
293
+ srcModTime = fs.statSync(srcPath).mtimeMs;
294
+ destModTime = fs.statSync(destPath).mtimeMs;
318
295
  debug(`srcModTime = ${srcModTime}`);
319
296
  debug(`destModTime = ${destModTime}`);
320
297
  if (destModTime >= srcModTime) {
@@ -1,9 +1,7 @@
1
1
  # indent_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
-
5
3
  import {
6
- undef, error, escapeStr,
4
+ assert, undef, error, escapeStr,
7
5
  OL, isInteger, isString, isArray, isEmpty, rtrim,
8
6
  } from '@jdeighan/coffee-utils'
9
7
  import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
@@ -124,7 +122,7 @@ export tabify = (str, numSpaces=undef) ->
124
122
  n = prefix.length
125
123
  if (prefix.indexOf('\t') != -1)
126
124
  error "tabify(): leading TAB characters not allowed"
127
- if not numSpaces?
125
+ if ! numSpaces?
128
126
  numSpaces = n
129
127
  if (n % numSpaces != 0)
130
128
  error "tabify(): Invalid # of leading space chars"
@@ -1,10 +1,7 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
2
  // indent_utils.coffee
3
3
  import {
4
- strict as assert
5
- } from 'assert';
6
-
7
- import {
4
+ assert,
8
5
  undef,
9
6
  error,
10
7
  escapeStr,
@@ -1,10 +1,9 @@
1
1
  # log_utils.coffee
2
2
 
3
- import {strict as assert} from 'assert'
4
3
  import yaml from 'js-yaml'
5
4
 
6
5
  import {
7
- undef, isNumber, isString, isHash, isFunction, escapeStr,
6
+ assert, undef, isNumber, isString, isHash, isFunction, escapeStr,
8
7
  } from '@jdeighan/coffee-utils'
9
8
  import {blockToArray} from '@jdeighan/coffee-utils/block'
10
9
  import {tabify} from '@jdeighan/coffee-utils/indent'
@@ -17,15 +16,13 @@ logger = console.log # for strings
17
16
  export tamlStringify = (obj) ->
18
17
 
19
18
  str = yaml.dump(obj, {
20
- skipInvalid: true
21
- indent: 1
22
- sortKeys: false
23
- lineWidth: -1
24
- })
19
+ skipInvalid: true
20
+ indent: 1
21
+ sortKeys: false
22
+ lineWidth: -1
23
+ })
25
24
  str = "---\n" + tabify(str)
26
- str = str.replace(/\t/g, ' ') # because fr***ing Windows Terminal
27
- # has no way of adjusting display
28
- # of TAB chars
25
+ str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
29
26
  return str
30
27
 
31
28
  # ---------------------------------------------------------------------------
@@ -108,9 +105,9 @@ export log = (lArgs...) ->
108
105
  else
109
106
  prefix = itemPrefix = ''
110
107
 
111
- if (not logItem)
108
+ if (! logItem)
112
109
  logger "#{prefix}#{str}"
113
- else if not item?
110
+ else if ! item?
114
111
  logger "#{prefix}#{str} = undef"
115
112
  else if isNumber(item)
116
113
  logger "#{prefix}#{str} = #{item}"
package/src/log_utils.js CHANGED
@@ -2,13 +2,10 @@
2
2
  // log_utils.coffee
3
3
  var logger, maxOneLine;
4
4
 
5
- import {
6
- strict as assert
7
- } from 'assert';
8
-
9
5
  import yaml from 'js-yaml';
10
6
 
11
7
  import {
8
+ assert,
12
9
  undef,
13
10
  isNumber,
14
11
  isString,
@@ -39,9 +36,7 @@ export var tamlStringify = function(obj) {
39
36
  lineWidth: -1
40
37
  });
41
38
  str = "---\n" + tabify(str);
42
- str = str.replace(/\t/g, ' '); // because fr***ing Windows Terminal
43
- // has no way of adjusting display
44
- // of TAB chars
39
+ str = str.replace(/\t/g, ' '); // fr***ing Windows Terminal
45
40
  return str;
46
41
  };
47
42
 
@@ -1,6 +1,6 @@
1
1
  # private_env.coffee
2
2
 
3
- import {strict as assert} from 'assert'
3
+ import {assert} from '@jdeighan/coffee-utils'
4
4
  import {log} from '@jdeighan/coffee-utils/log'
5
5
 
6
6
  # --- Use by simply importing and using hEnvLib
@@ -1,8 +1,8 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
2
  // private_env.coffee
3
3
  import {
4
- strict as assert
5
- } from 'assert';
4
+ assert
5
+ } from '@jdeighan/coffee-utils';
6
6
 
7
7
  import {
8
8
  log