포르투갈어 동사변형 앱
1시험 1앱 프로젝트의 일환로 만들었다.
서버Permalink
- 서버는 함수를 조합해서 만들었다.
- getConj 함수는 매개변수 없이 Pointfree 스타일로 작성했다.
- takeFive 함수는 지연평가를 통해 불필요한 배열 순회를 줄였다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('mz/fs') | |
const _ = require('partial-js') | |
const trim = s => s.trim() | |
const verbPath = verb => `content/${verb[0]}/${verb}.json` | |
const getJson = _.pipe(fs.readFile, JSON.parse) | |
const remove2ndPerson = _.reject(c => ![0, 2, 3, 4].includes(c.group_sort) && c.sort == 1 || c.sort == 4) | |
const getConj = _.pipe(trim, verbPath, getJson, v => v.conjugations, remove2ndPerson, _.groupBy('group')) | |
const categoryPath = verb => `categories/${verb[0]}.json` | |
const verbCategories = {} | |
const cachedCategory = verb => verbCategories[verb[0]] | |
const memoize = k => v => (verbCategories[k] = v, v) | |
const startsWith = w => str => str.startsWith(w) | |
const getCategory = _.pipe(trim, _.first) | |
const getVerbIndex = category => cachedCategory(category) || _.go(category, categoryPath, getJson, memoize(category)) | |
const takeFive = verb => _.pipe(L.filter(startsWith(verb)), L.take(5)) | |
const searchVerb = verb => _.go(verb, getCategory, getVerbIndex, takeFive(verb)) | |
const rootIndex = {} | |
_.go(getJson('roots/roots.json'), _(Object.assign, rootIndex, _)) | |
const getRoots = verbs => rootIndex[verbs] | |
// getConj('passar').then(console.log).catch(console.warn) | |
// searchVerb('pas').then(console.log).catch(console.warn) | |
// getRoots('passaria').then(console.log).catch(console.warn) | |
module.exports = { getConj, searchVerb, getRoots } |
클라이언트Permalink
- 자동 완성 검색창과 지우기 버튼으로 사용이 편리한 UI를 만들었다.
- v-select의 input 요소에 접근하기 위해 $refs 접근을 두번해야 했다.