Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

morse-decoder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

morse-decoder - npm Package Compare versions

Comparing version 3.0.1 to 4.0.0

src/audio.ts

2

dist/morse-decoder.min.js

@@ -1,1 +0,1 @@

"use strict";function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(a,b){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a)){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _iterableToArray(a){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}(function(a,b,c){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))?module.exports=c():"function"==typeof define&&define.amd?define(c):b[a]=c()})("morse-decoder",void 0,function(){'use strict';var a={1:{A:"01",B:"1000",C:"1010",D:"100",E:"0",F:"0010",G:"110",H:"0000",I:"00",J:"0111",K:"101",L:"0100",M:"11",N:"10",O:"111",P:"0110",Q:"1101",R:"010",S:"000",T:"1",U:"001",V:"0001",W:"011",X:"1001",Y:"1011",Z:"1100"},2:{0:"11111",1:"01111",2:"00111",3:"00011",4:"00001",5:"00000",6:"10000",7:"11000",8:"11100",9:"11110"},3:{".":"010101",",":"110011","?":"001100","'":"011110","!":"101011","/":"10010","(":"10110",")":"101101","&":"01000",":":"111000",";":"101010","=":"10001","+":"01010","-":"100001",_:"001101",'"':"010010",$:"0001001","@":"011010","¿":"00101","¡":"110001"},4:{Ã:"01101",Á:"01101",Å:"01101",À:"01101",Â:"01101",Ä:"0101",Ą:"0101",Æ:"0101",Ç:"10100",Ć:"10100",Ĉ:"10100",Č:"110",Ð:"00110",È:"01001",Ę:"00100",Ë:"00100",É:"00100",Ê:"10010",Ğ:"11010",Ĝ:"11010",Ĥ:"1111",İ:"01001",Ï:"10011",Ì:"01110",Ĵ:"01110",Ł:"01001",Ń:"11011",Ñ:"11011",Ó:"1110",Ò:"1110",Ö:"1110",Ô:"1110",Ø:"1110",Ś:"0001000",Ş:"01100",Ș:"1111",Š:"1111",Ŝ:"00010",ß:"000000",Þ:"01100",Ü:"0011",Ù:"0011",Ŭ:"0011",Ž:"11001",Ź:"110010",Ż:"11001"},5:{А:"01",Б:"1000",В:"011",Г:"110",Д:"100",Е:"0",Ж:"0001",З:"1100",И:"00",Й:"0111",К:"101",Л:"0100",М:"11",Н:"10",О:"111",П:"0110",Р:"010",С:"000",Т:"1",У:"001",Ф:"0010",Х:"0000",Ц:"1010",Ч:"1110",Ш:"1111",Щ:"1101",Ъ:"11011",Ы:"1011",Ь:"1001",Э:"00100",Ю:"0011",Я:"0101",Ї:"01110",Є:"00100",І:"00",Ґ:"110"},6:{Α:"01",Β:"1000",Γ:"110",Δ:"100",Ε:"0",Ζ:"1100",Η:"0000",Θ:"1010",Ι:"00",Κ:"101",Λ:"0100",Μ:"11",Ν:"10",Ξ:"1001",Ο:"111",Π:"0110",Ρ:"010",Σ:"000",Τ:"1",Υ:"1011",Φ:"0010",Χ:"1111",Ψ:"1101",Ω:"011"},7:{א:"01",ב:"1000",ג:"110",ד:"100",ה:"111",ו:"0",ז:"1100",ח:"0000",ט:"001",י:"00",כ:"101",ל:"0100",מ:"11",נ:"10",ס:"1010",ע:"0111",פ:"0110",צ:"011",ק:"1101",ר:"010",ש:"000",ת:"1"},8:{ا:"01",ب:"1000",ت:"1",ث:"1010",ج:"0111",ح:"0000",خ:"111",د:"100",ذ:"1100",ر:"010",ز:"1110",س:"000",ش:"1111",ص:"1001",ض:"0001",ط:"001",ظ:"1011",ع:"0101",غ:"110",ف:"0010",ق:"1101",ك:"101",ل:"0100",م:"11",ن:"10",ه:"00100",و:"011",ي:"00",ﺀ:"0"},9:{ا:"01",ب:"1000",پ:"0110",ت:"1",ث:"1010",ج:"0111",چ:"1110",ح:"0000",خ:"1001",د:"100",ذ:"0001",ر:"010",ز:"1100",ژ:"110",س:"000",ش:"1111",ص:"0101",ض:"00100",ط:"001",ظ:"1011",ع:"111",غ:"0011",ف:"0010",ق:"111000",ک:"101",گ:"1101",ل:"0100",م:"11",ن:"10",و:"011",ه:"0",ی:"00"},10:{ア:"11011",カ:"0100",サ:"10101",タ:"10",ナ:"010",ハ:"1000",マ:"1001",ヤ:"011",ラ:"000",ワ:"101",イ:"01",キ:"10100",シ:"11010",チ:"0010",ニ:"1010",ヒ:"11001",ミ:"00101",リ:"110",ヰ:"01001",ウ:"001",ク:"0001",ス:"11101",ツ:"0110",ヌ:"0000",フ:"1100",ム:"1",ユ:"10011",ル:"10110",ン:"01010",エ:"10111",ケ:"1011",セ:"01110",テ:"01011",ネ:"1101",ヘ:"0",メ:"10001",レ:"111",ヱ:"01100",オ:"01000",コ:"1111",ソ:"1110",ト:"00100",ノ:"0011",ホ:"100",モ:"10010",ヨ:"11",ロ:"0101",ヲ:"0111","゛":"00","゜":"00110","。":"010100",ー:"01101","、":"010101","(":"101101",")":"010010"},11:{ㄱ:"0100",ㄴ:"0010",ㄷ:"1000",ㄹ:"0001",ㅁ:"11",ㅂ:"011",ㅅ:"110",ㅇ:"101",ㅈ:"0110",ㅊ:"1010",ㅋ:"1001",ㅌ:"1100",ㅍ:"111",ㅎ:"0111",ㅏ:"0",ㅑ:"00",ㅓ:"1",ㅕ:"000",ㅗ:"01",ㅛ:"10",ㅜ:"0000",ㅠ:"010",ㅡ:"100",ㅣ:"001"},12:{ก:"110",ข:"1010",ค:"101",ง:"10110",จ:"10010",ฉ:"1111",ช:"1001",ซ:"1100",ญ:"0111",ด:"100",ต:"1",ถ:"10100",ท:"10011",น:"10",บ:"1000",ป:"0110",ผ:"1101",ฝ:"10101",พ:"01100",ฟ:"0010",ม:"11",ย:"1011",ร:"010",ล:"0100",ว:"011",ส:"000",ห:"0000",อ:"10001",ฮ:"11011",ฤ:"01011",ะ:"01000",า:"01","ิ":"00100","ี":"00","ึ":"00110","ื":"0011","ุ":"00101","ู":"1110",เ:"0",แ:"0101",ไ:"01001",โ:"111",ำ:"00010","่":"001","้":"0001","๊":"11000","๋":"01010","ั":"01101","็":"11100","์":"11001",ๆ:"10111",ฯ:"11010"}},b=function(b,c){var e=d(b),f={};for(var g in a)for(var h in f[g]={},a[g])f[g][h]=a[g][h].replace(/0/g,e.dot).replace(/1/g,e.dash);return!0!==c&&delete f[0],f},c=function(a){var c={},d=b(a,!0);for(var e in d)for(var f in d[e])"undefined"==typeof c[d[e][f]]&&(c[d[e][f]]=f);return c},d=function(b){return b=b||{},b.oscillator=b.oscillator||{},b={dash:b.dash||"-",dot:b.dot||".",space:b.space||"/",separator:b.separator||" ",invalid:b.invalid||"#",priority:b.priority||1,unit:b.unit||.08,fwUnit:b.fwUnit||b.unit||.08,oscillator:{type:b.oscillator.type||"sine",frequency:b.oscillator.frequency||500,onended:b.oscillator.onended||null}},a[1][b.separator]=b.space,a[0]=a[b.priority],b},e=function(b,c){var e=d(c);return _toConsumableArray(b.replace(/\s+/g,e.separator).trim().toLocaleUpperCase()).map(function(b){for(var c in a)if("undefined"!=typeof a[c]&&"undefined"!=typeof a[c][b])return a[c][b];return e.invalid}).join(e.separator).replace(/0/g,e.dot).replace(/1/g,e.dash)},f=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:0,d=[],e=0;d.push([0,e]);for(var f=function(a){d.push([1,c+e]),e+=a*b.unit},g=function(a){d.push([0,c+e]),e+=a*b.unit},h=function(a){d.push([0,c+e]),e+=a*b.fwUnit},j=0;j<=a.length;j++)a[j]===b.space?h(7):a[j]===b.dot?(f(1),g(1)):a[j]===b.dash?(f(3),g(1)):"undefined"!=typeof a[j+1]&&a[j+1]!==b.space&&"undefined"!=typeof a[j-1]&&a[j-1]!==b.space&&h(3);return[d,e]},g=function(a,b){var c=new ArrayBuffer(44+2*b.length),d=new DataView(c),e=function(a,b,c){for(var d=0;d<c.length;d++)a.setUint8(b+d,c.charCodeAt(d))};e(d,0,"RIFF"),d.setUint32(4,36+2*b.length,!0),e(d,8,"WAVE"),e(d,12,"fmt "),d.setUint32(16,16,!0),d.setUint16(20,1,!0),d.setUint16(22,1,!0),d.setUint32(24,a,!0),d.setUint32(28,4*a,!0),d.setUint16(32,2,!0),d.setUint16(34,16,!0),e(d,36,"data"),d.setUint32(40,2*b.length,!0);return function(a,b,c){for(var d=Math.max,e=Math.min,f,g=0;g<c.length;g++,b+=2)f=d(-1,e(1,c[g])),a.setInt16(b,0>f?32768*f:32767*f,!0)}(d,44,b),d};return{characters:b,decode:function(a,b){var e=d(b),f=c(e);return a.replace(/\s+/g,e.separator).trim().split(e.separator).map(function(a){return"undefined"==typeof f[a]?e.invalid:f[a]}).join("")},encode:e,audio:function(a,b,c){var h,i=null,j=null,k=null,l=null,m=d(b),n=c||e(a,b),o=f(n,m),p=_slicedToArray(o,2),q=p[0],r=p[1];null===i&&"undefined"!=typeof window&&(i=window.AudioContext||window.webkitAudioContext,k=new i,h=k.createBufferSource(),h.connect(k.destination)),null===j&&"undefined"!=typeof window&&(j=window.OfflineAudioContext||window.webkitOfflineAudioContext,l=new j(1,44100*r,44100));var s=l.createOscillator(),t=l.createGain();s.type=m.oscillator.type,s.frequency.value=m.oscillator.frequency,q.forEach(function(a){var b=_slicedToArray(a,2),c=b[0],d=b[1];return t.gain.setValueAtTime(c,d)}),s.connect(t),t.connect(l.destination),h.onended=m.oscillator.onended;var u,v=new Promise(function(a){s.start(0),l.startRendering(),l.oncomplete=function(b){h.buffer=b.renderedBuffer,a()}}),w=function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,v;case 2:h.start(k.currentTime),u=setTimeout(function(){return x()},1e3*r);case 4:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}(),x=function(){clearTimeout(u),u=0,h.stop(0)},y=function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,v;case 2:return b=g(l.sampleRate,h.buffer.getChannelData(0)),a.abrupt("return",new Blob([b],{type:"audio/wav"}));case 4:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}(),z=function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(){var b;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,y();case 2:return b=a.sent,a.abrupt("return",URL.createObjectURL(b));case 4:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}(),A=function(){var a=_asyncToGenerator(regeneratorRuntime.mark(function a(b){var c,d;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,z();case 2:c=a.sent,d=document.createElement("a"),d.href=c,d.target="_blank",d.download=b||"morse.wav",d.click();case 8:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}();return{play:w,stop:x,getWaveBlob:y,getWaveUrl:z,exportWave:A,context:k,oscillator:s,gainNode:t}}}});
"use strict";const e={1:{A:"01",B:"1000",C:"1010",D:"100",E:"0",F:"0010",G:"110",H:"0000",I:"00",J:"0111",K:"101",L:"0100",M:"11",N:"10",O:"111",P:"0110",Q:"1101",R:"010",S:"000",T:"1",U:"001",V:"0001",W:"011",X:"1001",Y:"1011",Z:"1100"},2:{0:"11111",1:"01111",2:"00111",3:"00011",4:"00001",5:"00000",6:"10000",7:"11000",8:"11100",9:"11110"},3:{".":"010101",",":"110011","?":"001100","'":"011110","!":"101011","/":"10010","(":"10110",")":"101101","&":"01000",":":"111000",";":"101010","=":"10001","+":"01010","-":"100001",_:"001101",'"':"010010",$:"0001001","@":"011010","¿":"00101","¡":"110001"},4:{"Ã":"01101","Á":"01101","Å":"01101","À":"01101","Â":"01101","Ä":"0101","Ą":"0101","Æ":"0101","Ç":"10100","Ć":"10100","Ĉ":"10100","Č":"110","Ð":"00110","È":"01001","Ę":"00100","Ë":"00100","É":"00100","Ê":"10010","Ğ":"11010","Ĝ":"11010","Ĥ":"1111","İ":"01001","Ï":"10011","Ì":"01110","Ĵ":"01110","Ł":"01001","Ń":"11011","Ñ":"11011","Ó":"1110","Ò":"1110","Ö":"1110","Ô":"1110","Ø":"1110","Ś":"0001000","Ş":"01100","Ș":"1111","Š":"1111","Ŝ":"00010","ß":"000000","Þ":"01100","Ü":"0011","Ù":"0011","Ŭ":"0011","Ž":"11001","Ź":"110010","Ż":"11001"},5:{"А":"01","Б":"1000","В":"011","Г":"110","Д":"100","Е":"0","Ж":"0001","З":"1100","И":"00","Й":"0111","К":"101","Л":"0100","М":"11","Н":"10","О":"111","П":"0110","Р":"010","С":"000","Т":"1","У":"001","Ф":"0010","Х":"0000","Ц":"1010","Ч":"1110","Ш":"1111","Щ":"1101","Ъ":"11011","Ы":"1011","Ь":"1001","Э":"00100","Ю":"0011","Я":"0101","Ї":"01110","Є":"00100","І":"00","Ґ":"110"},6:{"Α":"01","Β":"1000","Γ":"110","Δ":"100","Ε":"0","Ζ":"1100","Η":"0000","Θ":"1010","Ι":"00","Κ":"101","Λ":"0100","Μ":"11","Ν":"10","Ξ":"1001","Ο":"111","Π":"0110","Ρ":"010","Σ":"000","Τ":"1","Υ":"1011","Φ":"0010","Χ":"1111","Ψ":"1101","Ω":"011"},7:{"א":"01","ב":"1000","ג":"110","ד":"100","ה":"111","ו":"0","ז":"1100","ח":"0000","ט":"001","י":"00","כ":"101","ל":"0100","מ":"11","נ":"10","ס":"1010","ע":"0111","פ":"0110","צ":"011","ק":"1101","ר":"010","ש":"000","ת":"1"},8:{"ا":"01","ب":"1000","ت":"1","ث":"1010","ج":"0111","ح":"0000","خ":"111","د":"100","ذ":"1100","ر":"010","ز":"1110","س":"000","ش":"1111","ص":"1001","ض":"0001","ط":"001","ظ":"1011","ع":"0101","غ":"110","ف":"0010","ق":"1101","ك":"101","ل":"0100","م":"11","ن":"10","ه":"00100","و":"011","ي":"00","ﺀ":"0"},9:{"ا":"01","ب":"1000","پ":"0110","ت":"1","ث":"1010","ج":"0111","چ":"1110","ح":"0000","خ":"1001","د":"100","ذ":"0001","ر":"010","ز":"1100","ژ":"110","س":"000","ش":"1111","ص":"0101","ض":"00100","ط":"001","ظ":"1011","ع":"111","غ":"0011","ف":"0010","ق":"111000","ک":"101","گ":"1101","ل":"0100","م":"11","ن":"10","و":"011","ه":"0","ی":"00"},10:{"ア":"11011","カ":"0100","サ":"10101","タ":"10","ナ":"010","ハ":"1000","マ":"1001","ヤ":"011","ラ":"000","ワ":"101","イ":"01","キ":"10100","シ":"11010","チ":"0010","ニ":"1010","ヒ":"11001","ミ":"00101","リ":"110","ヰ":"01001","ウ":"001","ク":"0001","ス":"11101","ツ":"0110","ヌ":"0000","フ":"1100","ム":"1","ユ":"10011","ル":"10110","ン":"01010","エ":"10111","ケ":"1011","セ":"01110","テ":"01011","ネ":"1101","ヘ":"0","メ":"10001","レ":"111","ヱ":"01100","オ":"01000","コ":"1111","ソ":"1110","ト":"00100","ノ":"0011","ホ":"100","モ":"10010","ヨ":"11","ロ":"0101","ヲ":"0111","゛":"00","゜":"00110","。":"010100","ー":"01101","、":"010101","(":"101101",")":"010010"},11:{"ㄱ":"0100","ㄴ":"0010","ㄷ":"1000","ㄹ":"0001","ㅁ":"11","ㅂ":"011","ㅅ":"110","ㅇ":"101","ㅈ":"0110","ㅊ":"1010","ㅋ":"1001","ㅌ":"1100","ㅍ":"111","ㅎ":"0111","ㅏ":"0","ㅑ":"00","ㅓ":"1","ㅕ":"000","ㅗ":"01","ㅛ":"10","ㅜ":"0000","ㅠ":"010","ㅡ":"100","ㅣ":"001"},12:{"ก":"110","ข":"1010","ค":"101","ง":"10110","จ":"10010","ฉ":"1111","ช":"1001","ซ":"1100","ญ":"0111","ด":"100","ต":"1","ถ":"10100","ท":"10011","น":"10","บ":"1000","ป":"0110","ผ":"1101","ฝ":"10101","พ":"01100","ฟ":"0010","ม":"11","ย":"1011","ร":"010","ล":"0100","ว":"011","ส":"000","ห":"0000","อ":"10001","ฮ":"11011","ฤ":"01011","ะ":"01000","า":"01","ิ":"00100","ี":"00","ึ":"00110","ื":"0011","ุ":"00101","ู":"1110","เ":"0","แ":"0101","ไ":"01001","โ":"111","ำ":"00010","่":"001","้":"0001","๊":"11000","๋":"01010","ั":"01101","็":"11100","์":"11001","ๆ":"10111","ฯ":"11010"}},t=t=>Object.assign(Object.assign({},e),{0:e[t.priority],1:Object.assign(Object.assign({},e[1]),{[t.separator]:t.space})}),n=(e,n)=>{const o={},i=t(e);for(const t in i){o[t]={};for(const n in i[t])o[t][n]=i[t][n].replace(/0/g,e.dot).replace(/1/g,e.dash)}return n||delete o[0],o},o=(e={})=>{var t,n,o;return Object.assign(Object.assign({},e),{dash:e.dash||"-",dot:e.dot||".",space:e.space||"/",separator:e.separator||" ",invalid:e.invalid||"#",priority:e.priority||1,wpm:e.wpm,unit:e.unit||.08,fwUnit:e.fwUnit||e.unit||.08,volume:e.volume||100,oscillator:Object.assign(Object.assign({},e.oscillator),{type:(null===(t=e.oscillator)||void 0===t?void 0:t.type)||"sine",frequency:(null===(n=e.oscillator)||void 0===n?void 0:n.frequency)||500,onended:(null===(o=e.oscillator)||void 0===o?void 0:o.onended)||null})})},i=(e,t)=>{let n,o=null,i=null,r=null,a=null;const[s,c]=((e,t,n=0)=>{const o=[];let{unit:i,fwUnit:r}=t,a=0;t.wpm&&(i=r=60/(50*t.wpm)),o.push([0,a]);const s=e=>{o.push([t.volume/100*1,n+a]),a+=e*i},c=e=>{o.push([0,n+a]),a+=e*i},l=e=>{o.push([0,n+a]),a+=e*r};for(let n=0,o=!1;n<=e.length;n++)e[n]===t.space?(l(7),o=!1):e[n]===t.dot?(o?c(1):o=!0,s(1)):e[n]===t.dash?(o?c(1):o=!0,s(3)):void 0!==e[n+1]&&e[n+1]!==t.space&&void 0!==e[n-1]&&e[n-1]!==t.space&&(l(3),o=!1);return[o,a]})(e,t);null===o&&"undefined"!=typeof window&&(o=window.AudioContext||window.webkitAudioContext,r=new o,n=r.createBufferSource(),n.connect(r.destination)),null===i&&"undefined"!=typeof window&&(i=window.OfflineAudioContext||window.webkitOfflineAudioContext,a=new i(1,44100*c,44100));const l=a.createOscillator(),d=a.createGain();l.type=t.oscillator.type,l.frequency.value=t.oscillator.frequency,s.forEach((([e,t])=>d.gain.setValueAtTime(e,t))),l.connect(d),d.connect(a.destination),n.onended=t.oscillator.onended;const u=new Promise((e=>{l.start(0),a.startRendering(),a.oncomplete=t=>{n.buffer=t.renderedBuffer,e()}}));let p;const f=()=>{clearTimeout(p),p=0,n.stop(0)},w=async()=>{await u;const e=((e,t)=>{const n=new ArrayBuffer(44+2*t.length),o=new DataView(n),i=(e,t,n)=>{for(let o=0;o<n.length;o++)e.setUint8(t+o,n.charCodeAt(o))};return i(o,0,"RIFF"),o.setUint32(4,36+2*t.length,!0),i(o,8,"WAVE"),i(o,12,"fmt "),o.setUint32(16,16,!0),o.setUint16(20,1,!0),o.setUint16(22,1,!0),o.setUint32(24,e,!0),o.setUint32(28,4*e,!0),o.setUint16(32,2,!0),o.setUint16(34,16,!0),i(o,36,"data"),o.setUint32(40,2*t.length,!0),((e,t,n)=>{for(let o=0;o<n.length;o++,t+=2){const i=Math.max(-1,Math.min(1,n[o]));e.setInt16(t,i<0?32768*i:32767*i,!0)}})(o,44,t),o})(a.sampleRate,n.buffer.getChannelData(0));return new Blob([e],{type:"audio/wav"})},g=async()=>{const e=await w();return URL.createObjectURL(e)};return{play:async()=>{await u,n.start(r.currentTime),p=setTimeout((()=>{f()}),1e3*c)},stop:f,getWaveBlob:w,getWaveUrl:g,exportWave:async e=>{const t=await g(),n=document.createElement("a");n.href=t,n.target="_blank",n.download=e||"morse.wav",n.click()},context:r,oscillator:l,gainNode:d}};var r,a;r=globalThis,a=()=>{const e=(e,n)=>{const i=o(n),r=t(i);return[...e.replace(/\s+/g,i.separator).trim().toLocaleUpperCase()].map((function(e){for(const t in r)if(void 0!==r[t]&&void 0!==r[t][e])return r[t][e];return i.invalid})).join(i.separator).replace(/0/g,i.dot).replace(/1/g,i.dash)};return{characters:(e,t)=>n(o(e),t),decode:(e,t)=>{const i=o(t),r=(e=>{const t={},o=n(e,!0);for(const e in o)for(const n in o[e])void 0===t[o[e][n]]&&(t[o[e][n]]=n);return t})(i);return e.replace(/\s+/g,i.separator).trim().split(i.separator).map((function(e){return void 0!==r[e]?r[e]:i.invalid})).join("")},encode:e,audio:(t,n,r)=>{const a=r||e(t,n),s=o(n);return i(a,s)}}},"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):void 0!==r&&(r["morse-decoder"]=a());
{
"name": "morse-decoder",
"version": "3.0.1",
"description": "Morse code translator, Morse encoder and decoder which can also generate audio.",
"version": "4.0.0",
"description": "Morse code translator and decoder, which can also play audio.",
"keywords": [
"morse",
"morsify",
"morse alphabet",
"morse audio",
"morse characters",
"morse code",

@@ -15,21 +12,7 @@ "morse decoder",

"morse translator",
"morse code translator",
"samuel morse",
"codigo morse",
"codice morse",
"морзе",
"азбука морзе",
"mors kodu",
"mors alfabesi",
"kod morse'a",
"모스 부호",
"モールス信号",
"摩爾斯電碼",
"รหัสมอร์ส",
"קוד מורס",
"شفرة مورس"
"morse code translator"
],
"license": "MIT",
"homepage": "https://github.com/ozdemirburak/morse-decoder",
"author": "Burak Özdemir (https://ozdemirburak.com)",
"homepage": "https://morsedecoder.com",
"author": "Burak Özdemir",
"repository": {

@@ -40,13 +23,15 @@ "type": "git",

"devDependencies": {
"@babel/core": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"coveralls": "^3.0.9",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-babel-minify": "^0.5.1",
"gulp-concat": "^2.6.1",
"istanbul": "^0.4.5",
"jshint": "^2.12.0",
"lodash": "^4.17.20",
"mocha": "^6.2.2"
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"eslint": "^8.51.0",
"eslint-config-standard-with-typescript": "^39.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-promise": "^6.1.1",
"mocha": "10.2.0",
"nyc": "^15.1.0",
"rollup": "^4.0.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},

@@ -61,5 +46,8 @@ "main": "./src/index.js",

"scripts": {
"test": "npm run lint && mocha",
"test-cov": "istanbul cover _mocha",
"lint": "jshint ./src/index.js"
"build": "rollup -c",
"build-rel": "rollup -c -p @rollup/plugin-terser -o ./dist/morse-decoder.min.js",
"tsc": "tsc --noEmit",
"test": "mocha",
"test-cov": "nyc mocha",
"lint": "eslint ./src/index.ts"
},

@@ -66,0 +54,0 @@ "engines": {

@@ -23,3 +23,3 @@ # [Morse Code Translator](https://morsedecoder.com) with Audio - Morse Decoder

## Usage
### Common JS
```js

@@ -32,3 +32,3 @@ const morse = require('morse-decoder');

audio.play(); // play audio
audio.stop(); // stop audio
audio.stop(); // stop audio (cannot resume)
audio.exportWave(); // download audio wave file (promise)

@@ -38,3 +38,15 @@ const url = await audio.getWaveUrl(); // get audio wave url (promise)

```
### Browser
Morse decoder exports a global object named 'morse-decoder';
```js
const morse = window['morse-decoder']
const audioElement = document.querySelector('audio');
const helloAudio = morse.audio('Hello world');
helloAudio.getWaveUrl().then((url) => {
document.querySelector('#morse')
.setAttribute('src', url);
});
```
### Options and localization

@@ -69,4 +81,6 @@

const arabicAudio = morse.audio('البراق', { // generates the Morse .- .-.. -... .-. .- --.- then generates the audio from it
wpm: 18, // sets the wpm based on the Paris method, note that setting this will override and set the unit and fwUnits accordingly
unit: 0.1, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
fwUnit: 0.1, // period of one Farnsworth unit to control intercharacter and interword gaps
volume: 100, // the volume in percent (0-100)
oscillator: {

@@ -96,5 +110,7 @@ type: 'sine', // sine, square, sawtooth, triangle

``` bash
$ npm install --global gulp-cli
$ npm install
$ gulp
# generate `index.js` inside `src`
$ npm run build
# generate `morse-decoder.min.js` (minified) inside `dist`
$ npm run build-rel
```

@@ -101,0 +117,0 @@

@@ -1,230 +0,189 @@

;(((name, root, factory) => {
if (typeof exports === 'object') {
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
define(factory);
} else {
root[name] = factory();
}
})('morse-decoder', this, () => {
'use strict';
'use strict';
const characters = {
'1': { // Latin => https://en.wikipedia.org/wiki/Morse_code
'A': '01', 'B': '1000', 'C': '1010', 'D': '100', 'E': '0', 'F': '0010',
'G': '110', 'H': '0000', 'I': '00', 'J': '0111', 'K': '101', 'L': '0100',
'M': '11', 'N': '10', 'O': '111', 'P': '0110', 'Q': '1101', 'R': '010',
'S': '000', 'T': '1', 'U': '001', 'V': '0001', 'W': '011', 'X': '1001',
'Y': '1011', 'Z': '1100'
const baseCharacters = {
'1': {
'A': '01', 'B': '1000', 'C': '1010', 'D': '100', 'E': '0', 'F': '0010',
'G': '110', 'H': '0000', 'I': '00', 'J': '0111', 'K': '101', 'L': '0100',
'M': '11', 'N': '10', 'O': '111', 'P': '0110', 'Q': '1101', 'R': '010',
'S': '000', 'T': '1', 'U': '001', 'V': '0001', 'W': '011', 'X': '1001',
'Y': '1011', 'Z': '1100'
},
'2': { // Numbers
'0': '11111', '1': '01111', '2': '00111', '3': '00011', '4': '00001',
'5': '00000', '6': '10000', '7': '11000', '8': '11100', '9': '11110'
'2': {
'0': '11111', '1': '01111', '2': '00111', '3': '00011', '4': '00001',
'5': '00000', '6': '10000', '7': '11000', '8': '11100', '9': '11110'
},
'3': { // Punctuation
'.': '010101', ',': '110011', '?': '001100', '\'': '011110', '!': '101011', '/': '10010',
'(': '10110', ')': '101101', '&': '01000', ':': '111000', ';': '101010', '=': '10001',
'+': '01010', '-': '100001', '_': '001101', '"': '010010', '$': '0001001', '@': '011010',
'¿': '00101', '¡': '110001'
'3': {
'.': '010101', ',': '110011', '?': '001100', '\'': '011110', '!': '101011', '/': '10010',
'(': '10110', ')': '101101', '&': '01000', ':': '111000', ';': '101010', '=': '10001',
'+': '01010', '-': '100001', '_': '001101', '"': '010010', '$': '0001001', '@': '011010',
'¿': '00101', '¡': '110001'
},
'4': { // Latin Extended => https://ham.stackexchange.com/questions/1379/international-characters-in-morse-code
'Ã': '01101', 'Á': '01101', 'Å': '01101', 'À': '01101', 'Â': '01101', 'Ä': '0101',
'Ą': '0101', 'Æ': '0101', 'Ç': '10100', 'Ć': '10100', 'Ĉ': '10100', 'Č': '110',
'Ð': '00110', 'È': '01001', 'Ę': '00100', 'Ë': '00100', 'É': '00100',
'Ê': '10010', 'Ğ': '11010', 'Ĝ': '11010', 'Ĥ': '1111', 'İ': '01001', 'Ï': '10011',
'Ì': '01110', 'Ĵ': '01110', 'Ł': '01001', 'Ń': '11011', 'Ñ': '11011', 'Ó': '1110',
'Ò': '1110', 'Ö': '1110', 'Ô': '1110', 'Ø': '1110', 'Ś': '0001000', 'Ş': '01100',
'Ș': '1111', 'Š': '1111', 'Ŝ': '00010', 'ß': '000000', 'Þ': '01100', 'Ü': '0011',
'Ù': '0011', 'Ŭ': '0011', 'Ž': '11001', 'Ź': '110010', 'Ż': '11001'
'4': {
'Ã': '01101', 'Á': '01101', 'Å': '01101', 'À': '01101', 'Â': '01101', 'Ä': '0101',
'Ą': '0101', 'Æ': '0101', 'Ç': '10100', 'Ć': '10100', 'Ĉ': '10100', 'Č': '110',
'Ð': '00110', 'È': '01001', 'Ę': '00100', 'Ë': '00100', 'É': '00100',
'Ê': '10010', 'Ğ': '11010', 'Ĝ': '11010', 'Ĥ': '1111', 'İ': '01001', 'Ï': '10011',
'Ì': '01110', 'Ĵ': '01110', 'Ł': '01001', 'Ń': '11011', 'Ñ': '11011', 'Ó': '1110',
'Ò': '1110', 'Ö': '1110', 'Ô': '1110', 'Ø': '1110', 'Ś': '0001000', 'Ş': '01100',
'Ș': '1111', 'Š': '1111', 'Ŝ': '00010', 'ß': '000000', 'Þ': '01100', 'Ü': '0011',
'Ù': '0011', 'Ŭ': '0011', 'Ž': '11001', 'Ź': '110010', 'Ż': '11001'
},
'5': { // Cyrillic Alphabet => https://en.wikipedia.org/wiki/Russian_Morse_code
'А': '01', 'Б': '1000', 'В': '011', 'Г': '110', 'Д': '100', 'Е': '0',
'Ж': '0001', 'З': '1100', 'И': '00', 'Й': '0111', 'К': '101','Л': '0100',
'М': '11', 'Н': '10', 'О': '111', 'П': '0110', 'Р': '010', 'С': '000',
'Т': '1', 'У': '001', 'Ф': '0010', 'Х': '0000', 'Ц': '1010', 'Ч': '1110',
'Ш': '1111', 'Щ': '1101', 'Ъ': '11011', 'Ы': '1011', 'Ь': '1001', 'Э': '00100',
'Ю': '0011', 'Я': '0101', 'Ї': '01110', 'Є': '00100', 'І': '00', 'Ґ': '110'
'5': {
'А': '01', 'Б': '1000', 'В': '011', 'Г': '110', 'Д': '100', 'Е': '0',
'Ж': '0001', 'З': '1100', 'И': '00', 'Й': '0111', 'К': '101', 'Л': '0100',
'М': '11', 'Н': '10', 'О': '111', 'П': '0110', 'Р': '010', 'С': '000',
'Т': '1', 'У': '001', 'Ф': '0010', 'Х': '0000', 'Ц': '1010', 'Ч': '1110',
'Ш': '1111', 'Щ': '1101', 'Ъ': '11011', 'Ы': '1011', 'Ь': '1001', 'Э': '00100',
'Ю': '0011', 'Я': '0101', 'Ї': '01110', 'Є': '00100', 'І': '00', 'Ґ': '110'
},
'6': { // Greek Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
'Α': '01', 'Β':'1000', 'Γ':'110', 'Δ':'100', 'Ε':'0', 'Ζ':'1100',
'Η':'0000', 'Θ':'1010', 'Ι': '00', 'Κ': '101', 'Λ': '0100', 'Μ': '11',
'Ν': '10', 'Ξ': '1001', 'Ο': '111', 'Π': '0110', 'Ρ': '010', 'Σ':'000',
'Τ':'1', 'Υ': '1011', 'Φ':'0010', 'Χ': '1111', 'Ψ': '1101', 'Ω':'011'
'6': {
'Α': '01', 'Β': '1000', 'Γ': '110', 'Δ': '100', 'Ε': '0', 'Ζ': '1100',
'Η': '0000', 'Θ': '1010', 'Ι': '00', 'Κ': '101', 'Λ': '0100', 'Μ': '11',
'Ν': '10', 'Ξ': '1001', 'Ο': '111', 'Π': '0110', 'Ρ': '010', 'Σ': '000',
'Τ': '1', 'Υ': '1011', 'Φ': '0010', 'Χ': '1111', 'Ψ': '1101', 'Ω': '011'
},
'7': { // Hebrew Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
'א': '01', 'ב': '1000', 'ג': '110', 'ד': '100', 'ה': '111', 'ו': '0',
'ז': '1100', 'ח': '0000', 'ט': '001', 'י': '00', 'כ': '101', 'ל': '0100',
'מ': '11', 'נ': '10', 'ס': '1010', 'ע': '0111', 'פ': '0110', 'צ': '011',
'ק': '1101', 'ר': '010', 'ש': '000', 'ת': '1'
'7': {
'א': '01', 'ב': '1000', 'ג': '110', 'ד': '100', 'ה': '111', 'ו': '0',
'ז': '1100', 'ח': '0000', 'ט': '001', 'י': '00', 'כ': '101', 'ל': '0100',
'מ': '11', 'נ': '10', 'ס': '1010', 'ע': '0111', 'פ': '0110', 'צ': '011',
'ק': '1101', 'ר': '010', 'ש': '000', 'ת': '1'
},
'8': { // Arabic Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
'ا': '01', 'ب': '1000', 'ت': '1', 'ث': '1010', 'ج': '0111', 'ح': '0000',
'خ': '111', 'د': '100', 'ذ': '1100', 'ر': '010', 'ز': '1110', 'س': '000',
'ش': '1111', 'ص': '1001', 'ض': '0001', 'ط': '001', 'ظ': '1011', 'ع': '0101',
'غ': '110', 'ف': '0010', 'ق': '1101', 'ك': '101', 'ل': '0100', 'م': '11',
'ن': '10', 'ه': '00100', 'و': '011', 'ي': '00', 'ﺀ': '0'
'8': {
'ا': '01', 'ب': '1000', 'ت': '1', 'ث': '1010', 'ج': '0111', 'ح': '0000',
'خ': '111', 'د': '100', 'ذ': '1100', 'ر': '010', 'ز': '1110', 'س': '000',
'ش': '1111', 'ص': '1001', 'ض': '0001', 'ط': '001', 'ظ': '1011', 'ع': '0101',
'غ': '110', 'ف': '0010', 'ق': '1101', 'ك': '101', 'ل': '0100', 'م': '11',
'ن': '10', 'ه': '00100', 'و': '011', 'ي': '00', 'ﺀ': '0'
},
'9': { // Persian Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
'ا': '01', 'ب': '1000', 'پ': '0110', 'ت': '1', 'ث': '1010', 'ج': '0111',
'چ': '1110', 'ح': '0000', 'خ' : '1001', 'د': '100', 'ذ': '0001', 'ر': '010',
'ز': '1100', 'ژ': '110', 'س': '000', 'ش': '1111', 'ص': '0101', 'ض': '00100',
'ط': '001', 'ظ': '1011', 'ع': '111', 'غ': '0011', 'ف': '0010', 'ق': '111000',
'ک': '101', 'گ': '1101', 'ل': '0100', 'م': '11', 'ن': '10', 'و': '011',
'ه': '0', 'ی': '00'
'9': {
'ا': '01', 'ب': '1000', 'پ': '0110', 'ت': '1', 'ث': '1010', 'ج': '0111',
'چ': '1110', 'ح': '0000', 'خ': '1001', 'د': '100', 'ذ': '0001', 'ر': '010',
'ز': '1100', 'ژ': '110', 'س': '000', 'ش': '1111', 'ص': '0101', 'ض': '00100',
'ط': '001', 'ظ': '1011', 'ع': '111', 'غ': '0011', 'ف': '0010', 'ق': '111000',
'ک': '101', 'گ': '1101', 'ل': '0100', 'م': '11', 'ن': '10', 'و': '011',
'ه': '0', 'ی': '00'
},
'10': { // Japanese Alphabet => https://ja.wikipedia.org/wiki/%E3%83%A2%E3%83%BC%E3%83%AB%E3%82%B9%E7%AC%A6%E5%8F%B7#%E5%92%8C%E6%96%87%E3%83%A2%E3%83%BC%E3%83%AB%E3%82%B9%E7%AC%A6%E5%8F%B7
'ア': '11011', 'カ': '0100', 'サ': '10101', 'タ': '10', 'ナ': '010', 'ハ': '1000',
'マ': '1001', 'ヤ': '011', 'ラ': '000', 'ワ': '101', 'イ': '01', 'キ': '10100',
'シ': '11010', 'チ': '0010', 'ニ': '1010', 'ヒ': '11001', 'ミ': '00101', 'リ': '110',
'ヰ': '01001', 'ウ': '001', 'ク': '0001', 'ス': '11101', 'ツ': '0110', 'ヌ': '0000',
'フ': '1100', 'ム': '1', 'ユ': '10011', 'ル': '10110', 'ン': '01010', 'エ': '10111',
'ケ': '1011', 'セ': '01110', 'テ': '01011', 'ネ': '1101', 'ヘ': '0', 'メ': '10001',
'レ': '111', 'ヱ': '01100', 'オ': '01000', 'コ': '1111', 'ソ':'1110', 'ト': '00100',
'ノ': '0011', 'ホ': '100', 'モ': '10010', 'ヨ': '11', 'ロ': '0101', 'ヲ': '0111',
'゛': '00', '゜': '00110', '。': '010100', 'ー': '01101', '、': '010101',
'(': '101101', ')': '010010'
'10': {
'ア': '11011', 'カ': '0100', 'サ': '10101', 'タ': '10', 'ナ': '010', 'ハ': '1000',
'マ': '1001', 'ヤ': '011', 'ラ': '000', 'ワ': '101', 'イ': '01', 'キ': '10100',
'シ': '11010', 'チ': '0010', 'ニ': '1010', 'ヒ': '11001', 'ミ': '00101', 'リ': '110',
'ヰ': '01001', 'ウ': '001', 'ク': '0001', 'ス': '11101', 'ツ': '0110', 'ヌ': '0000',
'フ': '1100', 'ム': '1', 'ユ': '10011', 'ル': '10110', 'ン': '01010', 'エ': '10111',
'ケ': '1011', 'セ': '01110', 'テ': '01011', 'ネ': '1101', 'ヘ': '0', 'メ': '10001',
'レ': '111', 'ヱ': '01100', 'オ': '01000', 'コ': '1111', 'ソ': '1110', 'ト': '00100',
'ノ': '0011', 'ホ': '100', 'モ': '10010', 'ヨ': '11', 'ロ': '0101', 'ヲ': '0111',
'゛': '00', '゜': '00110', '。': '010100', 'ー': '01101', '、': '010101',
'(': '101101', ')': '010010'
},
'11': { // Korean Alphabet => https://en.wikipedia.org/wiki/SKATS
'ㄱ': '0100', 'ㄴ': '0010', 'ㄷ': '1000', 'ㄹ': '0001', 'ㅁ': '11', 'ㅂ': '011',
'ㅅ': '110', 'ㅇ': '101', 'ㅈ': '0110', 'ㅊ': '1010', 'ㅋ': '1001', 'ㅌ': '1100',
'ㅍ': '111', 'ㅎ': '0111', 'ㅏ': '0', 'ㅑ': '00', 'ㅓ': '1', 'ㅕ': '000',
'ㅗ': '01', 'ㅛ': '10', 'ㅜ': '0000', 'ㅠ': '010', 'ㅡ': '100', 'ㅣ': '001'
'11': {
'ㄱ': '0100', 'ㄴ': '0010', 'ㄷ': '1000', 'ㄹ': '0001', 'ㅁ': '11', 'ㅂ': '011',
'ㅅ': '110', 'ㅇ': '101', 'ㅈ': '0110', 'ㅊ': '1010', 'ㅋ': '1001', 'ㅌ': '1100',
'ㅍ': '111', 'ㅎ': '0111', 'ㅏ': '0', 'ㅑ': '00', 'ㅓ': '1', 'ㅕ': '000',
'ㅗ': '01', 'ㅛ': '10', 'ㅜ': '0000', 'ㅠ': '010', 'ㅡ': '100', 'ㅣ': '001'
},
'12' : { // Thai Alphabet => https://th.wikipedia.org/wiki/รหัสมอร์ส
'ก': '110', 'ข': '1010', 'ค': '101', 'ง': '10110', 'จ': '10010',
'ฉ': '1111', 'ช': '1001', 'ซ': '1100', 'ญ': '0111', 'ด': '100',
'ต': '1', 'ถ': '10100', 'ท': '10011', 'น': '10', 'บ': '1000',
'ป': '0110', 'ผ':'1101', 'ฝ': '10101', 'พ': '01100', 'ฟ': '0010',
'ม': '11', 'ย': '1011', 'ร': '010', 'ล': '0100', 'ว': '011',
'ส': '000', 'ห': '0000', 'อ': '10001', 'ฮ': '11011', 'ฤ': '01011',
'ะ': '01000', 'า': '01', 'ิ': '00100', 'ี': '00', 'ึ': '00110',
'ื': '0011', 'ุ': '00101', 'ู': '1110', 'เ': '0', 'แ': '0101',
'ไ': '01001', 'โ': '111', 'ำ': '00010', '่': '001', '้': '0001',
'๊': '11000', '๋':'01010', 'ั': '01101', '็': '11100', '์': '11001',
'ๆ': '10111', 'ฯ': '11010'
'12': {
'ก': '110', 'ข': '1010', 'ค': '101', 'ง': '10110', 'จ': '10010',
'ฉ': '1111', 'ช': '1001', 'ซ': '1100', 'ญ': '0111', 'ด': '100',
'ต': '1', 'ถ': '10100', 'ท': '10011', 'น': '10', 'บ': '1000',
'ป': '0110', 'ผ': '1101', 'ฝ': '10101', 'พ': '01100', 'ฟ': '0010',
'ม': '11', 'ย': '1011', 'ร': '010', 'ล': '0100', 'ว': '011',
'ส': '000', 'ห': '0000', 'อ': '10001', 'ฮ': '11011', 'ฤ': '01011',
'ะ': '01000', 'า': '01', 'ิ': '00100', 'ี': '00', 'ึ': '00110',
'ื': '0011', 'ุ': '00101', 'ู': '1110', 'เ': '0', 'แ': '0101',
'ไ': '01001', 'โ': '111', 'ำ': '00010', '่': '001', '้': '0001',
'๊': '11000', '๋': '01010', 'ั': '01101', '็': '11100', '์': '11001',
'ๆ': '10111', 'ฯ': '11010'
}
};
const getCharacters = (opts, usePriority) => {
const options = getOptions(opts);
};
const getCharacters = (options) => (Object.assign(Object.assign({}, baseCharacters), { '0': baseCharacters[options.priority], '1': Object.assign(Object.assign({}, baseCharacters['1']), { [options.separator]: options.space }) }));
const getMappedCharacters = (options, usePriority) => {
const mapped = {};
const characters = getCharacters(options);
for (const set in characters) {
mapped[set] = {};
for (const key in characters[set]) {
mapped[set][key] = characters[set][key].replace(/0/g, options.dot).replace(/1/g, options.dash);
}
mapped[set] = {};
for (const key in characters[set]) {
mapped[set][key] = characters[set][key].replace(/0/g, options.dot).replace(/1/g, options.dash);
}
}
if (usePriority !== true) {
delete mapped[0];
if (!usePriority) {
delete mapped['0'];
}
return mapped;
};
const swapCharacters = (options) => {
};
const swapCharacters = (options) => {
const swapped = {};
const mappedCharacters = getCharacters(options, true);
const mappedCharacters = getMappedCharacters(options, true);
for (const set in mappedCharacters) {
for (const key in mappedCharacters[set]) {
if (typeof swapped[mappedCharacters[set][key]] === 'undefined') {
swapped[mappedCharacters[set][key]] = key;
for (const key in mappedCharacters[set]) {
if (typeof swapped[mappedCharacters[set][key]] === 'undefined') {
swapped[mappedCharacters[set][key]] = key;
}
}
}
}
return swapped;
};
};
const getOptions = (options) => {
options = options || {};
options.oscillator = options.oscillator || {};
options = {
dash: options.dash || '-',
dot: options.dot || '.',
space: options.space || '/',
separator: options.separator || ' ',
invalid: options.invalid || '#',
priority: options.priority || 1,
unit: options.unit || 0.08, // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
fwUnit: options.fwUnit || options.unit || 0.08, // Farnsworth unit to control intercharacter and interword gaps
oscillator: {
type: options.oscillator.type || 'sine', // sine, square, sawtooth, triangle
frequency: options.oscillator.frequency || 500, // value in hertz
onended: options.oscillator.onended || null // event that fires when the tone has stopped playing
}
};
characters[1][options.separator] = options.space;
characters[0] = characters[options.priority];
const getOptions = (opts = {}) => {
var _a, _b, _c;
const options = Object.assign(Object.assign({}, opts), { dash: opts.dash || '-', dot: opts.dot || '.', space: opts.space || '/', separator: opts.separator || ' ', invalid: opts.invalid || '#', priority: opts.priority || 1, wpm: opts.wpm, unit: opts.unit || 0.08, fwUnit: opts.fwUnit || opts.unit || 0.08, volume: opts.volume || 100, oscillator: Object.assign(Object.assign({}, opts.oscillator), { type: ((_a = opts.oscillator) === null || _a === void 0 ? void 0 : _a.type) || 'sine', frequency: ((_b = opts.oscillator) === null || _b === void 0 ? void 0 : _b.frequency) || 500, onended: ((_c = opts.oscillator) === null || _c === void 0 ? void 0 : _c.onended) || null // event that fires when the tone has stopped playing
}) });
return options;
};
};
const encode = (text, opts) => {
const options = getOptions(opts);
return [...text.replace(/\s+/g, options.separator).trim().toLocaleUpperCase()].map(function(character) {
for (let set in characters) {
if (typeof characters[set] !== 'undefined' && typeof characters[set][character] !== 'undefined') {
return characters[set][character];
}
}
return options.invalid;
}).join(options.separator).replace(/0/g, options.dot).replace(/1/g, options.dash);
};
const decode = (morse, opts) => {
const options = getOptions(opts), swapped = swapCharacters(options);
return morse.replace(/\s+/g, options.separator).trim().split(options.separator).map(function(characters) {
if (typeof swapped[characters] !== 'undefined') {
return swapped[characters];
}
return options.invalid;
}).join('');
};
const getGainTimings = (morse, opts, currentTime = 0) => {
let timings = [];
const getGainTimings = (morse, opts, currentTime = 0) => {
const timings = [];
let { unit, fwUnit } = opts;
let time = 0;
if (opts.wpm) {
// wpm mode uses standardised units
unit = fwUnit = 60 / (opts.wpm * 50);
}
timings.push([0, time]);
const tone = (i) => {
timings.push([1, currentTime + time]);
time += i * opts.unit;
timings.push([1 * (opts.volume / 100.0), currentTime + time]);
time += i * unit;
};
const silence = (i) => {
timings.push([0, currentTime + time]);
time += i * opts.unit;
timings.push([0, currentTime + time]);
time += i * unit;
};
const gap = (i) => {
timings.push([0, currentTime + time]);
time += i * opts.fwUnit;
timings.push([0, currentTime + time]);
time += i * fwUnit;
};
for (let i = 0; i <= morse.length; i++) {
if (morse[i] === opts.space) {
gap(7);
} else if (morse[i] === opts.dot) {
tone(1);
silence(1);
} else if (morse[i] === opts.dash) {
tone(3);
silence(1);
} else if (
(typeof morse[i + 1] !== 'undefined' && morse[i + 1] !== opts.space) &&
(typeof morse[i - 1] !== 'undefined' && morse[i - 1] !== opts.space)
) {
gap(3);
}
for (let i = 0, addSilence = false; i <= morse.length; i++) {
if (morse[i] === opts.space) {
gap(7);
addSilence = false;
}
else if (morse[i] === opts.dot) {
if (addSilence)
silence(1);
else
addSilence = true;
tone(1);
}
else if (morse[i] === opts.dash) {
if (addSilence)
silence(1);
else
addSilence = true;
tone(3);
}
else if ((typeof morse[i + 1] !== 'undefined' && morse[i + 1] !== opts.space) &&
(typeof morse[i - 1] !== 'undefined' && morse[i - 1] !== opts.space)) {
gap(3);
addSilence = false;
}
}
return [timings, time];
};
// Source: https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js#L155
const encodeWAV = (sampleRate, samples) => {
let buffer = new ArrayBuffer(44 + samples.length * 2);
let view = new DataView(buffer);
};
// Source: https://github.com/mattdiamond/Recorderjs/blob/master/src/recorder.js#L155
const encodeWAV = (sampleRate, samples) => {
const buffer = new ArrayBuffer(44 + samples.length * 2);
const view = new DataView(buffer);
const writeString = (view, offset, string) => {
for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
};

@@ -259,12 +218,11 @@ // RIFF identifier

const floatTo16BitPCM = (output, offset, input) => {
for (let i = 0; i < input.length; i++, offset += 2) {
let s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
for (let i = 0; i < input.length; i++, offset += 2) {
const s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
};
floatTo16BitPCM(view, 44, samples);
return view;
};
const audio = (text, opts, morseString) => {
};
const audio = (morse, options) => {
let AudioContext = null;

@@ -275,93 +233,115 @@ let OfflineAudioContext = null;

let source;
const options = getOptions(opts);
const morse = morseString || encode(text, opts);
const [gainValues, totalTime] = getGainTimings(morse, options);
if (AudioContext === null && typeof window !== 'undefined') {
AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
source = context.createBufferSource();
source.connect(context.destination);
AudioContext = window.AudioContext || window.webkitAudioContext;
context = new AudioContext();
source = context.createBufferSource();
source.connect(context.destination);
}
if (OfflineAudioContext === null && typeof window !== 'undefined') {
OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
offlineContext = new OfflineAudioContext(1, 44100 * totalTime, 44100);
OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
offlineContext = new OfflineAudioContext(1, 44100 * totalTime, 44100);
}
const oscillator = offlineContext.createOscillator();
const gainNode = offlineContext.createGain();
oscillator.type = options.oscillator.type;
oscillator.frequency.value = options.oscillator.frequency;
gainValues.forEach(([value, time]) => gainNode.gain.setValueAtTime(value, time));
oscillator.connect(gainNode);
gainNode.connect(offlineContext.destination);
source.onended = options.oscillator.onended;
// Inspired by: http://joesul.li/van/tale-of-no-clocks/
let render = new Promise(resolve => {
oscillator.start(0);
offlineContext.startRendering();
offlineContext.oncomplete = (e) => {
source.buffer = e.renderedBuffer;
resolve();
};
const render = new Promise(resolve => {
oscillator.start(0);
offlineContext.startRendering();
offlineContext.oncomplete = (e) => {
source.buffer = e.renderedBuffer;
resolve();
};
});
let timeout;
const play = async () => {
await render;
source.start(context.currentTime);
timeout = setTimeout(() => stop(), totalTime * 1000);
await render;
source.start(context.currentTime);
timeout = setTimeout(() => { stop(); }, totalTime * 1000);
};
const stop = () => {
clearTimeout(timeout);
timeout = 0;
source.stop(0);
clearTimeout(timeout);
timeout = 0;
source.stop(0);
};
const getWaveBlob = async () => {
await render;
const waveData = encodeWAV(offlineContext.sampleRate, source.buffer.getChannelData(0));
return new Blob([waveData], { 'type': 'audio/wav' });
await render;
const waveData = encodeWAV(offlineContext.sampleRate, source.buffer.getChannelData(0));
return new Blob([waveData], { 'type': 'audio/wav' });
};
const getWaveUrl = async () => {
const audioBlob = await getWaveBlob();
return URL.createObjectURL(audioBlob);
const audioBlob = await getWaveBlob();
return URL.createObjectURL(audioBlob);
};
const exportWave = async (filename) => {
let waveUrl = await getWaveUrl();
let anchor = document.createElement('a');
anchor.href = waveUrl;
anchor.target = '_blank';
anchor.download = filename || 'morse.wav';
anchor.click();
const waveUrl = await getWaveUrl();
const anchor = document.createElement('a');
anchor.href = waveUrl;
anchor.target = '_blank';
anchor.download = filename || 'morse.wav';
anchor.click();
};
return {
play,
stop,
getWaveBlob,
getWaveUrl,
exportWave,
context,
oscillator,
gainNode
};
};
(((name, root, factory) => {
if (typeof exports === 'object') {
module.exports = factory();
}
else if (typeof define === 'function' && define.amd) {
define(factory);
}
else if (root !== undefined) {
root[name] = factory();
}
})('morse-decoder', globalThis, () => {
const encode = (text, opts) => {
const options = getOptions(opts);
const characters = getCharacters(options);
return [...text.replace(/\s+/g, options.separator).trim().toLocaleUpperCase()].map(function (character) {
for (const set in characters) {
if (typeof characters[set] !== 'undefined' && typeof characters[set][character] !== 'undefined') {
return characters[set][character];
}
}
return options.invalid;
}).join(options.separator).replace(/0/g, options.dot).replace(/1/g, options.dash);
};
const decode = (morse, opts) => {
const options = getOptions(opts);
const swapped = swapCharacters(options);
return morse.replace(/\s+/g, options.separator).trim().split(options.separator).map(function (characters) {
if (typeof swapped[characters] !== 'undefined') {
return swapped[characters];
}
return options.invalid;
}).join('');
};
const characters = (options, usePriority) => getMappedCharacters(getOptions(options), usePriority);
const audio$1 = (text, opts, morseString) => {
const morse = morseString || encode(text, opts);
const options = getOptions(opts);
return audio(morse, options);
};
return {
play,
stop,
getWaveBlob,
getWaveUrl,
exportWave,
context,
oscillator,
gainNode
characters,
decode,
encode,
audio: audio$1
};
};
return {
characters: getCharacters,
decode,
encode,
audio
};
}));
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc