Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { currentId, review, category } = meta;
const answerValue = cleanseInput(value);
const isValid = isInputValid(answerValue);
if (!isMarked) {
console.log('not marked');
pristineReview = review;
}
if (!isValid) {
console.log('invalid');
dispatch(quiz.answer.update({ isMarked: true, isValid: false }));
}
if (isValid) {
console.log('valid');
const match = findMatch(answerValue, review);
const type = isKana(answerValue) ? 'kana' : 'kanji';
const updatedAnswer = {
type,
value: answerValue,
isMarked: true,
isValid: true,
isDisabled: true,
isCorrect: false,
isIncorrect: false,
};
if (match == null) {
console.log('no match');
dispatch(quiz.answer.update({ ...updatedAnswer, isIncorrect: true }));
dispatch(app.review.update({ ...review, incorrect: increment(review.incorrect), streak: decrement(review.streak) }));
dispatch(app[category].incorrect.add(currentId));
} else {
console.log('match');
process({ getState, action }, dispatch, done) {
const { answerValue, current, previouslyIncorrect } = action.payload;
const { autoAdvance, autoExpandCorrect, autoExpandIncorrect } = selectQuizSettings(getState());
const matchedAnswer = matchAnswer(answerValue, combineAnswers(current));
const type = isKana(answerValue) ? 'kana' : 'kanji';
const updatedAnswer = {
type,
value: answerValue,
focus: false,
isMarked: true,
isValid: true,
isDisabled: true,
isCorrect: false,
isIncorrect: false,
};
if (matchedAnswer) {
dispatch(
quiz.answer.update({
...updatedAnswer,
value: matchedAnswer,
const mapStateToProps = (state) => {
const answerValue = selectAnswerValue(state);
const answerType = isKana(answerValue) ? 'kana' : 'kanji';
const kanji = answerType === 'kanji' ? answerValue : '';
const kana = answerType === 'kana' ? answerValue : '';
return {
activePanel: selectInfoActivePanel(state),
answerValue,
answerType,
initialValues: {
kanji,
kana,
},
};
};
}
}
if (policy.sanitize){
value = sanitize(value);
}
if (policy.character){
if (policy.character === "katakana"){
if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
value = wanakana.toKatakana(value)
} else {
throw new Error("be_parser__should_be_katakana")
}
} else if (policy.character === "hiragana"){
if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
value = wanakana.toHiragana(value)
} else {
throw new Error("be_parser__should_be_hiragana")
}
} else if (policy.character === "kana"){
if (!wanakana.isKana(value.replace(/(\s| )/g, ""))){
throw new Error("be_parser__should_be_kana")
}
}
}
if (policy.zenkaku){
if (!value.match(/^[^\x01-\x7E]+$/)){
throw Error("be_parser__should_be_zenkaku")
}
}
export const onlyKana = (value = '') => isKana(value) ? undefined : 'Must be hiragana or katakana';
const mapStateToProps = (state) => {
const answerValue = selectAnswerValue(state);
const answerType = isKana(answerValue) ? 'kana' : 'kanji';
const kanji = answerType === 'kanji' ? answerValue : '';
const kana = answerType === 'kana' ? answerValue : '';
return {
activePanel: selectInfoActivePanel(state),
answerValue,
answerType,
initialValues: {
kanji,
kana,
},
};
};
process({ getState, action }, dispatch, done) {
const { isDisabled } = selectAnswer(getState());
const answerValue = cleanseInput(action.payload);
const isValid = isInputValid(answerValue);
dispatch(
quiz.answer.update({
value: answerValue,
type: isKana(answerValue) ? ANSWER_TYPES.READING : ANSWER_TYPES.WORD,
})
);
if (!isValid) {
dispatch(quiz.answer.update({ isMarked: true, isValid: false }));
}
if (isValid && !isDisabled) {
dispatch(quiz.answer.check());
}
if (isValid && isDisabled) {
dispatch(quiz.answer.confirm());
}
done();
},
});
if (policy.character){
if (policy.character === "katakana"){
if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
value = wanakana.toKatakana(value)
} else {
throw new Error("be_parser__should_be_katakana")
}
} else if (policy.character === "hiragana"){
if (wanakana.isKana(value.replace(/(\s| )/g, ""))){
value = wanakana.toHiragana(value)
} else {
throw new Error("be_parser__should_be_hiragana")
}
} else if (policy.character === "kana"){
if (!wanakana.isKana(value.replace(/(\s| )/g, ""))){
throw new Error("be_parser__should_be_kana")
}
}
}
if (policy.zenkaku){
if (!value.match(/^[^\x01-\x7E]+$/)){
throw Error("be_parser__should_be_zenkaku")
}
}
if (Array.isArray(policy.exclude)){
if (policy.exclude.includes(value)){
throw new Error(`be_parser__unavailable_word`)
}
}