diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..1d0ae73 --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +- [ ] Ordinals +- [ ] Fractions +- [ ] Other locales (long count, languages, etc.) diff --git a/packages/core/.eslintrc b/packages/core/.eslintrc index 35cfb79..e479339 100644 --- a/packages/core/.eslintrc +++ b/packages/core/.eslintrc @@ -1,5 +1,9 @@ { "root": true, + "rules": { + "indent": ["error", "tab"], + "no-tabs": "off" + }, "extends": [ "lxsmnsyc/typescript" ], diff --git a/packages/core/.gitignore b/packages/core/.gitignore index 53992de..bea7415 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -105,3 +105,4 @@ dist .tern-port .npmrc +types/ diff --git a/packages/core/src/converter.ts b/packages/core/src/converter.ts index ec5b09c..f4ccb47 100644 --- a/packages/core/src/converter.ts +++ b/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; diff --git a/packages/core/src/exponent.ts b/packages/core/src/exponent.ts index 0b29d36..a4dad5f 100644 --- a/packages/core/src/exponent.ts +++ b/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);