Skip to content

Commit

Permalink
♻️refactor: replace lodash/toNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Jan 9, 2025
1 parent b4752e6 commit 24fa2d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/field/src/components/Percent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useIntl } from '@ant-design/pro-provider';
import { InputNumber } from 'antd';
import toNumber from 'lodash-es/toNumber';
import { toNumber } from './util';
import type { ReactNode } from 'react';
import React, { Fragment, useMemo } from 'react';
import type { ProFieldFC } from '../../index';
Expand Down
12 changes: 12 additions & 0 deletions packages/field/src/components/Percent/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ export function getRealTextWithPrecision(
) {
return precision >= 0 ? realValue?.toFixed(precision) : realValue;
}

/**
* 转化为数字
* @copy from https://github.com/toss/es-toolkit/blob/32a183828c244d675f46810935e45dfefec81a54/src/compat/util/toNumber.ts#L19
*/
export function toNumber(value: any): number {
if (typeof value === 'symbol' || value instanceof Symbol) {
return NaN;
}

return Number(value);
}
2 changes: 1 addition & 1 deletion packages/field/src/components/Progress/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useIntl } from '@ant-design/pro-provider';
import { InputNumber, Progress } from 'antd';
import toNumber from 'lodash-es/toNumber';
import { toNumber } from '../Percent/util';
import React, { useMemo } from 'react';
import type { ProFieldFC } from '../../index';

Expand Down

0 comments on commit 24fa2d1

Please sign in to comment.