Browse Source

Update lint

Use ESLint for formatting.
master
TheoryOfNekomata 10 months ago
parent
commit
b0762fd47c
5 changed files with 26 additions and 12 deletions
  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 View File

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

+ 4
- 0
packages/core/.eslintrc View File

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


+ 1
- 0
packages/core/.gitignore View File

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


.npmrc .npmrc
types/

+ 8
- 8
packages/core/src/converter.ts View File

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


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


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


if (value.startsWith('-')) { if (value.startsWith('-')) {
return system.makeNegative(stringify(value.slice(1), options)); 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); const stringValue = system.combineGroups(groups);


switch (type) { 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; return stringValue;


+ 10
- 4
packages/core/src/exponent.ts View File

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


/** /**
* Converts a numeric value to a string in exponential notation. Supports numbers of all types. * Converts a numeric value to a string in exponential notation. Supports numbers of all types.
* @param value - The value to convert. * @param value - The value to convert.
* @param options - Options to use when extracting components. * @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') { if (typeof stringValueRaw === 'bigint' || typeof stringValueRaw === 'number') {
return numberToExponential(stringValueRaw.toString(), options); return numberToExponential(stringValueRaw.toString(), options);


Loading…
Cancel
Save