@jdeighan/coffee-utils 4.1.24 → 4.1.28
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 +4 -3
- package/src/browser_utils.coffee +11 -5
- package/src/browser_utils.js +16 -5
- 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.28",
|
|
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.coffee
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
# browser_utils.coffee
|
|
2
2
|
|
|
3
|
+
import {undef} from '@jdeighan/coffee-utils'
|
|
4
|
+
|
|
5
|
+
audio = undef # audio context - create only when needed, then keep
|
|
6
|
+
|
|
3
7
|
# ---------------------------------------------------------------------------
|
|
4
8
|
# beep - play a sound
|
|
5
9
|
|
|
6
10
|
export beep = (volume=100, freq=520, duration=200) ->
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
if audio == undef
|
|
13
|
+
audio = new AudioContext()
|
|
14
|
+
v = audio.createOscillator()
|
|
15
|
+
u = audio.createGain()
|
|
10
16
|
v.connect(u)
|
|
11
17
|
v.frequency.value = freq
|
|
12
18
|
v.type = "square"
|
|
13
|
-
u.connect(
|
|
19
|
+
u.connect(audio.destination)
|
|
14
20
|
u.gain.value = volume * 0.01
|
|
15
|
-
v.start(
|
|
16
|
-
v.stop(
|
|
21
|
+
v.start(audio.currentTime)
|
|
22
|
+
v.stop(audio.currentTime + duration * 0.001)
|
|
17
23
|
return
|
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/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
|
+
};
|