Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
japanese-moji
Advanced tools
The word "Moji" translates to "Character" in English
Table of Contents
yarn add japanese-moji
npm install --save japanese-moji
Validates Rare Kanji, Common and Uncommon Kanji, and Kanji compatibility ideographs
import { isValidKanji, isKanjiPresent, howMuchKanjiIsPresent } from 'japanese-moji';
// Strict validation
const isValidKanjiResult = isValidKanji('some string here');
// Default threshold is 85 (2nd argument)
const isKanjiPresentResult = isKanjiPresent('some string here', 90);
// Returns % of Kanji present in a string
const howMuchKanjiIsPresentResult = howMuchKanjiIsPresent('some string here');
Validates Katakana, Half-width Katakana, and Katakana phonetic extensions
import { isValidKana, isKanaPresent, howMuchKanaIsPresent } from 'japanese-moji';
// Strict validation
const isValidKanaResult = isValidKana('some string here');
// Default threshold is 85 (2nd argument)
const isKanaPresentResult = isKanaPresent('some string here', 90);
// Returns % of Kana present in a string
const howMuchKanaIsPresentResult = howMuchKanaIsPresent('some string here');
Validates CJK punctuations, Hiragana, Katakana, Katakana phonetic extensions, Rare Kanji, Common and
Uncommon Kanji, Kanji compatibility ideographs, Half-width Katakana forms, and Full-width (roman)
forms including punctuations
import { isValidJapanese, isJapanesePresent, howMuchJapaneseIsPresent } from 'japanese-moji';
// Strict validation
const isValidJapaneseResult = isValidJapanese('some string here');
// Default threshold is 85 (2nd argument)
const isJapanesePresentResult = isJapanesePresent('some string here', 90);
// Returns % of Japanese present in a string
const howMuchJapaneseIsPresentResult = howMuchJapaneseIsPresent('some string here');
enum CharacterSet {
CJKPunctuations = 'CJKPunctuations',
Hiragana = 'Hiragana',
Katakana = 'Katakana',
KatakanaPhoneticExtension = 'KatakanaPhoneticExtension',
RareKanji = 'RareKanji',
KanjiCompatibilityIdeographs = 'KanjiCompatibilityIdeographs',
CommonUncommonKanji = 'CommonUncommonKanji',
HalfWidthKatakana = 'HalfWidthKatakana',
FullWidthUpperCase = 'FullWidthUpperCase',
FullWidthLowerCase = 'FullWidthLowerCase',
FullWidthNumbers = 'FullWidthNumbers',
FullWidthPunctuations = 'FullWidthPunctuations',
}
interface UnicodeRange {
start: string;
end: string;
}
interface CreateValidatorOptions {
characterSets: CharacterSet[];
customRanges?: UnicodeRange[];
customUnicodes?: string[];
}
type StrictValidator = (arg: string) => boolean;
type ThresholdBasedValidator = (arg: string, threshold?: number) => boolean;
type MatchScoreCalculator = (arg: string) => number;
You could create custom validators too, should the existing validators not fit your use case.
There are also ready-to-use, copy-pastable code snippets that may fit your use cases here
import {
// Types
UnicodeRange,
CreateValidatorOptions,
StrictValidator,
ThresholdBasedValidator,
MatchScoreCalculator,
CharacterSet,
// Functions
createStrictValidator,
createThresholdBasedValidator,
createMatchScoreCalculator,
} from 'japanese-moji';
// Requires escaped unicode characters
const LatinUnicodeRange: UnicodeRange = {
start: '\\u0020',
end: '\\u007F',
};
const customRanges: UnicodeRange[] = [LatinUnicodeRange];
// Provide escaped unicode characters
const customUnicodes = ['\\u00A0'];
const options: CreateValidatorOptions = {
// Required
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, // Optional
customUnicodes, // Optional
};
const isValidCustom: StrictValidator = createStrictValidator(options);
const isCustomPresent: ThresholdBasedValidator = createThresholdBasedValidator(options);
const howMuchIsCustomPresent: MatchScoreCalculator = createMatchScoreCalculator(options);
// Strict validation
const isValidCustomResult = isValidCustom('some string here');
// Default threshold is 85 (2nd argument)
const isCustomPresentResult = isCustomPresent('some string here', 90);
// Returns % of Japanese present in a string
const howMuchIsCustomPresentResult = howMuchIsCustomPresent('some string here');
Find code snippets containing variety of combinations that makes creating custom validators easy in
docs/RECIPES.md
Find contribution guides, code convention, release flows etc. in CONTRIBUTING.md
Full change log available in the docs/CHANGELOG.md
FAQs
A toolkit to validate Japanese characters
The npm package japanese-moji receives a total of 4 weekly downloads. As such, japanese-moji popularity was classified as not popular.
We found that japanese-moji demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.