浏览代码

Update lint

Use ESLint for formatting.
master
TheoryOfNekomata 9 个月前
父节点
当前提交
b0762fd47c
共有 5 个文件被更改,包括 26 次插入12 次删除
  1. +3
    -0
      TODO.md
  2. +4
    -0
      packages/core/.eslintrc
  3. +1
    -0
      packages/core/.gitignore
  4. +8
    -8
      packages/core/src/converter.ts
  5. +10
    -4
      packages/core/src/exponent.ts

+ 3
- 0
TODO.md 查看文件

@@ -0,0 +1,3 @@
- [ ] Ordinals
- [ ] Fractions
- [ ] Other locales (long count, languages, etc.)

+ 4
- 0
packages/core/.eslintrc 查看文件

@@ -1,5 +1,9 @@
{
"root": true,
"rules": {
"indent": ["error", "tab"],
"no-tabs": "off"
},
"extends": [
"lxsmnsyc/typescript"
],


+ 1
- 0
packages/core/.gitignore 查看文件

@@ -105,3 +105,4 @@ dist
.tern-port

.npmrc
types/

+ 8
- 8
packages/core/src/converter.ts 查看文件

@@ -10,14 +10,14 @@ export interface StringifyOptions {

export const stringify = (
valueRaw: StringifyValue,
options = {} as StringifyOptions
options = {} as StringifyOptions,
): string => {
if (!(['bigint', 'number', 'string'].includes(typeof (valueRaw as unknown)))) {
throw new TypeError('value must be a string, number, or bigint');
}

const value = valueRaw.toString().replace(/\s/g, '');
const { system = enUS, makeGroupOptions} = options;
const { system = enUS, makeGroupOptions } = options;

if (value.startsWith('-')) {
return system.makeNegative(stringify(value.slice(1), options));
@@ -47,12 +47,12 @@ export const parse = (value: string, options = {} as ParseOptions) => {
const stringValue = system.combineGroups(groups);

switch (type) {
case 'number':
return Number(stringValue);
case 'bigint':
return BigInt(stringValue);
default:
break;
case 'number':
return Number(stringValue);
case 'bigint':
return BigInt(stringValue);
default:
break;
}

return stringValue;


+ 10
- 4
packages/core/src/exponent.ts 查看文件

@@ -26,7 +26,10 @@ export interface NumberToExponentialOptions {
* @param value - The string value to extract components from.
* @param options - Options to use when extracting components.
*/
export const extractExponentialComponents = (value: string, options = {} as NumberToExponentialOptions) => {
export const extractExponentialComponents = (
value: string,
options = {} as NumberToExponentialOptions,
) => {
const {
decimalPoint = '.',
groupingSymbol = ',',
@@ -67,15 +70,18 @@ export const extractExponentialComponents = (value: string, options = {} as Numb
exponent: exponentValue < 0 ? exponentValue.toString() : `+${exponentValue}`,
fractional,
};
}
};

/**
* Converts a numeric value to a string in exponential notation. Supports numbers of all types.
* @param value - The value to convert.
* @param options - Options to use when extracting components.
*/
export const numberToExponential = (value: ValidValue, options = {} as NumberToExponentialOptions): string => {
const stringValueRaw = value as unknown
export const numberToExponential = (
value: ValidValue,
options = {} as NumberToExponentialOptions,
): string => {
const stringValueRaw = value as unknown;

if (typeof stringValueRaw === 'bigint' || typeof stringValueRaw === 'number') {
return numberToExponential(stringValueRaw.toString(), options);


正在加载...
取消
保存