Skip to content

Commit

Permalink
unicodeなんたらを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
mehm8128 committed Mar 24, 2024
1 parent 0d51273 commit 952de64
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 57 deletions.
33 changes: 0 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion workspaces/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"react-dom": "18.2.0",
"react-hook-form": "7.51.1",
"regexparam": "3.0.0",
"unicode-collation-algorithm2": "0.5.0",
"yup": "1.4.0"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions workspaces/admin/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './setup';

import { ChakraProvider, useToast } from '@chakra-ui/react';
import { QueryClientProvider } from '@tanstack/react-query';
import { RouterProvider } from '@tanstack/react-router';
Expand Down
12 changes: 6 additions & 6 deletions workspaces/admin/src/lib/filter/isContains.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { compareWithFlags, PRIMARY as UCA_L1_FLAG, SECONDARY as UCA_L2_FLAG } from 'unicode-collation-algorithm2';

// UCA_L1_FLAG はベース文字、UCA_L2_FLAG は濁点・半濁点・アクセントを区別する (sensitivity: accent に相当)
const SENSITIVITY_ACCENT_FLAG = UCA_L1_FLAG ^ UCA_L2_FLAG;

type Params = {
query: string;
target: string;
};

const collator = new Intl.Collator('ja', {
sensitivity: 'accent',
usage: 'search',
});

// ひらがな・カタカナ・半角・全角を区別せずに文字列が含まれているかを調べる
export function isContains({ query, target }: Params): boolean {
// target の先頭から順に query が含まれているかを調べる
TARGET_LOOP: for (let offset = 0; offset <= target.length - query.length; offset++) {
for (let idx = 0; idx < query.length; idx++) {
// 1文字ずつ Unicode Collation Algorithm で比較する
// unicode-collation-algorithm2 は Default Unicode Collation Element Table (DUCET) を collation として使う
if (compareWithFlags(target[offset + idx]!, query[idx]!, SENSITIVITY_ACCENT_FLAG) !== 0) {
if (collator.compare(target[offset + idx]!, query[idx]!) !== 0) {
continue TARGET_LOOP;
}
}
Expand Down
3 changes: 0 additions & 3 deletions workspaces/admin/src/setup.ts

This file was deleted.

1 change: 0 additions & 1 deletion workspaces/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"swr": "2.2.4",
"three": "0.162.0",
"tiny-invariant": "1.3.3",
"unicode-collation-algorithm2": "0.5.0",
"zod": "3.22.4"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions workspaces/app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './setup';

import { Dialog } from './foundation/components/Dialog';
import { GlobalStyle } from './foundation/styles/GlobalStyle';
import { Router } from './routes';
Expand Down
12 changes: 6 additions & 6 deletions workspaces/app/src/lib/filter/isContains.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { compareWithFlags, PRIMARY as UCA_L1_FLAG, SECONDARY as UCA_L2_FLAG } from 'unicode-collation-algorithm2';

// UCA_L1_FLAG はベース文字、UCA_L2_FLAG は濁点・半濁点・アクセントを区別する (sensitivity: accent に相当)
const SENSITIVITY_ACCENT_FLAG = UCA_L1_FLAG ^ UCA_L2_FLAG;

type Params = {
query: string;
target: string;
};

const collator = new Intl.Collator('ja', {
sensitivity: 'accent',
usage: 'search',
});

// ひらがな・カタカナ・半角・全角を区別せずに文字列が含まれているかを調べる
export function isContains({ query, target }: Params): boolean {
// target の先頭から順に query が含まれているかを調べる
TARGET_LOOP: for (let offset = 0; offset <= target.length - query.length; offset++) {
for (let idx = 0; idx < query.length; idx++) {
// 1文字ずつ Unicode Collation Algorithm で比較する
// unicode-collation-algorithm2 は Default Unicode Collation Element Table (DUCET) を collation として使う
if (compareWithFlags(target[offset + idx]!, query[idx]!, SENSITIVITY_ACCENT_FLAG) !== 0) {
if (collator.compare(target[offset + idx]!, query[idx]!) !== 0) {
continue TARGET_LOOP;
}
}
Expand Down
3 changes: 0 additions & 3 deletions workspaces/app/src/setup.ts

This file was deleted.

0 comments on commit 952de64

Please sign in to comment.