A collection of code snippets to make creating custom validators easy. These recipes could be supplied to create custom validators. Kana, Kanji and Japanese character validators are available out-of-the-box. Check out README.md for more details.
Copy/paste this template and replace "options" with your choice of set from below
import {
// Types
UnicodeRange,
CreateValidatorOptions,
StrictValidator,
ThresholdBasedValidator,
MatchScoreCalculator,
CharacterSet,
// Functions
createStrictValidator,
createThresholdBasedValidator,
createMatchScoreCalculator,
} from 'japanese-moji';
const options: CreateValidatorOptions = {
// Required property
characterSets: [
// Mix/Match character sets here
],
// Optional properties
// customRanges?: UnicodeRange[];
// customUnicodes?: string[];
};
const isValidCustom: StrictValidator = createStrictValidator(options);
const isCustomPresent: ThresholdBasedValidator = createThresholdBasedValidator(options);
const howMuchIsCustomPresent: MatchScoreCalculator = createMatchScoreCalculator(options);
const options: CreateValidatorOptions = {
characterSets: [CharacterSet.Hiragana],
};
const options: CreateValidatorOptions = {
characterSets: [CharacterSet.Hiragana, CharacterSet.CJKPunctuations],
};
const options: CreateValidatorOptions = {
characterSets: [
CharacterSet.Hiragana,
CharacterSet.Katakana,
CharacterSet.KatakanaPhoneticExtension,
CharacterSet.HalfWidthKatakana,
],
};
const options: CreateValidatorOptions = {
characterSets: [
CharacterSet.Hiragana,
CharacterSet.RareKanji,
CharacterSet.CommonUncommonKanji,
CharacterSet.KanjiCompatibilityIdeographs,
],
};
const options: CreateValidatorOptions = {
characterSets: [
CharacterSet.FullWidthUpperCase,
CharacterSet.FullWidthLowerCase,
CharacterSet.FullWidthNumbers,
CharacterSet.FullWidthPunctuations,
],
};
// includes: " " (space), !"#$%&'()*+,-./
const LatinPunctuations: UnicodeRange = {
start: '\\u0020',
end: '\\u002f',
};
// includes: :;<=>?@
const LatinPunctuationsExtensionA: UnicodeRange = {
start: '\\u003a',
end: '\\u0040',
};
// includes: [\]^_`
const LatinPunctuationsExtensionB: UnicodeRange = {
start: '\\u005b',
end: '\\u0060',
};
// includes: {|}~
const LatinPunctuationsExtensionC: UnicodeRange = {
start: '\\u007b',
end: '\\u007e',
};
const LatinPunctuationsRanges: UnicodeRange[] = [
LatinPunctuations,
LatinPunctuationsExtensionA,
LatinPunctuationsExtensionB,
LatinPunctuationsExtensionC,
];
const options: CreateValidatorOptions = {
characterSets: [
CharacterSet.CJKPunctuations,
CharacterSet.Hiragana,
CharacterSet.Katakana,
CharacterSet.KatakanaPhoneticExtension,
CharacterSet.RareKanji,
CharacterSet.CommonUncommonKanji,
CharacterSet.KanjiCompatibilityIdeographs,
CharacterSet.HalfWidthKatakana,
CharacterSet.FullWidthUpperCase,
CharacterSet.FullWidthLowerCase,
CharacterSet.FullWidthNumbers,
CharacterSet.FullWidthPunctuations,
],
customRanges: [...LatinPunctuationsRanges],
};