@jdeighan/coffee-utils 16.0.1 → 16.0.2

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "16.0.1",
4
+ "version": "16.0.2",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
package/src/fs.coffee CHANGED
@@ -14,7 +14,7 @@ import NReadLines from 'n-readlines'
14
14
  import {
15
15
  undef, pass, defined, notdefined, rtrim, isEmpty, nonEmpty,
16
16
  isString, isArray, isHash, isRegExp, isFunction, isBoolean,
17
- OL, toBlock, getOptions,
17
+ OL, toBlock, getOptions, isArrayOfStrings,
18
18
  } from '@jdeighan/base-utils'
19
19
  import {assert, croak} from '@jdeighan/base-utils/exceptions'
20
20
  import {LOG, LOGVALUE} from '@jdeighan/base-utils/log'
@@ -93,7 +93,7 @@ export rmFileSync = (filepath) =>
93
93
 
94
94
  export fixOutput = (contents) =>
95
95
 
96
- if fix
96
+ if fix && isString(contents)
97
97
  return rtrim(contents) + "\n"
98
98
  else
99
99
  return contents
@@ -398,12 +398,11 @@ export barf = (filepath, contents='', hOptions={}) =>
398
398
  contents = JSON.stringify(contents, null, 3)
399
399
  else
400
400
  assert notdefined(format), "Unknown format: #{format}"
401
- if isArray(contents)
402
- contents = toBlock(contents)
403
- else if ! isString(contents)
404
- croak "barf(): Invalid contents"
405
- contents = fixOutput(contents)
406
- fs.writeFileSync(filepath, contents, {encoding: 'utf8'})
401
+ if isArrayOfStrings(contents)
402
+ contents = fixOutput(toBlock(contents))
403
+ else if isString(contents)
404
+ contents = fixOutput(contents)
405
+ fs.writeFileSync(filepath, contents)
407
406
  return
408
407
 
409
408
  # ---------------------------------------------------------------------------
package/src/fs.js CHANGED
@@ -41,7 +41,8 @@ import {
41
41
  isBoolean,
42
42
  OL,
43
43
  toBlock,
44
- getOptions
44
+ getOptions,
45
+ isArrayOfStrings
45
46
  } from '@jdeighan/base-utils';
46
47
 
47
48
  import {
@@ -133,7 +134,7 @@ export var rmFileSync = (filepath) => {
133
134
 
134
135
  // --------------------------------------------------------------------------
135
136
  export var fixOutput = (contents) => {
136
- if (fix) {
137
+ if (fix && isString(contents)) {
137
138
  return rtrim(contents) + "\n";
138
139
  } else {
139
140
  return contents;
@@ -461,16 +462,13 @@ export var barf = (filepath, contents = '', hOptions = {}) => {
461
462
  break;
462
463
  default:
463
464
  assert(notdefined(format), `Unknown format: ${format}`);
464
- if (isArray(contents)) {
465
- contents = toBlock(contents);
466
- } else if (!isString(contents)) {
467
- croak("barf(): Invalid contents");
465
+ if (isArrayOfStrings(contents)) {
466
+ contents = fixOutput(toBlock(contents));
467
+ } else if (isString(contents)) {
468
+ contents = fixOutput(contents);
468
469
  }
469
- contents = fixOutput(contents);
470
470
  }
471
- fs.writeFileSync(filepath, contents, {
472
- encoding: 'utf8'
473
- });
471
+ fs.writeFileSync(filepath, contents);
474
472
  };
475
473
 
476
474
  // ---------------------------------------------------------------------------