Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intl defintions #1270

Closed
arv opened this issue Jan 12, 2016 · 5 comments
Closed

Add Intl defintions #1270

arv opened this issue Jan 12, 2016 · 5 comments
Labels
Library definitions Issues or pull requests about core library definitions

Comments

@arv
Copy link

arv commented Jan 12, 2016

Should go in lib/intl.js or lib/ecma402.js

http://www.ecma-international.org/ecma-402/2.0/

It seems like TypeScript moved this out of .d.ts to make it part of the core compiler.

@mroch mroch added the Library definitions Issues or pull requests about core library definitions label May 31, 2016
@ianp
Copy link

ianp commented Jun 9, 2016

Any workaround for this in the meantime?

@vanwagonet
Copy link
Contributor

I've been using the following locally. It's not complete, but it's a start.

declare var Intl: {
  Collator: Class<Collator>,
  DateTimeFormat: Class<DateTimeFormat>,
  NumberFormat: Class<NumberFormat>
}

declare class Collator {
  constructor (
    locales?: string | string[],
    options?: CollatorOptions
  ): Collator;

  static (
    locales?: string | string[],
    options?: CollatorOptions
  ): Collator;

  compare (a: string, b: string): number;
}

type CollatorOptions = {
  localeMatcher?: 'lookup' | 'best fit',
  usage?: 'sort' | 'search',
  sensitivity?: 'base' | 'accent' | 'case' | 'variant',
  ignorePunctuation?: boolean,
  numeric?: boolean,
  caseFirst?: 'upper' | 'lower' | 'false'
}

declare class DateTimeFormat {
  constructor (
    locales?: string | string[],
    options?: DateTimeFormatOptions
  ): DateTimeFormat;

  static (
    locales?: string | string[],
    options?: DateTimeFormatOptions
  ): DateTimeFormat;

  format (a: Date | number): string;
}

type DateTimeFormatOptions = {
  localeMatcher?: 'lookup' | 'best fit',
  timeZone?: string,
  hour12?: boolean,
  formatMatcher?: 'basic' | 'best fit',
  weekday?: 'narrow' | 'short' | 'long',
  era?: 'narrow' | 'short' | 'long',
  year?: 'numeric' | '2-digit',
  month?: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
  day?: 'numeric' | '2-digit',
  hour?: 'numeric' | '2-digit',
  minute?: 'numeric' | '2-digit',
  second?: 'numeric' | '2-digit',
  timeZoneName?: 'short' | 'long'
}

declare class NumberFormat {
  constructor (
    locales?: string | string[],
    options?: NumberFormatOptions
  ): NumberFormat;

  static (
    locales?: string | string[],
    options?: NumberFormatOptions
  ): NumberFormat;

  format (a: number): string;
}

type NumberFormatOptions = {
  localeMatcher?: 'lookup' | 'best fit',
  style?: 'decimal' | 'currency' | 'percent',
  currency?: string,
  currencyDisplay?: 'symbol' | 'code' | 'name',
  useGrouping?: boolean,
  minimumIntegerDigits?: number,
  minimumFractionDigits?: number,
  maximumFractionDigits?: number,
  minimumSignificantDigits?: number,
  maximumSignificantDigits?: number
}

@arjun-menon
Copy link

Any plans to make this part of the Flow built-in library definitions?

@mike1808
Copy link

@thetalecrafter according to specs the first arg of DateTimeFormat.prototype.format can be nullable https://www.ecma-international.org/ecma-402/2.0/#sec-datetime-format-functions

@vanwagonet
Copy link
Contributor

@mike1808 yeah you're right. I hadn't covered that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Library definitions Issues or pull requests about core library definitions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants