@jdeighan/coffee-utils 16.0.5 → 16.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/package.json +3 -3
  2. package/src/fs.coffee +2 -60
  3. package/src/fs.js +2 -63
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "16.0.5",
4
+ "version": "16.0.6",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -45,14 +45,14 @@
45
45
  },
46
46
  "homepage": "https://github.com/johndeighan/coffee-utils#readme",
47
47
  "dependencies": {
48
- "@jdeighan/base-utils": "^4.0.33",
48
+ "@jdeighan/base-utils": "^6.0.0",
49
49
  "cross-env": "^7.0.3",
50
50
  "n-readlines": "^1.0.1",
51
51
  "readline-sync": "^1.4.10",
52
52
  "svelte": "^3.59.1"
53
53
  },
54
54
  "devDependencies": {
55
- "@jdeighan/unit-tester": "^3.0.47",
55
+ "@jdeighan/unit-tester": "^3.0.52",
56
56
  "ava": "^5.3.0"
57
57
  }
58
58
  }
package/src/fs.coffee CHANGED
@@ -17,14 +17,14 @@ import {
17
17
  OL, toBlock, getOptions, isArrayOfStrings,
18
18
  } from '@jdeighan/base-utils'
19
19
  import {
20
- mkpath, isFile, isDir, mkdirSync,
20
+ mkpath, isFile, isDir, rmFileSync, mkdirSync,
21
21
  } from '@jdeighan/base-utils/fs'
22
22
  import {assert, croak} from '@jdeighan/base-utils/exceptions'
23
23
  import {LOG, LOGVALUE} from '@jdeighan/base-utils/log'
24
24
  import {dbg, dbgEnter, dbgReturn} from '@jdeighan/base-utils/debug'
25
25
  import {fromTAML} from '@jdeighan/base-utils/taml'
26
26
 
27
- export {mkpath, isFile, isDir, mkdirSync}
27
+ export {mkpath, isFile, isDir, rmFileSync, mkdirSync}
28
28
 
29
29
  fix = true
30
30
 
@@ -56,13 +56,6 @@ export rmFile = (filepath) =>
56
56
  await rm filepath
57
57
  return
58
58
 
59
- # ---------------------------------------------------------------------------
60
-
61
- export rmFileSync = (filepath) =>
62
-
63
- fs.rmSync filepath
64
- return
65
-
66
59
  # --------------------------------------------------------------------------
67
60
 
68
61
  export fixOutput = (contents) =>
