@jdeighan/coffee-utils 4.1.25 → 4.1.26
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/browser_utils.js +16 -5
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.26",
|
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"
|
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
|
};
|