@jdeighan/coffee-utils 8.0.7 → 8.0.10

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.7",
4
+ "version": "8.0.10",
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.11"
59
59
  }
60
60
  }
@@ -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
  // ---------------------------------------------------------------------------