@@ -317,50 +310,6 @@ export forEachSetOfBlocks = (filepath, func,
317
310
  func(lBlocks, firstLineNum)
318
311
  return
319
312
 
320
- # ---------------------------------------------------------------------------
321
- # slurp - read a file into a string
322
-
323
- export slurp = (filepath, hOptions={}) =>
324
-
325
- {maxLines, format} = getOptions(hOptions)
326
- if defined(maxLines)
327
- lLines = []
328
- forEachLineInFile filepath, (line, nLines) ->
329
- lLines.push line
330
- return (nLines >= maxLines)
331
- contents = toBlock(lLines)
332
- else
333
- filepath = filepath.replace(/\//g, "\\")
334
- contents = fs.readFileSync(filepath, 'utf8').toString()
335
- switch format
336
- when 'TAML'
337
- return fromTAML(contents)
338
- when 'JSON'
339
- return JSON.parse(contents)
340
- else
341
- assert notdefined(format), "Unknown format: #{format}"
342
- return contents
343
-
344
- # ---------------------------------------------------------------------------
345
- # barf - write a string to a file
346
-
347
- export barf = (filepath, contents='', hOptions={}) =>
348
-
349
- {format} = getOptions(hOptions)
350
- switch format
351
- when 'TAML'
352
- contents = toTAML(contents)
353
- when 'JSON'
354
- contents = JSON.stringify(contents, null, 3)
355
- else
356
- assert notdefined(format), "Unknown format: #{format}"
357
- if isArrayOfStrings(contents)
358
- contents = fixOutput(toBlock(contents))
359
- else if isString(contents)
360
- contents = fixOutput(contents)
361
- fs.writeFileSync(filepath, contents)
362
- return
363
-
364
313
  # ---------------------------------------------------------------------------
365
314
  # withExt - change file extention in a file name
366
315
 
@@ -594,10 +543,3 @@ export parseSource = (source) =>
594
543
  hSourceInfo.purpose = lMatches[1]
595
544
  dbgReturn "parseSource", hSourceInfo
596
545
  return hSourceInfo
597
-
598
- # ---------------------------------------------------------------------------
599
- # slurpTAML - read TAML from a file
600
-
601
- export slurpTAML = (filepath) =>
602
-
603
- return slurp(filepath, {format: 'TAML'})
package/src/fs.js CHANGED
@@ -49,6 +49,7 @@ import {
49
49
  mkpath,
50
50
  isFile,
51
51
  isDir,
52
+ rmFileSync,
52
53
  mkdirSync
53
54
  } from '@jdeighan/base-utils/fs';
54
55
 
@@ -76,6 +77,7 @@ export {
76
77
  mkpath,
77
78
  isFile,
78
79
  isDir,
80
+ rmFileSync,
79
81
  mkdirSync
80
82
  };
81
83
 
@@ -105,11 +107,6 @@ export var rmFile = async(filepath) => {
105
107
  await rm(filepath);
106
108
  };
107
109
 
108
- // ---------------------------------------------------------------------------
109
- export var rmFileSync = (filepath) => {
110
- fs.rmSync(filepath);
111
- };
112
-
113
110
  // --------------------------------------------------------------------------
114
111
  export var fixOutput = (contents) => {
115
112
  if (fix && isString(contents)) {
@@ -381,56 +378,6 @@ export var forEachSetOfBlocks = (filepath, func, block_regexp = /^-{16,}$/, set_
381
378
  }
382
379
  };
383
380
 
384
- // ---------------------------------------------------------------------------
385
- // slurp - read a file into a string
386
- export var slurp = (filepath, hOptions = {}) => {
387
- var contents, format, lLines, maxLines;
388
- ({maxLines, format} = getOptions(hOptions));
389
- if (defined(maxLines)) {
390
- lLines = [];
391
- forEachLineInFile(filepath, function(line, nLines) {
392
- lLines.push(line);
393
- return nLines >= maxLines;
394
- });
395
- contents = toBlock(lLines);
396
- } else {
397
- filepath = filepath.replace(/\//g, "\\");
398
- contents = fs.readFileSync(filepath, 'utf8').toString();
399
- }
400
- switch (format) {
401
- case 'TAML':
402
- return fromTAML(contents);
403
- case 'JSON':
404
- return JSON.parse(contents);
405
- default:
406
- assert(notdefined(format), `Unknown format: ${format}`);
407
- return contents;
408
- }
409
- };
410
-
411
- // ---------------------------------------------------------------------------
412
- // barf - write a string to a file
413
- export var barf = (filepath, contents = '', hOptions = {}) => {
414
- var format;
415
- ({format} = getOptions(hOptions));
416
- switch (format) {
417
- case 'TAML':
418
- contents = toTAML(contents);
419
- break;
420
- case 'JSON':
421
- contents = JSON.stringify(contents, null, 3);
422
- break;
423
- default:
424
- assert(notdefined(format), `Unknown format: ${format}`);
425
- if (isArrayOfStrings(contents)) {
426
- contents = fixOutput(toBlock(contents));
427
- } else if (isString(contents)) {
428
- contents = fixOutput(contents);
429
- }
430
- }
431
- fs.writeFileSync(filepath, contents);
432
- };
433
-
434
381
  // ---------------------------------------------------------------------------
435
382
  // withExt - change file extention in a file name
436
383
  export var withExt = (path, newExt) => {
@@ -696,11 +643,3 @@ export var parseSource = (source) => {
696
643
  dbgReturn("parseSource", hSourceInfo);
697
644
  return hSourceInfo;
698
645
  };
699
-
700
- // ---------------------------------------------------------------------------
701
- // slurpTAML - read TAML from a file
702
- export var slurpTAML = (filepath) => {
703
- return slurp(filepath, {
704
- format: 'TAML'
705
- });
706
- };