@jdeighan/coffee-utils 11.0.13 → 11.0.15
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +4 -4
- package/src/indent.coffee +12 -5
- package/src/indent.js +14 -4
- package/src/utils.coffee +17 -2
- package/src/utils.js +29 -3
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "11.0.
|
4
|
+
"version": "11.0.15",
|
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.
|
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.
|
58
|
+
"svelte": "^3.52.0"
|
59
59
|
},
|
60
60
|
"devDependencies": {
|
61
|
-
"@jdeighan/unit-tester": "^2.0.
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
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() {
|
package/src/utils.coffee
CHANGED
@@ -21,9 +21,8 @@ export {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
# ---------------------------------------------------------------------------
|
24
|
-
# TEMP!!!!!
|
25
24
|
|
26
|
-
export
|
25
|
+
export isHashComment = (line) =>
|
27
26
|
|
28
27
|
lMatches = line.match(///^
|
29
28
|
\s*
|
@@ -75,6 +74,22 @@ export oneof = (word, lWords...) ->
|
|
75
74
|
|
76
75
|
# ---------------------------------------------------------------------------
|
77
76
|
|
77
|
+
export removeKeys = (h, lKeys) =>
|
78
|
+
|
79
|
+
for key in lKeys
|
80
|
+
delete h[key]
|
81
|
+
for own key,value of h
|
82
|
+
if defined(value)
|
83
|
+
if isArray(value)
|
84
|
+
for item in value
|
85
|
+
if isHash(item)
|
86
|
+
removeKeys(item, lKeys)
|
87
|
+
else if (typeof value == 'object')
|
88
|
+
removeKeys value, lKeys
|
89
|
+
return
|
90
|
+
|
91
|
+
# ---------------------------------------------------------------------------
|
92
|
+
|
78
93
|
export isNonEmptyString = (x) ->
|
79
94
|
|
80
95
|
if typeof x != 'string' && x ! instanceof String
|
package/src/utils.js
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
// Generated by CoffeeScript 2.7.0
|
2
|
-
|
2
|
+
// utils.coffee
|
3
|
+
var hasProp = {}.hasOwnProperty;
|
4
|
+
|
3
5
|
import {
|
4
6
|
assert,
|
5
7
|
croak
|
@@ -76,8 +78,7 @@ export {
|
|
76
78
|
};
|
77
79
|
|
78
80
|
// ---------------------------------------------------------------------------
|
79
|
-
|
80
|
-
export var isComment = (line) => {
|
81
|
+
export var isHashComment = (line) => {
|
81
82
|
var lMatches;
|
82
83
|
lMatches = line.match(/^\s*\#(\s|$)/);
|
83
84
|
return defined(lMatches);
|
@@ -122,6 +123,31 @@ export var oneof = function(word, ...lWords) {
|
|
122
123
|
return lWords.indexOf(word) >= 0;
|
123
124
|
};
|
124
125
|
|
126
|
+
// ---------------------------------------------------------------------------
|
127
|
+
export var removeKeys = (h, lKeys) => {
|
128
|
+
var i, item, j, key, len, len1, value;
|
129
|
+
for (i = 0, len = lKeys.length; i < len; i++) {
|
130
|
+
key = lKeys[i];
|
131
|
+
delete h[key];
|
132
|
+
}
|
133
|
+
for (key in h) {
|
134
|
+
if (!hasProp.call(h, key)) continue;
|
135
|
+
value = h[key];
|
136
|
+
if (defined(value)) {
|
137
|
+
if (isArray(value)) {
|
138
|
+
for (j = 0, len1 = value.length; j < len1; j++) {
|
139
|
+
item = value[j];
|
140
|
+
if (isHash(item)) {
|
141
|
+
removeKeys(item, lKeys);
|
142
|
+
}
|
143
|
+
}
|
144
|
+
} else if (typeof value === 'object') {
|
145
|
+
removeKeys(value, lKeys);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
125
151
|
// ---------------------------------------------------------------------------
|
126
152
|
export var isNonEmptyString = function(x) {
|
127
153
|
if (typeof x !== 'string' && !(x instanceof String)) {
|