Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onSubmit: ({ searchInput }, dispatch) => {
if (isMixed(searchInput) || isEmpty(searchInput)) {
// TODO: notify? shake? color searchbar?
console.warn('Invalid search input');
return false;
}
const payload = {
meaningContains: isRomaji(searchInput) ? searchInput : '',
readingContains: isJapanese(searchInput) ? searchInput : '',
};
return dispatch(app.review.search.request(payload));
},
})(SearchBar);
onSubmit: ({ searchInput }, dispatch) => {
if (isMixed(searchInput) || isEmpty(searchInput)) {
// TODO: notify? shake? color searchbar?
console.warn('Invalid search input');
return false;
}
const payload = {
meaningContains: isRomaji(searchInput) ? searchInput : '',
readingContains: isJapanese(searchInput) ? searchInput : '',
};
return dispatch(app.review.search.request(payload));
},
})(SearchBar);
onSubmit: ({ searchInput }, dispatch) => {
if (isMixed(searchInput) || isEmpty(searchInput)) {
// TODO: notify? shake? color searchbar?
console.warn("Invalid search input");
return false;
}
const payload = {
meaningContains: isRomaji(searchInput) ? searchInput : "",
readingContains: isJapanese(searchInput) ? searchInput : "",
};
return dispatch(app.review.search.request(payload));
},
})(SearchBar);
onSubmit: ({ searchInput }, dispatch) => {
if (isMixed(searchInput) || isEmpty(searchInput)) {
// TODO: notify? shake? color searchbar?
console.warn("Invalid search input");
return false;
}
const payload = {
meaningContains: isRomaji(searchInput) ? searchInput : "",
readingContains: isJapanese(searchInput) ? searchInput : "",
};
return dispatch(app.review.search.request(payload));
},
})(SearchBar);
onSubmit: ({ searchInput }, dispatch) => {
if (isMixed(searchInput) || isEmpty(searchInput)) {
// TODO: notify? shake? color searchbar?
console.warn('Invalid search input');
return false;
}
const payload = {
meaningContains: isRomaji(searchInput) ? searchInput : '',
readingContains: isJapanese(searchInput) ? searchInput : '',
};
return dispatch(app.review.search.request(payload));
},
})(SearchBar);
export function basicFuri(word = '', reading = '') {
if (!word) {
return [];
}
if (word && isEmpty(reading)) {
return [['', word]];
}
// NOTE: with weird combos like 缶ビール and ハート型
// it's better to just render entire reading if no furi provided
if ([...word].some(isKanji) && [...word].some(isKatakana)) {
return [[reading, word]];
}
const mainLength = stripOkurigana(word).length - word.length || reading.length;
const mainReading = [reading.slice(0, mainLength), stripOkurigana(word)];
const okurigana = word.slice(mainLength);
return okurigana ? [mainReading, ['', okurigana]] : [mainReading];
}
export function basicFuri(word = '', reading = '') {
if (!word) {
return [];
}
if (word && isEmpty(reading)) {
return [['', word]];
}
// NOTE: with weird combos like 缶ビール and ハート型
// it's better to just render entire reading if no furi provided
if ([...word].some(isKanji) && [...word].some(isKatakana)) {
return [[reading, word]];
}
const mainLength = stripOkurigana(word).length - word.length || reading.length;
const mainReading = [reading.slice(0, mainLength), stripOkurigana(word)];
const okurigana = word.slice(mainLength);
return okurigana ? [mainReading, ['', okurigana]] : [mainReading];
}
...inflectVerb(base, verbType)
.map(({ form }) => form)
.sort((a, b) => b.length - a.length)
);
} else if (adjType) {
matchers.push(
...inflectAdjective(base, adjType)
.map(({ form }) => form)
.sort((a, b) => b.length - a.length)
);
// basic stem matching fallback if no verbType or adjType provided
} else if (reading) {
// 'づけ' => 'づ' via 漬け
matchers.push(stripOkurigana(base, { matchKanji: word }));
// 'おかね' => 'かね' via お金
matchers.push(stripOkurigana(base, { matchKanji: word, leading: true }));
// 'つけ' => 'ツケ'
matchers.push(toKatakana(base));
} else {
matchers.push(stripOkurigana(base)); // '飛び込む' => '飛び込'
matchers.push(stripOkurigana(base, { leading: true })); // 'お金' => '金'
}
return [...new Set(matchers)];
}
matchers.push(
...inflectAdjective(base, adjType)
.map(({ form }) => form)
.sort((a, b) => b.length - a.length)
);
// basic stem matching fallback if no verbType or adjType provided
} else if (reading) {
// 'づけ' => 'づ' via 漬け
matchers.push(stripOkurigana(base, { matchKanji: word }));
// 'おかね' => 'かね' via お金
matchers.push(stripOkurigana(base, { matchKanji: word, leading: true }));
// 'つけ' => 'ツケ'
matchers.push(toKatakana(base));
} else {
matchers.push(stripOkurigana(base)); // '飛び込む' => '飛び込'
matchers.push(stripOkurigana(base, { leading: true })); // 'お金' => '金'
}
return [...new Set(matchers)];
}
export default function splitSentenceByMatch(sentence = '', word = '', reading = '') {
const stripKana = (k) => k.replace(tokenize(cleanChars).pop(), '') || k;
const hasChars = !!word.length;
const hasKana = !!reading.length;
let cleanChars;
let strippedChars;
let onlyChars;
let cleanKana;
let cleanKata;
let strippedKana;
if (hasChars) {
cleanChars = stripTilde(word); // '〜漬け' => '漬け'
strippedChars = stripOkurigana(cleanChars); // '飛び込む' => '飛び込'
onlyChars = stripOkurigana(cleanChars, { all: true }); // '売り上げ' => '売上'
}
const charRegex = hasChars ? joinPipe([cleanChars, strippedChars, onlyChars]) : '';
if (hasKana) {
cleanKana = stripTilde(reading); // '〜つけ' => 'つけ'
cleanKata = toKatakana(cleanKana); // '〜つけ' => 'ツケ'
strippedKana = stripKana(cleanKana); // '〜つけ' => 'つ'
}
const kanaRegex = hasKana ? `${joinPipe([cleanKana, cleanKata, strippedKana])}` : '';
// '売り上げ' => /(.*?)(売り上げ|売り上|売上|うりあげ|ウリアゲ|うりあ)(.*)/
const regex = new RegExp(`(.*?)(${charRegex}${hasChars && hasKana ? '|' : ''}${kanaRegex})(.*)`);