Skip to content

Commit

Permalink
add an initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Sep 23, 2017
1 parent 6523fb0 commit cf0405c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions index.js
@@ -0,0 +1,28 @@
const jishon = require('jishon')

const flatten = (result, next) =>
result.concat(next)

flatten.args = [flatten, []]

const pluck = key => item =>
item[key]

const pluckAudio = pluck('audio')

module.exports = async ({term, reading}) => {
const words = (await jishon(term)).words

if (reading) {
const word = words
.find(word => word.furigana === reading)

if (!word) return []

return Object.values(pluckAudio(word))
}

return words.map(pluckAudio)
.map(Object.values)
.reduce(...flatten.args)
}

0 comments on commit cf0405c

Please sign in to comment.