Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run formatcheck
- run: npm run build
- run: npm test
- run: npm run format -- --check
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": false,
"printWidth": 100,
"tabWidth": 2
}
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Node.js CI](https://github.com/mastercw/cw.js/workflows/Node.js%20CI/badge.svg)](https://github.com/mastercw/cw.js/actions)
[![NPM](https://img.shields.io/npm/v/cw)](https://www.npmjs.com/package/cw)

A comprehensive Morse Code (CW) library
A comprehensive Morse Code (CW) library, brought to you by [Master CW](https://www.mastercw.com/).

## Usage

Expand Down Expand Up @@ -31,7 +31,23 @@ $ npm install
$ npm run build
```

Which will create `dist/cw.js` and `dist/cw.min.js`. Or you can just use it from our CDN:
Which will create `dist/cw.js` and `dist/cw.min.js`. Or you can use it from a CDN:

#### jsDelivr CDN (Recommended)

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

or just use `latest`:

```html
<script src="https://cdn.jsdelivr.net/npm/cw@latest/dist/cw.min.js"></script>
```

#### Legacy CDN

Serving version 0.2.1 for backwards compatability:

```html
<script src="https://cwjs.mastercw.com/cw.min.js"></script>
Expand Down
122 changes: 122 additions & 0 deletions examples/jsdelivr-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>cw.js - jsDelivr Demo</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}

pre {
background-color: #f5f5f5;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}

button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}

button:hover {
background-color: #45a049;
}

.result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>

<body>
<h1>cw.js - Morse Code Library</h1>
<p>This demo shows how to use the cw.js library via jsDelivr CDN.</p>

<h2>Example 1: Calculate Timing</h2>
<pre>// Calculate dit length at 20 WPM
const ditLength = cw.tdit(20);
console.log(`Dit length at 20 WPM: ${ditLength} seconds`);

// Calculate Farnsworth dit length at 20 WPM with character speed of 10 WPM
const farnsworthDitLength = cw.tfdit(20, 10);
console.log(`Farnsworth dit length: ${farnsworthDitLength} seconds`);</pre>

<button id="runTimingExample">Run Timing Example</button>
<div id="timingResult" class="result"></div>

<h2>Example 2: Morse Code Mapping</h2>
<pre>// Get morse code for a character
const morseC = cw.codes["C"];
console.log(`Morse code for 'C': ${morseC}`);

// Get morse code for a number
const morse8 = cw.codes["8"];
console.log(`Morse code for '8': ${morse8}`);</pre>

<button id="runMappingExample">Run Mapping Example</button>
<div id="mappingResult" class="result"></div>

<h2>Example 3: Play Morse Code</h2>
<p>Click the button to play "CQ" in Morse code:</p>
<button id="playMorse">Play CQ</button>

<h2>How to Include cw.js in Your Project</h2>
<h3>Via jsDelivr CDN:</h3>
<pre>&lt;script src="https://cdn.jsdelivr.net/npm/cw@0.3.0/dist/cw.min.js"&gt;&lt;/script&gt;</pre>

<h3>Via npm:</h3>
<pre>npm install cw</pre>

<h3>ES Module Import:</h3>
<pre>import { tdit, tfdit, codes, initAudioContext, play } from 'cw';</pre>

<!-- Include the library from jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/cw@0.3.0/dist/cw.min.js"></script>

<script>
// Initialize audio context
cw.initAudioContext();

// Timing example
document.getElementById('runTimingExample').addEventListener('click', function () {
const ditLength = cw.tdit(20);
const farnsworthDitLength = cw.tfdit(20, 10);

document.getElementById('timingResult').innerHTML =
`Dit length at 20 WPM: ${ditLength} seconds<br>` +
`Farnsworth dit length: ${farnsworthDitLength} seconds`;
});

// Mapping example
document.getElementById('runMappingExample').addEventListener('click', function () {
const morseC = cw.codes["C"];
const morse8 = cw.codes["8"];

document.getElementById('mappingResult').innerHTML =
`Morse code for 'C': ${morseC}<br>` +
`Morse code for '8': ${morse8}`;
});

// Play example
document.getElementById('playMorse').addEventListener('click', function () {
// Play "CQ" in Morse code (-.-. --.-) at 20 WPM
cw.play("-.-. --.-", 20);
});
</script>
</body>

</html>
Loading