Skip to content

Commit b43b71d

Browse files
refactor: better destructuring and find usage
1 parent c5cac82 commit b43b71d

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/dtmf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const decode = (input, options = {}) => {
2626
if (lookup.hasOwnProperty(i)) {
2727
return lookup[i]
2828
}
29+
2930
return throwOrSilent(options, `Could not decode ${i} - No matching value`)
3031
}).join('')
3132
}
@@ -53,10 +54,10 @@ const encode = (input, options = {}) => {
5354

5455
return [...input].map(i => {
5556
const result = Object.entries(LOOKUP).map(([key, freqOb]) => {
56-
const foundFreq = Object.entries(freqOb).find(([k, v]) => v === i)
57+
const foundFreq = Object.entries(freqOb).find(([, v]) => v === i)
5758

5859
return foundFreq ? encodeResult([key, foundFreq[0]], options) : false
59-
}).find(o => o)
60+
}).find(Boolean)
6061

6162
return !result ? throwOrSilent(options, 'Invalid input') : result
6263
}).join(options.separator)

src/morse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const decode = (input, options = {}) => {
44
options = { ...DEFAULT_OPTIONS, ...options }
55

66
return input.split(options.separator).map(character => {
7-
const decodedCharacter = Object.entries(ALPHABET).find(([_, morse]) => morse === character)
7+
const decodedCharacter = Object.entries(ALPHABET).find(([, morse]) => morse === character)
88

99
if (decodedCharacter) {
1010
return decodedCharacter[0]

src/multiTap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const encode = (input, options = {}) => {
44
options = { ...DEFAULT_OPTIONS, ...options }
55
return [...input.toUpperCase()]
66
.map(c => {
7-
const decodedCharacter = Object.entries(alphabetWithSpaceKey(options.customMapping)).find(([k, v]) => v.includes(c))
7+
const decodedCharacter = Object.entries(alphabetWithSpaceKey(options.customMapping)).find(([, v]) => v.includes(c))
88
if (decodedCharacter) {
99
const amount = decodedCharacter[1].indexOf(c) + 1
1010
return (options.exponentForm ? `${decodedCharacter[0]}^${amount}` : `${decodedCharacter[0]}`.repeat(amount))

src/pollux.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const decode = (input, keys = {}, morseOptions = {}) => {
66
sanitizeKeys(keys)
77

88
input = [...input].map(c => {
9-
const decodedCharacter = Object.entries(keys).find(([k, v]) => v.includes(c))
9+
const decodedCharacter = Object.entries(keys).find(([, v]) => v.includes(c))
1010
const morseCode = decodedCharacter ? propToKey(decodedCharacter[0]) : false
1111

1212
if (!morseCode) {

0 commit comments

Comments
 (0)