@jdeighan/coffee-utils 4.1.26 → 4.1.30

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": "4.1.26",
4
+ "version": "4.1.30",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -48,6 +48,7 @@
48
48
  "ava": "^3.15.0",
49
49
  "cross-env": "^7.0.3",
50
50
  "js-yaml": "^4.1.0",
51
- "readline-sync": "^1.4.10"
51
+ "readline-sync": "^1.4.10",
52
+ "svelte": "^3.46.3"
52
53
  }
53
54
  }
@@ -381,3 +381,24 @@ export envVarsWithPrefix = (prefix, hOptions={}) ->
381
381
 
382
382
  # ---------------------------------------------------------------------------
383
383
 
384
+ export getTimeStr = (date=undef) ->
385
+
386
+ if date == undef
387
+ date = new Date()
388
+ return date.toLocaleTimeString('en-US')
389
+
390
+ # ---------------------------------------------------------------------------
391
+
392
+ export getDateStr = (date=undef) ->
393
+
394
+ if date == undef
395
+ date = new Date()
396
+ return date.toLocaleDateString('en-US')
397
+
398
+ # ---------------------------------------------------------------------------
399
+
400
+ export strcat = (lItems...) ->
401
+ str = ''
402
+ for item in lItems
403
+ str += item.toString()
404
+ return str
@@ -417,3 +417,28 @@ export var envVarsWithPrefix = function(prefix, hOptions = {}) {
417
417
  };
418
418
 
419
419
  // ---------------------------------------------------------------------------
420
+ export var getTimeStr = function(date = undef) {
421
+ if (date === undef) {
422
+ date = new Date();
423
+ }
424
+ return date.toLocaleTimeString('en-US');
425
+ };
426
+
427
+ // ---------------------------------------------------------------------------
428
+ export var getDateStr = function(date = undef) {
429
+ if (date === undef) {
430
+ date = new Date();
431
+ }
432
+ return date.toLocaleDateString('en-US');
433
+ };
434
+
435
+ // ---------------------------------------------------------------------------
436
+ export var strcat = function(...lItems) {
437
+ var i, item, len, str;
438
+ str = '';
439
+ for (i = 0, len = lItems.length; i < len; i++) {
440
+ item = lItems[i];
441
+ str += item.toString();
442
+ }
443
+ return str;
444
+ };
@@ -1,5 +1,8 @@
1
1
  # svelte_utils.coffee
2
2
 
3
+ import {assert, isFunction} from '@jdeighan/coffee-utils'
4
+ import {log} from '@jdeighan/coffee-utils/log'
5
+
3
6
  # ---------------------------------------------------------------------------
4
7
  # svelteSourceCodeEsc - to display source code for a *.starbucks page
5
8
 
@@ -24,3 +27,15 @@ export svelteHtmlEsc = (str) ->
24
27
 
25
28
  # ---------------------------------------------------------------------------
26
29
 
30
+ export onInterval = (func, secs, doLog=false) ->
31
+
32
+ assert isFunction(func), "onInterval(): 1st arg not a function"
33
+ ms = Math.floor(1000 * secs)
34
+ if doLog
35
+ log "calling func every #{ms} ms."
36
+ interval = setInterval(func, ms)
37
+
38
+ return () ->
39
+ if doLog
40
+ log "destroying interval timer"
41
+ clearInterval interval
@@ -1,5 +1,13 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
- // svelte_utils.coffee
2
+ // svelte_utils.coffee
3
+ import {
4
+ assert,
5
+ isFunction
6
+ } from '@jdeighan/coffee-utils';
7
+
8
+ import {
9
+ log
10
+ } from '@jdeighan/coffee-utils/log';
3
11
 
4
12
  // ---------------------------------------------------------------------------
5
13
  // svelteSourceCodeEsc - to display source code for a *.starbucks page
@@ -14,3 +22,18 @@ export var svelteHtmlEsc = function(str) {
14
22
  };
15
23
 
16
24
  // ---------------------------------------------------------------------------
25
+ export var onInterval = function(func, secs, doLog = false) {
26
+ var interval, ms;
27
+ assert(isFunction(func), "onInterval(): 1st arg not a function");
28
+ ms = Math.floor(1000 * secs);
29
+ if (doLog) {
30
+ log(`calling func every ${ms} ms.`);
31
+ }
32
+ interval = setInterval(func, ms);
33
+ return function() {
34
+ if (doLog) {
35
+ log("destroying interval timer");
36
+ }
37
+ return clearInterval(interval);
38
+ };
39
+ };