Skip to content

Commit f8fc670

Browse files
committed
refactor
1 parent 886247c commit f8fc670

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/message/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type MessageContext = {
5656

5757
const DEFAULT_MODIFIER = (str: unknown): unknown => str
5858
const DEFAULT_MESSAGE = (ctx: MessageContext): unknown => '' // eslint-disable-line
59-
const DEFAULT_TYPE = 'text'
59+
export const DEFAULT_MESSAGE_DATA_TYPE = 'text'
6060
const DEFAULT_NORMALIZE = (values: unknown[]): unknown =>
6161
values.length === 0 ? values[0] : values.join('')
6262
const DEFAULT_INTERPOLATE = toDisplayString
@@ -152,7 +152,7 @@ export function createMessageContext<N = {}>(
152152
const type =
153153
isPlainObject(options.processor) && isString(options.processor.type)
154154
? options.processor.type
155-
: DEFAULT_TYPE
155+
: DEFAULT_MESSAGE_DATA_TYPE
156156

157157
const normalize =
158158
isPlainObject(options.processor) && isFunction(options.processor.normalize)

src/runtime/context.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { MessageFunction } from '../message/compiler'
22
import {
33
LinkedModifiers,
44
PluralizationRules,
5-
MessageProcessor
5+
MessageProcessor,
6+
DEFAULT_MESSAGE_DATA_TYPE
67
} from '../message/context'
78
import { Path } from '../path'
89
import {
@@ -89,12 +90,12 @@ export type RuntimeContext = {
8990

9091
const DEFAULT_LINKDED_MODIFIERS: LinkedModifiers = {
9192
upper: (val: unknown, type: string): unknown =>
92-
type === 'text' ? (val as string).toUpperCase() : val,
93+
type === DEFAULT_MESSAGE_DATA_TYPE ? (val as string).toUpperCase() : val,
9394
lower: (val: unknown, type: string): unknown =>
94-
type === 'text' ? (val as string).toLowerCase() : val,
95+
type === DEFAULT_MESSAGE_DATA_TYPE ? (val as string).toLowerCase() : val,
9596
// prettier-ignore
9697
capitalize: (val: unknown, type: string): unknown =>
97-
type === 'text'
98+
type === DEFAULT_MESSAGE_DATA_TYPE
9899
? `${(val as string).charAt(0).toLocaleUpperCase()}${(val as string).substr(1)}`
99100
: val
100101
}

0 commit comments

Comments
 (0)