@jdeighan/coffee-utils 4.1.22 → 4.1.26
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,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.
|
|
4
|
+
"version": "4.1.26",
|
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
|
6
6
|
"main": "coffee_utils.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./src/coffee_utils.js",
|
|
9
|
-
"./
|
|
9
|
+
"./server": "./src/server_utils.js",
|
|
10
|
+
"./browser": "./src/browser_utils.js",
|
|
10
11
|
"./fs": "./src/fs_utils.js",
|
|
11
12
|
"./log": "./src/log_utils.js",
|
|
12
13
|
"./block": "./src/block_utils.js",
|
|
@@ -25,8 +26,7 @@
|
|
|
25
26
|
},
|
|
26
27
|
"scripts": {
|
|
27
28
|
"build": "cls && rm -f ./src/*.js && coffee -c ./src",
|
|
28
|
-
"
|
|
29
|
-
"pretest": "cls && cielo -ckq .",
|
|
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"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# browser_utils.coffee
|
|
2
|
+
|
|
3
|
+
import {undef} from '@jdeighan/coffee-utils'
|
|
4
|
+
|
|
5
|
+
audio = undef # audio context - create only when needed, then keep
|
|
6
|
+
|
|
7
|
+
# ---------------------------------------------------------------------------
|
|
8
|
+
# beep - play a sound
|
|
9
|
+
|
|
10
|
+
export beep = (volume=100, freq=520, duration=200) ->
|
|
11
|
+
|
|
12
|
+
if audio == undef
|
|
13
|
+
audio = new AudioContext()
|
|
14
|
+
v = audio.createOscillator()
|
|
15
|
+
u = audio.createGain()
|
|
16
|
+
v.connect(u)
|
|
17
|
+
v.frequency.value = freq
|
|
18
|
+
v.type = "square"
|
|
19
|
+
u.connect(audio.destination)
|
|
20
|
+
u.gain.value = volume * 0.01
|
|
21
|
+
v.start(audio.currentTime)
|
|
22
|
+
v.stop(audio.currentTime + duration * 0.001)
|
|
23
|
+
return
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
|
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
|
+
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// beep - play a sound
|
|
14
|
+
export var beep = function(volume = 100, freq = 520, duration = 200) {
|
|
15
|
+
var u, v;
|
|
16
|
+
if (audio === undef) {
|
|
17
|
+
audio = new AudioContext();
|
|
18
|
+
}
|
|
19
|
+
v = audio.createOscillator();
|
|
20
|
+
u = audio.createGain();
|
|
21
|
+
v.connect(u);
|
|
22
|
+
v.frequency.value = freq;
|
|
23
|
+
v.type = "square";
|
|
24
|
+
u.connect(audio.destination);
|
|
25
|
+
u.gain.value = volume * 0.01;
|
|
26
|
+
v.start(audio.currentTime);
|
|
27
|
+
v.stop(audio.currentTime + duration * 0.001);
|
|
28
|
+
};
|