How to use the wanakana.isKana function in wanakana

To help you get started, we’ve selected a few wanakana examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kaniwani / kw-frontend / app / containers / SessionPage / logic.js View on Github external
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');
github Kaniwani / kw-frontend / app / old / containers / QuizPage / logic.js View on Github external
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,
github Kaniwani / kw-frontend / app / components / QuizInfo / AddSynonymPanel / index.js View on Github external
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,
    },
  };
};
github nkjm / bot-express / module / parser / string.js View on Github external
}
        }

        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")
            }
        }
github Kaniwani / kw-frontend / app / common / validations.js View on Github external
export const onlyKana = (value = '') => isKana(value) ? undefined : 'Must be hiragana or katakana';
github Kaniwani / kw-frontend / app / containers / QuizInfo / AddSynonymPanel / index.js View on Github external
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,
    },
  };
};
github Kaniwani / kw-frontend / app / features / quiz / QuizSession / QuizAnswer / logic.js View on Github external
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();
  },
});
github nkjm / bot-express / module / parser / string.js View on Github external
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`)
            }
        }