diff --git a/types/js-money/index.d.ts b/types/js-money/index.d.ts new file mode 100644 index 0000000000..5288384f6e --- /dev/null +++ b/types/js-money/index.d.ts @@ -0,0 +1,187 @@ +// Type definitions for js-money 0.6 +// Project: https://github.com/davidkalosi/js-money +// Definitions by: Kanat Kubash +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Currency } from './lib/currency'; + +type Currencies = 'USD' | 'CAD' | 'EUR' | 'BTC' | 'AED' | 'AFN' + | 'ALL' | 'AMD' | 'ARS' | 'AUD' | 'AZN' | 'BAM' | 'BDT' + | 'BGN' | 'BHD' | 'BIF' | 'BND' | 'BOB' | 'BRL' | 'BWP' + | 'BYR' | 'BZD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' + | 'CRC' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' + | 'EEK' | 'EGP' | 'ERN' | 'ETB' | 'GBP' | 'GEL' | 'GHS' + | 'GNF' | 'GTQ' | 'HKD' | 'HNL' | 'HRK' | 'HUF' | 'IDR' + | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' + | 'JPY' | 'KES' | 'KHR' | 'KMF' | 'KRW' | 'KWD' | 'KZT' + | 'LAK' | 'LBP' | 'LKR' | 'LTL' | 'LVL' | 'LYD' | 'MAD' + | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MOP' | 'MUR' | 'MXN' + | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' + | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PHP' | 'PKR' | 'PLN' + | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' + | 'SDG' | 'SEK' | 'SGD' | 'SOS' | 'SYP' | 'THB' | 'TND' + | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' + | 'UYU' | 'UZS' | 'VEF' | 'VND' | 'XAF' | 'XOF' | 'YER' + | 'ZAR' | 'ZMK' | string; + +interface MoneyObjectOut { + amount: number; + currency: string; +} + +type Rounders = 'round' | 'floor' | 'ceil'; + +type RoundFunction = (num: number) => number; + +declare class Money { + constructor(amount: number, currency: Currencies | Currency); + amount: number; + currency: string; + static fromInteger(amount: number, currency: Currencies | Currency): Money; + static fromDecimal(amount: number, currency: Currencies | Currency, rounder?: Rounders | RoundFunction): Money; + equals(other: Money): boolean; + add(other: Money): Money; + subtract(other: Money): Money; + multiply(multiplier: number, rounder?: RoundFunction): Money; + divide(divisor: number, rounder?: RoundFunction): Money; + allocate(ratios: number[]): Money[]; + compare(other: Money): number; + greaterThan(other: Money): boolean; + greaterThanOrEqual(other: Money): boolean; + lessThan(other: Money): boolean; + lessThanOrEqual(other: Money): boolean; + isZero(): boolean; + isPositive(): boolean; + isNegative(): boolean; + toDecimal(): number; + toString(): string; + toJSON(): MoneyObjectOut; + getAmount(): number; + getCurrency(): string; + //#region Currencies + static USD: Currency; + static CAD: Currency; + static EUR: Currency; + static BTC: Currency; + static AED: Currency; + static AFN: Currency; + static ALL: Currency; + static AMD: Currency; + static ARS: Currency; + static AUD: Currency; + static AZN: Currency; + static BAM: Currency; + static BDT: Currency; + static BGN: Currency; + static BHD: Currency; + static BIF: Currency; + static BND: Currency; + static BOB: Currency; + static BRL: Currency; + static BWP: Currency; + static BYR: Currency; + static BZD: Currency; + static CDF: Currency; + static CHF: Currency; + static CLP: Currency; + static CNY: Currency; + static COP: Currency; + static CRC: Currency; + static CVE: Currency; + static CZK: Currency; + static DJF: Currency; + static DKK: Currency; + static DOP: Currency; + static DZD: Currency; + static EEK: Currency; + static EGP: Currency; + static ERN: Currency; + static ETB: Currency; + static GBP: Currency; + static GEL: Currency; + static GHS: Currency; + static GNF: Currency; + static GTQ: Currency; + static HKD: Currency; + static HNL: Currency; + static HRK: Currency; + static HUF: Currency; + static IDR: Currency; + static ILS: Currency; + static INR: Currency; + static IQD: Currency; + static IRR: Currency; + static ISK: Currency; + static JMD: Currency; + static JOD: Currency; + static JPY: Currency; + static KES: Currency; + static KHR: Currency; + static KMF: Currency; + static KRW: Currency; + static KWD: Currency; + static KZT: Currency; + static LAK: Currency; + static LBP: Currency; + static LKR: Currency; + static LTL: Currency; + static LVL: Currency; + static LYD: Currency; + static MAD: Currency; + static MDL: Currency; + static MGA: Currency; + static MKD: Currency; + static MMK: Currency; + static MOP: Currency; + static MUR: Currency; + static MXN: Currency; + static MYR: Currency; + static MZN: Currency; + static NAD: Currency; + static NGN: Currency; + static NIO: Currency; + static NOK: Currency; + static NPR: Currency; + static NZD: Currency; + static OMR: Currency; + static PAB: Currency; + static PEN: Currency; + static PHP: Currency; + static PKR: Currency; + static PLN: Currency; + static PYG: Currency; + static QAR: Currency; + static RON: Currency; + static RSD: Currency; + static RUB: Currency; + static RWF: Currency; + static SAR: Currency; + static SDG: Currency; + static SEK: Currency; + static SGD: Currency; + static SOS: Currency; + static SYP: Currency; + static THB: Currency; + static TND: Currency; + static TOP: Currency; + static TRY: Currency; + static TTD: Currency; + static TWD: Currency; + static TZS: Currency; + static UAH: Currency; + static UGX: Currency; + static UYU: Currency; + static UZS: Currency; + static VEF: Currency; + static VND: Currency; + static XAF: Currency; + static XOF: Currency; + static YER: Currency; + static ZAR: Currency; + static ZMK: Currency; + //#endregion +} + +/// to supress new Money() error +declare namespace Money { } +export = Money; diff --git a/types/js-money/js-money-tests.ts b/types/js-money/js-money-tests.ts new file mode 100644 index 0000000000..8c28cc554e --- /dev/null +++ b/types/js-money/js-money-tests.ts @@ -0,0 +1,63 @@ +import * as Money from "js-money"; +import * as CurrencyObjects from "js-money/lib/currency"; + +const money = new Money(1500, 'USD'); +const other = new Money(100, Money.THB); + +// instance method checks +new Money(123, Money.TRY); // $ExpectType Money +new Money(1500, 'USD'); // $ExpectType Money +money.amount; // $ExpectType number +money.currency; // $ExpectType string +money.equals(other); // $ExpectType boolean +money.add(other); // $ExpectType Money +money.subtract(other); // $ExpectType Money +money.multiply(1); // $ExpectType Money +money.multiply(2, Math.round); // $ExpectType Money +money.divide(1); // $ExpectType Money +money.divide(1, Math.ceil); // $ExpectType Money +money.allocate([1, 2, 3]); // $ExpectType Money[] +money.compare(other); // $ExpectType number +money.greaterThan(other); // $ExpectType boolean +money.greaterThanOrEqual(other); // $ExpectType boolean +money.lessThan(other); // $ExpectType boolean +money.lessThanOrEqual(other); // $ExpectType boolean +money.isZero(); // $ExpectType boolean +money.isPositive(); // $ExpectType boolean +money.isNegative(); // $ExpectType boolean +money.toDecimal(); // $ExpectType number +money.toString(); // $ExpectType string +money.toJSON(); // $ExpectType MoneyObjectOut +money.toJSON().amount; // $ExpectType number +money.toJSON().currency; // $ExpectType string +money.getAmount(); // $ExpectType number +money.getCurrency(); // $ExpectType string + +// static method checks +Money.fromInteger(100, 'USD'); // $ExpectType Money +Money.fromDecimal(100, Money.KZT, 'ceil'); // $ExpectType Money +Money.fromDecimal(100, Money.KZT); // $ExpectType Money +Money.fromDecimal(100, Money.KZT, Math.ceil); // $ExpectType Money + +// static properties (currency) check +Money.KZT; // $ExpectType Currency +Money.RUB; // $ExpectType Currency +Money.BLABLA; // $ExpectError +// currency object check +Money.RUB.code; // $ExpectType string +Money.RUB.decimal_digits; // $ExpectType number +Money.RUB.name; // $ExpectType string +Money.RUB.name_plural; // $ExpectType string +Money.RUB.rounding; // $ExpectType number +Money.RUB.symbol; // $ExpectType string +Money.RUB.symbol_native; // $ExpectType string + +// Currency module check +CurrencyObjects.NIO.code; // $ExpectType string +CurrencyObjects.NIO.decimal_digits; // $ExpectType number +CurrencyObjects.NIO.name; // $ExpectType string +CurrencyObjects.NIO.name_plural; // $ExpectType string +CurrencyObjects.NIO.rounding; // $ExpectType number +CurrencyObjects.NIO.symbol; // $ExpectType string +CurrencyObjects.NIO.symbol_native; // $ExpectType string +CurrencyObjects['UAH'].code; // $ExpectType string diff --git a/types/js-money/lib/currency.d.ts b/types/js-money/lib/currency.d.ts new file mode 100644 index 0000000000..1abac4a9ca --- /dev/null +++ b/types/js-money/lib/currency.d.ts @@ -0,0 +1,144 @@ +// Type definitions for js-money 0.6 +// Project: https://github.com/davidkalosi/js-money#readme +// Definitions by: Kanat Kubash +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace Currencies { + interface Currency { + symbol: string; + name: string; + symbol_native: string; + decimal_digits: number; + rounding: number; + code: string; + name_plural: string; + } + interface Currencies { + [key: string]: Currencies.Currency; + USD: Currencies.Currency; + CAD: Currencies.Currency; + EUR: Currencies.Currency; + BTC: Currencies.Currency; + AED: Currencies.Currency; + AFN: Currencies.Currency; + ALL: Currencies.Currency; + AMD: Currencies.Currency; + ARS: Currencies.Currency; + AUD: Currencies.Currency; + AZN: Currencies.Currency; + BAM: Currencies.Currency; + BDT: Currencies.Currency; + BGN: Currencies.Currency; + BHD: Currencies.Currency; + BIF: Currencies.Currency; + BND: Currencies.Currency; + BOB: Currencies.Currency; + BRL: Currencies.Currency; + BWP: Currencies.Currency; + BYR: Currencies.Currency; + BZD: Currencies.Currency; + CDF: Currencies.Currency; + CHF: Currencies.Currency; + CLP: Currencies.Currency; + CNY: Currencies.Currency; + COP: Currencies.Currency; + CRC: Currencies.Currency; + CVE: Currencies.Currency; + CZK: Currencies.Currency; + DJF: Currencies.Currency; + DKK: Currencies.Currency; + DOP: Currencies.Currency; + DZD: Currencies.Currency; + EEK: Currencies.Currency; + EGP: Currencies.Currency; + ERN: Currencies.Currency; + ETB: Currencies.Currency; + GBP: Currencies.Currency; + GEL: Currencies.Currency; + GHS: Currencies.Currency; + GNF: Currencies.Currency; + GTQ: Currencies.Currency; + HKD: Currencies.Currency; + HNL: Currencies.Currency; + HRK: Currencies.Currency; + HUF: Currencies.Currency; + IDR: Currencies.Currency; + ILS: Currencies.Currency; + INR: Currencies.Currency; + IQD: Currencies.Currency; + IRR: Currencies.Currency; + ISK: Currencies.Currency; + JMD: Currencies.Currency; + JOD: Currencies.Currency; + JPY: Currencies.Currency; + KES: Currencies.Currency; + KHR: Currencies.Currency; + KMF: Currencies.Currency; + KRW: Currencies.Currency; + KWD: Currencies.Currency; + KZT: Currencies.Currency; + LAK: Currencies.Currency; + LBP: Currencies.Currency; + LKR: Currencies.Currency; + LTL: Currencies.Currency; + LVL: Currencies.Currency; + LYD: Currencies.Currency; + MAD: Currencies.Currency; + MDL: Currencies.Currency; + MGA: Currencies.Currency; + MKD: Currencies.Currency; + MMK: Currencies.Currency; + MOP: Currencies.Currency; + MUR: Currencies.Currency; + MXN: Currencies.Currency; + MYR: Currencies.Currency; + MZN: Currencies.Currency; + NAD: Currencies.Currency; + NGN: Currencies.Currency; + NIO: Currencies.Currency; + NOK: Currencies.Currency; + NPR: Currencies.Currency; + NZD: Currencies.Currency; + OMR: Currencies.Currency; + PAB: Currencies.Currency; + PEN: Currencies.Currency; + PHP: Currencies.Currency; + PKR: Currencies.Currency; + PLN: Currencies.Currency; + PYG: Currencies.Currency; + QAR: Currencies.Currency; + RON: Currencies.Currency; + RSD: Currencies.Currency; + RUB: Currencies.Currency; + RWF: Currencies.Currency; + SAR: Currencies.Currency; + SDG: Currencies.Currency; + SEK: Currencies.Currency; + SGD: Currencies.Currency; + SOS: Currencies.Currency; + SYP: Currencies.Currency; + THB: Currencies.Currency; + TND: Currencies.Currency; + TOP: Currencies.Currency; + TRY: Currencies.Currency; + TTD: Currencies.Currency; + TWD: Currencies.Currency; + TZS: Currencies.Currency; + UAH: Currencies.Currency; + UGX: Currencies.Currency; + UYU: Currencies.Currency; + UZS: Currencies.Currency; + VEF: Currencies.Currency; + VND: Currencies.Currency; + XAF: Currencies.Currency; + XOF: Currencies.Currency; + YER: Currencies.Currency; + ZAR: Currencies.Currency; + ZMK: Currencies.Currency; + } +} + + + +declare var Currencies: Currencies.Currencies; +export = Currencies; \ No newline at end of file diff --git a/types/js-money/tsconfig.json b/types/js-money/tsconfig.json new file mode 100644 index 0000000000..9277913003 --- /dev/null +++ b/types/js-money/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "strictFunctionTypes": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "js-money-tests.ts" + ] +} \ No newline at end of file diff --git a/types/js-money/tslint.json b/types/js-money/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/js-money/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }