scurker / currency.js

A javascript library for handling currencies

Home Page:https://currency.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`groups` missing in interface `Options` for typescript

yuklai opened this issue · comments

Hi all, when Format function's option (Options interface) parameter should have a groups attribute, right?
It's missing in the typescript definition for me but when I step through the code, groups is valid.

I'm using the latest 2.0.4 version. Did I miss anything? Thanks!

declare module 'currency.js' {
  namespace currency {
    type Any = number | string | currency;
    type Format = (currency?: currency, opts?: Options) => string;
    interface Constructor {
      (value: currency.Any, opts?: currency.Options): currency,
      new(value: currency.Any, opts?: currency.Options): currency
    }
    interface Options {
      symbol?: string,
      separator?: string,
      decimal?: string,
      errorOnInvalid?: boolean,
      precision?: number,
      increment?: number,
      useVedic?: boolean,
      pattern?: string,
      negativePattern?: string,
      format?: currency.Format,
      fromCents?: boolean
    }
  }

  interface currency {
    add(number: currency.Any): currency;
    subtract(number: currency.Any): currency;
    multiply(number: currency.Any): currency;
    divide(number: currency.Any): currency;
    distribute(count: number): Array<currency>;
    dollars(): number;
    cents(): number;
    format(opts?: currency.Options | currency.Format): string;
    toString(): string;
    toJSON(): number;
    readonly intValue: number;
    readonly value: number;
  }

  const currency: currency.Constructor;

  export = currency;
}

@yuklai The groups attribute is for internal use, it simply stores a regex, based on the numbering system you picked, all you have to do is select the numbering system using useVedic attribute

Even if you managed to pass a groups attribute, it will always be overwritten by the else clause, so I'd say don't worry much about it 😁

  if(settings.useVedic) {
    settings.groups = vedicRegex;
  } else {
    settings.groups = groupRegex;
  }