Skip to content

Commit

Permalink
v2.0, change default encoding and decoding behaviour of Morsify to ma…
Browse files Browse the repository at this point in the history
…ke it compatible with other tools around the web, split the string into words instead of characters.
  • Loading branch information
ozdemirburak committed Apr 3, 2019
1 parent 37b9496 commit 723ca96
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 154 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ root = true
[*]
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ coverage/
node_modules/
npm-debug.log
package-lock.json
yarn-error.log
yarn.lock
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
coverage/
npm-debug.log
package-lock.json
yarn-error.log
yarn.lock
.idea
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: node_js
node_js:
- node
- 6
- 4

after_script:
- npm run test-cov
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) Burak Özdemir <mail@burakozdemir.co.uk>
Copyright (c) 2019 Burak Özdemir <mail@burakozdemir.co.uk>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ $ yarn add morsify

```js
const morsify = require('morsify');
const encoded = morsify.encode('SOS'); // .../---/...
const decoded = morsify.decode('.../---/...'); // S O S
const encoded = morsify.encode('SOS'); // ... --- ...
const decoded = morsify.decode('... --- ...'); // SOS
const characters = morsify.characters(); // {'1': {'A': '.-', ...}, ..., '11': {'ㄱ': '.-..', ...}}
const audio = morsify.audio('SOS');
audio.play(); // play audio
Expand All @@ -39,8 +39,8 @@ Or alternatively, you can also use the library directly with including the sourc
```html
<script src="https://rawgit.com/ozdemirburak/morsify/master/dist/morsify.min.js"></script>
<script>
var encoded = morsify.encode('SOS'); // .../---/...
var decoded = morsify.decode('.../---/...'); // S O S
var encoded = morsify.encode('SOS'); // ... --- ...
var decoded = morsify.decode('... --- ...'); // SOS
var characters = morsify.characters(); // {'1': {'A': '.-', ...}, ..., '11': {'ㄱ': '.-..', ...}}
var audio = morsify.audio('SOS');
var oscillator = audio.oscillator; // OscillatorNode
Expand Down Expand Up @@ -75,12 +75,12 @@ Set the priority option according to the list below.
- 13 => Unicode (Chinese and the others)

```js
const cyrillic = morsify.encode('Ленинград', { priority: 5 }); // .-.././-./../-./--./.-./.-/-..
const greek = morsify.decode('.../.-/--./.-/.--./.--', { priority: 6 }); // Σ Α Γ Α Π Ω
const hebrew = morsify.decode('––– –... ––– . ––. .. .–.. –––', { dash: '', dot: '.', space: ' ', priority: 7 }); // ה ב ה נ ג י ל ה
const chinese = morsify.encode('你好', { priority: 13 }); // -..----.--...../-.--..-.-----.-
const cyrillic = morsify.encode('Ленинград', { priority: 5 }); // .-.. . -. .. -. --. .-. .- -..
const greek = morsify.decode('... .- --. .- .--. .--', { priority: 6 }); // ΣΑΓΑΠΩ
const hebrew = morsify.decode('.. ––– . ––', { dash: '', dot: '.', priority: 7 }); // יהוה
const chinese = morsify.encode('你好', { priority: 13 }); // -..----.--..... -.--..-.-----.-
const characters = morsify.characters({ dash: '', dot: '' }); // {'1': {'A': '•–', ...}, ..., '11': {'ㄱ': '•–••', ...}}
const arabicAudio = morsify.audio('البُراق‎‎', { // generates the morse .-/.-../-.../.-./.-/--.- then generates the audio from it
const arabicAudio = morsify.audio('البراق', { // generates the morse .- .-.. -... .-. .- --.- then generates the audio from it
unit: 0.1, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
oscillator: {
type: 'sine', // sine, square, sawtooth, triangle
Expand Down
17 changes: 13 additions & 4 deletions dist/morsify.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

;
Expand Down Expand Up @@ -495,33 +503,34 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat

}
};
characters[1][' '] = options.space;
characters[0] = characters[options.priority];
return options;
};

var encode = function encode(text, opts) {
var options = getOptions(opts);
return text.replace(/\s+/g, '').toLocaleUpperCase().split('').map(function (character) {
return _toConsumableArray(text.replace(/\s+/g, ' ').trim().toLocaleUpperCase()).map(function (character) {
for (var set in characters) {
if (typeof characters[set] !== 'undefined' && typeof characters[set][character] !== 'undefined') {
return characters[set][character];
}
}

return parseInt(options.priority) === 13 ? unicodeToMorse(character) : options.invalid;
}).join(options.space).replace(/0/g, options.dot).replace(/1/g, options.dash);
}).join(' ').replace(/0/g, options.dot).replace(/1/g, options.dash);
};

var decode = function decode(morse, opts) {
var options = getOptions(opts),
swapped = swapCharacters(options);
return morse.split(options.space).map(function (characters) {
return morse.replace(/\s+/g, ' ').trim().split(' ').map(function (characters) {
if (typeof swapped[characters] !== 'undefined') {
return swapped[characters];
}

return parseInt(options.priority) === 13 ? unicodeToHex(characters, options) : options.invalid;
}).join(' ').replace(/\s+/g, ' ');
}).join('');
};

var isBrowser = typeof window !== 'undefined';
Expand Down
2 changes: 1 addition & 1 deletion dist/morsify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "morsify",
"version": "1.0.0",
"description": "Morse code translator and decoder which also generates audio.",
"version": "2.0.0",
"description": "Morse code translator, morse encoder and decoder, which can also generate audio.",
"keywords": [
"morse",
"morse alphabet",
Expand All @@ -27,15 +27,15 @@
"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"coveralls": "^2.13.3",
"gulp": "^3.9.1",
"coveralls": "^3.0.3",
"gulp": "^4.0.0",
"gulp-babel": "^8.0.0",
"gulp-babel-minify": "^0.5.0",
"gulp-concat": "^2.6.1",
"istanbul": "^0.4.5",
"jshint": "^2.9.6",
"lodash": "^4.17.11",
"mocha": "^3.5.3"
"mocha": "^6.0.2"
},
"main": "./src/morsify.js",
"files": [
Expand Down
Loading

0 comments on commit 723ca96

Please sign in to comment.