@jdeighan/coffee-utils 11.0.14 → 11.0.15

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": "11.0.14",
4
+ "version": "11.0.15",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
package/src/utils.coffee CHANGED
@@ -21,9 +21,8 @@ export {
21
21
  }
22
22
 
23
23
  # ---------------------------------------------------------------------------
24
- # TEMP!!!!!
25
24
 
26
- export isComment = (line) =>
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
- // utils.coffee
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
- // TEMP!!!!!
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)) {