|
|
@@ -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; |
|
|
|