@jdeighan/coffee-utils 8.0.0 → 8.0.1

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.0",
4
+ "version": "8.0.1",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -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 h[item]
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
@@ -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 (h[item]) {
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;