Skip to content

Commit

Permalink
Merge 935781e into be1a8ec
Browse files Browse the repository at this point in the history
  • Loading branch information
zalbia committed Aug 16, 2018
2 parents be1a8ec + 935781e commit 2b5a57f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homepage": "https://sarahdayan.github.io/dinero.js",
"repository": "https://github.com/sarahdayan/dinero.js",
"main": "build/cjs/dinero.js",
"types": "build/ems/dinero.d.ts",
"scripts": {
"precommit": "lint-staged",
"cz": "git-cz",
Expand Down
81 changes: 81 additions & 0 deletions src/dinero.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export type Options = Partial<ObjectLiteral>

export interface ConversionOptions {
readonly endpoint: string
readonly propertyPath: string
readonly headers?: object
readonly roundingMode?: RoundingMode
}

// Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type ExchangeRatesApi = Omit<ConversionOptions, "roundingMode">

export type RoundingMode =
| 'HALF_ODD'
| 'HALF_EVEN'
| 'HALF_UP'
| 'HALF_DOWN'
| 'HALF_TOWARDS_ZERO'
| 'HALF_AWAY_FROM_ZERO'

export interface ObjectLiteral {
readonly amount: number,
readonly currency: string,
readonly precision: number
}

export interface Defaults {
defaultAmount: number
defaultCurrency: string
defaultPrecision: number
}

interface Globals {
globalLocale: string
globalFormat: string
globalRoundingMode: RoundingMode
globalFormatRoundingMode: RoundingMode
globalExchangeRatesApi: ExchangeRatesApi
}

export type Dinero = Base & Defaults & Globals

interface Base {
getAmount(): number
getCurrency(): string
getLocale(): string
setLocale(newLocale: string): Dinero
getPrecision(): number
convertPrecision(newPrecision: number): Dinero
add(addend: Dinero): Dinero
subtract(subtrahend: Dinero): Dinero
multiply(multiplier: number, roundingMode?: RoundingMode): Dinero
divide(divisor: number, roundingMode?: RoundingMode): Dinero
percentage(percentage: number): Dinero
allocate(ratios: number[]): Dinero[]
convert(currency: string, options: ConversionOptions): Promise<Dinero>
equalsTo(comparator: Dinero): boolean
lessThan(comparator: Dinero): boolean
lessThanOrEqual(comparator: Dinero): boolean
greaterThan(comparator: Dinero): boolean
greaterThanOrEqual(comparator: Dinero): boolean
isZero(): boolean
isPositive(): boolean
isNegative(): boolean
hasSubUnits(): boolean
/**
* @deprecated since version 1.4.0, will be removed in 2.0.0.
* Use {@link hasSubUnits} instead.
*/
hasCents(): boolean
hasSameCurrency(comparator: Dinero): boolean
hasSameAmount(comparator: Dinero): boolean
toFormat(format?: string, roundingMode?: RoundingMode): string
toUnit(): number
toRoundedUnit(digits, roundingMode?: RoundingMode): number
toObject(): ObjectLiteral
normalizePrecision(objects: Dinero[]): Dinero[]
}

export default function DineroConstructor(options: Options): Dinero
5 changes: 5 additions & 0 deletions tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs')
const rollup = require('rollup')
const babel = require('rollup-plugin-babel')
const minify = require('rollup-plugin-babel-minify')
Expand Down Expand Up @@ -99,3 +100,7 @@ const buildOutputs = (bundle, suffix = '') => {
})
})
}

fs.mkdirSync('build')
fs.mkdirSync('build/esm')
fs.copyFileSync('src/dinero.d.ts', 'build/esm/dinero.d.ts')

0 comments on commit 2b5a57f

Please sign in to comment.