@jdeighan/coffee-utils 4.1.25 → 4.1.29
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +4 -3
- package/src/browser_utils.js +16 -5
- package/src/coffee_utils.coffee +13 -0
- package/src/coffee_utils.js +14 -0
- package/src/svelte_utils.coffee +15 -0
- package/src/svelte_utils.js +24 -1
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "4.1.
|
4
|
+
"version": "4.1.29",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -26,7 +26,7 @@
|
|
26
26
|
},
|
27
27
|
"scripts": {
|
28
28
|
"build": "cls && rm -f ./src/*.js && coffee -c ./src",
|
29
|
-
"pretest": "cls && cielo -qfc ./test && coffee -c
|
29
|
+
"pretest": "cls && cielo -qfc ./test && coffee -c .",
|
30
30
|
"test": "ava ./test/*.test.js",
|
31
31
|
"prefinaltest": "npm run pretest",
|
32
32
|
"finaltest": "cross-env FINALTEST=yes ava ./test/*.test.js"
|
@@ -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
|
}
|
package/src/browser_utils.js
CHANGED
@@ -1,17 +1,28 @@
|
|
1
1
|
// Generated by CoffeeScript 2.6.1
|
2
2
|
// browser_utils.coffee
|
3
|
+
var audio;
|
4
|
+
|
5
|
+
import {
|
6
|
+
undef
|
7
|
+
} from '@jdeighan/coffee-utils';
|
8
|
+
|
9
|
+
audio = undef; // audio context - create only when needed, then keep
|
10
|
+
|
3
11
|
|
4
12
|
// ---------------------------------------------------------------------------
|
5
13
|
// beep - play a sound
|
6
14
|
export var beep = function(volume = 100, freq = 520, duration = 200) {
|
7
15
|
var u, v;
|
8
|
-
|
9
|
-
|
16
|
+
if (audio === undef) {
|
17
|
+
audio = new AudioContext();
|
18
|
+
}
|
19
|
+
v = audio.createOscillator();
|
20
|
+
u = audio.createGain();
|
10
21
|
v.connect(u);
|
11
22
|
v.frequency.value = freq;
|
12
23
|
v.type = "square";
|
13
|
-
u.connect(
|
24
|
+
u.connect(audio.destination);
|
14
25
|
u.gain.value = volume * 0.01;
|
15
|
-
v.start(
|
16
|
-
v.stop(
|
26
|
+
v.start(audio.currentTime);
|
27
|
+
v.stop(audio.currentTime + duration * 0.001);
|
17
28
|
};
|
package/src/coffee_utils.coffee
CHANGED
@@ -381,3 +381,16 @@ 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')
|
package/src/coffee_utils.js
CHANGED
@@ -417,3 +417,17 @@ 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
|
+
};
|
package/src/svelte_utils.coffee
CHANGED
@@ -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
|
package/src/svelte_utils.js
CHANGED
@@ -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
|
+
};
|