@jdeighan/coffee-utils 10.0.8 → 10.0.11

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": "10.0.8",
4
+ "version": "10.0.11",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -56,6 +56,6 @@
56
56
  "svelte": "^3.49.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@jdeighan/unit-tester": "^2.0.21"
59
+ "@jdeighan/unit-tester": "^2.0.23"
60
60
  }
61
61
  }
@@ -10,6 +10,7 @@ import {
10
10
 
11
11
  # ---------------------------------------------------------------------------
12
12
  # blockToArray - split a block into lines
13
+ # DEPRECATED - use toArray()
13
14
 
14
15
  export blockToArray = (block) ->
15
16
 
@@ -68,7 +69,8 @@ export toArray = (item, option=undef) ->
68
69
  return lNewLines
69
70
 
70
71
  # ---------------------------------------------------------------------------
71
- # arrayToBlock - block will have no trailing whitespace
72
+ # arrayToBlock - block and lines in block will have no trailing whitespace
73
+ # DEPRECATED - use toBlock()
72
74
 
73
75
  export arrayToBlock = (lLines) ->
74
76
 
@@ -90,11 +92,11 @@ export toBlock = (lLines) ->
90
92
  if (lLines == undef)
91
93
  return undef
92
94
  assert isArray(lLines), "lLines is not an array"
93
- lLines = lLines.filter((line) => defined(line));
94
- if lLines.length == 0
95
- return undef
96
- else
97
- return lLines.join('\n')
95
+ lNewLines = []
96
+ for line in lLines
97
+ if defined(line)
98
+ lNewLines.push rtrim(line)
99
+ return lNewLines.join("\n")
98
100
 
99
101
  # ---------------------------------------------------------------------------
100
102
 
@@ -23,6 +23,7 @@ import {
23
23
 
24
24
  // ---------------------------------------------------------------------------
25
25
  // blockToArray - split a block into lines
26
+ // DEPRECATED - use toArray()
26
27
  export var blockToArray = function(block) {
27
28
  var lLines, len;
28
29
  if (isEmpty(block)) {
@@ -89,7 +90,8 @@ export var toArray = function(item, option = undef) {
89
90
  };
90
91
 
91
92
  // ---------------------------------------------------------------------------
92
- // arrayToBlock - block will have no trailing whitespace
93
+ // arrayToBlock - block and lines in block will have no trailing whitespace
94
+ // DEPRECATED - use toBlock()
93
95
  export var arrayToBlock = function(lLines) {
94
96
  if (lLines === undef) {
95
97
  return undef;
@@ -109,18 +111,19 @@ export var arrayToBlock = function(lLines) {
109
111
  // toBlock - block may have trailing whitespace
110
112
  // but undef items are ignored
111
113
  export var toBlock = function(lLines) {
114
+ var i, lNewLines, len1, line;
112
115
  if (lLines === undef) {
113
116
  return undef;
114
117
  }
115
118
  assert(isArray(lLines), "lLines is not an array");
116
- lLines = lLines.filter((line) => {
117
- return defined(line);
118
- });
119
- if (lLines.length === 0) {
120
- return undef;
121
- } else {
122
- return lLines.join('\n');
119
+ lNewLines = [];
120
+ for (i = 0, len1 = lLines.length; i < len1; i++) {
121
+ line = lLines[i];
122
+ if (defined(line)) {
123
+ lNewLines.push(rtrim(line));
124
+ }
123
125
  }
126
+ return lNewLines.join("\n");
124
127
  };
125
128
 
126
129
  // ---------------------------------------------------------------------------
@@ -223,6 +223,22 @@ export nonEmpty = (x) ->
223
223
 
224
224
  # ---------------------------------------------------------------------------
225
225
 
226
+ export notInArray = (lItems, item) ->
227
+
228
+ return (lItems.indexOf(item) == -1)
229
+
230
+ # ---------------------------------------------------------------------------
231
+
232
+ export pushCond = (lItems, item, doPush=notInArray) ->
233
+
234
+ if doPush(lItems, item)
235
+ lItems.push item
236
+ return true
237
+ else
238
+ return false
239
+
240
+ # ---------------------------------------------------------------------------
241
+
226
242
  export words = (str) ->
227
243
 
228
244
  return str.trim().split(/\s+/)
@@ -236,6 +236,21 @@ export var nonEmpty = function(x) {
236
236
  }
237
237
  };
238
238
 
239
+ // ---------------------------------------------------------------------------
240
+ export var notInArray = function(lItems, item) {
241
+ return lItems.indexOf(item) === -1;
242
+ };
243
+
244
+ // ---------------------------------------------------------------------------
245
+ export var pushCond = function(lItems, item, doPush = notInArray) {
246
+ if (doPush(lItems, item)) {
247
+ lItems.push(item);
248
+ return true;
249
+ } else {
250
+ return false;
251
+ }
252
+ };
253
+
239
254
  // ---------------------------------------------------------------------------
240
255
  export var words = function(str) {
241
256
  return str.trim().split(/\s+/);