Skip to content

Commit 0c933ae

Browse files
committed
refactor(text-tokenizer): move TEXT_TYPE constants and types to utils module
1 parent 1455153 commit 0c933ae

3 files changed

Lines changed: 21 additions & 22 deletions

File tree

src/rules/space-around-word/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { Text } from 'mdast'
22
import type { ValueOf } from '@/types'
3-
import { TEXT_TYPE } from '@/types/text-tokenizer'
43
import { createRule } from '@/utils'
54
import { getNodeContextByParent } from '@/utils/ast'
6-
import { buildTextNodeAst, isLatinWord } from '@/utils/text-tokenizer'
5+
import { buildTextNodeAst, isLatinWord, TEXT_TYPE } from '@/utils/text-tokenizer'
76

87
export const RULE_NAME = 'space-around-word'
98
export const MESSAGE_IDS = {

src/types/text-tokenizer.d.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
import type { Text } from 'mdast'
2-
import type { ValueOf } from '@/types/index'
3-
4-
export const TEXT_TYPE = {
5-
'cjk': 'cjk',
6-
'latin': 'latin',
7-
'number': 'number',
8-
'space': 'space',
9-
'newline': 'newline',
10-
'fullwidth-punctuation': 'fullwidth-punctuation',
11-
'halfwidth-punctuation': 'halfwidth-punctuation',
12-
'dash': 'dash',
13-
'symbol': 'symbol',
14-
'emoji': 'emoji',
15-
'invisible': 'invisible',
16-
'other': 'other',
17-
} as const
18-
19-
export type TextType = ValueOf<typeof TEXT_TYPE>
2+
import type { TextType } from '@/utils/text-tokenizer'
203

214
/**
225
* Source location point compatible with mdast position points

src/utils/text-tokenizer.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
import type { Text } from 'mdast'
2-
import type { TextAst, TextPoint, TextPosition, TextToken, TextType } from '@/types/text-tokenizer'
3-
import { TEXT_TYPE } from '@/types/text-tokenizer'
2+
import type { ValueOf } from '@/types'
3+
import type { TextAst, TextPoint, TextPosition, TextToken } from '@/types/text-tokenizer'
44
import { isDashPunctuation, isFullwidthPunctuation, isHalfwidthPunctuation } from './punctuation'
55

6+
export const TEXT_TYPE = {
7+
'cjk': 'cjk',
8+
'latin': 'latin',
9+
'number': 'number',
10+
'space': 'space',
11+
'newline': 'newline',
12+
'fullwidth-punctuation': 'fullwidth-punctuation',
13+
'halfwidth-punctuation': 'halfwidth-punctuation',
14+
'dash': 'dash',
15+
'symbol': 'symbol',
16+
'emoji': 'emoji',
17+
'invisible': 'invisible',
18+
'other': 'other',
19+
} as const
20+
21+
export type TextType = ValueOf<typeof TEXT_TYPE>
22+
623
const CJK_RE = /^\p{Script=Han}$|^\p{Script=Hiragana}$|^\p{Script=Katakana}$|^\p{Script=Hangul}$/u
724
const LATIN_RE = /^\p{Script=Latin}$/u
825
const NUMBER_RE = /^\p{Number}$/u

0 commit comments

Comments
 (0)