Skip to content

Commit

Permalink
Release stable (#44)
Browse files Browse the repository at this point in the history
* feat: add full width characters (#36)

* perf: improve regex perf. by fixing catastrophic backtracking

* test: polish tests for kana/kanji fns

* feat: add full width characters

* docs(readme.md): add link to the website containing demos

* chore(release): 1.1.0-next.1 [skip ci]

# [1.1.0-next.1](v1.0.0...v1.1.0-next.1) (2022-02-20)

### Features

* add full width characters ([#36](#36)) ([13c162b](13c162b))

* docs: add recipes, contribution guide and TOCs (#37)

* docs: add recipes, contribution guide and TOCs

* chore(package.json): mark package as no side effects

* docs(CONTRIBUTING.md): update size of release diagram

* docs(readme.md): add types summary to TOC

* docs(readme.md): add treeshake support badge

* feat: allow importing package.json (#38)

* chore(release): 1.1.0-next.2 [skip ci]

# [1.1.0-next.2](v1.1.0-next.1...v1.1.0-next.2) (2022-02-21)

### Features

* allow importing package.json ([#38](#38)) ([36198a9](36198a9))

* feat: add support for node >=12.22.0 and remove yarn from engine (#40)

* chore(release): 1.1.0-next.3 [skip ci]

# [1.1.0-next.3](v1.1.0-next.2...v1.1.0-next.3) (2022-02-21)

### Features

* add support for node >=12.22.0 and remove yarn from engine ([#40](#40)) ([5b23783](5b23783))

* docs: add custom recipes to the demo page (#39)

* docs: improve seo for docs website

* chore(package.json): update keywords for npmjs

* docs: add custom recipes to the demo page

* docs: upgrade japanese-moji version

* docs: make thresholds on demo page configurable (#41)

* docs: improve anchor scrolling

* docs: make thresholds on demo page configurable

* docs: add analytics to the website (#42)

* docs: add demo links to recipes.md (#43)

Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
  • Loading branch information
arjunvegda and semantic-release-bot authored Feb 21, 2022
1 parent bfd1b2a commit 2d1c2c8
Show file tree
Hide file tree
Showing 48 changed files with 2,285 additions and 967 deletions.
143 changes: 143 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Contributing to Japanese Moji

We are open to, and grateful for, any contributions made to this repository by you. Please review
the following guide to keep track of our best practices

**Table of Contents**

- [Reporting Issues](#reporting-issues)
- [Local setup](#local-setup)
- [Building](#building)
- [Testing and Linting](#testing-and-linting)
- [New Features](#new-features)
- [Submitting Changes](#submitting-changes)
- [Making a Pull Request?](#making-a-pull-request)
- [Commit Convention](#commit-convention)
- [Release flow](#release-flow)

## Reporting Issues

Before opening an issue, please search the
[issue tracker](https://github.com/arjunvegda/japanese-moji/issues) to make sure your issue hasn't
already been reported.

Please ask any general and implementation specific questions via
[GitHub Discussion](https://github.com/arjunvegda/japanese-moji/discussions)

## Local setup

Visit the [Issue tracker](https://github.com/arjunvegda/japanese-moji/issues) to find a list of open
issues that need attention.

Fork, then clone the repo:

```
git clone https://github.com/your-username/japanese-moji.git
```

This repository uses Yarn v3 to manage this pacakage and documentations. You'll need to have Yarn
v1.22 installed globally on your system first, as Yarn v3 depends on that being available first.
Install dependencies with:

```
yarn install
# if you want to work on the documentation locally
cd website && yarn install
```

## Building

Running the `build` task will create CommonJS, ESM, and a UMD build under `/dist`

```
yarn build
```

## Testing and Linting

We use Jest to test our code. Therefore, yarn run test\* supports passing of all the arguments as
Jest

To run the tests:

```
yarn test
```

To continuously watch and run tests, run the following (supports all the arguments as jest):

```
yarn test:watch
```

To run tests with coverage, run the following (supports all the arguments as jest):

```
yarn test:coverage
```

To perform linting with `eslint`, run the following:

```
yarn lint
```

To perform linting with `eslint` and fix it, run the following:

```
yarn lint:fix
```

## New Features

Please open an issue with a proposal for a new feature or refactoring before starting on the work.
We don't want you to waste your efforts on a pull request that we won't want to accept.

## Submitting Changes

- Open a new issue in the [Issue tracker](https://github.com/arjunvegda/japanese-moji/issues)
- Fork the repo
- Create a new feature branch based off the `next` branch
- Make sure all tests pass and that there are no linting errors
- Submit a pull request, referencing any issues it addresses

### Making a Pull Request?

Pull requests require an approval from the maintainers of the project.

#### Commit Convention

We use
[Angular's Conventional commit conventions](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#type).
Please use `category(scope or module): message` format in your commit message and use the following
categories

🚨 **All the changes under `./website/*` are categorized as `docs`, please use `docs` as category
for your commit message in those cases**

- **build**: Changes that affect the build system or external dependencies (example scopes: npm,
yarn)
- **ci**: Changes to our CI configuration files and scripts (examples: GitHub Actions)
- **docs**: Documentation only changes
- **feat**: A new feature
- **fix**: A bug fix
- **perf**: A code change that improves performance
- **refactor**: A code change that neither fixes a bug nor adds a feature
- **test**: Adding missing tests or correcting existing tests
- **chore**: All changes other changes to the repository that do not fit into any of the above
categories

Please try to keep your pull request focused in scope and avoid including unrelated commits.

After you have submitted your pull request, we'll try to get back to you as soon as possible. We may
suggest some changes or improvements.

Thank you for contributing 🙌!

## Release flow

We automatically release new versions of `next` branch to next channel on each merge. We also
release new versions of `main` branch on the stable channel on each merge.

<img src="./docs/release-flow.gif" width="400" alt="Release diagram"/>
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,49 @@
<p align="center">
<img alt="Japanese Moji Logo" src="./docs/logo-light.svg">
<a href="https://japanese-moji.vercel.app">
<img alt="Japanese Moji Logo" src="./docs/logo-light.svg">
</a>
</p>
<p align="center">
<a href="https://www.npmjs.com/package/japanese-moji">
<img src="https://badgen.net/github/release/arjunvegda/japanese-moji"/>
<img src="https://badgen.net/github/release/arjunvegda/japanese-moji/stable"/>
</a>
<a href="https://bundlephobia.com/package/japanese-moji">
<img src="https://badgen.net/bundlephobia/minzip/japanese-moji?color=green"/>
</a>
<a href="https://bundlephobia.com/package/japanese-moji">
<img src="https://badgen.net/bundlephobia/dependency-count/japanese-moji?color=green"/>
</a>
<a href="https://bundlephobia.com/package/japanese-moji">
<img src="https://badgen.net/bundlephobia/tree-shaking/japanese-moji"/>
</a>
<a href="https://codecov.io/gh/arjunvegda/japanese-moji">
<img src="https://codecov.io/gh/arjunvegda/japanese-moji/branch/main/graph/badge.svg?token=GZ8GBUVYD8"/>
</a>
<a href="https://japanese-moji.vercel.app">
<img src="https://img.shields.io/badge/website-%F0%9F%8C%8E-green" alt="Website" />
</a>
<a href="./LICENSE">
<img src="https://badgen.net/npm/license/japanese-moji?color=blue"/>
</a>
<hr/>

The word "Moji" translates to "Character" in English

## 🚀 Features
**Table of Contents**

- [Features](#-features)
- [Install](#-install)
- [Quick start](#-quick-start)
- [Kanji](#kanji)
- [Kana](#kana)
- [Japanese](#japanese)
- [Types summary](#-types-summary)
- [Build Your Own Validators](#-build-your-own-validators)
- [Recipes](#-recipes)
- [Contributing](#-contributing)
- [Changelog](#-changelog)

## ✨ Features

- Very small footprint with zero dependencies
- Supports strict and threshold-based validation for Kanji, Kana, and all the Japanese characters
Expand All @@ -31,6 +53,7 @@ The word "Moji" translates to "Character" in English
- Supports custom single Unicode and Unicode ranges out-of-the-box
- 100% TypeScript friendly
- ESM, CJS, and UMD builds
- Only pay for what you use — its fully tree-shakable

## 📦 Install

Expand All @@ -50,7 +73,9 @@ npm install --save japanese-moji

### Kanji

Validates Rare Kanji, Common and Uncommon Kanji, and Kanji compatibility ideographs
Validates Rare Kanji, Common and Uncommon Kanji, and Kanji compatibility ideographs <br/><br/>
<a href="https://japanese-moji.vercel.app/demos#kanji">
<img src="https://img.shields.io/badge/demo-%F0%9F%9A%80-green" alt="Demo" /> </a>

```ts
import { isValidKanji, isKanjiPresent, howMuchKanjiIsPresent } from 'japanese-moji';
Expand All @@ -67,7 +92,9 @@ const howMuchKanjiIsPresentResult = howMuchKanjiIsPresent('some string here');

### Kana

Validates Katakana, Half-width Katakana, and Katakana phonetic extensions
Validates Katakana, Half-width Katakana, and Katakana phonetic extensions <br/><br/>
<a href="https://japanese-moji.vercel.app/demos#kana">
<img src="https://img.shields.io/badge/demo-%F0%9F%9A%80-green" alt="Demo" /> </a>

```ts
import { isValidKana, isKanaPresent, howMuchKanaIsPresent } from 'japanese-moji';
Expand All @@ -85,7 +112,9 @@ const howMuchKanaIsPresentResult = howMuchKanaIsPresent('some string here');
### Japanese

Validates CJK punctuations, Hiragana, Katakana, Katakana phonetic extensions, Rare Kanji, Common and
Uncommon Kanji, Kanji compatibility ideographs, and Half-width Katakana forms
Uncommon Kanji, Kanji compatibility ideographs, Half-width Katakana forms, and Full-width (roman)
forms including punctuations <br/><br/> <a href="https://japanese-moji.vercel.app/demos#japanese">
<img src="https://img.shields.io/badge/demo-%F0%9F%9A%80-green" alt="Demo" /> </a>

```ts
import { isValidJapanese, isJapanesePresent, howMuchJapaneseIsPresent } from 'japanese-moji';
Expand All @@ -100,7 +129,7 @@ const isJapanesePresentResult = isJapanesePresent('some string here', 90);
const howMuchJapaneseIsPresentResult = howMuchJapaneseIsPresent('some string here');
```

### 📝 Types summary
## 📝 Types summary

```ts
enum CharacterSet {
Expand All @@ -112,6 +141,10 @@ enum CharacterSet {
KanjiCompatibilityIdeographs = 'KanjiCompatibilityIdeographs',
CommonUncommonKanji = 'CommonUncommonKanji',
HalfWidthKatakana = 'HalfWidthKatakana',
FullWidthUpperCase = 'FullWidthUpperCase',
FullWidthLowerCase = 'FullWidthLowerCase',
FullWidthNumbers = 'FullWidthNumbers',
FullWidthPunctuations = 'FullWidthPunctuations',
}

interface UnicodeRange {
Expand Down Expand Up @@ -172,6 +205,10 @@ const options: CreateValidatorOptions = {
CharacterSet.CommonUncommonKanji,
CharacterSet.KanjiCompatibilityIdeographs,
CharacterSet.HalfWidthKatakana,
CharacterSet.FullWidthUpperCase,
CharacterSet.FullWidthLowerCase,
CharacterSet.FullWidthNumbers,
CharacterSet.FullWidthPunctuations,
],
customRanges, // Optional
customUnicodes, // Optional
Expand All @@ -191,6 +228,18 @@ const isCustomPresentResult = isCustomPresent('some string here', 90);
const howMuchIsCustomPresentResult = howMuchIsCustomPresent('some string here');
```

### 📄 Changelog
## 📚 Recipes

Find code snippets containing variety of combinations that makes creating custom validators easy in
[docs/RECIPES.md](./docs/RECIPES.md) <br/><br/>
<a href="https://japanese-moji.vercel.app/demos#custom-recipes">
<img src="https://img.shields.io/badge/demos-%F0%9F%9A%80-green" alt="Demo" /> </a>

## 🙌 Contributing

Find contribution guides, code convention, release flows etc. in
[CONTRIBUTING.md](./CONTRIBUTING.md)

## 📄 Changelog

Full change log available in the [docs/CHANGELOG.md](./docs/CHANGELOG.md)
42 changes: 42 additions & 0 deletions __tests__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,45 @@ export const MockHalfWidthKatakana: UnicodeRange = {
start: '\uff66',
end: '\uff9f',
};

export const MockFullWidthUpperCaseRange: UnicodeRange = {
start: '\uff21',
end: '\uff3a',
};

export const MockFullWidthLowerCaseRange: UnicodeRange = {
start: '\uff41',
end: '\uff5a',
};

export const MockFullWidthNumbersRange: UnicodeRange = {
start: '\uff10',
end: '\uff19',
};

export const MockFullWidthPunctuations: UnicodeRange = {
start: '\uff00',
end: '\uff0f',
};

const MockFullWidthPunctuationsExtensionA: UnicodeRange = {
start: '\uff1a',
end: '\uff20',
};

const MockFullWidthPunctuationsExtensionB: UnicodeRange = {
start: '\uff3b',
end: '\uff40',
};

const MockFullWidthPunctuationsExtensionC: UnicodeRange = {
start: '\uff5b',
end: '\uff65',
};

export const MockFullWidthPunctuationsRange: UnicodeRange[] = [
MockFullWidthPunctuations,
MockFullWidthPunctuationsExtensionA,
MockFullWidthPunctuationsExtensionB,
MockFullWidthPunctuationsExtensionC,
];
27 changes: 23 additions & 4 deletions __tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import type { UnicodeRange } from '../src';
import { makeString } from '../src/utils';

export const generateCharactersFromRange = (start: string, end: string): string => {
// Useful when string is huge and we want to test both ends of the string
// For example, test abc...xyz instead of the full abcdef... string, Since we only care about the start/end
const truncateMiddle = (str: string, width: number) => {
if (str.length <= width) {
return str;
}

const start = Math.ceil(width / 2);
const end = Math.floor(width / 2);

return str.substring(0, start) + str.substring(str.length - end);
};

export const generateCharactersFromRange = (start: string, end: string, width?: number): string => {
const startCode = start.charCodeAt(0);
const endCode = end.charCodeAt(0);
const length = endCode - startCode + 1;
return Array.from({ length }, (_, i) => String.fromCharCode(startCode + i)).join('');
const fullStr = Array.from({ length }, (_, i) => String.fromCharCode(startCode + i)).join('');

if (typeof width === 'number') {
return truncateMiddle(fullStr, width);
}

return fullStr;
};

export const generateCharactersFromRanges = (ranges: UnicodeRange[]): string => {
export const generateCharactersFromRanges = (ranges: UnicodeRange[], width?: number): string => {
return ranges.reduce((acc, range) => {
return acc + generateCharactersFromRange(range.start, range.end);
return acc + generateCharactersFromRange(range.start, range.end, width);
}, '');
};

Expand Down
Loading

1 comment on commit 2d1c2c8

@vercel
Copy link

@vercel vercel bot commented on 2d1c2c8 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.