@jdeighan/coffee-utils 8.0.0 → 8.0.1
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 +1 -1
- package/src/coffee_utils.coffee +16 -2
- package/src/coffee_utils.js +19 -2
package/package.json
CHANGED
package/src/coffee_utils.coffee
CHANGED
@@ -135,6 +135,16 @@ export isString = (x) ->
|
|
135
135
|
|
136
136
|
# ---------------------------------------------------------------------------
|
137
137
|
|
138
|
+
export isNonEmptyString = (x) ->
|
139
|
+
|
140
|
+
if typeof x != 'string' && x ! instanceof String
|
141
|
+
return false
|
142
|
+
if x.match(/^\s*$/)
|
143
|
+
return false
|
144
|
+
return true
|
145
|
+
|
146
|
+
# ---------------------------------------------------------------------------
|
147
|
+
|
138
148
|
export isBoolean = (x) ->
|
139
149
|
|
140
150
|
return typeof x == 'boolean'
|
@@ -269,13 +279,17 @@ export isInteger = (x) ->
|
|
269
279
|
|
270
280
|
# ---------------------------------------------------------------------------
|
271
281
|
|
272
|
-
export isUniqueList = (lItems) ->
|
282
|
+
export isUniqueList = (lItems, func=undef) ->
|
273
283
|
|
274
284
|
if ! lItems?
|
275
285
|
return true # empty list is unique
|
286
|
+
if defined(func)
|
287
|
+
assert isFunction(func), "Not a function: #{OL(func)}"
|
276
288
|
h = {}
|
277
289
|
for item in lItems
|
278
|
-
if
|
290
|
+
if defined(func) && !func(item)
|
291
|
+
return false
|
292
|
+
if defined(h[item])
|
279
293
|
return false
|
280
294
|
h[item] = 1
|
281
295
|
return true
|
package/src/coffee_utils.js
CHANGED
@@ -128,6 +128,17 @@ export var isString = function(x) {
|
|
128
128
|
return typeof x === 'string' || x instanceof String;
|
129
129
|
};
|
130
130
|
|
131
|
+
// ---------------------------------------------------------------------------
|
132
|
+
export var isNonEmptyString = function(x) {
|
133
|
+
if (typeof x !== 'string' && !(x instanceof String)) {
|
134
|
+
return false;
|
135
|
+
}
|
136
|
+
if (x.match(/^\s*$/)) {
|
137
|
+
return false;
|
138
|
+
}
|
139
|
+
return true;
|
140
|
+
};
|
141
|
+
|
131
142
|
// ---------------------------------------------------------------------------
|
132
143
|
export var isBoolean = function(x) {
|
133
144
|
return typeof x === 'boolean';
|
@@ -270,15 +281,21 @@ export var isInteger = function(x) {
|
|
270
281
|
};
|
271
282
|
|
272
283
|
// ---------------------------------------------------------------------------
|
273
|
-
export var isUniqueList = function(lItems) {
|
284
|
+
export var isUniqueList = function(lItems, func = undef) {
|
274
285
|
var h, i, item, len;
|
275
286
|
if (lItems == null) {
|
276
287
|
return true; // empty list is unique
|
277
288
|
}
|
289
|
+
if (defined(func)) {
|
290
|
+
assert(isFunction(func), `Not a function: ${OL(func)}`);
|
291
|
+
}
|
278
292
|
h = {};
|
279
293
|
for (i = 0, len = lItems.length; i < len; i++) {
|
280
294
|
item = lItems[i];
|
281
|
-
if (
|
295
|
+
if (defined(func) && !func(item)) {
|
296
|
+
return false;
|
297
|
+
}
|
298
|
+
if (defined(h[item])) {
|
282
299
|
return false;
|
283
300
|
}
|
284
301
|
h[item] = 1;
|