@jdeighan/coffee-utils 8.0.6 → 8.0.9

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": "8.0.6",
4
+ "version": "8.0.9",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -52,9 +52,9 @@
52
52
  "js-yaml": "^4.1.0",
53
53
  "n-readlines": "^1.0.1",
54
54
  "readline-sync": "^1.4.10",
55
- "svelte": "^3.48.0"
55
+ "svelte": "^3.49.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@jdeighan/unit-tester": "^2.0.9"
58
+ "@jdeighan/unit-tester": "^2.0.10"
59
59
  }
60
60
  }
@@ -12,34 +12,34 @@ export class Section
12
12
 
13
13
  constructor: (@name) ->
14
14
 
15
- @lLines = []
15
+ @lParts = []
16
16
 
17
17
  # ..........................................................
18
18
 
19
19
  length: () ->
20
20
 
21
- return @lLines.length
21
+ return @lParts.length
22
22
 
23
23
  # ..........................................................
24
24
 
25
25
  indent: (level=1) ->
26
26
 
27
- lNewLines = for line in @lLines
27
+ lNewLines = for line in @lParts
28
28
  indented(line, level)
29
- @lLines = lNewLines
29
+ @lParts = lNewLines
30
30
  return
31
31
 
32
32
  # ..........................................................
33
33
 
34
34
  isEmpty: () ->
35
35
 
36
- return (@lLines.length == 0)
36
+ return (@lParts.length == 0)
37
37
 
38
38
  # ..........................................................
39
39
 
40
40
  nonEmpty: () ->
41
41
 
42
- return (@lLines.length > 0)
42
+ return (@lParts.length > 0)
43
43
 
44
44
  # ..........................................................
45
45
 
@@ -47,9 +47,9 @@ export class Section
47
47
 
48
48
  if isArray(data)
49
49
  for line in data
50
- @lLines.push line
50
+ @lParts.push line
51
51
  else
52
- @lLines.push data
52
+ @lParts.push data
53
53
  return
54
54
 
55
55
  # ..........................................................
@@ -57,16 +57,22 @@ export class Section
57
57
  prepend: (data) ->
58
58
 
59
59
  if isArray(data)
60
- @lLines = [data..., @lLines...]
60
+ @lParts = [data..., @lParts...]
61
61
  else
62
- @lLines = [data, @lLines...]
62
+ @lParts = [data, @lParts...]
63
63
  return
64
64
 
65
65
  # ..........................................................
66
66
 
67
+ getParts: () ->
68
+
69
+ return @lParts
70
+
71
+ # ..........................................................
72
+
67
73
  getBlock: () ->
68
74
 
69
- if (@lLines.length == 0)
75
+ if (@lParts.length == 0)
70
76
  return undef
71
77
  else
