diff --git a/README.md b/README.md index a1cece2..d60772a 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,17 @@ Install the package via `npm` or `yarn`: $ npm install cw ``` -You can then use: +#### ES Modules -```node +```javascript +import cw from "cw"; +console.log(cw.codes["C"]); // "-.-." +cw.play("hello world"); +``` + +#### CommonJS + +```javascript const cw = require("cw"); console.log(cw.codes["C"]); // "-.-." ``` @@ -74,8 +82,10 @@ cw.play("abcd", { In cases of multiple plays, it is recommended to create a global `audioContext` object: ```js +// Initialize audio context once let actx = cw.initAudioContext({ tone: 600 }); // tone is passed here +// Reuse the audio context for multiple plays cw.play("abcd", { actx, wpm: 10 }); cw.play("efgh", { actx, wpm: 20 }); cw.play("ijkl", { actx, wpm: 30 }); diff --git a/examples/jsdelivr-demo.html b/examples/jsdelivr-demo.html index c6a0261..3dc6b1b 100644 --- a/examples/jsdelivr-demo.html +++ b/examples/jsdelivr-demo.html @@ -76,16 +76,16 @@

Example 3: Play Morse Code

How to Include cw.js in Your Project

Via jsDelivr CDN:

-
<script src="https://cdn.jsdelivr.net/npm/cw@0.3.0/dist/cw.min.js"></script>
+
<script src="https://cdn.jsdelivr.net/npm/cw@0.4.0/dist/cw.min.js"></script>

Via npm:

npm install cw

ES Module Import:

-
import { tdit, tfdit, codes, initAudioContext, play } from 'cw';
+
import cw from 'cw';
- +