@jdeighan/coffee-utils 4.1.25 → 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,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.1.25",
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 ./test",
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"
@@ -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
- v = this.audio.createOscillator();
9
- u = this.audio.createGain();
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(this.audio.destination);
24
+ u.connect(audio.destination);
14
25
  u.gain.value = volume * 0.01;
15
- v.start(this.audio.currentTime);
16
- v.stop(this.audio.currentTime + duration * 0.001);
26
+ v.start(audio.currentTime);
27
+ v.stop(audio.currentTime + duration * 0.001);
17
28
  };