@jdeighan/coffee-utils 4.0.23 → 4.1.3

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.
@@ -9,10 +9,22 @@ import {
9
9
  import {blockToArray} from '@jdeighan/coffee-utils/block'
10
10
  import {tabify} from '@jdeighan/coffee-utils/indent'
11
11
 
12
+ # --- This logger only ever gets passed a single string argument
12
13
  logger = console.log # for strings
13
14
 
14
15
  # ---------------------------------------------------------------------------
15
- # the default stringifier
16
+
17
+ export setLogger = (func) ->
18
+
19
+ orgLogger = logger
20
+ if func?
21
+ assert isFunction(func), "setLogger() not a function"
22
+ logger = func
23
+ else
24
+ logger = console.log
25
+ return orgLogger
26
+
27
+ # ---------------------------------------------------------------------------
16
28
 
17
29
  export tamlStringify = (obj) ->
18
30
 
@@ -27,19 +39,23 @@ export tamlStringify = (obj) ->
27
39
  return str
28
40
 
29
41
  # ---------------------------------------------------------------------------
42
+ # the default stringifier
30
43
 
31
- export stringify = tamlStringify # for non-strings
44
+ export orderedStringify = (obj) ->
32
45
 
33
- # ---------------------------------------------------------------------------
46
+ str = yaml.dump(obj, {
47
+ skipInvalid: true
48
+ indent: 1
49
+ sortKeys: true
50
+ lineWidth: -1
51
+ })
52
+ str = "---\n" + tabify(str)
53
+ str = str.replace(/\t/g, ' ') # fr***ing Windows Terminal
54
+ return str
34
55
 
35
- export setLogger = (func) ->
56
+ # ---------------------------------------------------------------------------
36
57
 
37
- if func?
38
- assert isFunction(func), "setLogger() not a function"
39
- logger = func
40
- else
41
- logger = console.log
42
- return
58
+ export stringify = orderedStringify # for non-strings
43
59
 
44
60
  # ---------------------------------------------------------------------------
45
61
 
@@ -49,7 +65,7 @@ export setStringifier = (func) ->
49
65
  assert isFunction(func), "setStringifier() not a function"
50
66
  stringify = func
51
67
  else
52
- stringify = tamlStringify
68
+ stringify = orderedStringify
53
69
  return
54
70
 
55
71
  # ---------------------------------------------------------------------------
@@ -73,8 +89,8 @@ maxOneLine = 32
73
89
  export log = (lArgs...) ->
74
90
  # --- (str, item, hOptions)
75
91
  # valid options:
76
- # prefix
77
92
  # logItem
93
+ # prefix
78
94
  # itemPrefix
79
95
 
80
96
  if (lArgs.length==0)
package/src/log_utils.js CHANGED
@@ -23,11 +23,24 @@ import {
23
23
  tabify
24
24
  } from '@jdeighan/coffee-utils/indent';
25
25
 
26
+ // --- This logger only ever gets passed a single string argument
26
27
  logger = console.log; // for strings
27
28
 
28
29
 
29
30
  // ---------------------------------------------------------------------------
30
- // the default stringifier
31
+ export var setLogger = function(func) {
32
+ var orgLogger;
33
+ orgLogger = logger;
34
+ if (func != null) {
35
+ assert(isFunction(func), "setLogger() not a function");
36
+ logger = func;
37
+ } else {
38
+ logger = console.log;
39
+ }
40
+ return orgLogger;
41
+ };
42
+
43
+ // ---------------------------------------------------------------------------
31
44
  export var tamlStringify = function(obj) {
32
45
  var str;
33
46
  str = yaml.dump(obj, {
@@ -42,18 +55,23 @@ export var tamlStringify = function(obj) {
42
55
  };
43
56
 
44
57
  // ---------------------------------------------------------------------------
45
- export var stringify = tamlStringify; // for non-strings
46
-
58
+ // the default stringifier
59
+ export var orderedStringify = function(obj) {
60
+ var str;
61
+ str = yaml.dump(obj, {
62
+ skipInvalid: true,
63
+ indent: 1,
64
+ sortKeys: true,
65
+ lineWidth: -1
66
+ });
67
+ str = "---\n" + tabify(str);
68
+ str = str.replace(/\t/g, ' '); // fr***ing Windows Terminal
69
+ return str;
70
+ };
47
71
 
48
72
  // ---------------------------------------------------------------------------
49
- export var setLogger = function(func) {
50
- if (func != null) {
51
- assert(isFunction(func), "setLogger() not a function");
52
- logger = func;
53
- } else {
54
- logger = console.log;
55
- }
56
- };
73
+ export var stringify = orderedStringify; // for non-strings
74
+
57
75
 
58
76
  // ---------------------------------------------------------------------------
59
77
  export var setStringifier = function(func) {
@@ -61,7 +79,7 @@ export var setStringifier = function(func) {
61
79
  assert(isFunction(func), "setStringifier() not a function");
62
80
  stringify = func;
63
81
  } else {
64
- stringify = tamlStringify;
82
+ stringify = orderedStringify;
65
83
  }
66
84
  };
67
85
 
@@ -83,8 +101,8 @@ export var log = function(...lArgs) {
83
101
  var esc, hOptions, i, item, itemPrefix, j, json, len, len1, line, logItem, prefix, ref, ref1, str;
84
102
  // --- (str, item, hOptions)
85
103
  // valid options:
86
- // prefix
87
104
  // logItem
105
+ // prefix
88
106
  // itemPrefix
89
107
  if (lArgs.length === 0) {
90
108
  return;
@@ -1,6 +0,0 @@
1
- import {UnitTester} from '@jdeighan/coffee-utils/test'
2
-
3
- simple = new UnitTester()
4
- simple.equal 39, pathTo('test.txt', dir), \
5
- "#{dir}/subdirectory/test.txt"
6
-