72
- return arrayToBlock(@lLines)
78
+ return arrayToBlock(@lParts)
package/src/Section.js CHANGED
@@ -21,12 +21,12 @@ import {
21
21
  export var Section = class Section {
22
22
  constructor(name) {
23
23
  this.name = name;
24
- this.lLines = [];
24
+ this.lParts = [];
25
25
  }
26
26
 
27
27
  // ..........................................................
28
28
  length() {
29
- return this.lLines.length;
29
+ return this.lParts.length;
30
30
  }
31
31
 
32
32
  // ..........................................................
@@ -34,7 +34,7 @@ export var Section = class Section {
34
34
  var lNewLines, line;
35
35
  lNewLines = (function() {
36
36
  var i, len, ref, results;
37
- ref = this.lLines;
37
+ ref = this.lParts;
38
38
  results = [];
39
39
  for (i = 0, len = ref.length; i < len; i++) {
40
40
  line = ref[i];
@@ -42,17 +42,17 @@ export var Section = class Section {
42
42
  }
43
43
  return results;
44
44
  }).call(this);
45
- this.lLines = lNewLines;
45
+ this.lParts = lNewLines;
46
46
  }
47
47
 
48
48
  // ..........................................................
49
49
  isEmpty() {
50
- return this.lLines.length === 0;
50
+ return this.lParts.length === 0;
51
51
  }
52
52
 
53
53
  // ..........................................................
54
54
  nonEmpty() {
55
- return this.lLines.length > 0;
55
+ return this.lParts.length > 0;
56
56
  }
57
57
 
58
58
  // ..........................................................
@@ -61,28 +61,33 @@ export var Section = class Section {
61
61
  if (isArray(data)) {
62
62
  for (i = 0, len = data.length; i < len; i++) {
63
63
  line = data[i];
64
- this.lLines.push(line);
64
+ this.lParts.push(line);
65
65
  }
66
66
  } else {
67
- this.lLines.push(data);
67
+ this.lParts.push(data);
68
68
  }
69
69
  }
70
70
 
71
71
  // ..........................................................
72
72
  prepend(data) {
73
73
  if (isArray(data)) {
74
- this.lLines = [...data, ...this.lLines];
74
+ this.lParts = [...data, ...this.lParts];
75
75
  } else {
76
- this.lLines = [data, ...this.lLines];
76
+ this.lParts = [data, ...this.lParts];
77
77
  }
78
78
  }
79
79
 
80
+ // ..........................................................
81
+ getParts() {
82
+ return this.lParts;
83
+ }
84
+
80
85
  // ..........................................................
81
86
  getBlock() {
82
- if (this.lLines.length === 0) {
87
+ if (this.lParts.length === 0) {
83
88
  return undef;
84
89
  } else {
85
- return arrayToBlock(this.lLines);
90
+ return arrayToBlock(this.lParts);
86
91
  }
87
92
  }
88
93
 
@@ -120,7 +120,8 @@ export class SectionMap
120
120
  return
121
121
 
122
122
  # ..........................................................
123
- # --- procFunc should be (name, text) -> return processedText
123
+ # --- procFunc should be (name, block) ->
124
+ # return processed block
124
125
 
125
126
  getBlock: (procFunc=undef, lTree=undef) ->
126
127
 
package/src/SectionMap.js CHANGED
@@ -147,7 +147,8 @@ export var SectionMap = class SectionMap {
147
147
  }
148
148
 
149
149
  // ..........................................................
150
- // --- procFunc should be (name, text) -> return processedText
150
+ // --- procFunc should be (name, block) ->
151
+ // return processed block
151
152
  getBlock(procFunc = undef, lTree = undef) {
152
153
  var j, lParts, len, part, result, text;
153
154
  debug("enter getBlock()");
@@ -6,6 +6,15 @@ import {
6
6
  } from '@jdeighan/coffee-utils'
7
7
  import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
8
8
 
9
+ # ---------------------------------------------------------------------------
10
+
11
+ export splitPrefix = (line) ->
12
+
13
+ assert isString(line), "non-string #{OL(line)}"
14
+ line = rtrim(line)
15
+ lMatches = line.match(/^(\s*)(.*)$/)
16
+ return [lMatches[1], lMatches[2]]
17
+
9
18
  # ---------------------------------------------------------------------------
10
19
  # NOTE: Currently, only TAB indentation is supported
11
20
  # ---------------------------------------------------------------------------
@@ -13,11 +22,8 @@ import {arrayToBlock, blockToArray} from '@jdeighan/coffee-utils/block'
13
22
 
14
23
  export splitLine = (line) ->
15
24
 
16
- assert defined(line), "splitLine(): line is undef"
17
- assert isString(line), "splitLine(): non-string #{OL(line)}"
18
- line = rtrim(line)
19
- lMatches = line.match(/^(\s*)(.*)$/)
20
- return [lMatches[1].length, lMatches[2]]
25
+ [prefix, str] = splitPrefix(line)
26
+ return [indentLevel(prefix), str]
21
27
 
22
28
  # ---------------------------------------------------------------------------
23
29
  # indentation - return appropriate indentation string for given level
@@ -19,17 +19,23 @@ import {
19
19
  blockToArray
20
20
  } from '@jdeighan/coffee-utils/block';
21
21
 
22
+ // ---------------------------------------------------------------------------
23
+ export var splitPrefix = function(line) {
24
+ var lMatches;
25
+ assert(isString(line), `non-string ${OL(line)}`);
26
+ line = rtrim(line);
27
+ lMatches = line.match(/^(\s*)(.*)$/);
28
+ return [lMatches[1], lMatches[2]];
29
+ };
30
+
22
31
  // ---------------------------------------------------------------------------
23
32
  // NOTE: Currently, only TAB indentation is supported
24
33
  // ---------------------------------------------------------------------------
25
34
  // splitLine - separate a line into [level, line]
26
35
  export var splitLine = function(line) {
27
- var lMatches;
28
- assert(defined(line), "splitLine(): line is undef");
29
- assert(isString(line), `splitLine(): non-string ${OL(line)}`);
30
- line = rtrim(line);
31
- lMatches = line.match(/^(\s*)(.*)$/);
32
- return [lMatches[1].length, lMatches[2]];
36
+ var prefix, str;
37
+ [prefix, str] = splitPrefix(line);
38
+ return [indentLevel(prefix), str];
33
39
  };
34
40
 
35
41
  // ---------------------------------------------------------------------------