@jdeighan/coffee-utils 11.0.12 → 11.0.14

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": "11.0.12",
4
+ "version": "11.0.14",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -50,14 +50,14 @@
50
50
  },
51
51
  "homepage": "https://github.com/johndeighan/coffee-utils#readme",
52
52
  "dependencies": {
53
- "@jdeighan/exceptions": "^1.0.9",
53
+ "@jdeighan/exceptions": "^1.0.11",
54
54
  "cross-env": "^7.0.3",
55
55
  "js-yaml": "^4.1.0",
56
56
  "n-readlines": "^1.0.1",
57
57
  "readline-sync": "^1.4.10",
58
- "svelte": "^3.51.0"
58
+ "svelte": "^3.52.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@jdeighan/unit-tester": "^2.0.34"
61
+ "@jdeighan/unit-tester": "^2.0.36"
62
62
  }
63
63
  }
package/src/indent.coffee CHANGED
@@ -71,11 +71,18 @@ export isUndented = (line) ->
71
71
 
72
72
  export indented = (input, level=1, oneIndent="\t") ->
73
73
 
74
- assert (level >= 0), "indented(): negative level"
75
- if (level == 0)
76
- return input
77
-
78
- toAdd = indentation(level, oneIndent)
74
+ if isString(level)
75
+ # --- level can be a string
76
+ if (level == "")
77
+ return input
78
+ toAdd = level
79
+ else if isInteger(level)
80
+ assert (level >= 0), "indented(): negative level"
81
+ if (level == 0)
82
+ return input
83
+ toAdd = indentation(level, oneIndent)
84
+ else
85
+ croak "level must be a string or integer"
79
86
 
80
87
  # --- NOTE: toArray(input) just returns input if it's an array
81
88
  # else it splits the string into an array of lines
package/src/indent.js CHANGED
@@ -83,11 +83,21 @@ export var isUndented = function(line) {
83
83
  // - returns the same type as input, i.e. array or string
84
84
  export var indented = function(input, level = 1, oneIndent = "\t") {
85
85
  var lLines, line, toAdd;
86
- assert(level >= 0, "indented(): negative level");
87
- if (level === 0) {
88
- return input;
86
+ if (isString(level)) {
87
+ // --- level can be a string
88
+ if (level === "") {
89
+ return input;
90
+ }
91
+ toAdd = level;
92
+ } else if (isInteger(level)) {
93
+ assert(level >= 0, "indented(): negative level");
94
+ if (level === 0) {
95
+ return input;
96
+ }
97
+ toAdd = indentation(level, oneIndent);
98
+ } else {
99
+ croak("level must be a string or integer");
89
100
  }
90
- toAdd = indentation(level, oneIndent);
91
101
  // --- NOTE: toArray(input) just returns input if it's an array
92
102
  // else it splits the string into an array of lines
93
103
  lLines = (function() {